<?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
 */


defined('_JEXEC') or die;

// Include the HTML helpers.
Joomla\CMS\HTML\HTMLHelper::addIncludePath(JPATH_ROOT.'/administrator/components/com_djcatalog2' . '/helpers/html');

Joomla\CMS\Factory::getDocument()->getWebAssetManager()->useScript('form.validate');
Joomla\CMS\HTML\HTMLHelper::_('behavior.keepalive');

JFactory::getDocument()->addScriptDeclaration("
		Joomla.submitbutton = function(task)
		{
			if (task == 'template.cancel' || document.formvalidator.isValid(document.getElementById('template-form')))
			{
				Joomla.submitform(task, document.getElementById('template-form'));
			}
		};
");
?>
<form action="<?php echo JRoute::_('index.php?option=com_djcatalog2&id=' . (int)$this->item->id); ?>" method="post"
      name="adminForm" id="template-form" class="form-validate form-horizontal">

    <div class="row row-fluid">
        <div class="col-md-7">
            <fieldset class="adminform">
            
            	<?php echo $this->form->renderField('name'); ?>
            	<?php echo $this->form->renderField('type'); ?>
            	<?php echo $this->form->renderField('state'); ?>
            	<?php echo $this->form->renderField('subject'); ?>
            	<?php echo $this->form->renderField('body'); ?>
            	<?php echo $this->form->renderField('attachments'); ?>
            	<?php echo $this->form->renderField('id'); ?>
            </fieldset>
        </div>
        <div class="col-md-5">
            <div class="alert alert-info">
                <?php $legend = JText::_('COM_DJCATALOG2_CFG_TEMPLATE_COMMON_LEGEND'); ?>

                <?php if ($this->item->id > 0 && trim($this->item->type) != '' && JFactory::getLanguage()->hasKey('COM_DJCATALOG2_CFG_TEMPLATE_LEGEND_' . strtoupper($this->item->type))) { ?>
                    <?php $legend .= '<br /><br />' . JText::_('COM_DJCATALOG2_CFG_TEMPLATE_LEGEND_' . strtoupper($this->item->type)); ?>
                <?php } ?>

                <?php //echo str_replace(array('[[', ']]'), array('<code>[[', ']]</code>'), $legend); ?>
                <?php echo preg_replace('#\[\[([a-z0-9_]+)\]\]#iU', '<code onclick="codeCopyToClip(this);">[[$1]]<input type="text" style="display: none;" value="[[$1]]" /></code>', $legend); ?>
            </div>
            <script>
                function codeCopyToClip(element) {
                    var copyText = jQuery(element).find('input').first();
                    //copyText.select();
                    //document.execCommand("copy");
                    jInsertEditorText(copyText.val(), 'jform_body');
                    //alert("Copied the text: " + copyText.val());
                }
            </script>
        </div>
    </div>
    <input type="hidden" name="task" value=""/>
    <?php echo Joomla\CMS\HTML\HTMLHelper::_('form.token'); ?>
</form>
