partkeepr

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

GridPresetButton.js (1687B)


      1 Ext.define("PartKeepr.Components.Grid.GridPresetButton", {
      2     extend: "Ext.button.Button",
      3 
      4     iconCls: 'fugue-icon folder-open-table',
      5     tooltip: i18n("Choose preset…"),
      6     overflowText: i18n("Choose preset…"),
      7 
      8     grid: null,
      9 
     10     initComponent: function ()
     11     {
     12         this.menu = Ext.create("Ext.ux.menu.StoreMenu", {
     13             model: "PartKeepr.FrontendBundle.Entity.GridPreset",
     14             nameField: 'name',
     15             items: [{
     16                 text: i18n("Default"),
     17                 iconCls: "fugue-icon inbox-table",
     18                 default: true
     19             }],
     20             offset: 2,
     21             listeners: {
     22                 click: this.onPresetSelect,
     23                 scope: this
     24             }
     25         });
     26         this.callParent(arguments);
     27 
     28         if (this.grid !== null) {
     29             this.setGrid(this.grid);
     30         }
     31     },
     32     setGrid: function (grid)
     33     {
     34         this.menu.store.setFilters();
     35         this.menu.store.addFilter({
     36             property: "grid",
     37             operator: "=",
     38             value: grid.$className
     39         });
     40 
     41         this.grid = grid;
     42     },
     43     onPresetSelect: function (menu, item)
     44     {
     45         var config;
     46 
     47         if (item.default)
     48         {
     49             config = this.grid.getDefaultColumnConfiguration();
     50             this.grid.reconfigure(this.grid.store, config);
     51             return;
     52         }
     53         var matchedIndex = this.menu.store.findExact("name", item.text);
     54 
     55         if (matchedIndex !== -1)
     56         {
     57             var record = this.menu.store.getAt(matchedIndex);
     58             config = Ext.decode(record.get("configuration"));
     59 
     60             this.grid.reconfigure(this.grid.store, config);
     61         }
     62     }
     63 });