partkeepr

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

FootprintNavigation.js (3549B)


      1 Ext.define("PartKeepr.FootprintNavigation", {
      2     extend: 'Ext.panel.Panel',
      3 
      4     layout: 'border',
      5 
      6     /**
      7      * @var {Ext.data.Store}
      8      */
      9     store: null,
     10 
     11     initComponent: function ()
     12     {
     13         this.items = [
     14             {
     15                 xtype: 'partkeepr.FootprintTree',
     16                 region: 'center',
     17                 rootVisible: false
     18             }, {
     19                 xtype: 'partkeepr.FootprintGrid',
     20                 resizable: true,
     21                 split: true,
     22                 store: this.store,
     23                 region: 'south',
     24                 height: "50%",
     25                 titleProperty: "name",
     26                 viewConfig: {
     27                     plugins: {
     28                         ddGroup: 'FootprintCategoryTree',
     29                         ptype: 'gridviewdragdrop',
     30                         enableDrop: false
     31                     }
     32                 },
     33                 enableDragDrop: true,
     34 
     35             }
     36         ];
     37 
     38         this.callParent(arguments);
     39 
     40         this.down("partkeepr\\.FootprintTree").on("itemclick", this.onCategoryClick, this);
     41         this.down("partkeepr\\.FootprintGrid").on("itemAdd", this.onAddFootprint, this);
     42         this.down("partkeepr\\.FootprintGrid").on("itemDelete", function (id)
     43             {
     44                 this.fireEvent("itemDelete", id);
     45             }, this
     46         );
     47         this.down("partkeepr\\.FootprintGrid").on("itemEdit", function (id)
     48             {
     49                 this.fireEvent("itemEdit", id);
     50             }, this
     51         );
     52 
     53     },
     54     /**
     55      * Applies the category filter to the store when a category is selected
     56      *
     57      * @param {Ext.tree.View} tree The tree view
     58      * @param {Ext.data.Model} record the selected record
     59      */
     60     onCategoryClick: function (tree, record)
     61     {
     62         var filter = Ext.create("PartKeepr.util.Filter", {
     63             property: 'category',
     64             operator: 'IN',
     65             value: this.getChildrenIds(record)
     66         });
     67 
     68         this.store.addFilter(filter);
     69     },
     70     /**
     71      * Returns the ID for this node and all child nodes
     72      *
     73      * @param {Ext.data.Model} The node
     74      * @return Array
     75      */
     76     getChildrenIds: function (node)
     77     {
     78         var childNodes = [node.getId()];
     79 
     80         if (node.hasChildNodes()) {
     81             for (var i = 0; i < node.childNodes.length; i++) {
     82                 childNodes = childNodes.concat(this.getChildrenIds(node.childNodes[i]));
     83             }
     84         }
     85 
     86         return childNodes;
     87     },
     88     /**
     89      * Called when a footprint is about to be added. This prepares the to-be-edited record with the proper category id.
     90      */
     91     onAddFootprint: function ()
     92     {
     93         var selection = this.down("partkeepr\\.FootprintTree").getSelection();
     94 
     95         var category;
     96         if (selection.length === 0) {
     97             category = this.down("partkeepr\\.FootprintTree").getRootNode().firstChild.getId();
     98         } else {
     99             var item = selection.shift();
    100             category = item.getId();
    101         }
    102 
    103         this.fireEvent("itemAdd", {
    104             category: category
    105         });
    106     },
    107     /**
    108      * Triggers a reload of the store when an edited record affects the store
    109      */
    110     syncChanges: function ()
    111     {
    112         this.down("partkeepr\\.FootprintGrid").getStore().load();
    113     },
    114     /**
    115      * Returns the selection model of the footprint grid
    116      * @return {Ext.selection.Model} The selection model
    117      */
    118     getSelectionModel: function ()
    119     {
    120         "use strict";
    121         return this.down("partkeepr\\.FootprintGrid").getSelectionModel();
    122     }
    123 
    124 
    125 });