// Categories tree
This commit is contained in:
1 parent
0ff6b25f56
commit
49c9afec40
9 files changed
+89
-50
No files matched your search
+10
-15
@@ -22,18 +22,13 @@
|
|||||||
* @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> <input type="text"{if isset($id)} id="{$id}"{/if}{if isset($name)} name="{$name}"{/if}{if isset($class)} class="{$class}"{/if} />
|
<li class="tree-folder">
|
||||||
{if isset($typeahead_source) && isset($id)}
|
<span class="tree-folder-name{if isset($node['disabled']) && $node['disabled'] == true} tree-folder-name-disable{/if}">
|
||||||
<script type="text/javascript">
|
<input type="radio" name="id_parent" value="{$node['id_category']}"{if isset($node['disabled']) && $node['disabled'] == true} disabled="disabled"{/if} />
|
||||||
$(document).ready(
|
<i class="icon-folder-close"></i>
|
||||||
function()
|
<label class="tree-toggler ">{$node['name']}</label>
|
||||||
{
|
</span>
|
||||||
$("#{$id}").typeahead(
|
<ul class="tree">
|
||||||
{
|
{$children}
|
||||||
name: "{$name}",
|
</ul>
|
||||||
local: [{$typeahead_source}]
|
</li>
|
||||||
});
|
|
||||||
}
|
|
||||||
);
|
|
||||||
</script>
|
|
||||||
{/if}
|
|
||||||
+7
-3
@@ -22,6 +22,10 @@
|
|||||||
* @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}"{if isset($action)}onclick="{$action}"{/if} class="btn btn-default btn-xs">
|
<li class="tree-item">
|
||||||
{if isset($icon_class)}<i class="{$icon_class}"></i> {/if}{l s=$label}
|
<label class="tree-item-name{if isset($node['disabled']) && $node['disabled'] == true} tree-item-name-disable{/if}">
|
||||||
</a>
|
<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'}
|
{elseif $input.type == 'shop'}
|
||||||
{$input.html}
|
{$input.html}
|
||||||
{elseif $input.type == 'categories'}
|
{elseif $input.type == 'categories'}
|
||||||
{include file='helpers/form/form_category.tpl' categories=$input.values}
|
{$categories_tree}
|
||||||
{elseif $input.type == 'categories_select'}
|
{elseif $input.type == 'categories_select'}
|
||||||
{$input.category_tree}
|
{$input.category_tree}
|
||||||
{elseif $input.type == 'asso_shop' && isset($asso_shop) && $asso_shop}
|
{elseif $input.type == 'asso_shop' && isset($asso_shop) && $asso_shop}
|
||||||
|
|||||||
File renamed without changes.
File renamed without changes.
File renamed without changes.
@@ -477,15 +477,19 @@ class CategoryCore extends ObjectModel
|
|||||||
return $categories;
|
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 = '',
|
$id_lang = false, $active = true, $sql_filter = '', $sql_sort = '',
|
||||||
$sql_limit = '')
|
$sql_limit = '')
|
||||||
{
|
{
|
||||||
|
if (!isset($root_category))
|
||||||
|
$root_category = self::getRootCategory($id_lang)->id;
|
||||||
|
|
||||||
if (!Validate::isInt($root_category))
|
if (!Validate::isInt($root_category))
|
||||||
die(Tools::displayError());
|
die(Tools::displayError());
|
||||||
|
|
||||||
if (!Validate::isBool($active))
|
if (!Validate::isBool($active))
|
||||||
die(Tools::displayError());
|
die(Tools::displayError());
|
||||||
|
|
||||||
$result = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS('
|
$result = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS('
|
||||||
SELECT *
|
SELECT *
|
||||||
FROM `'._DB_PREFIX_.'category` c
|
FROM `'._DB_PREFIX_.'category` c
|
||||||
|
|||||||
@@ -89,16 +89,7 @@ class HelperFormCore extends Helper
|
|||||||
case 'categories':
|
case 'categories':
|
||||||
if ($categories)
|
if ($categories)
|
||||||
{
|
{
|
||||||
// Added Jquery plugin treeview (css and js files)
|
$this->context->smarty->assign('categories_tree', $params['categories_tree']);
|
||||||
$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');
|
|
||||||
$categories = false;
|
$categories = false;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|||||||
@@ -335,12 +335,27 @@ 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_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'));
|
$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'));
|
||||||
@@ -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>');
|
$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>');
|
||||||
$root_category = Category::getRootCategory();
|
$categories = Category::getNestedCategories(
|
||||||
$root_category = array('id_category' => $root_category->id, 'name' => $root_category->name);
|
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(
|
$this->fields_form = array(
|
||||||
'tinymce' => true,
|
'tinymce' => true,
|
||||||
'legend' => array(
|
'legend' => array(
|
||||||
@@ -386,24 +445,10 @@ class AdminCategoriesControllerCore extends AdminController
|
|||||||
)
|
)
|
||||||
),
|
),
|
||||||
array(
|
array(
|
||||||
'type' => 'categories',
|
'type' => 'categories',
|
||||||
'label' => $this->l('Parent category:'),
|
'label' => $this->l('Parent category:'),
|
||||||
'name' => 'id_parent',
|
'name' => 'id_parent',
|
||||||
'values' => array(
|
'categories_tree' => $categories_tree_render
|
||||||
'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,
|
|
||||||
)
|
|
||||||
),
|
),
|
||||||
array(
|
array(
|
||||||
'type' => 'textarea',
|
'type' => 'textarea',
|
||||||
|
|||||||
Reference in new issue
Block a user