partkeepr

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

commit 1a125c41ecf5675c533d8004d23fcca0b8d5eece
parent 03b5db3e0607b4824d22aa393410fc077b770b15
Author: Felicitus <felicitus@felicitus.org>
Date:   Mon, 20 Jul 2015 00:45:42 +0200

Filter by the children IDs, refactored hardcoded root node URL to dynamic URL

Diffstat:
Msrc/PartKeepr/FrontendBundle/Resources/public/js/Components/Footprint/FootprintNavigation.js | 38++++++++++++++++++++++++++++++++++----
1 file changed, 34 insertions(+), 4 deletions(-)

diff --git a/src/PartKeepr/FrontendBundle/Resources/public/js/Components/Footprint/FootprintNavigation.js b/src/PartKeepr/FrontendBundle/Resources/public/js/Components/Footprint/FootprintNavigation.js @@ -34,7 +34,7 @@ Ext.define("PartKeepr.FootprintNavigation", { direction: 'ASC' }], root: { - "@id": "/~felicitus/PartKeepr/web/app_dev.php/api/footprint_categories/1" + "@id": PartKeepr.FootprintBundle.Entity.FootprintCategory.getProxy().getConfig("url") + "/1" }, model: "PartKeepr.FootprintBundle.Entity.FootprintCategory", proxy: { @@ -62,23 +62,46 @@ Ext.define("PartKeepr.FootprintNavigation", { ); }, + /** + * 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: '=', - value: record.getId() + 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 a footprint is about to be added. This prepares the to-be-edited record with the proper category id. */ onAddFootprint: function () { var selection = this.down("partkeepr\\.FootprintTree").getSelection(); var category; - if (selection.length == 0) { + if (selection.length === 0) { category = this.down("partkeepr\\.FootprintTree").getRootNode().getId(); } else { var item = selection.shift(); @@ -89,9 +112,16 @@ Ext.define("PartKeepr.FootprintNavigation", { category: category }); }, + /** + * Triggers a reload of the store when an edited record affects the store + */ syncChanges: function () { this.down("partkeepr\\.FootprintGrid").getStore().load(); }, + /** + * Returns the selection model of the footprint grid + * @return {Ext.selection.Model} The selection model + */ getSelectionModel: function () { "use strict"; return this.down("partkeepr\\.FootprintGrid").getSelectionModel();