diff --git a/admin-dev/themes/default/js/tree.js b/admin-dev/themes/default/js/tree.js new file mode 100644 index 000000000..1b0cd5e4b --- /dev/null +++ b/admin-dev/themes/default/js/tree.js @@ -0,0 +1,76 @@ +var Tree = function (element, options) +{ + this.$element = $(element); + this.options = $.extend({}, $.fn.tree.defaults, options); + this.init(); +}; + +Tree.prototype = +{ + constructor: Tree, + + init: function () + { + this.$element.find("label.tree-toggler").click( + function () + { + if ($(this).parent().children("ul.tree").is(":visible")) + $(this).parent().children(".icon-folder-open") + .removeClass("icon-folder-open") + .addClass("icon-folder-close"); + else + $(this).parent().children(".icon-folder-close") + .removeClass("icon-folder-close") + .addClass("icon-folder-open"); + + $(this).parent().children("ul.tree").toggle(300); + } + ); + }, + + collapseAll : function($speed) + { + this.$element.find("label.tree-toggler").each( + function() + { + $(this).parent().children(".icon-folder-open") + .removeClass("icon-folder-open") + .addClass("icon-folder-close"); + $(this).parent().children("ul.tree").hide($speed); + } + ); + }, + + expandAll : function($speed) + { + this.$element.find("label.tree-toggler").each( + function() + { + $(this).parent().children(".icon-folder-close") + .removeClass("icon-folder-close") + .addClass("icon-folder-open"); + $(this).parent().children("ul.tree").show($speed); + } + ); + }, +}; + +$.fn.tree = function (option, value) +{ + var methodReturn; + var $set = this.each( + function () + { + var $this = $(this); + var data = $this.data('tree'); + var options = typeof option === 'object' && option; + + if (!data) $this.data('tree', (data = new Tree(this, options))); + if (typeof option === 'string') methodReturn = data[option](value); + } + ); + + return (methodReturn === undefined) ? $set : methodReturn; +}; + +$.fn.tree.Constructor = Tree; \ No newline at end of file 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 new file mode 100644 index 000000000..9b0cbc1b2 --- /dev/null +++ b/admin-dev/themes/default/template/controllers/products/helpers/tree/tree.tpl @@ -0,0 +1,30 @@ +{* +* 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 +*} +
+ {if $header}{$header}{/if} + {if $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 new file mode 100644 index 000000000..a7845e0bf --- /dev/null +++ b/admin-dev/themes/default/template/controllers/products/helpers/tree/tree_header.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 +*} +
{l s=$title}{if $toolbar}{$toolbar}{/if}
\ No newline at end of file diff --git a/admin-dev/themes/default/template/controllers/products/helpers/tree/tree_node_folder.tpl b/admin-dev/themes/default/template/controllers/products/helpers/tree/tree_node_folder.tpl new file mode 100644 index 000000000..d190e0d65 --- /dev/null +++ b/admin-dev/themes/default/template/controllers/products/helpers/tree/tree_node_folder.tpl @@ -0,0 +1,32 @@ +{* +* 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/controllers/products/helpers/tree/tree_node_folder_associations.tpl b/admin-dev/themes/default/template/controllers/products/helpers/tree/tree_node_folder_associations.tpl new file mode 100644 index 000000000..02bb79f3d --- /dev/null +++ b/admin-dev/themes/default/template/controllers/products/helpers/tree/tree_node_folder_associations.tpl @@ -0,0 +1,32 @@ +{* +* 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/controllers/products/helpers/tree/tree_node_item.tpl b/admin-dev/themes/default/template/controllers/products/helpers/tree/tree_node_item.tpl new file mode 100644 index 000000000..89f825460 --- /dev/null +++ b/admin-dev/themes/default/template/controllers/products/helpers/tree/tree_node_item.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 +*} +
  •  {$name}
  • \ No newline at end of file diff --git a/admin-dev/themes/default/template/controllers/products/helpers/tree/tree_node_item_associations.tpl b/admin-dev/themes/default/template/controllers/products/helpers/tree/tree_node_item_associations.tpl new file mode 100644 index 000000000..75c8c2003 --- /dev/null +++ b/admin-dev/themes/default/template/controllers/products/helpers/tree/tree_node_item_associations.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 +*} +
  •  {$name}
  • \ 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 new file mode 100644 index 000000000..1384c0a0c --- /dev/null +++ b/admin-dev/themes/default/template/controllers/products/helpers/tree/tree_toolbar.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 +*} +
    {if $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_link.tpl b/admin-dev/themes/default/template/controllers/products/helpers/tree/tree_toolbar_link.tpl new file mode 100644 index 000000000..966f91549 --- /dev/null +++ b/admin-dev/themes/default/template/controllers/products/helpers/tree/tree_toolbar_link.tpl @@ -0,0 +1,27 @@ +{* +* 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 +*} + +  {l s=$label} + \ 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 new file mode 100644 index 000000000..9b0cbc1b2 --- /dev/null +++ b/admin-dev/themes/default/template/helpers/tree/tree.tpl @@ -0,0 +1,30 @@ +{* +* 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 +*} +
    + {if $header}{$header}{/if} + {if $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 new file mode 100644 index 000000000..a7845e0bf --- /dev/null +++ b/admin-dev/themes/default/template/helpers/tree/tree_header.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 +*} +
    {l s=$title}{if $toolbar}{$toolbar}{/if}
    \ No newline at end of file diff --git a/admin-dev/themes/default/template/helpers/tree/tree_node_folder.tpl b/admin-dev/themes/default/template/helpers/tree/tree_node_folder.tpl new file mode 100644 index 000000000..44aaac520 --- /dev/null +++ b/admin-dev/themes/default/template/helpers/tree/tree_node_folder.tpl @@ -0,0 +1,31 @@ +{* +* 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_node_item.tpl b/admin-dev/themes/default/template/helpers/tree/tree_node_item.tpl new file mode 100644 index 000000000..22565afee --- /dev/null +++ b/admin-dev/themes/default/template/helpers/tree/tree_node_item.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 +*} +
  • {$name}
  • \ 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 new file mode 100644 index 000000000..1384c0a0c --- /dev/null +++ b/admin-dev/themes/default/template/helpers/tree/tree_toolbar.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 +*} +
    {if $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_link.tpl b/admin-dev/themes/default/template/helpers/tree/tree_toolbar_link.tpl new file mode 100644 index 000000000..966f91549 --- /dev/null +++ b/admin-dev/themes/default/template/helpers/tree/tree_toolbar_link.tpl @@ -0,0 +1,27 @@ +{* +* 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 +*} + +  {l s=$label} + \ No newline at end of file diff --git a/classes/helper/HelperITreeToolbarButton.php b/classes/helper/HelperITreeToolbarButton.php new file mode 100644 index 000000000..e98ced91b --- /dev/null +++ b/classes/helper/HelperITreeToolbarButton.php @@ -0,0 +1,41 @@ + +* @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 +*/ + +interface HelperITreeToolbarButtonCore +{ + public function __toString(); + public function setAction($value); + public function getAction(); + public function setContext($value); + public function getContext(); + public function setLabel($value); + public function getLabel(); + public function setTemplate($value); + public function getTemplate(); + public function setTemplateDirectory($value); + public function getTemplateDirectory(); + public function render(); +} \ No newline at end of file diff --git a/classes/helper/HelperITreeToolbarCore.php b/classes/helper/HelperITreeToolbarCore.php new file mode 100644 index 000000000..91f6fcf47 --- /dev/null +++ b/classes/helper/HelperITreeToolbarCore.php @@ -0,0 +1,40 @@ + +* @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 +*/ + +interface HelperITreeToolbarCore +{ + public function __toString(); + public function setActions($value); + public function getActions(); + public function setContext($value); + public function getContext(); + public function setTemplate($value); + public function getTemplate(); + public function setTemplateDirectory($value); + public function getTemplateDirectory(); + public function addAction($action); + public function render(); +} \ No newline at end of file diff --git a/classes/helper/HelperTree.php b/classes/helper/HelperTree.php new file mode 100644 index 000000000..c4af5a2fc --- /dev/null +++ b/classes/helper/HelperTree.php @@ -0,0 +1,337 @@ + +* @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 HelperTreeCore +{ + const DEFAULT_TEMPLATE_DIRECTORY = 'helpers/tree'; + const DEFAULT_TEMPLATE = 'tree.tpl'; + const DEFAULT_HEADER_TEMPLATE = 'tree_header.tpl'; + const DEFAULT_NODE_FOLDER_TEMPLATE = 'tree_node_folder.tpl'; + const DEFAULT_NODE_ITEM_TEMPLATE = 'tree_node_item.tpl'; + + private $_context; + private $_data; + private $_headerTemplate; + private $_id; + private $_node_folder_template; + private $_node_item_template; + private $_template_directory; + private $_title; + + public function __construct($id, $data = null) + { + $this->setId($id); + + if (isset($data)) + $this->setData($data); + } + + public function __toString() + { + return $this->render(); + } + + public function setActions($value) + { + if (!isset($this->_toolbar)) + $this->setToolbar(new HelperTreeToolbarCore()); + + $this->getToolbar()->setActions($value); + return $this; + } + + public function getActions() + { + if (!isset($this->_toolbar)) + $this->setToolbar(new HelperTreeToolbarCore()); + + return $this->getToolbar()->getActions(); + } + + public function addAction($action) + { + if (!isset($this->_toolbar)) + $this->setToolbar(new HelperTreeToolbarCore()); + + $this->getToolbar()->addAction($action); + return $this; + } + + public function setContext($value) + { + $this->_context = $value; + return $this; + } + + public function getContext() + { + if (!isset($this->_context)) + $this->_context = Context::getContext(); + + return $this->_context; + } + + public function setData($value) + { + if (!is_array($value) && !$value instanceof Traversable) + throw new PrestaShopException('Data value must be an traversable array'); + + $this->_data = $value; + return $this; + } + + public function getData() + { + if (!isset($this->_data)) + $this->_data = array(); + + return $this->_data; + } + + public function setHeaderTemplate($value) + { + $this->_headerTemplate = $value; + return $this; + } + + public function getHeaderTemplate() + { + if (!isset($this->_headerTemplate)) + $this->setHeaderTemplate(self::DEFAULT_HEADER_TEMPLATE); + + return $this->_headerTemplate; + } + + public function setId($value) + { + $this->_id = $value; + return $this; + } + + public function getId() + { + return $this->_id; + } + + public function setNodeFolderTemplate($value) + { + $this->_node_folder_template = $value; + return $this; + } + + public function getNodeFolderTemplate() + { + if (!isset($this->_node_folder_template)) + $this->setNodeFolderTemplate(self::DEFAULT_NODE_FOLDER_TEMPLATE); + + return $this->_node_folder_template; + } + + public function setNodeItemTemplate($value) + { + $this->_node_item_template = $value; + return $this; + } + + public function getNodeItemTemplate() + { + if (!isset($this->_node_item_template)) + $this->setNodeItemTemplate(self::DEFAULT_NODE_ITEM_TEMPLATE); + + return $this->_node_item_template; + } + + public function setTemplate($value) + { + $this->_template = $value; + return $this; + } + + public function getTemplate() + { + if (!isset($this->_template)) + $this->setTemplate(self::DEFAULT_TEMPLATE); + + return $this->_template; + } + + public function setTemplateDirectory($value) + { + $this->_template_directory = $this->_normalizeDirectory($value); + return $this; + } + + public function getTemplateDirectory() + { + if (!isset($this->_template_directory)) + { + $this->_template_directory = $this->_normalizeDirectory( + $this->getContext()->smarty->getTemplateDir(0) + .self::DEFAULT_TEMPLATE_DIRECTORY); + } + + return $this->_template_directory; + } + + public function setTitle($value) + { + $this->_title = $value; + return $this; + } + + public function getTitle() + { + return $this->_title; + } + + public function setToolbar($value) + { + if (!is_object($value)) + throw new PrestaShopException('Toolbar must be a class object'); + + $reflection = new ReflectionClass($value); + + if (!$reflection->implementsInterface('HelperITreeToolbarCore')) + throw new PrestaShopException('Toolbar class must implements ITreeToolbarCore interface'); + + $this->_toolbar = $value; + return $this; + } + + public function getToolbar() + { + return $this->_toolbar; + } + + public function useInput() + { + return isset($this->_input_type); + } + + public function useToolbar() + { + return isset($this->_toolbar); + } + + public function render($data = null) + { + //Adding tree.js + $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/tree.js'); + + //Create Tree Template + $template = $this->getContext()->smarty->createTemplate( + $this->getTemplateDirectory().$this->getTemplate(), + $this->getContext()->smarty + ); + + if (trim($this->getTitle()) != '' || $this->useToolbar()) + { + //Create Tree Header Template + $headerTemplate = $this->getContext()->smarty->createTemplate( + $this->getTemplateDirectory().$this->getHeaderTemplate(), + $this->getContext()->smarty + ); + $headerTemplate->assign(array( + 'title' => $this->getTitle(), + 'toolbar' => $this->useToolbar() ? $this->renderToolbar() : null + )); + $template->assign('header', $headerTemplate->fetch()); + } + + //Assign Tree nodes + $template->assign(array( + 'id' => $this->getId(), + 'nodes' => $this->renderNodes($data) + )); + + return $template->fetch(); + } + + public function renderNodes($data = null) + { + if (!isset($data)) + $data = $this->getData(); + + if (!is_array($data) && !$data instanceof Traversable) + throw new PrestaShopException('Data value must be an traversable array'); + + $html = ''; + + foreach ($data as $item) + { + if (array_key_exists('children', $item) && !empty($item['children'])) + $html .= $this->getContext()->smarty->createTemplate( + $this->getTemplateDirectory().$this->getNodeFolderTemplate(), + $this->getContext()->smarty + ) + ->assign(array( + 'name' => $item['name'], + 'children' => $this->renderNodes($item['children']), + 'node' => $item + )) + ->fetch(); + else + $html .= $this->getContext()->smarty->createTemplate( + $this->getTemplateDirectory().$this->getNodeItemTemplate(), + $this->getContext()->smarty + ) + ->assign(array( + 'name' => $item['name'], + 'node' => $item + )) + ->fetch(); + } + + return $html; + } + + public function renderToolbar() + { + return $this->getToolbar()->render(); + } + + private function _normalizeDirectory($directory) + { + $last = $directory[strlen($directory) - 1]; + + if (in_array($last, array('/', '\\'))) { + $directory[strlen($directory) - 1] = DIRECTORY_SEPARATOR; + return $directory; + } + + $directory .= DIRECTORY_SEPARATOR; + return $directory; + } +} \ No newline at end of file diff --git a/classes/helper/HelperTreeToolbar.php b/classes/helper/HelperTreeToolbar.php new file mode 100644 index 000000000..7e9e62bfd --- /dev/null +++ b/classes/helper/HelperTreeToolbar.php @@ -0,0 +1,141 @@ + +* @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 HelperTreeToolbarCore implements HelperITreeToolbarCore +{ + const DEFAULT_TEMPLATE_DIRECTORY = 'helpers/tree'; + const DEFAULT_TEMPLATE = 'tree_toolbar.tpl'; + + private $_actions; + private $_context; + private $_template; + private $_template_directory; + + public function __toString() + { + return $this->render(); + } + + public function setActions($value) + { + if (!is_array($value) && !$value instanceof Traversable) + throw new PrestaShopException('Action value must be an traversable array'); + + $this->_actions = $value; + } + + public function getActions() + { + if (!isset($this->_actions)) + $this->_actions = array(); + + return $this->_actions; + } + + public function setContext($value) + { + $this->_context = $value; + return $this; + } + + public function getContext() + { + if (!isset($this->_context)) + $this->_context = Context::getContext(); + + return $this->_context; + } + + public function setTemplate($value) + { + $this->_template = $value; + return $this; + } + + public function getTemplate() + { + if (!isset($this->_template)) + $this->setTemplate(self::DEFAULT_TEMPLATE); + + return $this->_template; + } + + public function setTemplateDirectory($value) + { + $this->_template_directory = $this->_normalizeDirectory($value); + return $this; + } + + public function getTemplateDirectory() + { + if (!isset($this->_template_directory)) + $this->_template_directory = $this->_normalizeDirectory( + $this->getContext()->smarty->getTemplateDir(0) + .self::DEFAULT_TEMPLATE_DIRECTORY); + + return $this->_template_directory; + } + + public function addAction($action) + { + if (!is_object($action)) + throw new PrestaShopException('Action must be a class object'); + + $reflection = new ReflectionClass($action); + + if (!$reflection->implementsInterface('HelperITreeToolbarButtonCore')) + throw new PrestaShopException('Action class must implements ITreeToolbarButtonCore interface'); + + if (!isset($this->_actions)) + $this->_actions = array(); + + $this->_actions[] = $action; + return $this; + } + + public function render() + { + return $this->getContext()->smarty->createTemplate( + $this->getTemplateDirectory().$this->getTemplate(), + $this->getContext()->smarty + ) + ->assign('actions', $this->getActions()) + ->fetch(); + } + + private function _normalizeDirectory($directory) + { + $last = $directory[strlen($directory) - 1]; + + if (in_array($last, array('/', '\\'))) { + $directory[strlen($directory) - 1] = DIRECTORY_SEPARATOR; + return $directory; + } + + $directory .= DIRECTORY_SEPARATOR; + return $directory; + } +} \ No newline at end of file diff --git a/classes/helper/HelperTreeToolbarButton.php b/classes/helper/HelperTreeToolbarButton.php new file mode 100644 index 000000000..972f42c60 --- /dev/null +++ b/classes/helper/HelperTreeToolbarButton.php @@ -0,0 +1,131 @@ + +* @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 +*/ + +abstract class HelperTreeToolbarButtonCore +{ + const DEFAULT_TEMPLATE_DIRECTORY = 'helpers/tree'; + + private $_action; + private $_context; + private $_label; + protected $_template; + protected $_template_directory; + + public function __construct($label, $action = null) + { + $this->setLabel($label); + $this->setAction($action); + } + + public function __toString() + { + return $this->render(); + } + + public function setAction($value) + { + $this->_action = $value; + return $this; + } + + public function getAction() + { + return $this->_action; + } + + public function setContext($value) + { + $this->_context = $value; + return $this; + } + + public function getContext() + { + if (!isset($this->_context)) + $this->_context = Context::getContext(); + + return $this->_context; + } + + public function setLabel($value) + { + $this->_label = $value; + return $this; + } + + public function getLabel() + { + return $this->_label; + } + + public function setTemplate($value) + { + $this->_template = $value; + return $this; + } + + public function getTemplate() + { + return $this->_template; + } + + public function setTemplateDirectory($value) + { + $this->_template_directory = $this->_normalizeDirectory($value); + return $this; + } + + public function getTemplateDirectory() + { + if (!isset($this->_template_directory)) + $this->_template_directory = $this->_normalizeDirectory( + $this->getContext()->smarty->getTemplateDir(0) + .self::DEFAULT_TEMPLATE_DIRECTORY); + + return $this->_template_directory; + } + + public function render() + { + return $this->getContext()->smarty->createTemplate( + $this->getTemplateDirectory().$this->getTemplate(), + $this->getContext()->smarty + ); + } + + private function _normalizeDirectory($directory) + { + $last = $directory[strlen($directory) - 1]; + + if (in_array($last, array('/', '\\'))) { + $directory[strlen($directory) - 1] = DIRECTORY_SEPARATOR; + return $directory; + } + + $directory .= DIRECTORY_SEPARATOR; + return $directory; + } +} \ No newline at end of file diff --git a/classes/helper/HelperTreeToolbarLink.php b/classes/helper/HelperTreeToolbarLink.php new file mode 100644 index 000000000..0af277e2c --- /dev/null +++ b/classes/helper/HelperTreeToolbarLink.php @@ -0,0 +1,77 @@ + +* @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 HelperTreeToolbarLinkCore extends HelperTreeToolbarButtonCore implements + HelperITreeToolbarButtonCore +{ + private $_icon_class; + private $_link; + protected $_template = 'tree_toolbar_link.tpl'; + + public function __construct($label, $action = null, $link, $iconClass) + { + parent::__construct($label, $action); + $this->setLink($link); + $this->setIconClass($iconClass); + } + + public function setIconClass($value) + { + $this->_icon_class = $value; + return $this; + } + + public function getIconClass() + { + return $this->_icon_class; + } + + public function setLink($value) + { + $this->_link = $value; + return $this; + } + + public function getLink() + { + if (!isset($this->_link)) + $this->_link = ''; + + return $this->_link; + } + + public function render() + { + $template = parent::render(); + $template->assign(array( + 'link' => $this->getLink(), + 'action' => $this->getAction(), + 'label' => $this->getLabel(), + 'icon_class' => $this->getIconClass() + )); + return $template->fetch(); + } +} \ No newline at end of file