// Toolbar

This commit is contained in:
Jerome Nadaud
2013-09-10 14:08:29 +02:00
parent 03d1697e19
commit 85dc552667
15 changed files with 368 additions and 96 deletions
File diff suppressed because one or more lines are too long
@@ -24,7 +24,7 @@
*} *}
<li class="tree-folder"> <li class="tree-folder">
<span class="tree-folder-name"> <span class="tree-folder-name">
<input type="checkbox" name="id-category[]" value="{$node['id_category']}" /> <input type="checkbox" name="categoryBox[]" value="{$node['id_category']}" />
<i class="icon-folder-close"></i> <i class="icon-folder-close"></i>
<label class="tree-toggler">{$name}</label> <label class="tree-toggler">{$name}</label>
</span> </span>
@@ -24,7 +24,7 @@
*} *}
<li class="tree-item"> <li class="tree-item">
<label class="tree-item-name"> <label class="tree-item-name">
<input type="checkbox" name="id-category[]" value="{$node['id_category']}" /> <input type="checkbox" name="categoryBox[]" value="{$node['id_category']}" />
<i class="tree-dot"></i> <i class="tree-dot"></i>
{$name} {$name}
</label> </label>
@@ -22,6 +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
*} *}
<a href="{$link}" onclick="{$action}" class="btn btn-default btn-xs"> <a href="{$link}"{if isset($action)}onclick="{$action}"{/if} class="btn btn-default btn-xs">
<i class="{$icon_class}"></i>&nbsp;{l s=$label} {if isset($icon_class)}<i class="{$icon_class}"></i>&nbsp;{/if}{l s=$label}
</a> </a>
@@ -22,4 +22,18 @@
* @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
*} *}
<label for="node-search">{l s=$label}</label>&nbsp;<input type="text" id="node-search" name="node-search"{if isset($class)} class="{$class}"{/if}{if isset($categories_name)} data-provide="typeahead" data-source="[{$categories_name}]"{/if} /> <label for="node-search">{l s=$label}</label>&nbsp;<input type="text"{if isset($id)} id="{$id}"{/if}{if isset($name)} name="{$name}"{/if}{if isset($class)} class="{$class}"{/if} />
{if isset($typeahead_source) && isset($id)}
<script type="text/javascript">
$(document).ready(
function()
{
$("#{$id}").typeahead(
{
name: "{$name}",
local: [{$typeahead_source}]
});
}
);
</script>
{/if}
@@ -22,6 +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
*} *}
<a href="{$link}" onclick="{$action}" class="btn btn-default btn-xs"> <a href="{$link}"{if isset($action)}onclick="{$action}"{/if} class="btn btn-default btn-xs">
<i class="{$icon_class}"></i>&nbsp;{l s=$label} {if isset($icon_class)}<i class="{$icon_class}"></i>&nbsp;{/if}{l s=$label}
</a> </a>
@@ -22,4 +22,19 @@
* @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
*} *}
<label for="node-search">{l s=$label}</label>&nbsp;<input type="text" id="node-search" name="node-search"{if isset($class)} class="{$class}"{/if}{if isset($data_source)} data-provide="typeahead" data-source="[{$data_source}]"{/if} /> <label for="node-search">{l s=$label}</label>&nbsp;<input type="text"{if isset($id)} id="{$id}"{/if}{if isset($name)} name="{$name}"{/if}{if isset($class)} class="{$class}"{/if} />
{if isset($typeahead_source) && isset($id)}
<script type="text/javascript">
$(document).ready(
function()
{
$("#{$id}").typeahead(
{
name: "{$name}",
valueKey: 'name',
local: [{$typeahead_source}]
});
}
);
</script>
{/if}
@@ -31,10 +31,12 @@ interface HelperITreeToolbarCore
public function getActions(); public function getActions();
public function setContext($value); public function setContext($value);
public function getContext(); public function getContext();
public function setData($value);
public function getData();
public function setTemplate($value); public function setTemplate($value);
public function getTemplate(); public function getTemplate();
public function setTemplateDirectory($value); public function setTemplateDirectory($value);
public function getTemplateDirectory(); public function getTemplateDirectory();
public function addAction($action); public function addAction($action);
public function render(); public function render();
} }
+7 -3
View File
@@ -27,20 +27,24 @@
interface HelperITreeToolbarButtonCore interface HelperITreeToolbarButtonCore
{ {
public function __toString(); public function __toString();
public function setAction($value); public function setAttribute($name, $value);
public function getAction(); public function getAttribute($name);
public function setAttributes($value); public function setAttributes($value);
public function getAttributes(); public function getAttributes();
public function setClass($value); public function setClass($value);
public function getClass(); public function getClass();
public function setContext($value); public function setContext($value);
public function getContext(); public function getContext();
public function setId($value);
public function getId();
public function setLabel($value); public function setLabel($value);
public function getLabel(); public function getLabel();
public function setName($value);
public function getName();
public function setTemplate($value); public function setTemplate($value);
public function getTemplate(); public function getTemplate();
public function setTemplateDirectory($value); public function setTemplateDirectory($value);
public function getTemplateDirectory(); public function getTemplateDirectory();
public function addAttribute($name, $value); public function hasAttribute($name);
public function render(); public function render();
} }
+53 -4
View File
@@ -32,10 +32,13 @@ 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 $_children_key;
private $_context; private $_context;
private $_data; private $_data;
private $_headerTemplate; private $_headerTemplate;
private $_id; private $_id;
private $_id_key;
private $_name_key;
private $_node_folder_template; private $_node_folder_template;
private $_node_item_template; private $_node_item_template;
private $_template_directory; private $_template_directory;
@@ -80,6 +83,20 @@ class HelperTreeCore
return $this; return $this;
} }
public function setChildrenKey($value)
{
$this->_children_key = (string)$value;
return $this;
}
public function getChildrenKey()
{
if (!isset($this->_children_key))
$this->setChildrenKey('children');
return $this->_children_key;
}
public function setContext($value) public function setContext($value)
{ {
$this->_context = $value; $this->_context = $value;
@@ -136,6 +153,34 @@ class HelperTreeCore
return $this->_id; return $this->_id;
} }
public function setIdKey($value)
{
$this->_id_key = (string)$value;
return $this;
}
public function getIdKey()
{
if (!isset($this->_id_key))
$this->setIdKey('id');
return $this->_id_key;
}
public function setNameKey($value)
{
$this->_name_key = (string)$value;
return $this;
}
public function getNameKey()
{
if (!isset($this->_name_key))
$this->setNameKey('name');
return $this->_name_key;
}
public function setNodeFolderTemplate($value) public function setNodeFolderTemplate($value)
{ {
$this->_node_folder_template = $value; $this->_node_folder_template = $value;
@@ -223,6 +268,9 @@ class HelperTreeCore
public function getToolbar() public function getToolbar()
{ {
if (isset($this->_toolbar))
$this->_toolbar->setData($this->getData());
return $this->_toolbar; return $this->_toolbar;
} }
@@ -296,13 +344,14 @@ class HelperTreeCore
foreach ($data as $item) foreach ($data as $item)
{ {
if (array_key_exists('children', $item) && !empty($item['children'])) if (array_key_exists($this->getChildrenKey(), $item)
&& !empty($item[$this->getChildrenKey()]))
$html .= $this->getContext()->smarty->createTemplate( $html .= $this->getContext()->smarty->createTemplate(
$this->getTemplateDirectory().$this->getNodeFolderTemplate(), $this->getTemplateDirectory().$this->getNodeFolderTemplate(),
$this->getContext()->smarty $this->getContext()->smarty
)->assign(array( )->assign(array(
'name' => $item['name'], 'name' => $item[$this->getNameKey()],
'children' => $this->renderNodes($item['children']), 'children' => $this->renderNodes($item[$this->getChildrenKey()]),
'node' => $item 'node' => $item
))->fetch(); ))->fetch();
else else
@@ -310,7 +359,7 @@ class HelperTreeCore
$this->getTemplateDirectory().$this->getNodeItemTemplate(), $this->getTemplateDirectory().$this->getNodeItemTemplate(),
$this->getContext()->smarty $this->getContext()->smarty
)->assign(array( )->assign(array(
'name' => $item['name'], 'name' => $item[$this->getNameKey()],
'node' => $item 'node' => $item
))->fetch(); ))->fetch();
} }
+21
View File
@@ -31,6 +31,7 @@ class HelperTreeToolbarCore implements HelperITreeToolbarCore
private $_actions; private $_actions;
private $_context; private $_context;
private $_data;
private $_template; private $_template;
private $_template_directory; private $_template_directory;
@@ -69,6 +70,20 @@ class HelperTreeToolbarCore implements HelperITreeToolbarCore
return $this->_context; 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()
{
return $this->_data;
}
public function setTemplate($value) public function setTemplate($value)
{ {
$this->_template = $value; $this->_template = $value;
@@ -118,6 +133,12 @@ class HelperTreeToolbarCore implements HelperITreeToolbarCore
public function render() public function render()
{ {
foreach ($this->getActions() as $action)
{
if (is_subclass_of($action, 'HelperTreeToolbarSearchCore'))
$action->setAttribute('data', $this->getData());
}
return $this->getContext()->smarty->createTemplate( return $this->getContext()->smarty->createTemplate(
$this->getTemplateDirectory().$this->getTemplate(), $this->getTemplateDirectory().$this->getTemplate(),
$this->getContext()->smarty $this->getContext()->smarty
+41 -21
View File
@@ -28,18 +28,20 @@ abstract class HelperTreeToolbarButtonCore
{ {
const DEFAULT_TEMPLATE_DIRECTORY = 'helpers/tree'; const DEFAULT_TEMPLATE_DIRECTORY = 'helpers/tree';
private $_action; protected $_attributes;
private $_attributes;
private $_class; private $_class;
private $_context; private $_context;
private $_id;
private $_label; private $_label;
private $_name;
protected $_template; protected $_template;
protected $_template_directory; protected $_template_directory;
public function __construct($label, $action = null, $class = null) public function __construct($label, $id = null, $name = null, $class = null)
{ {
$this->setLabel($label); $this->setLabel($label);
$this->setAction($action); $this->setId($id);
$this->setName($name);
$this->setClass($class); $this->setClass($class);
} }
@@ -48,15 +50,18 @@ abstract class HelperTreeToolbarButtonCore
return $this->render(); return $this->render();
} }
public function setAction($value) public function setAttribute($name, $value)
{ {
$this->_action = $value; if (!isset($this->_attributes))
$this->_attributes = array();
$this->_attributes[$name] = $value;
return $this; return $this;
} }
public function getAction() public function getAttribute($name)
{ {
return $this->_action; return $this->hasAttribute($name) ? $this->_attributes[$name] : null;
} }
public function setAttributes($value) public function setAttributes($value)
@@ -78,13 +83,12 @@ abstract class HelperTreeToolbarButtonCore
public function setClass($value) public function setClass($value)
{ {
$this->_class = $value; return $this->setAttribute('class', $value);
return $this;
} }
public function getClass() public function getClass()
{ {
return $this->_class; return $this->getAttribute('class');
} }
public function setContext($value) public function setContext($value)
@@ -101,15 +105,34 @@ abstract class HelperTreeToolbarButtonCore
return $this->_context; return $this->_context;
} }
public function setId($value)
{
return $this->setAttribute('id', $value);
}
public function getId()
{
return $this->getAttribute('id');
}
public function setLabel($value) public function setLabel($value)
{ {
$this->_label = $value; return $this->setAttribute('label', $value);
return $this;
} }
public function getLabel() public function getLabel()
{ {
return $this->_label; return $this->getAttribute('label');
}
public function setName($value)
{
return $this->setAttribute('name', $value);
}
public function getName()
{
return $this->getAttribute('name');
} }
public function setTemplate($value) public function setTemplate($value)
@@ -139,13 +162,10 @@ abstract class HelperTreeToolbarButtonCore
return $this->_template_directory; return $this->_template_directory;
} }
public function addAttribute($name, $value) public function hasAttribute($name)
{ {
if (!isset($this->_attributes)) return (isset($this->_attributes)
$this->_attributes = array(); && array_key_exists($name, $this->_attributes));
$this->_attributes[$name] = $value;
return $this;
} }
public function render() public function render()
@@ -153,7 +173,7 @@ abstract class HelperTreeToolbarButtonCore
return $this->getContext()->smarty->createTemplate( return $this->getContext()->smarty->createTemplate(
$this->getTemplateDirectory().$this->getTemplate(), $this->getTemplateDirectory().$this->getTemplate(),
$this->getContext()->smarty $this->getContext()->smarty
)->assign($this->getAttributes()); )->assign($this->getAttributes())->fetch();
} }
private function _normalizeDirectory($directory) private function _normalizeDirectory($directory)
+19 -24
View File
@@ -27,52 +27,47 @@
class HelperTreeToolbarLinkCore extends HelperTreeToolbarButtonCore implements class HelperTreeToolbarLinkCore extends HelperTreeToolbarButtonCore implements
HelperITreeToolbarButtonCore HelperITreeToolbarButtonCore
{ {
private $_action;
private $_icon_class; private $_icon_class;
private $_link; private $_link;
protected $_template = 'tree_toolbar_link.tpl'; protected $_template = 'tree_toolbar_link.tpl';
public function __construct($label, $action = null, $link, $iconClass) public function __construct($label, $link, $action = null, $iconClass = null)
{ {
parent::__construct($label, $action); parent::__construct($label);
$this->setLink($link); $this->setLink($link);
$this->setAction($action);
$this->setIconClass($iconClass); $this->setIconClass($iconClass);
} }
public function setAction($value)
{
return $this->setAttribute('action', $value);
}
public function getAction()
{
return $this->getAttribute('action');
}
public function setIconClass($value) public function setIconClass($value)
{ {
$this->_icon_class = $value; return $this->setAttribute('icon_class', $value);
return $this;
} }
public function getIconClass() public function getIconClass()
{ {
return $this->_icon_class; return $this->getAttribute('icon_class');
} }
public function setLink($value) public function setLink($value)
{ {
$this->_link = $value; return $this->setAttribute('link', $value);
return $this;
} }
public function getLink() public function getLink()
{ {
if (!isset($this->_link)) return $this->getAttribute('link');
$this->_link = '';
return $this->_link;
}
public function render()
{
$template = parent::render();
$template->assign(array(
'link' => $this->getLink(),
'action' => $this->getAction(),
'label' => $this->getLabel(),
'class' => $this->getClass(),
'icon_class' => $this->getIconClass()
));
return $template->fetch();
} }
} }
+77 -7
View File
@@ -27,10 +27,68 @@
class HelperTreeToolbarSearchCore extends HelperTreeToolbarButtonCore implements class HelperTreeToolbarSearchCore extends HelperTreeToolbarButtonCore implements
HelperITreeToolbarButtonCore HelperITreeToolbarButtonCore
{ {
private $_children_key;
private $_id_key;
private $_name_key;
protected $_template = 'tree_toolbar_search.tpl'; protected $_template = 'tree_toolbar_search.tpl';
public function __construct($label, $id, $name = null, $class = null)
{
parent::__construct($label);
$this->setId($id);
$this->setName($name);
$this->setClass($class);
}
public function setChildrenKey($value)
{
$this->_children_key = (string)$value;
return $this;
}
public function getChildrenKey()
{
if (!isset($this->_children_key))
$this->setChildrenKey('children');
return $this->_children_key;
}
public function setIdKey($value)
{
$this->_id_key = (string)$value;
return $this;
}
public function getIdKey()
{
if (!isset($this->_id_key))
$this->setIdKey('id');
return $this->_id_key;
}
public function setNameKey($value)
{
$this->_name_key = (string)$value;
return $this;
}
public function getNameKey()
{
if (!isset($this->_name_key))
$this->setNameKey('name');
return $this->_name_key;
}
public function render() public function render()
{ {
if ($this->hasAttribute('data'))
$this->setAttribute('typeahead_source',
$this->_renderData($this->getAttribute('data')));
$admin_webpath = str_ireplace(_PS_ROOT_DIR_, '', _PS_ADMIN_DIR_); $admin_webpath = str_ireplace(_PS_ROOT_DIR_, '', _PS_ADMIN_DIR_);
$admin_webpath = preg_replace('/^'.preg_quote(DIRECTORY_SEPARATOR, '/').'/', '', $admin_webpath); $admin_webpath = preg_replace('/^'.preg_quote(DIRECTORY_SEPARATOR, '/').'/', '', $admin_webpath);
$bo_theme = ((Validate::isLoadedObject($this->getContext()->employee) $bo_theme = ((Validate::isLoadedObject($this->getContext()->employee)
@@ -47,12 +105,24 @@ class HelperTreeToolbarSearchCore extends HelperTreeToolbarButtonCore implements
$this->getContext()->controller->addJs(__PS_BASE_URI__.$admin_webpath $this->getContext()->controller->addJs(__PS_BASE_URI__.$admin_webpath
.'/themes/'.$bo_theme.'/js/vendor/typeahead.min.js'); .'/themes/'.$bo_theme.'/js/vendor/typeahead.min.js');
$template = parent::render(); return (isset($html)?$html:'').parent::render();
$template->assign(array( }
'action' => $this->getAction(),
'label' => $this->getLabel(), private function _renderData($data)
'class' => $this->getClass() {
)); if (!is_array($data) && !$data instanceof Traversable)
return (isset($html)?$html:'').$template->fetch(); throw new PrestaShopException('Data value must be an traversable array');
$html = '';
foreach ($data as $item)
{
if (array_key_exists($this->getChildrenKey(), $item) && !empty($item[$this->getChildrenKey()]))
$html .= '{id : '.$item[$this->getIdKey()].', name : "'.$item[$this->getNameKey()].'"},'.$this->_renderData($item[$this->getChildrenKey()]);
else
$html .= '{id : '.$item[$this->getIdKey()].', name : "'.$item[$this->getNameKey()].'"},';
}
return $html;
} }
} }
+103 -28
View File
@@ -2328,14 +2328,23 @@ class AdminProductsControllerCore extends AdminController
return parent::renderList(); return parent::renderList();
} }
public function renderCategoriesTree($selectedCategory = null) public function renderCategoriesTree($selected_category = null)
{ {
$tree = new HelperTree('categories-tree', Category::getNestedCategories()); $tree = new HelperTree('categories-tree', Category::getNestedCategories(
1, $this->context->employee->id_lang));
$html = $tree->setTitle('Filter by category') $html = $tree->setTitle('Filter by category')
->setActions(array( ->setActions(array(
new HelperTreeToolbarLink('Collapse All', '$(\'#categories-tree\').tree(\'collapseAll\')', '#', 'icon-collapse-alt'), new HelperTreeToolbarLink(
new HelperTreeToolbarLink('Expand All', '$(\'#categories-tree\').tree(\'expandAll\')', '#', 'icon-expand-alt') 'Collapse All',
'#',
'$(\'#categories-tree\').tree(\'collapseAll\')',
'icon-collapse-alt'),
new HelperTreeToolbarLink(
'Expand All',
'#',
'$(\'#categories-tree\').tree(\'expandAll\')',
'icon-expand-alt')
)) ))
->setTemplateDirectory($this->context->smarty->getTemplateDir(0).'/controllers/products/helpers/tree') ->setTemplateDirectory($this->context->smarty->getTemplateDir(0).'/controllers/products/helpers/tree')
->render(); ->render();
@@ -2351,13 +2360,14 @@ class AdminProductsControllerCore extends AdminController
} }
);'; );';
if (isset($selectedCategory)) if (isset($selected_category))
$html .= '$("#categories-tree").find(":input").each( $html .= '$("#categories-tree").find(":input").each(
function() function()
{ {
if ($(this).val() == '.$selectedCategory.') if ($(this).val() == '.$selected_category.')
{ {
$(this).prop("checked", true); $(this).prop("checked", true);
$(this).parent().addClass("tree-selected");
$(this).parents("ul.tree").each( $(this).parents("ul.tree").each(
function() function()
{ {
@@ -2375,36 +2385,51 @@ class AdminProductsControllerCore extends AdminController
return $html; return $html;
} }
public function renderAssociationsCategoriesTree() public function renderAssociationsCategoriesTree($root_category,
$selected_categories)
{ {
$categories = Category::getSimpleCategories(1); $tree = new HelperTree('associated-categories-tree',
$search_source = array(); Category::getNestedCategories(1, $this->context->employee->id_lang));
foreach ($categories as $key => $category) $search = new HelperTreeToolbarSearch('Find a category:',
$search_source[] = $category['name']; 'categories-search');
$search->setIdKey('id_category');
$tree = new HelperTree('associated-categories-tree', Category::getNestedCategories());
$search = new HelperTreeToolbarSearch('Find a category:');
$search->setTemplateDirectory($this->context->smarty->getTemplateDir(0).'/controllers/products/helpers/tree')
->addAttribute('categories_name', '"'.implode('","', $search_source).'"');
$html = $tree->setTitle('Associated categories') $html = $tree->setTitle('Associated categories')
->setActions(array( ->setActions(array(
new HelperTreeToolbarLink('Collapse All', '$(\'#associated-categories-tree\').tree(\'collapseAll\')', '#', 'icon-collapse-alt'), new HelperTreeToolbarLink(
new HelperTreeToolbarLink('Expand All', '$(\'#associated-categories-tree\').tree(\'expandAll\')', '#', 'icon-expand-alt'), 'Collapse All',
new HelperTreeToolbarLink('Check All', 'checkAllAssociatedCategories();', '#', 'icon-check-sign'), '#',
new HelperTreeToolbarLink('Uncheck All', 'uncheckAllAssociatedCategories();', '#', 'icon-check-empty'), '$(\'#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'),
$search $search
)) ))
->setTemplateDirectory($this->context->smarty->getTemplateDir(0).'/controllers/products/helpers/tree') ->setTemplateDirectory($this->context->smarty->getTemplateDir(0).'/controllers/products/helpers/tree')
->setNodeFolderTemplate('tree_node_folder_associations.tpl') ->setNodeFolderTemplate('tree_node_folder_associations.tpl')
->setNodeFolderTemplate('tree_node_item_associations.tpl') ->setNodeItemTemplate('tree_node_item_associations.tpl')
->render(); ->render();
$html .= '<script type="text/javascript">
$html .= '<script type="text/javascript">
function checkAllAssociatedCategories() function checkAllAssociatedCategories()
{ {
$("#associated-categories-tree").find(":input[type=checkbox]").each( $("#associated-categories-tree").find(":input[type=checkbox]").each(
function() function()
{ {
$(this).prop("checked", true); $(this).prop("checked", true);
$(this).parent().addClass("tree-selected");
} }
); );
} }
@@ -2415,13 +2440,60 @@ class AdminProductsControllerCore extends AdminController
function() function()
{ {
$(this).prop("checked", false); $(this).prop("checked", false);
$(this).parent().removeClass("tree-selected");
} }
); );
} }
$(document).ready(function () { $("#categories-search").bind("typeahead:selected", function(obj, datum) {
//$("#associated-categories-tree").tree("collapseAll"); $("#associated-categories-tree").find(":input").each(
function()
{
if ($(this).val() == datum.id)
{
$(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();
}
);
}
}
);
}); });
$(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(".icon-folder-close")
.removeClass("icon-folder-close")
.addClass("icon-folder-open");
$(this).show();
}
);
}
}
);
}
);
</script>'; </script>';
return $html; return $html;
} }
@@ -3027,14 +3099,17 @@ class AdminProductsControllerCore extends AdminController
$data->assign('accessories', $accessories); $data->assign('accessories', $accessories);
$product->manufacturer_name = Manufacturer::getNameById($product->id_manufacturer); $product->manufacturer_name = Manufacturer::getNameById($product->id_manufacturer);
$tab_root = array('id_category' => $root->id, 'name' => $root->name);
$category_tree = $helper->renderCategoryTree($tab_root, $selected_cat, 'categoryBox', false, true, array(), false, true); $categories = array();
$helper = new Helper(); foreach ($selected_cat as $key => $category)
$categories[] = $key;
$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' => $category_tree, 'category_tree' => $this->renderAssociationsCategoriesTree(
$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