partkeepr

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

PartManufacturerGrid.js (3180B)


      1 Ext.define('PartKeepr.PartManufacturerGrid', {
      2     extend: 'PartKeepr.BaseGrid',
      3     alias: 'widget.PartManufacturerGrid',
      4     border: false,
      5     selModel: {
      6         selType: 'rowmodel',
      7         mode: 'MULTI'
      8     },
      9     initComponent: function ()
     10     {
     11         this.store = Ext.create("Ext.data.Store", {
     12             model: 'PartKeepr.PartBundle.Entity.PartManufacturer',
     13             proxy: {
     14                 type: 'memory',
     15                 reader: {
     16                     type: 'json'
     17                 }
     18             }
     19 
     20         });
     21 
     22         this.editing = Ext.create('Ext.grid.plugin.RowEditing', {
     23             clicksToEdit: 2
     24         });
     25 
     26         this.plugins = [this.editing];
     27 
     28         this.deleteButton = Ext.create("Ext.button.Button", {
     29             text: 'Delete',
     30             disabled: true,
     31             itemId: 'delete',
     32             scope: this,
     33             iconCls: 'fugue-icon building--minus',
     34             handler: this.onDeleteClick
     35         });
     36 
     37         this.dockedItems = [
     38             {
     39                 xtype: 'toolbar',
     40                 items: [
     41                     {
     42                         text: 'Add',
     43                         scope: this,
     44                         iconCls: 'fugue-icon building--plus',
     45                         handler: this.onAddClick
     46                     }, this.deleteButton
     47                 ]
     48             }
     49         ];
     50 
     51         this.columns = [
     52             {
     53                 header: i18n("Manufacturer"),
     54                 dataIndex: 'manufacturer',
     55                 flex: 0.4,
     56                 renderer: function (val, p, rec)
     57                 {
     58                     if (rec.getManufacturer() !== null) {
     59                         return rec.getManufacturer().get("name");
     60                     } else {
     61                         return null;
     62                     }
     63                 },
     64                 editor: {
     65                     xtype: 'ManufacturerComboBox',
     66                     allowBlank: true,
     67                     returnObject: true
     68                 }
     69             },
     70             {
     71                 header: i18n("Part Number"),
     72                 dataIndex: 'partNumber',
     73                 flex: 0.4,
     74                 editor: {
     75                     xtype: 'textfield',
     76                     allowBlank: this.isOptional("partNumber")
     77                 }
     78             }
     79         ];
     80 
     81         this.callParent();
     82 
     83         this.getSelectionModel().on('selectionchange', this.onSelectChange, this);
     84     },
     85     onAddClick: function ()
     86     {
     87         this.editing.cancelEdit();
     88 
     89         var rec = Ext.create("PartKeepr.PartBundle.Entity.PartManufacturer");
     90 
     91         this.store.insert(0, rec);
     92 
     93         this.editing.startEdit(0, 0);
     94     },
     95     onDeleteClick: function ()
     96     {
     97        this.store.remove(this.getView().getSelectionModel().getSelection());
     98     },
     99     onSelectChange: function (selModel, selections)
    100     {
    101         this.deleteButton.setDisabled(selections.length === 0);
    102     },
    103     isOptional: function (field)
    104     {
    105         var fields = PartKeepr.getApplication().getSystemPreference("partkeepr.partManufacturer.requiredFields", []);
    106 
    107         if (Ext.Array.contains(fields, field)) {
    108             return false;
    109         } else {
    110             return true;
    111         }
    112     }
    113 });