<?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';

class AriSmartContentViewProviderSourcelist extends AriSmartContentAdminView 
{
	var $_title = '';
	var $_helpLink = null;
	
	function getTitle()
	{
		return $this->_title;
	}
	
	function display($tpl = null) 
	{
		$this->registerScripts();
		$this->setToolbar();
		$this->assignRef('dtItems', $this->getItemsDataTable());

		parent::display($tpl);
	}
	
	function registerScripts()
	{
		$doc = JFactory::getDocument();
		$doc->addScriptDeclaration(';YAHOO.ARISoft.page.viewName = "' . $this->getName() . '";');
	}

	protected function getItemsDataTable()
	{
		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' => '<input type="checkbox" class="adtCtrlCheckbox" />', 
					'formatter' => 'YAHOO.ARISoft.widgets.DataTable.formatters.formatCheckbox', 
					'className' => 'dtCenter dtColMin'
				)
			),
			new AriDataTableControlColumn(
				array(
					'key' => 'Id', 
					'label' => JText::_('COM_ARISMARTCONTENT_LABEL_ID'), 
					'className' => 'dtCenter dtColMin'
				)
			),
			new AriDataTableControlColumn(
				array(
					'key' => 'Name', 
					'label' => JText::_('COM_ARISMARTCONTENT_LABEL_NAME'), 
					'sortable' => true, 
					'formatter' => 'YAHOO.ARISoft.SmartContent.formatters.formatProviderSource'
				)
			)
		);

		$dataTable = new AriMultiPageDataTableControl(
			'dtItems',
			$columns, 
			array(
				'dataUrl' => 'index.php?option=com_arismartcontent&view=' . $this->getName() . '&task=ajaxGetItemList'
			),
			AriSmartContentHelper::getPaginatorOptions()
		);

		return $dataTable;
	}

	function setToolbar() 
	{
		JToolBarHelper::title(JText::_($this->getTitle()));
		
		JToolBarHelper::editList();
		JToolBarHelper::addNew();
		JToolBarHelper::spacer();
		JToolBarHelper::deleteList(
			JText::_('COM_ARISMARTCONTENT_MESSAGE_DELETE', true), 
			'ajaxDelete', 
			JText::_('COM_ARISMARTCONTENT_LABEL_DELETE')
		);

		if ($this->_helpLink)
		{
			JToolBarHelper::divider();
			AriSmartContentToolbarHelper::ariSmartContentHelp($this->_helpLink);
		}
	}
}