<?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 AriSmartContentViewProviderGroup extends AriSmartContentAdminView 
{
	var $_title = '';
	var $_helpLink = null;
	
	function getTitle()
	{
		return $this->_title;
	}
	
	function display($item, $tpl = null) 
	{
		$this->registerScripts();
		$this->setToolbar();

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

		$commonSettingsForm = new AriForm('commonSettings');
		$commonSettingsForm->load(AriSmartContentHelper::getFormPath('provider', 'group'));
		$commonSettingsForm->bind($item);
		
		$groupSettingsForm = new AriForm('groupSettings');
		$groupSettingsForm->load(AriSmartContentHelper::getFormPath($this->getName()));
		$groupSettingsForm->bind($item->Params);

		$this->assignRef('commonSettingsForm', $commonSettingsForm);
		$this->assignRef('groupSettingsForm', $groupSettingsForm);

		parent::display($tpl);
	}

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

	function setToolbar() 
	{
		$this->disableMainMenu();

		$id = JRequest::getInt('Id');
		$edit = ($id > 0);
		$text = ($edit ? JText::_('COM_ARISMARTCONTENT_LABEL_EDIT') : JText::_('COM_ARISMARTCONTENT_LABEL_NEW'));
		
		JToolBarHelper::title(JText::_($this->getTitle()) . ': <small><small>[ ' . $text . ' ]</small></small>', 'config.png');

		JToolBarHelper::save();
		JToolBarHelper::apply();

		if ($edit) 
			JToolBarHelper::cancel('cancel', JText::_('Close'));
		else 
			JToolBarHelper::cancel();

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