// Categories tree
This commit is contained in:
+10
-15
@@ -22,18 +22,13 @@
|
||||
* @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
|
||||
* International Registered Trademark & Property of PrestaShop SA
|
||||
*}
|
||||
<label for="node-search">{l s=$label}</label> <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}
|
||||
<li class="tree-folder">
|
||||
<span class="tree-folder-name{if isset($node['disabled']) && $node['disabled'] == true} tree-folder-name-disable{/if}">
|
||||
<input type="radio" name="id_parent" value="{$node['id_category']}"{if isset($node['disabled']) && $node['disabled'] == true} disabled="disabled"{/if} />
|
||||
<i class="icon-folder-close"></i>
|
||||
<label class="tree-toggler ">{$node['name']}</label>
|
||||
</span>
|
||||
<ul class="tree">
|
||||
{$children}
|
||||
</ul>
|
||||
</li>
|
||||
+7
-3
@@ -22,6 +22,10 @@
|
||||
* @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
|
||||
* International Registered Trademark & Property of PrestaShop SA
|
||||
*}
|
||||
<a href="{$link}"{if isset($action)}onclick="{$action}"{/if} class="btn btn-default btn-xs">
|
||||
{if isset($icon_class)}<i class="{$icon_class}"></i> {/if}{l s=$label}
|
||||
</a>
|
||||
<li class="tree-item">
|
||||
<label class="tree-item-name{if isset($node['disabled']) && $node['disabled'] == true} tree-item-name-disable{/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>
|
||||
{$node['name']}
|
||||
<label>
|
||||
</li>
|
||||
@@ -405,7 +405,7 @@
|
||||
{elseif $input.type == 'shop'}
|
||||
{$input.html}
|
||||
{elseif $input.type == 'categories'}
|
||||
{include file='helpers/form/form_category.tpl' categories=$input.values}
|
||||
{$categories_tree}
|
||||
{elseif $input.type == 'categories_select'}
|
||||
{$input.category_tree}
|
||||
{elseif $input.type == 'asso_shop' && isset($asso_shop) && $asso_shop}
|
||||
|
||||
@@ -477,15 +477,19 @@ class CategoryCore extends ObjectModel
|
||||
return $categories;
|
||||
}
|
||||
|
||||
public static function getNestedCategories($root_category = 1,
|
||||
public static function getNestedCategories($root_category = null,
|
||||
$id_lang = false, $active = true, $sql_filter = '', $sql_sort = '',
|
||||
$sql_limit = '')
|
||||
{
|
||||
if (!isset($root_category))
|
||||
$root_category = self::getRootCategory($id_lang)->id;
|
||||
|
||||
if (!Validate::isInt($root_category))
|
||||
die(Tools::displayError());
|
||||
|
||||
if (!Validate::isBool($active))
|
||||
die(Tools::displayError());
|
||||
|
||||
$result = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS('
|
||||
SELECT *
|
||||
FROM `'._DB_PREFIX_.'category` c
|
||||
|
||||
@@ -89,16 +89,7 @@ class HelperFormCore extends Helper
|
||||
case 'categories':
|
||||
if ($categories)
|
||||
{
|
||||
// Added Jquery plugin treeview (css and js files)
|
||||
$this->context->controller->addJqueryPlugin('treeview-categories');
|
||||
|
||||
// Added JS files
|
||||
$this->context->controller->addJS(_PS_JS_DIR_.'jquery/plugins/treeview-categories/jquery.treeview-categories.async.js');
|
||||
$this->context->controller->addJS(_PS_JS_DIR_.'jquery/plugins/treeview-categories/jquery.treeview-categories.edit.js');
|
||||
$this->context->controller->addJS(_PS_JS_DIR_.'admin-categories-tree.js');
|
||||
|
||||
if (isset($params['use_search']) && $params['use_search'])
|
||||
$this->context->controller->addJS(_PS_JS_DIR_.'jquery/plugins/autocomplete/jquery.autocomplete.js');
|
||||
$this->context->smarty->assign('categories_tree', $params['categories_tree']);
|
||||
$categories = false;
|
||||
}
|
||||
break;
|
||||
|
||||
@@ -335,12 +335,27 @@ 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_cat = array((isset($obj->id_parent) && $obj->isParentCategoryAvailable($id_shop))? (int)$obj->id_parent : (int)Tools::getValue('id_parent', Category::getRootCategory()->id));
|
||||
$selected_category = (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'));
|
||||
@@ -348,8 +363,52 @@ 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>');
|
||||
$root_category = Category::getRootCategory();
|
||||
$root_category = array('id_category' => $root_category->id, 'name' => $root_category->name);
|
||||
$categories = Category::getNestedCategories(
|
||||
Category::getRootCategory()->id,
|
||||
$this->context->employee->id_lang
|
||||
);
|
||||
$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,
|
||||
'legend' => array(
|
||||
@@ -386,24 +445,10 @@ class AdminCategoriesControllerCore extends AdminController
|
||||
)
|
||||
),
|
||||
array(
|
||||
'type' => 'categories',
|
||||
'type' => 'categories',
|
||||
'label' => $this->l('Parent category:'),
|
||||
'name' => 'id_parent',
|
||||
'values' => array(
|
||||
'trads' => array(
|
||||
'Root' => $root_category,
|
||||
'selected' => $this->l('Selected'),
|
||||
'Collapse All' => $this->l('Collapse All'),
|
||||
'Expand All' => $this->l('Expand All')
|
||||
),
|
||||
'selected_cat' => $selected_cat,
|
||||
'input_name' => 'id_parent',
|
||||
'use_radio' => true,
|
||||
'use_search' => false,
|
||||
'disabled_categories' => array(4),
|
||||
'top_category' => Category::getTopCategory(),
|
||||
'use_context' => true,
|
||||
)
|
||||
'name' => 'id_parent',
|
||||
'categories_tree' => $categories_tree_render
|
||||
),
|
||||
array(
|
||||
'type' => 'textarea',
|
||||
|
||||
Reference in New Issue
Block a user