// Hide collapse and expand button when not necessary

This commit is contained in:
Jerome Nadaud
2013-11-14 19:21:31 +01:00
parent 051ed32133
commit 80957666cf
3 changed files with 39 additions and 16 deletions
+12
View File
@@ -11,6 +11,8 @@ Tree.prototype =
init: function () init: function ()
{ {
var that = $(this);
this.$element.find("label.tree-toggler").click( this.$element.find("label.tree-toggler").click(
function () function ()
{ {
@@ -19,12 +21,16 @@ Tree.prototype =
$(this).parent().children(".icon-folder-open") $(this).parent().children(".icon-folder-open")
.removeClass("icon-folder-open") .removeClass("icon-folder-open")
.addClass("icon-folder-close"); .addClass("icon-folder-close");
that.trigger('collapse');
} }
else else
{ {
$(this).parent().children(".icon-folder-close") $(this).parent().children(".icon-folder-close")
.removeClass("icon-folder-close") .removeClass("icon-folder-close")
.addClass("icon-folder-open"); .addClass("icon-folder-open");
that.trigger('expand');
} }
$(this).parent().parent().children("ul.tree").toggle(300); $(this).parent().parent().children("ul.tree").toggle(300);
} }
@@ -36,6 +42,8 @@ Tree.prototype =
$('li input:checked').parent().addClass("tree-selected"); $('li input:checked').parent().addClass("tree-selected");
} }
); );
return $(this);
}, },
collapseAll : function($speed) collapseAll : function($speed)
@@ -49,6 +57,8 @@ Tree.prototype =
$(this).parent().parent().children("ul.tree").hide($speed); $(this).parent().parent().children("ul.tree").hide($speed);
} }
); );
return $(this);
}, },
expandAll : function($speed) expandAll : function($speed)
@@ -62,6 +72,8 @@ Tree.prototype =
$(this).parent().parent().children("ul.tree").show($speed); $(this).parent().parent().children("ul.tree").show($speed);
} }
); );
return $(this);
}, },
}; };
@@ -80,7 +80,17 @@
}); });
{/if} {/if}
$(document).ready(function () { $(document).ready(function () {
$("#{$id}").tree("collapseAll"); var tree = $("#{$id}").tree("collapseAll");
tree.on('collapse', function() {
$('#expand-all-{$id}').show();
});
tree.on('expand', function() {
$('#collapse-all-{$id}').show();
});
$('#collapse-all-{$id}').hide();
$("#{$id}").find(":input[type=radio]").click( $("#{$id}").find(":input[type=radio]").click(
function() function()
{ {
+16 -15
View File
@@ -212,36 +212,37 @@ class HelperTreeCategoriesCore extends TreeCore
$this->setAttribute('use_search', $this->useSearch()); $this->setAttribute('use_search', $this->useSearch());
} }
$this->addAction(new TreeToolbarLink( $collapse_all = new TreeToolbarLink(
'Collapse All', 'Collapse All',
'#', '#',
'$(\'#'.$this->getId().'\').tree(\'collapseAll\')', '$(\'#'.$this->getId().'\').tree(\'collapseAll\');$(\'#collapse-all-'.$this->getId().'\').hide();$(\'#expand-all-'.$this->getId().'\').show();',
'icon-collapse-alt') 'icon-collapse-alt');
); $collapse_all->setAttribute('id', 'collapse-all-'.$this->getId());
$expand_all = new TreeToolbarLink(
$this->addAction(new TreeToolbarLink(
'Expand All', 'Expand All',
'#', '#',
'$(\'#'.$this->getId().'\').tree(\'expandAll\')', '$(\'#'.$this->getId().'\').tree(\'expandAll\');$(\'#collapse-all-'.$this->getId().'\').show();$(\'#expand-all-'.$this->getId().'\').hide();',
'icon-expand-alt') 'icon-expand-alt');
); $expand_all->setAttribute('id', 'expand-all-'.$this->getId());
$this->addAction($collapse_all);
$this->addAction($expand_all);
if ($this->useCheckBox()) if ($this->useCheckBox())
{ {
$checkAll = new TreeToolbarLink( $check_all = new TreeToolbarLink(
'Check All', 'Check All',
'#', '#',
'checkAllAssociatedCategories($(\'#'.$this->getId().'\'));', 'checkAllAssociatedCategories($(\'#'.$this->getId().'\'));',
'icon-check-sign'); 'icon-check-sign');
$checkAll->setAttribute('id', 'check-all-'.$this->getId()); $check_all->setAttribute('id', 'check-all-'.$this->getId());
$unCheckAll = new TreeToolbarLink( $uncheck_all = new TreeToolbarLink(
'Uncheck All', 'Uncheck All',
'#', '#',
'uncheckAllAssociatedCategories($(\'#'.$this->getId().'\'));', 'uncheckAllAssociatedCategories($(\'#'.$this->getId().'\'));',
'icon-check-empty'); 'icon-check-empty');
$unCheckAll->setAttribute('id', 'uncheck-all-'.$this->getId()); $uncheck_all->setAttribute('id', 'uncheck-all-'.$this->getId());
$this->addAction($checkAll); $this->addAction($check_all);
$this->addAction($unCheckAll); $this->addAction($uncheck_all);
$this->setNodeFolderTemplate('tree_node_folder_checkbox.tpl'); $this->setNodeFolderTemplate('tree_node_folder_checkbox.tpl');
$this->setNodeItemTemplate('tree_node_item_checkbox.tpl'); $this->setNodeItemTemplate('tree_node_item_checkbox.tpl');
$this->setAttribute('use_checkbox', $this->useCheckBox()); $this->setAttribute('use_checkbox', $this->useCheckBox());