partkeepr

fork of partkeepr
git clone https://git.e1e0.net/partkeepr.git
Log | Files | Refs | Submodules | README | LICENSE

commit 115f4745e96aa1e7ee93e8298d48c2c50cf7555f
parent e6e19264c405d8421c688dd6e8946dec76ea83a4
Author: Felicitus <felicitus@felicitus.org>
Date:   Sat,  1 Aug 2015 19:59:14 +0200

Implemented filtering by categories

Diffstat:
Msrc/PartKeepr/FrontendBundle/Resources/public/js/Components/Part/PartsManager.js | 42++++++++++++++++++++++++++++++++++++------
1 file changed, 36 insertions(+), 6 deletions(-)

diff --git a/src/PartKeepr/FrontendBundle/Resources/public/js/Components/Part/PartsManager.js b/src/PartKeepr/FrontendBundle/Resources/public/js/Components/Part/PartsManager.js @@ -57,12 +57,8 @@ Ext.define('PartKeepr.PartManager', { this.tree = Ext.create("PartKeepr.PartCategoryTree", treeConfig); // Trigger a grid reload on category change - this.tree.on("selectionchange", Ext.bind(function (t,s) { - if (s.length > 0) { - this.grid.setCategory(s[0].get("id")); - } - }, this)); - + this.tree.on("itemclick", this.onCategoryClick, this); + // Create the detail panel this.detail = Ext.create("PartKeepr.PartDisplay", { title: i18n("Part Details") }); this.detail.on("editPart", this.onEditPart, this); @@ -154,6 +150,40 @@ Ext.define('PartKeepr.PartManager', { this.callParent(); }, /** + * Applies the category filter to the store when a category is selected + * + * @param {Ext.tree.View} tree The tree view + * @param {Ext.data.Model} record the selected record + */ + onCategoryClick: function (tree, record) + { + var filter = Ext.create("Ext.util.Filter", { + property: 'category', + operator: 'IN', + value: this.getChildrenIds(record) + }); + + this.store.addFilter(filter); + }, + /** + * Returns the ID for this node and all child nodes + * + * @param {Ext.data.Model} The node + * @return Array + */ + getChildrenIds: function (node) + { + var childNodes = [node.getId()]; + + if (node.hasChildNodes()) { + for (var i = 0; i < node.childNodes.length; i++) { + childNodes = childNodes.concat(this.getChildrenIds(node.childNodes[i])); + } + } + + return childNodes; + }, + /** * Called when the sync button was clicked. Highlights the category * of the selected part for a short time. We can't select the category * as this would affect the parts grid.