From accd2d77c1d38a5bb89fe4aa19ba5a74678fc84c Mon Sep 17 00:00:00 2001 From: Jerome Nadaud Date: Mon, 9 Sep 2013 12:20:58 +0200 Subject: [PATCH 1/3] [+] BO : Adding tree templates and functions --- .../products/helpers/tree/tree.tpl | 4 +- .../products/helpers/tree/tree_header.tpl | 2 +- .../products/helpers/tree/tree_toolbar.tpl | 2 +- .../helpers/tree/tree_toolbar_search.tpl | 25 ++++++++ .../default/template/helpers/tree/tree.tpl | 4 +- .../template/helpers/tree/tree_header.tpl | 2 +- .../template/helpers/tree/tree_toolbar.tpl | 2 +- .../helpers/tree/tree_toolbar_search.tpl | 25 ++++++++ classes/helper/HelperITreeToolbarButton.php | 5 ++ classes/helper/HelperTreeToolbarButton.php | 44 +++++++++++++- classes/helper/HelperTreeToolbarLink.php | 1 + classes/helper/HelperTreeToolbarSearch.php | 58 +++++++++++++++++++ 12 files changed, 164 insertions(+), 10 deletions(-) create mode 100644 admin-dev/themes/default/template/controllers/products/helpers/tree/tree_toolbar_search.tpl create mode 100644 admin-dev/themes/default/template/helpers/tree/tree_toolbar_search.tpl create mode 100644 classes/helper/HelperTreeToolbarSearch.php diff --git a/admin-dev/themes/default/template/controllers/products/helpers/tree/tree.tpl b/admin-dev/themes/default/template/controllers/products/helpers/tree/tree.tpl index 9b0cbc1b2..dab29780d 100644 --- a/admin-dev/themes/default/template/controllers/products/helpers/tree/tree.tpl +++ b/admin-dev/themes/default/template/controllers/products/helpers/tree/tree.tpl @@ -23,8 +23,8 @@ * International Registered Trademark & Property of PrestaShop SA *}
- {if $header}{$header}{/if} - {if $nodes} + {if isset($header)}{$header}{/if} + {if isset($nodes)} {/if}
\ No newline at end of file diff --git a/admin-dev/themes/default/template/controllers/products/helpers/tree/tree_header.tpl b/admin-dev/themes/default/template/controllers/products/helpers/tree/tree_header.tpl index a7845e0bf..fd0e68fc4 100644 --- a/admin-dev/themes/default/template/controllers/products/helpers/tree/tree_header.tpl +++ b/admin-dev/themes/default/template/controllers/products/helpers/tree/tree_header.tpl @@ -22,4 +22,4 @@ * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) * International Registered Trademark & Property of PrestaShop SA *} -
{l s=$title}{if $toolbar}{$toolbar}{/if}
\ No newline at end of file +
{l s=$title}{if isset($toolbar)}{$toolbar}{/if}
\ No newline at end of file diff --git a/admin-dev/themes/default/template/controllers/products/helpers/tree/tree_toolbar.tpl b/admin-dev/themes/default/template/controllers/products/helpers/tree/tree_toolbar.tpl index 1384c0a0c..d036a7932 100644 --- a/admin-dev/themes/default/template/controllers/products/helpers/tree/tree_toolbar.tpl +++ b/admin-dev/themes/default/template/controllers/products/helpers/tree/tree_toolbar.tpl @@ -22,4 +22,4 @@ * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) * International Registered Trademark & Property of PrestaShop SA *} -
{if $actions}{foreach from=$actions item=action}{$action}{/foreach}{/if}
\ No newline at end of file +
{if isset($actions)}{foreach from=$actions item=action}{$action}{/foreach}{/if}
\ No newline at end of file diff --git a/admin-dev/themes/default/template/controllers/products/helpers/tree/tree_toolbar_search.tpl b/admin-dev/themes/default/template/controllers/products/helpers/tree/tree_toolbar_search.tpl new file mode 100644 index 000000000..19c8426da --- /dev/null +++ b/admin-dev/themes/default/template/controllers/products/helpers/tree/tree_toolbar_search.tpl @@ -0,0 +1,25 @@ +{* +* 2007-2013 PrestaShop +* +* NOTICE OF LICENSE +* +* This source file is subject to the Academic Free License (AFL 3.0) +* that is bundled with this package in the file LICENSE.txt. +* It is also available through the world-wide-web at this URL: +* http://opensource.org/licenses/afl-3.0.php +* If you did not receive a copy of the license and are unable to +* obtain it through the world-wide-web, please send an email +* to license@prestashop.com so we can send you a copy immediately. +* +* DISCLAIMER +* +* Do not edit or add to this file if you wish to upgrade PrestaShop to newer +* versions in the future. If you wish to customize PrestaShop for your +* needs please refer to http://www.prestashop.com for more information. +* +* @author PrestaShop SA +* @copyright 2007-2013 PrestaShop SA +* @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) +* International Registered Trademark & Property of PrestaShop SA +*} +  \ No newline at end of file diff --git a/admin-dev/themes/default/template/helpers/tree/tree.tpl b/admin-dev/themes/default/template/helpers/tree/tree.tpl index 9b0cbc1b2..dab29780d 100644 --- a/admin-dev/themes/default/template/helpers/tree/tree.tpl +++ b/admin-dev/themes/default/template/helpers/tree/tree.tpl @@ -23,8 +23,8 @@ * International Registered Trademark & Property of PrestaShop SA *}
- {if $header}{$header}{/if} - {if $nodes} + {if isset($header)}{$header}{/if} + {if isset($nodes)} {/if}
\ No newline at end of file diff --git a/admin-dev/themes/default/template/helpers/tree/tree_header.tpl b/admin-dev/themes/default/template/helpers/tree/tree_header.tpl index a7845e0bf..fd0e68fc4 100644 --- a/admin-dev/themes/default/template/helpers/tree/tree_header.tpl +++ b/admin-dev/themes/default/template/helpers/tree/tree_header.tpl @@ -22,4 +22,4 @@ * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) * International Registered Trademark & Property of PrestaShop SA *} -
{l s=$title}{if $toolbar}{$toolbar}{/if}
\ No newline at end of file +
{l s=$title}{if isset($toolbar)}{$toolbar}{/if}
\ No newline at end of file diff --git a/admin-dev/themes/default/template/helpers/tree/tree_toolbar.tpl b/admin-dev/themes/default/template/helpers/tree/tree_toolbar.tpl index 1384c0a0c..d036a7932 100644 --- a/admin-dev/themes/default/template/helpers/tree/tree_toolbar.tpl +++ b/admin-dev/themes/default/template/helpers/tree/tree_toolbar.tpl @@ -22,4 +22,4 @@ * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) * International Registered Trademark & Property of PrestaShop SA *} -
{if $actions}{foreach from=$actions item=action}{$action}{/foreach}{/if}
\ No newline at end of file +
{if isset($actions)}{foreach from=$actions item=action}{$action}{/foreach}{/if}
\ No newline at end of file diff --git a/admin-dev/themes/default/template/helpers/tree/tree_toolbar_search.tpl b/admin-dev/themes/default/template/helpers/tree/tree_toolbar_search.tpl new file mode 100644 index 000000000..71624c5aa --- /dev/null +++ b/admin-dev/themes/default/template/helpers/tree/tree_toolbar_search.tpl @@ -0,0 +1,25 @@ +{* +* 2007-2013 PrestaShop +* +* NOTICE OF LICENSE +* +* This source file is subject to the Academic Free License (AFL 3.0) +* that is bundled with this package in the file LICENSE.txt. +* It is also available through the world-wide-web at this URL: +* http://opensource.org/licenses/afl-3.0.php +* If you did not receive a copy of the license and are unable to +* obtain it through the world-wide-web, please send an email +* to license@prestashop.com so we can send you a copy immediately. +* +* DISCLAIMER +* +* Do not edit or add to this file if you wish to upgrade PrestaShop to newer +* versions in the future. If you wish to customize PrestaShop for your +* needs please refer to http://www.prestashop.com for more information. +* +* @author PrestaShop SA +* @copyright 2007-2013 PrestaShop SA +* @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) +* International Registered Trademark & Property of PrestaShop SA +*} +  \ No newline at end of file diff --git a/classes/helper/HelperITreeToolbarButton.php b/classes/helper/HelperITreeToolbarButton.php index e98ced91b..2f875093e 100644 --- a/classes/helper/HelperITreeToolbarButton.php +++ b/classes/helper/HelperITreeToolbarButton.php @@ -29,6 +29,10 @@ interface HelperITreeToolbarButtonCore public function __toString(); public function setAction($value); public function getAction(); + public function setAttributes($value); + public function getAttributes(); + public function setClass($value); + public function getClass(); public function setContext($value); public function getContext(); public function setLabel($value); @@ -37,5 +41,6 @@ interface HelperITreeToolbarButtonCore public function getTemplate(); public function setTemplateDirectory($value); public function getTemplateDirectory(); + public function addAttribute($name, $value); public function render(); } \ No newline at end of file diff --git a/classes/helper/HelperTreeToolbarButton.php b/classes/helper/HelperTreeToolbarButton.php index 972f42c60..0c14ebd0f 100644 --- a/classes/helper/HelperTreeToolbarButton.php +++ b/classes/helper/HelperTreeToolbarButton.php @@ -29,15 +29,18 @@ abstract class HelperTreeToolbarButtonCore const DEFAULT_TEMPLATE_DIRECTORY = 'helpers/tree'; private $_action; + private $_attributes; + private $_class; private $_context; private $_label; protected $_template; protected $_template_directory; - public function __construct($label, $action = null) + public function __construct($label, $action = null, $class = null) { $this->setLabel($label); $this->setAction($action); + $this->setClass($class); } public function __toString() @@ -56,6 +59,34 @@ abstract class HelperTreeToolbarButtonCore return $this->_action; } + public function setAttributes($value) + { + if (!is_array($value) && !$value instanceof Traversable) + throw new PrestaShopException('Data value must be an traversable array'); + + $this->_attributes = $value; + return $this; + } + + public function getAttributes() + { + if (!isset($this->_attributes)) + $this->_attributes = array(); + + return $this->_attributes; + } + + public function setClass($value) + { + $this->_class = $value; + return $this; + } + + public function getClass() + { + return $this->_class; + } + public function setContext($value) { $this->_context = $value; @@ -108,12 +139,21 @@ abstract class HelperTreeToolbarButtonCore return $this->_template_directory; } + public function addAttribute($name, $value) + { + if (!isset($this->_attributes)) + $this->_attributes = array(); + + $this->_attributes[$name] = $value; + return $this; + } + public function render() { return $this->getContext()->smarty->createTemplate( $this->getTemplateDirectory().$this->getTemplate(), $this->getContext()->smarty - ); + )->assign($this->getAttributes()); } private function _normalizeDirectory($directory) diff --git a/classes/helper/HelperTreeToolbarLink.php b/classes/helper/HelperTreeToolbarLink.php index 0af277e2c..2e6c7d5c3 100644 --- a/classes/helper/HelperTreeToolbarLink.php +++ b/classes/helper/HelperTreeToolbarLink.php @@ -70,6 +70,7 @@ class HelperTreeToolbarLinkCore extends HelperTreeToolbarButtonCore implements 'link' => $this->getLink(), 'action' => $this->getAction(), 'label' => $this->getLabel(), + 'class' => $this->getClass(), 'icon_class' => $this->getIconClass() )); return $template->fetch(); diff --git a/classes/helper/HelperTreeToolbarSearch.php b/classes/helper/HelperTreeToolbarSearch.php new file mode 100644 index 000000000..c7e707885 --- /dev/null +++ b/classes/helper/HelperTreeToolbarSearch.php @@ -0,0 +1,58 @@ + +* @copyright 2007-2013 PrestaShop SA +* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) +* International Registered Trademark & Property of PrestaShop SA +*/ + +class HelperTreeToolbarSearchCore extends HelperTreeToolbarButtonCore implements + HelperITreeToolbarButtonCore +{ + protected $_template = 'tree_toolbar_search.tpl'; + + public function __construct($label, $action = null, $class = null) + { + parent::__construct($label, $action, $class); + + $admin_webpath = str_ireplace(_PS_ROOT_DIR_, '', _PS_ADMIN_DIR_); + $admin_webpath = preg_replace('/^'.preg_quote(DIRECTORY_SEPARATOR, '/').'/', '', $admin_webpath); + $bo_theme = ((Validate::isLoadedObject($this->getContext()->employee) + && $this->getContext()->employee->bo_theme) ? $this->getContext()->employee->bo_theme : 'default'); + + if (!file_exists(_PS_BO_ALL_THEMES_DIR_.$bo_theme.DIRECTORY_SEPARATOR + .'template')) + $bo_theme = 'default'; + $this->getContext()->controller->addJs(__PS_BASE_URI__.$admin_webpath + .'/themes/'.$bo_theme.'/js/vendor/typeahead.min.js'); + } + + public function render() + { + $template = parent::render(); + $template->assign(array( + 'action' => $this->getAction(), + 'label' => $this->getLabel(), + 'class' => $this->getClass() + )); + return $template->fetch(); + } +} \ No newline at end of file From c18dea7296b92249637f1b83ce2f0345a4f454eb Mon Sep 17 00:00:00 2001 From: Vincent Augagneur Date: Mon, 9 Sep 2013 14:14:57 +0200 Subject: [PATCH 2/3] //carrier wizard fix - bootstrap compatibility --- js/admin_carrier_wizard.js | 74 +++++++++++++++++++------------------- 1 file changed, 37 insertions(+), 37 deletions(-) diff --git a/js/admin_carrier_wizard.js b/js/admin_carrier_wizard.js index 209b0a42b..3c6c7b4a1 100644 --- a/js/admin_carrier_wizard.js +++ b/js/admin_carrier_wizard.js @@ -71,9 +71,9 @@ function displayRangeType() function onShowStepCallback() { $('.anchor li a').each( function () { - $(this).parent('li').addClass($(this).attr('class')); + $(this).closest('li').addClass($(this).attr('class')); }); - $('#carrier_logo_block').prependTo($('div.content').filter(function() { return $(this).css('display') != 'none' }).children('.defaultForm').children('fieldset')); + $('#carrier_logo_block').prependTo($('div.content').filter(function() { return $(this).css('display') != 'none' }).find('.defaultForm').find('fieldset')); resizeWizard(); } @@ -164,21 +164,21 @@ $('input[name$="range_inf[]"]').each(function(){ $('#summary_zones').html(''); $('.input_zone').each(function(){ if ($(this).attr('checked')) - $('#summary_zones').html($('#summary_zones').html() + '
  • ' + $(this).parent().prev().text() + '
  • '); + $('#summary_zones').html($('#summary_zones').html() + '
  • ' + $(this).closest().prev().text() + '
  • '); }); // Group restrictions $('#summary_groups').html(''); $('input[name$="groupBox[]"]').each(function(){ if ($(this).attr('checked')) - $('#summary_groups').html($('#summary_groups').html() + '
  • ' + $(this).parent().next().next().text() + '
  • '); + $('#summary_groups').html($('#summary_groups').html() + '
  • ' + $(this).closest().next().next().text() + '
  • '); }); // shop restrictions $('#summary_shops').html(''); $('.input_shop').each(function(){ if ($(this).attr('checked')) - $('#summary_shops').html($('#summary_shops').html() + '
  • ' + $(this).parent().text() + '
  • '); + $('#summary_shops').html($('#summary_shops').html() + '
  • ' + $(this).closest().text() + '
  • '); }); } @@ -242,10 +242,10 @@ function bind_inputs() $('tr.delete_range td button').off('click').on('click', function () { if (confirm(delete_range_confirm)) { - index = $(this).parent('td').index(); + index = $(this).closest('td').index(); $('tr.range_sup td:eq('+index+'), tr.range_inf td:eq('+index+'), tr.fees_all td:eq('+index+'), tr.delete_range td:eq('+index+')').remove(); $('tr.fees').each( function () { - $(this).children('td:eq('+index+')').remove(); + $(this).find('td:eq('+index+')').remove(); }); rebuildTabindex(); } @@ -271,14 +271,14 @@ $('#validate_range_button').off('click').on('click', function () { if($(this).is(':checked')) { - $(this).closest('tr').children('td').each( function () { + $(this).closest('tr').find('td').each( function () { index = $(this).index(); if ($('tr.fees_all td:eq('+index+')').hasClass('validated')) - $(this).children('input:text').removeAttr('disabled'); + $(this).find('input:text').removeAttr('disabled'); }); } else - $(this).closest('tr').children('td').children('input:text').attr('disabled', 'disabled'); + $(this).closest('tr').find('td').find('input:text').attr('disabled', 'disabled'); return false; }); @@ -287,7 +287,7 @@ $('#validate_range_button').off('click').on('click', function () { }); $('tr.range_sup td input:text, tr.range_inf td input:text').keypress( function (evn) { - index = $(this).parent('td').index(); + index = $(this).closest('td').index(); if (evn.keyCode == 13) { if (validateRange(index)) @@ -305,7 +305,7 @@ $('#validate_range_button').off('click').on('click', function () { wait: 1000, callback: function() { - index = $(this.el).parent('td').index(); + index = $(this.el).closest('td').index(); if (validateRange(index)) enableRange(index); else @@ -314,7 +314,7 @@ $('#validate_range_button').off('click').on('click', function () { }); $(document.body).off('change', 'tr.fees_all td input').on('change', 'tr.fees_all td input', function() { -    index = $(this).parent('td').index(); +    index = $(this).closest('td').index(); val = $(this).val(); $(this).val(''); $('tr.fees').each( function () { @@ -378,7 +378,7 @@ function showFees() if ($(this).index() >= 2) { //enable only if zone is active - tr = $(this).parent('tr'); + tr = $(this).closest('tr'); if ($(tr).index() > 2 && $(tr).find('td:eq(1) input').attr('checked') && $('tr.fees_all td:eq('+$(this).index()+')').hasClass('validated') || $(tr).hasClass('range_sup') || $(tr).hasClass('range_inf')) $(this).find('input:text').val('').removeAttr('disabled'); @@ -397,12 +397,12 @@ function validateRange(index) $('tr.range_inf td input:text').removeClass('field_error'); is_ok = true; - range_sup = parseFloat($('tr.range_sup td:eq('+index+')').children('input:text').val().trim()); - range_inf = parseFloat($('tr.range_inf td:eq('+index+')').children('input:text').val().trim()); + range_sup = parseFloat($('tr.range_sup td:eq('+index+')').find('input:text').val().trim()); + range_inf = parseFloat($('tr.range_inf td:eq('+index+')').find('input:text').val().trim()); if (isNaN(range_sup) || range_sup.length === 0) { - $('tr.range_sup td:eq('+index+')').children('input:text').addClass('field_error'); + $('tr.range_sup td:eq('+index+')').find('input:text').addClass('field_error'); is_ok = false; displayError([invalid_range], $("#carrier_wizard").smartWizard('currentStep')); } @@ -414,8 +414,8 @@ function validateRange(index) } else if (is_ok && range_inf >= range_sup) { - $('tr.range_sup td:eq('+index+')').children('input:text').addClass('field_error'); - $('tr.range_inf td:eq('+index+')').children('input:text').addClass('field_error'); + $('tr.range_sup td:eq('+index+')').find('input:text').addClass('field_error'); + $('tr.range_inf td:eq('+index+')').find('input:text').addClass('field_error'); is_ok = false; displayError([invalid_range], $("#carrier_wizard").smartWizard('currentStep')); } @@ -446,8 +446,8 @@ function validateRange(index) if (!is_ok) { - $('tr.range_sup td:eq('+index+')').children('input:text').addClass('field_error'); - $('tr.range_inf td:eq('+index+')').children('input:text').addClass('field_error'); + $('tr.range_sup td:eq('+index+')').find('input:text').addClass('field_error'); + $('tr.range_inf td:eq('+index+')').find('input:text').addClass('field_error'); displayError([range_is_overlapping], $("#carrier_wizard").smartWizard('currentStep')); } else @@ -460,14 +460,14 @@ function enableRange(index) { $('tr.fees').each( function () { //only enable fees for enabled zones - if ($(this).children('td').children('input:checkbox').attr('checked') == 'checked') - $(this).children('td:eq('+index+')').children('input').removeAttr('disabled'); + if ($(this).find('td').find('input:checkbox').attr('checked') == 'checked') + $(this).find('td:eq('+index+')').find('input').removeAttr('disabled'); }); $('span.fees_all').show(); - $('tr.fees_all td:eq('+index+')').children('input').show().removeAttr('disabled'); - $('tr.fees_all td:eq('+index+')').children('.currency_sign').show(); + $('tr.fees_all td:eq('+index+')').find('input').show().removeAttr('disabled'); + $('tr.fees_all td:eq('+index+')').find('.currency_sign').show(); $('tr.fees_all td:eq('+index+')').addClass('validated').removeClass('not_validated'); - $('tr.fees_all td:eq('+index+')').children('button').remove(); + $('tr.fees_all td:eq('+index+')').find('button').remove(); bind_inputs(); } @@ -475,10 +475,10 @@ function disableRange(index) { $('tr.fees').each( function () { //only enable fees for enabled zones - if ($(this).children('td').children('input:checkbox').attr('checked') == 'checked') - $(this).children('td:eq('+index+')').children('input').attr('disabled', 'disabled'); + if ($(this).find('td').find('input:checkbox').attr('checked') == 'checked') + $(this).find('td:eq('+index+')').find('input').attr('disabled', 'disabled'); }); - $('tr.fees_all td:eq('+index+')').children('input').attr('disabled', 'disabled'); + $('tr.fees_all td:eq('+index+')').find('input').attr('disabled', 'disabled'); $('tr.fees_all td:eq('+index+')').removeClass('validated').addClass('not_validated'); } @@ -498,7 +498,7 @@ function add_new_range() $('tr.fees_all td:last').after('
    '); $('tr.fees').each( function () { - $(this).children('td:last').after('
    '+currency_sign+'
    '); + $(this).find('td:last').after('
    '+currency_sign+'
    '); }); $('tr.delete_range td:last').after('