// Tree
This commit is contained in:
+108
@@ -0,0 +1,108 @@
|
|||||||
|
{*
|
||||||
|
* 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 <contact@prestashop.com>
|
||||||
|
* @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
|
||||||
|
*}
|
||||||
|
<div class="panel">
|
||||||
|
{if isset($header)}{$header}{/if}
|
||||||
|
{if isset($nodes)}
|
||||||
|
<ul id="{$id}" class="tree">
|
||||||
|
{$nodes}
|
||||||
|
</ul>
|
||||||
|
{/if}
|
||||||
|
</div>
|
||||||
|
<script type="text/javascript">
|
||||||
|
{if isset($use_checkbox) && $use_checkbox == true}
|
||||||
|
function checkAllAssociatedCategories($tree)
|
||||||
|
{
|
||||||
|
$tree.find(":input[type=checkbox]").each(
|
||||||
|
function()
|
||||||
|
{
|
||||||
|
$(this).prop("checked", true);
|
||||||
|
$(this).parent().addClass("tree-selected");
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
function uncheckAllAssociatedCategories($tree)
|
||||||
|
{
|
||||||
|
$tree.find(":input[type=checkbox]").each(
|
||||||
|
function()
|
||||||
|
{
|
||||||
|
$(this).prop("checked", false);
|
||||||
|
$(this).parent().removeClass("tree-selected");
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
|
{/if}
|
||||||
|
{if isset($use_search) && $use_search == true}
|
||||||
|
$("#{$id}-categories-search").bind("typeahead:selected", function(obj, datum) {
|
||||||
|
$("#{$id}").find(":input").each(
|
||||||
|
function()
|
||||||
|
{
|
||||||
|
if ($(this).val() == datum.id_category)
|
||||||
|
{
|
||||||
|
$(this).prop("checked", true);
|
||||||
|
$(this).parent().addClass("tree-selected");
|
||||||
|
$(this).parents("ul.tree").each(
|
||||||
|
function()
|
||||||
|
{
|
||||||
|
$(this).children().children().children(".icon-folder-close")
|
||||||
|
.removeClass("icon-folder-close")
|
||||||
|
.addClass("icon-folder-open");
|
||||||
|
$(this).show();
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
);
|
||||||
|
});
|
||||||
|
{/if}
|
||||||
|
$(document).ready(function () {
|
||||||
|
$("#{$id}").tree("collapseAll");
|
||||||
|
|
||||||
|
{if isset($selected_categories)}
|
||||||
|
{assign var=imploded_selected_categories value='","'|implode:$selected_categories}
|
||||||
|
var selected_categories = new Array("{$imploded_selected_categories}");
|
||||||
|
|
||||||
|
$("#{$id}").find(":input").each(
|
||||||
|
function()
|
||||||
|
{
|
||||||
|
if ($.inArray($(this).val(), selected_categories) != -1)
|
||||||
|
{
|
||||||
|
$(this).prop("checked", true);
|
||||||
|
$(this).parent().addClass("tree-selected");
|
||||||
|
$(this).parents("ul.tree").each(
|
||||||
|
function()
|
||||||
|
{
|
||||||
|
$(this).children().children().children(".icon-folder-close")
|
||||||
|
.removeClass("icon-folder-close")
|
||||||
|
.addClass("icon-folder-open");
|
||||||
|
$(this).show();
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
);
|
||||||
|
{/if}
|
||||||
|
});
|
||||||
|
</script>
|
||||||
+2
-2
@@ -22,8 +22,8 @@
|
|||||||
* @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
|
* @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
|
||||||
* International Registered Trademark & Property of PrestaShop SA
|
* International Registered Trademark & Property of PrestaShop SA
|
||||||
*}
|
*}
|
||||||
<li class="tree-item">
|
<li class="tree-item{if isset($node['disabled']) && $node['disabled'] == true} tree-item-disable{/if}">
|
||||||
<label class="tree-item-name{if isset($node['disabled']) && $node['disabled'] == true} tree-item-name-disable{/if}">
|
<label class="tree-item-name">
|
||||||
<input type="radio" name="id_parent" value="{$node['id_category']}"{if isset($node['disabled']) && $node['disabled'] == true} disabled="disabled"{/if} />
|
<input type="radio" name="id_parent" value="{$node['id_category']}"{if isset($node['disabled']) && $node['disabled'] == true} disabled="disabled"{/if} />
|
||||||
<i class="tree-dot"></i>
|
<i class="tree-dot"></i>
|
||||||
{$node['name']}
|
{$node['name']}
|
||||||
@@ -0,0 +1,116 @@
|
|||||||
|
{*
|
||||||
|
* 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 <contact@prestashop.com>
|
||||||
|
* @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
|
||||||
|
*}
|
||||||
|
<div class="panel">
|
||||||
|
{if isset($header)}{$header}{/if}
|
||||||
|
{if isset($nodes)}
|
||||||
|
<ul id="{$id}" class="tree">
|
||||||
|
{$nodes}
|
||||||
|
</ul>
|
||||||
|
{/if}
|
||||||
|
</div>
|
||||||
|
<script type="text/javascript">
|
||||||
|
{if isset($use_checkbox) && $use_checkbox == true}
|
||||||
|
function checkAllAssociatedCategories($tree)
|
||||||
|
{
|
||||||
|
$tree.find(":input[type=checkbox]").each(
|
||||||
|
function()
|
||||||
|
{
|
||||||
|
$(this).prop("checked", true);
|
||||||
|
$(this).parent().addClass("tree-selected");
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
function uncheckAllAssociatedCategories($tree)
|
||||||
|
{
|
||||||
|
$tree.find(":input[type=checkbox]").each(
|
||||||
|
function()
|
||||||
|
{
|
||||||
|
$(this).prop("checked", false);
|
||||||
|
$(this).parent().removeClass("tree-selected");
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
|
{/if}
|
||||||
|
{if isset($use_search) && $use_search == true}
|
||||||
|
$("#{$id}-categories-search").bind("typeahead:selected", function(obj, datum) {
|
||||||
|
$("#{$id}").find(":input").each(
|
||||||
|
function()
|
||||||
|
{
|
||||||
|
if ($(this).val() == datum.id_category)
|
||||||
|
{
|
||||||
|
$(this).prop("checked", true);
|
||||||
|
$(this).parent().addClass("tree-selected");
|
||||||
|
$(this).parents("ul.tree").each(
|
||||||
|
function()
|
||||||
|
{
|
||||||
|
$(this).children().children().children(".icon-folder-close")
|
||||||
|
.removeClass("icon-folder-close")
|
||||||
|
.addClass("icon-folder-open");
|
||||||
|
$(this).show();
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
);
|
||||||
|
});
|
||||||
|
{/if}
|
||||||
|
$(document).ready(function () {
|
||||||
|
$("#{$id}").tree("collapseAll");
|
||||||
|
$("#{$id}").find(":input[type=radio]").click(
|
||||||
|
function()
|
||||||
|
{
|
||||||
|
location.href = location.href.replace(
|
||||||
|
/&id_category=[0-9]*/, "")+"&id_category="
|
||||||
|
+$(this).val();
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
{if isset($selected_categories)}
|
||||||
|
{assign var=imploded_selected_categories value='","'|implode:$selected_categories}
|
||||||
|
var selected_categories = new Array("{$imploded_selected_categories}");
|
||||||
|
|
||||||
|
$("#{$id}").find(":input").each(
|
||||||
|
function()
|
||||||
|
{
|
||||||
|
if ($.inArray($(this).val(), selected_categories) != -1)
|
||||||
|
{
|
||||||
|
$(this).prop("checked", true);
|
||||||
|
$(this).parent().addClass("tree-selected");
|
||||||
|
$(this).parents("ul.tree").each(
|
||||||
|
function()
|
||||||
|
{
|
||||||
|
$(this).children().children().children(".icon-folder-close")
|
||||||
|
.removeClass("icon-folder-close")
|
||||||
|
.addClass("icon-folder-open");
|
||||||
|
$(this).show();
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
);
|
||||||
|
{/if}
|
||||||
|
});
|
||||||
|
</script>
|
||||||
@@ -22,7 +22,6 @@
|
|||||||
* @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
|
* @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
|
||||||
* International Registered Trademark & Property of PrestaShop SA
|
* International Registered Trademark & Property of PrestaShop SA
|
||||||
*}
|
*}
|
||||||
|
|
||||||
<li class="tree-folder">
|
<li class="tree-folder">
|
||||||
<span class="tree-folder-name">
|
<span class="tree-folder-name">
|
||||||
<i class="icon-folder-close"></i>
|
<i class="icon-folder-close"></i>
|
||||||
|
|||||||
+2
-2
@@ -23,8 +23,8 @@
|
|||||||
* International Registered Trademark & Property of PrestaShop SA
|
* International Registered Trademark & Property of PrestaShop SA
|
||||||
*}
|
*}
|
||||||
<li class="tree-folder">
|
<li class="tree-folder">
|
||||||
<span class="tree-folder-name">
|
<span class="tree-folder-name{if isset($node['disabled']) && $node['disabled'] == true} tree-folder-name-disable{/if}">
|
||||||
<input type="checkbox" name="categoryBox[]" value="{$node['id_category']}" />
|
<input type="checkbox" name="categoryBox[]" value="{$node['id_category']}"{if isset($node['disabled']) && $node['disabled'] == true} disabled="disabled"{/if} />
|
||||||
<i class="icon-folder-close"></i>
|
<i class="icon-folder-close"></i>
|
||||||
<label class="tree-toggler">{$node['name']}</label>
|
<label class="tree-toggler">{$node['name']}</label>
|
||||||
</span>
|
</span>
|
||||||
+2
-2
@@ -23,8 +23,8 @@
|
|||||||
* International Registered Trademark & Property of PrestaShop SA
|
* International Registered Trademark & Property of PrestaShop SA
|
||||||
*}
|
*}
|
||||||
<li class="tree-folder">
|
<li class="tree-folder">
|
||||||
<span class="tree-folder-name">
|
<span class="tree-folder-name{if isset($node['disabled']) && $node['disabled'] == true} tree-folder-name-disable{/if}">
|
||||||
<input type="radio" name="id-category" value="{$node['id_category']}" />
|
<input type="radio" name="id-category" value="{$node['id_category']}"{if isset($node['disabled']) && $node['disabled'] == true} disabled="disabled"{/if} />
|
||||||
<i class="icon-folder-close"></i>
|
<i class="icon-folder-close"></i>
|
||||||
<label class="tree-toggler ">{$node['name']}</label>
|
<label class="tree-toggler ">{$node['name']}</label>
|
||||||
</span>
|
</span>
|
||||||
+2
-2
@@ -22,9 +22,9 @@
|
|||||||
* @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
|
* @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
|
||||||
* International Registered Trademark & Property of PrestaShop SA
|
* International Registered Trademark & Property of PrestaShop SA
|
||||||
*}
|
*}
|
||||||
<li class="tree-item">
|
<li class="tree-item{if isset($node['disabled']) && $node['disabled'] == true} tree-item-disable{/if}">
|
||||||
<label class="tree-item-name">
|
<label class="tree-item-name">
|
||||||
<input type="checkbox" name="categoryBox[]" value="{$node['id_category']}" />
|
<input type="checkbox" name="categoryBox[]" value="{$node['id_category']}"{if isset($node['disabled']) && $node['disabled'] == true} disabled="disabled"{/if} />
|
||||||
<i class="tree-dot"></i>
|
<i class="tree-dot"></i>
|
||||||
{$node['name']}
|
{$node['name']}
|
||||||
</label>
|
</label>
|
||||||
+2
-2
@@ -22,9 +22,9 @@
|
|||||||
* @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
|
* @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
|
||||||
* International Registered Trademark & Property of PrestaShop SA
|
* International Registered Trademark & Property of PrestaShop SA
|
||||||
*}
|
*}
|
||||||
<li class="tree-item">
|
<li class="tree-item{if isset($node['disabled']) && $node['disabled'] == true} tree-item-disable{/if}">
|
||||||
<label class="tree-item-name">
|
<label class="tree-item-name">
|
||||||
<input type="radio" name="id-category" value="{$node['id_category']}" />
|
<input type="radio" name="id-category" value="{$node['id_category']}"{if isset($node['disabled']) && $node['disabled'] == true} disabled="disabled"{/if} />
|
||||||
<i class="tree-dot"></i>
|
<i class="tree-dot"></i>
|
||||||
{$node['name']}
|
{$node['name']}
|
||||||
<label>
|
<label>
|
||||||
@@ -89,7 +89,18 @@ class HelperFormCore extends Helper
|
|||||||
case 'categories':
|
case 'categories':
|
||||||
if ($categories)
|
if ($categories)
|
||||||
{
|
{
|
||||||
$this->context->smarty->assign('categories_tree', $params['categories_tree']);
|
$tree = new HelperTreeCategories($params['tree']['id'], isset($params['tree']['title']) ? $params['tree']['title'] : null);
|
||||||
|
|
||||||
|
if (isset($params['tree']['selected_categories']))
|
||||||
|
$tree->setSelectedCategories($params['tree']['selected_categories']);
|
||||||
|
|
||||||
|
if (isset($params['tree']['disabled_categories']))
|
||||||
|
$tree->setDisabledCategories($params['tree']['disabled_categories']);
|
||||||
|
|
||||||
|
if (isset($params['tree']['root_category']))
|
||||||
|
$tree->setRootCategory($params['tree']['root_category']);
|
||||||
|
|
||||||
|
$this->context->smarty->assign('categories_tree', $tree->render());
|
||||||
$categories = false;
|
$categories = false;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
@@ -216,6 +227,7 @@ class HelperFormCore extends Helper
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
$tpl = $this->createTemplate('assoshop.tpl');
|
$tpl = $this->createTemplate('assoshop.tpl');
|
||||||
$tree = Shop::getTree();
|
$tree = Shop::getTree();
|
||||||
$nb_shop = 0;
|
$nb_shop = 0;
|
||||||
|
|||||||
@@ -0,0 +1,265 @@
|
|||||||
|
<?php
|
||||||
|
/*
|
||||||
|
* 2007-2013 PrestaShop
|
||||||
|
*
|
||||||
|
* NOTICE OF LICENSE
|
||||||
|
*
|
||||||
|
* This source file is subject to the Open Software License (OSL 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/osl-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 <contact@prestashop.com>
|
||||||
|
* @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 HelperTreeCategories extends TreeCore
|
||||||
|
{
|
||||||
|
const DEFAULT_TEMPLATE = 'tree_categories.tpl';
|
||||||
|
const DEFAULT_NODE_FOLDER_TEMPLATE = 'tree_node_folder_radio.tpl';
|
||||||
|
const DEFAULT_NODE_ITEM_TEMPLATE = 'tree_node_item_radio.tpl';
|
||||||
|
|
||||||
|
private $_disabled_categories;
|
||||||
|
private $_lang;
|
||||||
|
private $_root_category;
|
||||||
|
private $_selected_categories;
|
||||||
|
private $_shop;
|
||||||
|
private $_use_checkbox;
|
||||||
|
private $_use_search;
|
||||||
|
|
||||||
|
public function __construct($id, $title = null, $root_category = null,
|
||||||
|
$lang = null, $shop = null)
|
||||||
|
{
|
||||||
|
parent::__construct($id);
|
||||||
|
|
||||||
|
if (isset($title))
|
||||||
|
$this->setTitle($title);
|
||||||
|
|
||||||
|
if (isset($root_category))
|
||||||
|
$this->setRootCategory($root_category);
|
||||||
|
|
||||||
|
$this->setLang($lang);
|
||||||
|
$this->setShop($shop);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getData()
|
||||||
|
{
|
||||||
|
if (!isset($this->_data))
|
||||||
|
$this->setData(Category::getNestedCategories(
|
||||||
|
$this->getRootCategory(), $this->getLang()));
|
||||||
|
|
||||||
|
return $this->_data;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setDisabledCategories($value)
|
||||||
|
{
|
||||||
|
$this->_disabled_categories = $value;
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getDisabledCategories()
|
||||||
|
{
|
||||||
|
return $this->_disabled_categories;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setLang($value)
|
||||||
|
{
|
||||||
|
$this->_lang = $value;
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getLang()
|
||||||
|
{
|
||||||
|
if (!isset($this->_lang))
|
||||||
|
$this->setLang($this->getContext()->employee->id_lang);
|
||||||
|
|
||||||
|
return $this->_lang;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getNodeFolderTemplate()
|
||||||
|
{
|
||||||
|
if (!isset($this->_node_folder_template))
|
||||||
|
$this->setNodeFolderTemplate(self::DEFAULT_NODE_FOLDER_TEMPLATE);
|
||||||
|
|
||||||
|
return $this->_node_folder_template;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getNodeItemTemplate()
|
||||||
|
{
|
||||||
|
if (!isset($this->_node_item_template))
|
||||||
|
$this->setNodeItemTemplate(self::DEFAULT_NODE_ITEM_TEMPLATE);
|
||||||
|
|
||||||
|
return $this->_node_item_template;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setRootCategory($value)
|
||||||
|
{
|
||||||
|
if (!Validate::isInt($value))
|
||||||
|
throw new PrestaShopException('Root category must be an integer value');
|
||||||
|
|
||||||
|
$this->_root_category = $value;
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getRootCategory()
|
||||||
|
{
|
||||||
|
if (!isset($this->_root_category))
|
||||||
|
$this->setRootCategory(Category::getRootCategory($this->getLang())
|
||||||
|
->id);
|
||||||
|
|
||||||
|
return $this->_root_category;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setSelectedCategories($value)
|
||||||
|
{
|
||||||
|
if (!is_array($value))
|
||||||
|
throw new PrestaShopException('Selected categories value must be an array');
|
||||||
|
|
||||||
|
$this->_selected_categories = $value;
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getSelectedCatgories()
|
||||||
|
{
|
||||||
|
if (!isset($this->_selected_categories))
|
||||||
|
$this->_selected_categories = array();
|
||||||
|
|
||||||
|
return $this->_selected_categories;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setShop($value)
|
||||||
|
{
|
||||||
|
$this->_shop = $value;
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getShop()
|
||||||
|
{
|
||||||
|
if (!isset($this->_shop))
|
||||||
|
{
|
||||||
|
if (Tools::isSubmit('id_shop'))
|
||||||
|
$this->setShop(new Shop(Tools::getValue('id_shop')));
|
||||||
|
else
|
||||||
|
if ($this->getContext()->shop->id)
|
||||||
|
$this->setShop(new Shop($this->getContext()->shop->id));
|
||||||
|
else
|
||||||
|
if (!Shop::isFeatureActive())
|
||||||
|
$this->setShop(new Shop(Configuration::get('PS_SHOP_DEFAULT')));
|
||||||
|
else
|
||||||
|
$this->setShop(new Shop(0));
|
||||||
|
}
|
||||||
|
|
||||||
|
return $this->_shop;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getTemplate()
|
||||||
|
{
|
||||||
|
if (!isset($this->_template))
|
||||||
|
$this->setTemplate(self::DEFAULT_TEMPLATE);
|
||||||
|
|
||||||
|
return $this->_template;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setUseCheckBox($value)
|
||||||
|
{
|
||||||
|
$this->_use_checkbox = (bool)$value;
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setUseSearch($value)
|
||||||
|
{
|
||||||
|
$this->_use_search = (bool)$value;
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function useCheckBox()
|
||||||
|
{
|
||||||
|
return (isset($this->_use_checkbox) && $this->_use_checkbox);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function useSearch()
|
||||||
|
{
|
||||||
|
return (isset($this->_use_search) && $this->_use_search);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function render($data = NULL)
|
||||||
|
{
|
||||||
|
if (!isset($data))
|
||||||
|
$data = $this->getData();
|
||||||
|
|
||||||
|
if (isset($this->_disabled_categories)
|
||||||
|
&& !empty($this->_disabled_categories))
|
||||||
|
$this->_disableCategories($data, $this->getDisabledCategories());
|
||||||
|
|
||||||
|
$this->setActions(array(
|
||||||
|
new TreeToolbarLink(
|
||||||
|
'Collapse All',
|
||||||
|
'#',
|
||||||
|
'$(\'#'.$this->getId().'\').tree(\'collapseAll\')',
|
||||||
|
'icon-collapse-alt'),
|
||||||
|
new TreeToolbarLink(
|
||||||
|
'Expand All',
|
||||||
|
'#',
|
||||||
|
'$(\'#'.$this->getId().'\').tree(\'expandAll\')',
|
||||||
|
'icon-expand-alt')
|
||||||
|
));
|
||||||
|
|
||||||
|
if ($this->useCheckBox())
|
||||||
|
{
|
||||||
|
$this->addAction(new TreeToolbarLink(
|
||||||
|
'Check All',
|
||||||
|
'#',
|
||||||
|
'checkAllAssociatedCategories($(\'#'.$this->getId().'\'));',
|
||||||
|
'icon-check-sign')
|
||||||
|
);
|
||||||
|
$this->addAction(new TreeToolbarLink(
|
||||||
|
'Uncheck All',
|
||||||
|
'#',
|
||||||
|
'uncheckAllAssociatedCategories($(\'#'.$this->getId().'\'));',
|
||||||
|
'icon-check-empty')
|
||||||
|
);
|
||||||
|
|
||||||
|
$this->setNodeFolderTemplate('tree_node_folder_checkbox.tpl');
|
||||||
|
$this->setNodeItemTemplate('tree_node_item_checkbox.tpl');
|
||||||
|
$this->setAttribute('use_checkbox', $this->useCheckBox());
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($this->useSearch())
|
||||||
|
{
|
||||||
|
$this->addAction(new TreeToolbarSearch(
|
||||||
|
'Find a category:',
|
||||||
|
$this->getId().'-categories-search')
|
||||||
|
);
|
||||||
|
$this->setAttribute('use_search', $this->useSearch());
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->setAttribute('selected_categories', $this->getSelectedCatgories());
|
||||||
|
return parent::render($data);
|
||||||
|
}
|
||||||
|
|
||||||
|
private function _disableCategories(&$categories, $disabled_categories = null)
|
||||||
|
{
|
||||||
|
foreach ($categories as &$category)
|
||||||
|
{
|
||||||
|
if (!isset($disabled_categories) || in_array($category['id_category'], $disabled_categories))
|
||||||
|
{
|
||||||
|
$category['disabled'] = true;
|
||||||
|
if (array_key_exists('children', $category) && is_array($category['children']))
|
||||||
|
self::_disableCategories($category['children']);
|
||||||
|
}
|
||||||
|
else if (array_key_exists('children', $category) && is_array($category['children']))
|
||||||
|
self::_disableCategories($category['children'], $disabled_categories);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -24,7 +24,7 @@
|
|||||||
* International Registered Trademark & Property of PrestaShop SA
|
* International Registered Trademark & Property of PrestaShop SA
|
||||||
*/
|
*/
|
||||||
|
|
||||||
interface HelperITreeToolbarCore
|
interface ITreeToolbarCore
|
||||||
{
|
{
|
||||||
public function __toString();
|
public function __toString();
|
||||||
public function setActions($value);
|
public function setActions($value);
|
||||||
@@ -24,7 +24,7 @@
|
|||||||
* International Registered Trademark & Property of PrestaShop SA
|
* International Registered Trademark & Property of PrestaShop SA
|
||||||
*/
|
*/
|
||||||
|
|
||||||
interface HelperITreeToolbarButtonCore
|
interface ITreeToolbarButtonCore
|
||||||
{
|
{
|
||||||
public function __toString();
|
public function __toString();
|
||||||
public function setAttribute($name, $value);
|
public function setAttribute($name, $value);
|
||||||
@@ -24,7 +24,7 @@
|
|||||||
* International Registered Trademark & Property of PrestaShop SA
|
* International Registered Trademark & Property of PrestaShop SA
|
||||||
*/
|
*/
|
||||||
|
|
||||||
class HelperTreeCore
|
class TreeCore
|
||||||
{
|
{
|
||||||
const DEFAULT_TEMPLATE_DIRECTORY = 'helpers/tree';
|
const DEFAULT_TEMPLATE_DIRECTORY = 'helpers/tree';
|
||||||
const DEFAULT_TEMPLATE = 'tree.tpl';
|
const DEFAULT_TEMPLATE = 'tree.tpl';
|
||||||
@@ -32,15 +32,16 @@ class HelperTreeCore
|
|||||||
const DEFAULT_NODE_FOLDER_TEMPLATE = 'tree_node_folder.tpl';
|
const DEFAULT_NODE_FOLDER_TEMPLATE = 'tree_node_folder.tpl';
|
||||||
const DEFAULT_NODE_ITEM_TEMPLATE = 'tree_node_item.tpl';
|
const DEFAULT_NODE_ITEM_TEMPLATE = 'tree_node_item.tpl';
|
||||||
|
|
||||||
private $_context;
|
protected $_attributes;
|
||||||
private $_data;
|
private $_context;
|
||||||
private $_headerTemplate;
|
protected $_data;
|
||||||
private $_id;
|
protected $_headerTemplate;
|
||||||
private $_node_folder_template;
|
private $_id;
|
||||||
private $_node_item_template;
|
protected $_node_folder_template;
|
||||||
private $_template;
|
protected $_node_item_template;
|
||||||
private $_template_directory;
|
protected $_template;
|
||||||
private $_title;
|
private $_template_directory;
|
||||||
|
private $_title;
|
||||||
|
|
||||||
public function __construct($id, $data = null)
|
public function __construct($id, $data = null)
|
||||||
{
|
{
|
||||||
@@ -58,7 +59,7 @@ class HelperTreeCore
|
|||||||
public function setActions($value)
|
public function setActions($value)
|
||||||
{
|
{
|
||||||
if (!isset($this->_toolbar))
|
if (!isset($this->_toolbar))
|
||||||
$this->setToolbar(new HelperTreeToolbarCore());
|
$this->setToolbar(new TreeToolbarCore());
|
||||||
|
|
||||||
$this->getToolbar()->setActions($value);
|
$this->getToolbar()->setActions($value);
|
||||||
return $this;
|
return $this;
|
||||||
@@ -67,7 +68,7 @@ class HelperTreeCore
|
|||||||
public function getActions()
|
public function getActions()
|
||||||
{
|
{
|
||||||
if (!isset($this->_toolbar))
|
if (!isset($this->_toolbar))
|
||||||
$this->setToolbar(new HelperTreeToolbarCore());
|
$this->setToolbar(new TreeToolbarCore());
|
||||||
|
|
||||||
return $this->getToolbar()->getActions();
|
return $this->getToolbar()->getActions();
|
||||||
}
|
}
|
||||||
@@ -75,12 +76,43 @@ class HelperTreeCore
|
|||||||
public function addAction($action)
|
public function addAction($action)
|
||||||
{
|
{
|
||||||
if (!isset($this->_toolbar))
|
if (!isset($this->_toolbar))
|
||||||
$this->setToolbar(new HelperTreeToolbarCore());
|
$this->setToolbar(new TreeToolbarCore());
|
||||||
|
|
||||||
$this->getToolbar()->addAction($action);
|
$this->getToolbar()->addAction($action);
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function setAttribute($name, $value)
|
||||||
|
{
|
||||||
|
if (!isset($this->_attributes))
|
||||||
|
$this->_attributes = array();
|
||||||
|
|
||||||
|
$this->_attributes[$name] = $value;
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getAttribute($name)
|
||||||
|
{
|
||||||
|
return $this->hasAttribute($name) ? $this->_attributes[$name] : null;
|
||||||
|
}
|
||||||
|
|
||||||
|
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 setContext($value)
|
public function setContext($value)
|
||||||
{
|
{
|
||||||
$this->_context = $value;
|
$this->_context = $value;
|
||||||
@@ -250,7 +282,7 @@ class HelperTreeCore
|
|||||||
|
|
||||||
$reflection = new ReflectionClass($value);
|
$reflection = new ReflectionClass($value);
|
||||||
|
|
||||||
if (!$reflection->implementsInterface('HelperITreeToolbarCore'))
|
if (!$reflection->implementsInterface('ITreeToolbarCore'))
|
||||||
throw new PrestaShopException('Toolbar class must implements ITreeToolbarCore interface');
|
throw new PrestaShopException('Toolbar class must implements ITreeToolbarCore interface');
|
||||||
|
|
||||||
$this->_toolbar = $value;
|
$this->_toolbar = $value;
|
||||||
@@ -315,7 +347,9 @@ class HelperTreeCore
|
|||||||
}
|
}
|
||||||
|
|
||||||
//Assign Tree nodes
|
//Assign Tree nodes
|
||||||
$template->assign(array(
|
$template
|
||||||
|
->assign($this->getAttributes())
|
||||||
|
->assign(array(
|
||||||
'id' => $this->getId(),
|
'id' => $this->getId(),
|
||||||
'nodes' => $this->renderNodes($data)
|
'nodes' => $this->renderNodes($data)
|
||||||
));
|
));
|
||||||
@@ -24,7 +24,7 @@
|
|||||||
* International Registered Trademark & Property of PrestaShop SA
|
* International Registered Trademark & Property of PrestaShop SA
|
||||||
*/
|
*/
|
||||||
|
|
||||||
class HelperTreeToolbarCore implements HelperITreeToolbarCore
|
class TreeToolbarCore implements ITreeToolbarCore
|
||||||
{
|
{
|
||||||
const DEFAULT_TEMPLATE_DIRECTORY = 'helpers/tree';
|
const DEFAULT_TEMPLATE_DIRECTORY = 'helpers/tree';
|
||||||
const DEFAULT_TEMPLATE = 'tree_toolbar.tpl';
|
const DEFAULT_TEMPLATE = 'tree_toolbar.tpl';
|
||||||
@@ -159,7 +159,7 @@ class HelperTreeToolbarCore implements HelperITreeToolbarCore
|
|||||||
|
|
||||||
$reflection = new ReflectionClass($action);
|
$reflection = new ReflectionClass($action);
|
||||||
|
|
||||||
if (!$reflection->implementsInterface('HelperITreeToolbarButtonCore'))
|
if (!$reflection->implementsInterface('ITreeToolbarButtonCore'))
|
||||||
throw new PrestaShopException('Action class must implements ITreeToolbarButtonCore interface');
|
throw new PrestaShopException('Action class must implements ITreeToolbarButtonCore interface');
|
||||||
|
|
||||||
if (!isset($this->_actions))
|
if (!isset($this->_actions))
|
||||||
@@ -173,7 +173,7 @@ class HelperTreeToolbarCore implements HelperITreeToolbarCore
|
|||||||
{
|
{
|
||||||
foreach ($this->getActions() as $action)
|
foreach ($this->getActions() as $action)
|
||||||
{
|
{
|
||||||
if ($action instanceof HelperTreeToolbarSearchCore)
|
if ($action instanceof TreeToolbarSearchCore)
|
||||||
$action->setAttribute('data', $this->getData());
|
$action->setAttribute('data', $this->getData());
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -24,7 +24,7 @@
|
|||||||
* International Registered Trademark & Property of PrestaShop SA
|
* International Registered Trademark & Property of PrestaShop SA
|
||||||
*/
|
*/
|
||||||
|
|
||||||
abstract class HelperTreeToolbarButtonCore
|
abstract class TreeToolbarButtonCore
|
||||||
{
|
{
|
||||||
const DEFAULT_TEMPLATE_DIRECTORY = 'helpers/tree';
|
const DEFAULT_TEMPLATE_DIRECTORY = 'helpers/tree';
|
||||||
|
|
||||||
@@ -24,8 +24,8 @@
|
|||||||
* International Registered Trademark & Property of PrestaShop SA
|
* International Registered Trademark & Property of PrestaShop SA
|
||||||
*/
|
*/
|
||||||
|
|
||||||
class HelperTreeToolbarLinkCore extends HelperTreeToolbarButtonCore implements
|
class TreeToolbarLinkCore extends TreeToolbarButtonCore implements
|
||||||
HelperITreeToolbarButtonCore
|
ITreeToolbarButtonCore
|
||||||
{
|
{
|
||||||
private $_action;
|
private $_action;
|
||||||
private $_icon_class;
|
private $_icon_class;
|
||||||
@@ -24,8 +24,8 @@
|
|||||||
* International Registered Trademark & Property of PrestaShop SA
|
* International Registered Trademark & Property of PrestaShop SA
|
||||||
*/
|
*/
|
||||||
|
|
||||||
class HelperTreeToolbarSearchCore extends HelperTreeToolbarButtonCore implements
|
class TreeToolbarSearchCore extends TreeToolbarButtonCore implements
|
||||||
HelperITreeToolbarButtonCore
|
ITreeToolbarButtonCore
|
||||||
{
|
{
|
||||||
protected $_template = 'tree_toolbar_search.tpl';
|
protected $_template = 'tree_toolbar_search.tpl';
|
||||||
|
|
||||||
@@ -335,27 +335,12 @@ class AdminCategoriesControllerCore extends AdminController
|
|||||||
$this->action = 'select_delete';
|
$this->action = 'select_delete';
|
||||||
}
|
}
|
||||||
|
|
||||||
private function _disableCategories(&$categories, $disabled_categories = null)
|
|
||||||
{
|
|
||||||
foreach ($categories as &$category)
|
|
||||||
{
|
|
||||||
if (!isset($disabled_categories) || in_array($category['id_category'], $disabled_categories))
|
|
||||||
{
|
|
||||||
$category['disabled'] = true;
|
|
||||||
if (array_key_exists('children', $category) && is_array($category['children']))
|
|
||||||
self::_disableCategories($category['children']);
|
|
||||||
}
|
|
||||||
else if (array_key_exists('children', $category) && is_array($category['children']))
|
|
||||||
self::_disableCategories($category['children'], $disabled_categories);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public function renderForm()
|
public function renderForm()
|
||||||
{
|
{
|
||||||
$this->initToolbar();
|
$this->initToolbar();
|
||||||
$obj = $this->loadObject(true);
|
$obj = $this->loadObject(true);
|
||||||
$id_shop = Context::getContext()->shop->id;
|
$id_shop = Context::getContext()->shop->id;
|
||||||
$selected_category = (isset($obj->id_parent) && $obj->isParentCategoryAvailable($id_shop))? (int)$obj->id_parent : (int)Tools::getValue('id_parent', Category::getRootCategory()->id);
|
$selected_categories = array((isset($obj->id_parent) && $obj->isParentCategoryAvailable($id_shop))? (int)$obj->id_parent : (int)Tools::getValue('id_parent', Category::getRootCategory()->id));
|
||||||
$unidentified = new Group(Configuration::get('PS_UNIDENTIFIED_GROUP'));
|
$unidentified = new Group(Configuration::get('PS_UNIDENTIFIED_GROUP'));
|
||||||
$guest = new Group(Configuration::get('PS_GUEST_GROUP'));
|
$guest = new Group(Configuration::get('PS_GUEST_GROUP'));
|
||||||
$default = new Group(Configuration::get('PS_CUSTOMER_GROUP'));
|
$default = new Group(Configuration::get('PS_CUSTOMER_GROUP'));
|
||||||
@@ -363,54 +348,6 @@ class AdminCategoriesControllerCore extends AdminController
|
|||||||
$unidentified_group_information = sprintf($this->l('%s - All people without a valid customer account.'), '<b>'.$unidentified->name[$this->context->language->id].'</b>');
|
$unidentified_group_information = sprintf($this->l('%s - All people without a valid customer account.'), '<b>'.$unidentified->name[$this->context->language->id].'</b>');
|
||||||
$guest_group_information = sprintf($this->l('%s - Customer who placed an order with the guest checkout.'), '<b>'.$guest->name[$this->context->language->id].'</b>');
|
$guest_group_information = sprintf($this->l('%s - Customer who placed an order with the guest checkout.'), '<b>'.$guest->name[$this->context->language->id].'</b>');
|
||||||
$default_group_information = sprintf($this->l('%s - All people who have created an account on this site.'), '<b>'.$default->name[$this->context->language->id].'</b>');
|
$default_group_information = sprintf($this->l('%s - All people who have created an account on this site.'), '<b>'.$default->name[$this->context->language->id].'</b>');
|
||||||
$categories = Category::getNestedCategories(
|
|
||||||
Category::getRootCategory()->id,
|
|
||||||
$this->context->employee->id_lang
|
|
||||||
);
|
|
||||||
|
|
||||||
if (!Tools::isSubmit('add'.$this->table))
|
|
||||||
$this->_disableCategories($categories, array($this->_category->id));
|
|
||||||
|
|
||||||
$categories_tree = new HelperTree('categories-tree', $categories);
|
|
||||||
$categories_tree_render = $categories_tree->setActions(array(
|
|
||||||
new HelperTreeToolbarLink(
|
|
||||||
'Collapse All',
|
|
||||||
'#',
|
|
||||||
'$(\'#categories-tree\').tree(\'collapseAll\')',
|
|
||||||
'icon-collapse-alt'),
|
|
||||||
new HelperTreeToolbarLink(
|
|
||||||
'Expand All',
|
|
||||||
'#',
|
|
||||||
'$(\'#categories-tree\').tree(\'expandAll\')',
|
|
||||||
'icon-expand-alt')
|
|
||||||
))
|
|
||||||
->setNodeFolderTemplate('tree_node_folder_category.tpl')
|
|
||||||
->setNodeItemTemplate('tree_node_item_category.tpl')
|
|
||||||
->render();
|
|
||||||
|
|
||||||
$categories_tree_render .= '<script type="text/javascript">
|
|
||||||
$(document).ready(function () {
|
|
||||||
$("#categories-tree").find(":input").each(
|
|
||||||
function()
|
|
||||||
{
|
|
||||||
if ($(this).val() == '.$selected_category.')
|
|
||||||
{
|
|
||||||
$(this).prop("checked", true);
|
|
||||||
$(this).parent().addClass("tree-selected");
|
|
||||||
$(this).parents("ul.tree").each(
|
|
||||||
function()
|
|
||||||
{
|
|
||||||
$(this).children().children(".icon-folder-close")
|
|
||||||
.removeClass("icon-folder-close")
|
|
||||||
.addClass("icon-folder-open");
|
|
||||||
$(this).show();
|
|
||||||
}
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
);
|
|
||||||
});
|
|
||||||
</script>';
|
|
||||||
|
|
||||||
$this->fields_form = array(
|
$this->fields_form = array(
|
||||||
'tinymce' => true,
|
'tinymce' => true,
|
||||||
@@ -451,7 +388,11 @@ class AdminCategoriesControllerCore extends AdminController
|
|||||||
'type' => 'categories',
|
'type' => 'categories',
|
||||||
'label' => $this->l('Parent category:'),
|
'label' => $this->l('Parent category:'),
|
||||||
'name' => 'id_parent',
|
'name' => 'id_parent',
|
||||||
'categories_tree' => $categories_tree_render
|
'tree' => array(
|
||||||
|
'id' => 'categories-tree',
|
||||||
|
'selected_categories' => $selected_categories,
|
||||||
|
'disabled_categories' => !Tools::isSubmit('add'.$this->table) ? array($this->_category->id) : null
|
||||||
|
)
|
||||||
),
|
),
|
||||||
array(
|
array(
|
||||||
'type' => 'textarea',
|
'type' => 'textarea',
|
||||||
|
|||||||
@@ -2309,7 +2309,9 @@ class AdminProductsControllerCore extends AdminController
|
|||||||
$this->tpl_list_vars['is_category_filter'] = (bool)$this->id_current_category;
|
$this->tpl_list_vars['is_category_filter'] = (bool)$this->id_current_category;
|
||||||
|
|
||||||
// Generate category selection tree
|
// Generate category selection tree
|
||||||
$this->tpl_list_vars['category_tree'] = $this->renderCategoriesTree((int)$id_category);
|
$tree = new HelperTreeCategories('categories-tree', 'Filter by category');
|
||||||
|
$tree->setSelectedCategories(array((int)$id_category));
|
||||||
|
$this->tpl_list_vars['category_tree'] = $tree->render();
|
||||||
|
|
||||||
// used to build the new url when changing category
|
// used to build the new url when changing category
|
||||||
$this->tpl_list_vars['base_url'] = preg_replace('#&id_category=[0-9]*#', '', self::$currentIndex).'&token='.$this->token;
|
$this->tpl_list_vars['base_url'] = preg_replace('#&id_category=[0-9]*#', '', self::$currentIndex).'&token='.$this->token;
|
||||||
@@ -2328,186 +2330,6 @@ class AdminProductsControllerCore extends AdminController
|
|||||||
return parent::renderList();
|
return parent::renderList();
|
||||||
}
|
}
|
||||||
|
|
||||||
public function renderCategoriesTree($selected_category = null)
|
|
||||||
{
|
|
||||||
if (Tools::isSubmit('id_shop'))
|
|
||||||
$id_shop = Tools::getValue('id_shop');
|
|
||||||
else
|
|
||||||
if (Context::getContext()->shop->id)
|
|
||||||
$id_shop = Context::getContext()->shop->id;
|
|
||||||
else
|
|
||||||
if (!Shop::isFeatureActive())
|
|
||||||
$id_shop = Configuration::get('PS_SHOP_DEFAULT');
|
|
||||||
else
|
|
||||||
$id_shop = 0;
|
|
||||||
|
|
||||||
$shop = new Shop($id_shop);
|
|
||||||
$root_category = Category::getRootCategory(null, $shop);
|
|
||||||
$tree = new HelperTree('categories-tree', Category::getNestedCategories(
|
|
||||||
$root_category->id, $this->context->employee->id_lang));
|
|
||||||
|
|
||||||
$html = $tree->setTitle('Filter by category')
|
|
||||||
->setActions(array(
|
|
||||||
new HelperTreeToolbarLink(
|
|
||||||
'Collapse All',
|
|
||||||
'#',
|
|
||||||
'$(\'#categories-tree\').tree(\'collapseAll\')',
|
|
||||||
'icon-collapse-alt'),
|
|
||||||
new HelperTreeToolbarLink(
|
|
||||||
'Expand All',
|
|
||||||
'#',
|
|
||||||
'$(\'#categories-tree\').tree(\'expandAll\')',
|
|
||||||
'icon-expand-alt')
|
|
||||||
))
|
|
||||||
->render();
|
|
||||||
$html .= '<script type="text/javascript">
|
|
||||||
$(document).ready(function () {
|
|
||||||
$("#categories-tree").tree("collapseAll");
|
|
||||||
$("#categories-tree").find(":input[type=radio]").click(
|
|
||||||
function()
|
|
||||||
{
|
|
||||||
location.href = location.href.replace(
|
|
||||||
/&id_category=[0-9]*/, "")+"&id_category="
|
|
||||||
+$(this).val();
|
|
||||||
}
|
|
||||||
);';
|
|
||||||
|
|
||||||
if (isset($selected_category))
|
|
||||||
$html .= '$("#categories-tree").find(":input").each(
|
|
||||||
function()
|
|
||||||
{
|
|
||||||
if ($(this).val() == '.$selected_category.')
|
|
||||||
{
|
|
||||||
$(this).prop("checked", true);
|
|
||||||
$(this).parent().addClass("tree-selected");
|
|
||||||
$(this).parents("ul.tree").each(
|
|
||||||
function()
|
|
||||||
{
|
|
||||||
$(this).children().children(".icon-folder-close")
|
|
||||||
.removeClass("icon-folder-close")
|
|
||||||
.addClass("icon-folder-open");
|
|
||||||
$(this).show();
|
|
||||||
}
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
);';
|
|
||||||
$html .= '});
|
|
||||||
</script>';
|
|
||||||
return $html;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function renderAssociationsCategoriesTree($root_category,
|
|
||||||
$selected_categories)
|
|
||||||
{
|
|
||||||
$tree = new HelperTree('associated-categories-tree',
|
|
||||||
Category::getNestedCategories($root_category, $this->context->employee->id_lang));
|
|
||||||
$html = $tree->setTitle('Associated categories')
|
|
||||||
->setActions(array(
|
|
||||||
new HelperTreeToolbarLink(
|
|
||||||
'Collapse All',
|
|
||||||
'#',
|
|
||||||
'$(\'#associated-categories-tree\').tree(\'collapseAll\')',
|
|
||||||
'icon-collapse-alt'),
|
|
||||||
new HelperTreeToolbarLink(
|
|
||||||
'Expand All',
|
|
||||||
'#',
|
|
||||||
'$(\'#associated-categories-tree\').tree(\'expandAll\')',
|
|
||||||
'icon-expand-alt'),
|
|
||||||
new HelperTreeToolbarLink(
|
|
||||||
'Check All',
|
|
||||||
'#',
|
|
||||||
'checkAllAssociatedCategories();',
|
|
||||||
'icon-check-sign'),
|
|
||||||
new HelperTreeToolbarLink(
|
|
||||||
'Uncheck All',
|
|
||||||
'#',
|
|
||||||
'uncheckAllAssociatedCategories();',
|
|
||||||
'icon-check-empty'),
|
|
||||||
new HelperTreeToolbarSearch(
|
|
||||||
'Find a category:',
|
|
||||||
'categories-search')
|
|
||||||
))
|
|
||||||
->setNodeFolderTemplate('tree_node_folder_associations.tpl')
|
|
||||||
->setNodeItemTemplate('tree_node_item_associations.tpl')
|
|
||||||
->render();
|
|
||||||
|
|
||||||
$html .= '<script type="text/javascript">
|
|
||||||
function checkAllAssociatedCategories()
|
|
||||||
{
|
|
||||||
$("#associated-categories-tree").find(":input[type=checkbox]").each(
|
|
||||||
function()
|
|
||||||
{
|
|
||||||
$(this).prop("checked", true);
|
|
||||||
$(this).parent().addClass("tree-selected");
|
|
||||||
}
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
function uncheckAllAssociatedCategories()
|
|
||||||
{
|
|
||||||
$("#associated-categories-tree").find(":input[type=checkbox]").each(
|
|
||||||
function()
|
|
||||||
{
|
|
||||||
$(this).prop("checked", false);
|
|
||||||
$(this).parent().removeClass("tree-selected");
|
|
||||||
}
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
$("#categories-search").bind("typeahead:selected", function(obj, datum) {
|
|
||||||
$("#associated-categories-tree").find(":input").each(
|
|
||||||
function()
|
|
||||||
{
|
|
||||||
if ($(this).val() == datum.id_category)
|
|
||||||
{
|
|
||||||
$(this).prop("checked", true);
|
|
||||||
$(this).parent().addClass("tree-selected");
|
|
||||||
$(this).parents("ul.tree").each(
|
|
||||||
function()
|
|
||||||
{
|
|
||||||
$(this).children().children().children(".icon-folder-close")
|
|
||||||
.removeClass("icon-folder-close")
|
|
||||||
.addClass("icon-folder-open");
|
|
||||||
$(this).show();
|
|
||||||
}
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
);
|
|
||||||
});
|
|
||||||
|
|
||||||
$(document).ready(
|
|
||||||
function()
|
|
||||||
{
|
|
||||||
$("#associated-categories-tree").tree("collapseAll");
|
|
||||||
|
|
||||||
var selected_categories = new Array("'.implode('","', $selected_categories).'");
|
|
||||||
$("#associated-categories-tree").find(":input").each(
|
|
||||||
function()
|
|
||||||
{
|
|
||||||
if ($.inArray($(this).val(), selected_categories) != -1)
|
|
||||||
{
|
|
||||||
$(this).prop("checked", true);
|
|
||||||
$(this).parent().addClass("tree-selected");
|
|
||||||
$(this).parents("ul.tree").each(
|
|
||||||
function()
|
|
||||||
{
|
|
||||||
$(this).children().children().children(".icon-folder-close")
|
|
||||||
.removeClass("icon-folder-close")
|
|
||||||
.addClass("icon-folder-open");
|
|
||||||
$(this).show();
|
|
||||||
}
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
);
|
|
||||||
}
|
|
||||||
);
|
|
||||||
</script>';
|
|
||||||
return $html;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function ajaxProcessProductManufacturers()
|
public function ajaxProcessProductManufacturers()
|
||||||
{
|
{
|
||||||
$manufacturers = Manufacturer::getManufacturers();
|
$manufacturers = Manufacturer::getManufacturers();
|
||||||
@@ -3114,12 +2936,17 @@ class AdminProductsControllerCore extends AdminController
|
|||||||
foreach ($selected_cat as $key => $category)
|
foreach ($selected_cat as $key => $category)
|
||||||
$categories[] = $key;
|
$categories[] = $key;
|
||||||
|
|
||||||
|
$tree = new HelperTreeCategories('associated-categories-tree', 'Associated categories');
|
||||||
|
$tree->setRootCategory($root->id)
|
||||||
|
->setUseCheckBox(true)
|
||||||
|
->setUseSearch(true)
|
||||||
|
->setSelectedCategories($categories);
|
||||||
|
|
||||||
$data->assign(array('default_category' => $default_category,
|
$data->assign(array('default_category' => $default_category,
|
||||||
'selected_cat_ids' => implode(',', array_keys($selected_cat)),
|
'selected_cat_ids' => implode(',', array_keys($selected_cat)),
|
||||||
'selected_cat' => $selected_cat,
|
'selected_cat' => $selected_cat,
|
||||||
'id_category_default' => $product->getDefaultCategory(),
|
'id_category_default' => $product->getDefaultCategory(),
|
||||||
'category_tree' => $this->renderAssociationsCategoriesTree(
|
'category_tree' => $tree->render(),
|
||||||
$root->id, $categories),
|
|
||||||
'product' => $product,
|
'product' => $product,
|
||||||
'link' => $this->context->link,
|
'link' => $this->context->link,
|
||||||
'is_shop_context' => Shop::getContext() == Shop::CONTEXT_SHOP
|
'is_shop_context' => Shop::getContext() == Shop::CONTEXT_SHOP
|
||||||
|
|||||||
Reference in New Issue
Block a user