<?php
/**
 * @package DJ-Catalog2
 * @copyright Copyright (C) DJ-Extensions.com, All rights reserved.
 * @license http://www.gnu.org/licenses GNU/GPL
 * @author url: http://dj-extensions.com
 * @author email contact@dj-extensions.com
 */

// no direct access
defined('_JEXEC') or die;

//Joomla\CMS\HTML\HTMLHelper::_('bootstrap.tooltip');
Joomla\CMS\Factory::getDocument()->getWebAssetManager()->useScript('form.validate');
//Joomla\CMS\HTML\HTMLHelper::_('formbehavior.chosen', 'select');

$app = JFactory::getApplication();


// if &tmpl=component used on first invocation, ensure it's on subsequent ones too
$input = JFactory::getApplication()->input;
$tmpl = $input->getCmd('tmpl', '') === 'component' ? '&tmpl=component' : '';

$bs_cl = JHtmlDJCatalog2::getBSClasses();

?>
<script type="text/javascript">
	Joomla.submitbutton = function(task)
	{
		if (task == 'category.cancel' || document.formvalidator.isValid(document.getElementById('category-form'))) {
			<?php //echo $this->form->getField('description')->save(); ?>
			Joomla.submitform(task, document.getElementById('category-form'));
		}
		else {
			alert('<?php echo $this->escape(JText::_('JGLOBAL_VALIDATION_FORM_FAILED'));?>');
		}
	}
</script>
<form action="<?php echo JRoute::_('index.php?option=com_djcatalog2&view=category&layout=edit&id='.(int) $this->item->id . $tmpl); ?>" method="post" name="adminForm" id="category-form" class="form-validate" enctype="multipart/form-data">
	<div class="row row-fluid">
		<div class="col-md-12 form-horizontal">
			<fieldset>
			
			<?php echo Joomla\CMS\HTML\HTMLHelper::_('uitab.startTabSet', 'myTab', array('recall' => true, 'active' => 'details')); ?>
			
			<?php echo Joomla\CMS\HTML\HTMLHelper::_('uitab.addTab', 'myTab', 'details', JText::_('COM_DJCATALOG2_EDIT')); ?>
				<div class="control-group">
					<div class="control-label"><?php echo $this->form->getLabel('name'); ?></div>
					<div class="controls"><?php echo $this->form->getInput('name'); ?></div>
				</div>
				
				<div class="control-group">
					<div class="control-label"><?php echo $this->form->getLabel('alias'); ?></div>
					<div class="controls"><?php echo $this->form->getInput('alias'); ?></div>
				</div>

				<div class="control-group">
					<div class="control-label"><?php echo $this->form->getLabel('language'); ?></div>
					<div class="controls"><?php echo $this->form->getInput('language'); ?></div>
				</div>
				
				<div class="control-group">
					<div class="control-label"><?php echo $this->form->getLabel('parent_id'); ?></div>
					<div class="controls"><?php echo $this->form->getInput('parent_id'); ?></div>
				</div>
				
				<div class="control-group">
					<div class="control-label"><?php echo $this->form->getLabel('published'); ?></div>
					<div class="controls"><?php echo $this->form->getInput('published'); ?></div>
				</div>
				
				<div class="control-group">
					<div class="control-label">
					<?php echo $this->form->getLabel('access'); ?>
					</div>
					<div class="controls">
					<?php echo $this->form->getInput('access'); ?>
					</div>
				</div>
				
				<div class="control-group">
					<div class="control-label"><?php echo $this->form->getLabel('id'); ?></div>
					<div class="controls"><?php echo $this->form->getInput('id'); ?></div>
				</div>
				
				<div class="control-group">
					<div class="control-label"><?php echo $this->form->getLabel('created'); ?></div>
					<div class="controls"><?php echo $this->form->getInput('created'); ?></div>
				</div>
				
				<div class="control-group">
					<div class="control-label"><?php echo $this->form->getLabel('created_by'); ?></div>
					<div class="controls"><?php echo $this->form->getInput('created_by'); ?></div>
				</div>
				
				<div class="control-group">
					<div class="control-label"><?php echo $this->form->getLabel('description'); ?></div>
					<div class="controls"><?php echo $this->form->getInput('description'); ?></div>
				</div>
			<?php echo Joomla\CMS\HTML\HTMLHelper::_('uitab.endTab'); ?>
			
			<?php if (JLanguageAssociations::isEnabled()) { ?>
			<?php echo Joomla\CMS\HTML\HTMLHelper::_('uitab.addTab', 'myTab', 'associations', JText::_('COM_DJCATALOG2_ASSOCIATIONS')); ?>
				 <div class="row row-fluid">
					<div class="col-md-12">
						<?php echo JLayoutHelper::render('joomla.edit.associations', $this);  ?>
					</div>
				</div>
			<?php echo Joomla\CMS\HTML\HTMLHelper::_('uitab.endTab'); ?>
			<?php } ?>
			
			<?php echo Joomla\CMS\HTML\HTMLHelper::_('uitab.addTab', 'myTab', 'publishing', JText::_('JGLOBAL_FIELDSET_PUBLISHING')); ?>
				<div class="control-group">
					<div class="control-label"><?php echo $this->form->getLabel('heading'); ?></div>
					<div class="controls"><?php echo $this->form->getInput('heading'); ?></div>
				</div>
				<div class="control-group">
					<div class="control-label"><?php echo $this->form->getLabel('metatitle'); ?></div>
					<div class="controls"><?php echo $this->form->getInput('metatitle'); ?></div>
				</div>
				
				<div class="control-group">
					<div class="control-label"><?php echo $this->form->getLabel('metadesc'); ?></div>
					<div class="controls"><?php echo $this->form->getInput('metadesc'); ?></div>
				</div>
				
				<div class="control-group">
					<div class="control-label"><?php echo $this->form->getLabel('metakey'); ?></div>
					<div class="controls"><?php echo $this->form->getInput('metakey'); ?></div>
				</div>
			<?php echo Joomla\CMS\HTML\HTMLHelper::_('uitab.endTab'); ?>
			
			<?php echo Joomla\CMS\HTML\HTMLHelper::_('uitab.addTab', 'myTab', 'images', JText::_('COM_DJCATALOG2_IMAGES')); ?>
				<?php echo DJCatalog2ImageHelper::renderInput('category',$app->input->get('id', null, 'int'), (bool)JComponentHelper::getParams('com_djcatalog2')->get('multiple_image_upload', true)); ?>
			<?php echo Joomla\CMS\HTML\HTMLHelper::_('uitab.endTab'); ?>
			
			<?php echo Joomla\CMS\HTML\HTMLHelper::_('uitab.addTab', 'myTab', 'sections', JText::_('COM_DJCATALOG2_SECTIONS')); ?>
				<?php echo $this->loadTemplate('sections'); ?>
			<?php echo Joomla\CMS\HTML\HTMLHelper::_('uitab.endTab'); ?>
			
			
			<?php $fieldSets = $this->form->getFieldsets('params'); ?>
			<?php foreach ($fieldSets as $name => $fieldSet) { ?>
				<?php echo Joomla\CMS\HTML\HTMLHelper::_('uitab.addTab', 'myTab', 'params-' . $name, ($fieldSet->label ? JText::_($fieldSet->label) : JText::_($fieldSet->name))); ?>
				<?php
				if (isset($fieldSet->description) && trim($fieldSet->description)) {
					echo '<p class="alert alert-info">' . $this->escape(JText::_($fieldSet->description)) . '</p>';
				}
				?>
				<?php foreach ($this->form->getFieldset($name) as $field) { ?>
					<?php echo $field->renderField(); ?>
					<?php //echo $this->form->getControlGroup($field->__get('fieldname'), 'params'); ?>
				<?php } ?>
				<?php echo Joomla\CMS\HTML\HTMLHelper::_('uitab.endTab'); ?>
			<?php } ?>

			<?php echo Joomla\CMS\HTML\HTMLHelper::_('uitab.endTabSet'); ?>
					
			</fieldset>
		</div>
	</div>
	<input type="hidden" name="task" value="" />
	<?php echo Joomla\CMS\HTML\HTMLHelper::_('form.token'); ?>
</form>
