<?php
/**
 * @copyright	Copyright (c) 2015 Skyline Technology Ltd (http://extstore.com). All rights reserved.
 * @license		http://www.gnu.org/licenses/gpl-2.0.html GNU/GPL
 */

// No direct access.
defined('_JEXEC') or die;

$config	= JComponentHelper::getParams('com_advpopup');

JHtml::_('behavior.tooltip');
JHtml::_('behavior.formvalidation');
JHtml::_('formbehavior.chosen', 'select');
JHtml::_('script', 'com_advpopup/libs/underscore.js', false, true);
JHtml::_('script', 'com_advpopup/libs/jquery-ui.js', false, true);
JHtml::_('script', 'com_advpopup/libs/jquery.ui.touch-punch.js', false, true);
JHtml::_('script', 'com_advpopup/libs/jquery.ui.rotatable.js', false, true);
JHtml::_('script', 'com_advpopup/libs/underscore.js', false, true);
JHtml::_('script', 'com_advpopup/libs/backbone.js', false, true);

JHtml::_('script', 'com_advpopup/libs/bootstrap-slider.js', false, true);
JHtml::_('script', 'com_advpopup/libs/colors.js', false, true);
JHtml::_('script', 'com_advpopup/libs/jqcolorpicker.js', false, true);
JHtml::_('script', 'com_advpopup/libs/jquery.minicolors.min.js', false, true);
JHtml::_('script', 'com_advpopup/libs/jquery.fancybox.js', false, true);

JHtml::_('script', 'com_advpopup/admin-app.js', false, true);

if (!$config->get('disable_image_layer')) {
	JHtml::_('script', 'com_advpopup/plugins/image.js', false, true);
}

if (!$config->get('disable_text_layer')) {
	JHtml::_('script', 'com_advpopup/plugins/text.js', false, true);
}


JHtml::_('stylesheet', 'com_advpopup/jquery.minicolors.css', false, true);
JHtml::_('stylesheet', 'com_advpopup/slider.css', false, true);
JHtml::_('stylesheet', 'com_advpopup/jquery.fancybox.css', false, true);

// get layer types
$this->layerTypes	= AdvPopupHelper::getLayerTypes();
?>

<script type="text/javascript">
	var AdvPopup			= AdvPopup || {};
	AdvPopup.Common			= AdvPopup.Common || {};
	AdvPopup.Common.siteUrl	= '<?php echo JUri::root(); ?>';

	Joomla.submitbutton	= function(task) {
		if (task == 'popup.cancel' || document.formvalidator.isValid(document.id('advpopup-app-wrapper'))) {
			Joomla.submitform(task, document.getElementById('advpopup-app-wrapper'));
		}
	};

	function jInsertFieldValue(value, id) {
		var $el	= jQuery('#' + id);

		if ($el.val() != value) {
			$el.val(value).trigger('change');
		}
	}

	function jModalClose() {
		jQuery.fancybox.close();
	}
</script>

<form action="<?php echo JRoute::_('index.php?option=com_advpopup&layout=edit&id=' . (int) $this->item->id); ?>" method="post" name="adminForm" id="advpopup-app-wrapper" class="form-validate">
	<?php echo JLayoutHelper::render('joomla.edit.title_alias', $this); ?>
	<div class="form-horizontal">
		<?php echo JHtml::_('bootstrap.startTabSet', 'myTab', array('active' => 'details')); ?>
		<?php echo JHtml::_('bootstrap.addTab', 'myTab', 'details', empty($this->item->id) ? JText::_('COM_ADVPOPUP_POPUP_NEW') : JText::sprintf('COM_ADVPOPUP_POPUP_EDIT', $this->item->id)); ?>

		<div class="row-fluid">
			<div class="span12">
				<fieldset class="adminform">
					<div class="span7 advp-builder-wrapper">
						<div class="panel">
							<div class="panel-heading"><?php echo JText::_('COM_ADVPOPUP_POPUP_BUILDER'); ?> <a class="advp-btn-fullscreen"><i class="fa fa-arrows-alt"></i></a></div>
							<div class="panel-body">
								<div class="advp-layers-toolbar clearfix">
									<div class="advp-layers-toolbar-left pull-left">
										<?php foreach ($this->layerTypes as $type) : ?>
											<a href="#" class="btn btn-layer-type btn-layer-type-<?php echo $type->type; ?>" data-layer-type="<?php echo $type->type; ?>">
												<?php echo $type->caption; ?>
											</a>
										<?php endforeach; ?>
									</div>
									<div class="advp-layers-toolbar-right pull-right">
										<a href="#" class="btn btn-danger btn-remove-layer">
											<?php echo JText::_('COM_ADVPOPUP_REMOVE_LAYER'); ?>
										</a>
										<a href="#" class="btn btn-danger btn-remove-layers">
											<?php echo JText::_('COM_ADVPOPUP_REMOVE_LAYERS'); ?>
										</a>
									</div>
								</div>

								<div class="advp-screen-wrapper">
									<div class="advp-overlay-wrapper"></div>
									<div class="advp-popup-wrapper"></div>
								</div>
							</div>
						</div>
					</div>
					<div class="span5 advp-adjustment-wrapper">
						<div class="advp-options-wrapper"></div>
						<div class="advp-ordering-wrapper">
							<div class="panel advp-static-layers-wrapper">

							</div>
							<div class="panel advp-dynamic-layers-wrapper">
								<div class="panel-heading"><?php echo JText::_('COM_ADVPOPUP_LAYER_ORDERING'); ?></div>
							</div>
						</div>
					</div>
				</fieldset>
			</div>
		</div>

		<?php echo JHtml::_('bootstrap.endTab'); ?>
		<?php echo JHtml::_('bootstrap.addTab', 'myTab', 'publishing', JText::_('JGLOBAL_FIELDSET_PUBLISHING', true)); ?>

		<div class="row-fluid form-horizontal-desktop">
			<div class="span9">
				<?php echo JLayoutHelper::render('joomla.edit.publishingdata', $this); ?>
			</div>
			<div class="span3">
				<?php echo JLayoutHelper::render('joomla.edit.global', $this); ?>
			</div>
		</div>
		<?php echo JHtml::_('bootstrap.endTab'); ?>

		<?php echo JLayoutHelper::render('joomla.edit.params', $this); ?>

		<?php echo JHtml::_('bootstrap.endTabSet'); ?>
	</div>

	<?php echo $this->form->getInput('data'); ?>
	<input type="hidden" name="task" value="" />
	<input type="hidden" name="return" value="<?php echo JFactory::getApplication()->input->getCmd('return');?>" />
	<?php echo JHtml::_('form.token'); ?>
</form>
<?php
echo AdvPopupFactory::getFooter();