<?php
/*
 *
 * @package		ARI Smart Content
 * @author		ARI Soft
 * @copyright	Copyright (c) 2011 www.ari-soft.com. All rights reserved
 * @license		GNU/GPL (http://www.gnu.org/copyleft/gpl.html)
 * 
 */

(defined('_JEXEC') && defined('ARI_FRAMEWORK_LOADED')) or die;

require_once dirname(__FILE__) . '/../view.php';

AriKernel::import('Joomla.Form.Form');

class AriSmartContentViewSources extends AriSmartContentAdminView 
{
	function display($callback, $sourceType, $category, $tpl = null) 
	{
		$currentUri = JURI::getInstance();
		$currentUri = $currentUri->toString(array('path', 'query'));
		
		$this->setToolbar();

		$filterForm = new AriForm('common');
		$filterForm->load(AriSmartContentHelper::getFormPath('sources', 'filters'));
		$filterForm->setParamAttribute('SourceType', 'category', $category);
		$filterForm->setParamAttribute('SourceType', 'onchange', 'YAHOO.ARISoft.page.pageManager.sourcesManager.changeFilters();');
		$filterForm->bind(array('SourceType' => $sourceType), array('_default'));

		$this->assign('currentUri', base64_encode($currentUri));
		$this->assign('callback', $callback);
		$this->assign('category', $category);
		$this->assignRef('filterForm', $filterForm);
		$this->assignRef('dtSources', $this->getSourcesDataTable($category, $sourceType));

		parent::display($tpl);
	}
	
	protected function getSourcesDataTable($category, $sourceType)
	{
		AriKernel::import('Web.Controls.Data.MultiPageDataTable');

		$columns = array(
			new AriDataTableControlColumn(
				array(
					'key' => '', 
					'label' => JText::_('COM_ARISMARTCONTENT_LABEL_NUMPOS'), 
					'formatter' => 'YAHOO.ARISoft.widgets.DataTable.formatters.formatPosition', 
					'className' => 'dtCenter dtColMin'
				)
			),
			new AriDataTableControlColumn(
				array(
					'key' => 'Id', 
					'label' => JText::_('COM_ARISMARTCONTENT_LABEL_ID'), 
					'sortable' => true, 
					'className' => 'dtCenter dtColMin'
				)
			),
			new AriDataTableControlColumn(
				array(
					'key' => 'Name', 
					'label' => JText::_('COM_ARISMARTCONTENT_LABEL_NAME'), 
					'sortable' => true, 
					'formatter' => 'YAHOO.ARISoft.SmartContent.formatters.formatSelectSource'
				)
			)
		);

		$dataTable = new AriMultiPageDataTableControl(
			'dtSources',
			$columns, 
			array(
				'dataUrl' => 'index.php?option=com_arismartcontent&view=sources&task=ajaxGetSourceList&cat=' . $category,
				'initialRequest' => '&adtInit=1&sourceType=' . $sourceType
			),
			AriSmartContentHelper::getPaginatorOptions()
		);

		return $dataTable;
	}

	function setToolbar() 
	{
		JToolBarHelper::title(JText::_('COM_ARISMARTCONTENT_LABEL_CONFIG'), 'config.png');
		
		JToolBarHelper::save();	
		JToolBarHelper::divider();
		AriSmartContentToolbarHelper::ariSmartContentHelp('ARISmartContentComponentReference1.html');
	}
}