// Tree
This commit is contained in:
@@ -335,27 +335,12 @@ class AdminCategoriesControllerCore extends AdminController
|
||||
$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()
|
||||
{
|
||||
$this->initToolbar();
|
||||
$obj = $this->loadObject(true);
|
||||
$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'));
|
||||
$guest = new Group(Configuration::get('PS_GUEST_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>');
|
||||
$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>');
|
||||
$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(
|
||||
'tinymce' => true,
|
||||
@@ -451,7 +388,11 @@ class AdminCategoriesControllerCore extends AdminController
|
||||
'type' => 'categories',
|
||||
'label' => $this->l('Parent category:'),
|
||||
'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(
|
||||
'type' => 'textarea',
|
||||
|
||||
@@ -2309,7 +2309,9 @@ class AdminProductsControllerCore extends AdminController
|
||||
$this->tpl_list_vars['is_category_filter'] = (bool)$this->id_current_category;
|
||||
|
||||
// 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
|
||||
$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();
|
||||
}
|
||||
|
||||
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()
|
||||
{
|
||||
$manufacturers = Manufacturer::getManufacturers();
|
||||
@@ -3114,12 +2936,17 @@ class AdminProductsControllerCore extends AdminController
|
||||
foreach ($selected_cat as $key => $category)
|
||||
$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,
|
||||
'selected_cat_ids' => implode(',', array_keys($selected_cat)),
|
||||
'selected_cat' => $selected_cat,
|
||||
'id_category_default' => $product->getDefaultCategory(),
|
||||
'category_tree' => $this->renderAssociationsCategoriesTree(
|
||||
$root->id, $categories),
|
||||
'category_tree' => $tree->render(),
|
||||
'product' => $product,
|
||||
'link' => $this->context->link,
|
||||
'is_shop_context' => Shop::getContext() == Shop::CONTEXT_SHOP
|
||||
|
||||
Reference in New Issue
Block a user