partkeepr

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

PartDistributorGrid.js (6225B)


      1 Ext.define('PartKeepr.PartDistributorGrid', {
      2     extend: 'PartKeepr.BaseGrid',
      3     alias: 'widget.PartDistributorGrid',
      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.PartDistributor',
     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: 'web-icon lorry_delete',
     34             handler: this.onDeleteClick
     35         });
     36 
     37         this.dockedItems = [
     38             {
     39                 xtype: 'toolbar',
     40                 items: [
     41                     {
     42                         text: 'Add',
     43                         scope: this,
     44                         iconCls: 'web-icon lorry_add',
     45                         handler: this.onAddClick
     46                     }, this.deleteButton
     47                 ]
     48             }
     49         ];
     50 
     51         this.columns = [
     52             {
     53                 header: i18n("Distributor"),
     54                 dataIndex: 'distributor',
     55                 renderer: function (val, p, rec)
     56                 {
     57                     if (rec.getDistributor() !== null) {
     58                         return rec.getDistributor().get("name");
     59                     } else {
     60                         return null;
     61                     }
     62                 },
     63                 flex: 1,
     64                 editor: {
     65                     xtype: 'DistributorComboBox',
     66                     returnObject: true,
     67                     allowBlank: false
     68                 }
     69             }, {
     70                 header: i18n("Order Number"),
     71                 dataIndex: 'orderNumber',
     72                 flex: 1,
     73                 editor: {
     74                     xtype: 'textfield',
     75                     allowBlank: this.isOptional("orderNumber")
     76                 }
     77             }, {
     78                 header: i18n("Packaging Unit"),
     79                 dataIndex: 'packagingUnit',
     80                 flex: 1,
     81                 editor: {
     82                     xtype: 'numberfield',
     83                     allowDecimals: false,
     84                     allowBlank: false,
     85                     minValue: 1
     86                 }
     87             }, {
     88                 header: i18n("Price per Item"),
     89                 dataIndex: 'price',
     90                 flex: 1,
     91                 renderer: function (val,m,rec)
     92                 {
     93                     return PartKeepr.getApplication().formatCurrency(val, rec.get("currency"));
     94                 },
     95                 editor: {
     96                     xtype: 'CurrencyField',
     97                     allowBlank: false
     98                 }
     99             }, {
    100                 header: i18n("Currency"),
    101                 dataIndex: 'currency',
    102                 editor: {
    103                     xtype: 'combobox',
    104                     displayField: 'code',
    105                     valueField: 'code',
    106                     store: PartKeepr.getApplication().getCurrencyStore(),
    107                     forceSelection: true,
    108                     queryMode: 'local'
    109                 }
    110             }, {
    111                 header: i18n("Package Price"),
    112                 flex: 1,
    113                 dataIndex: 'packagePrice',
    114                 renderer: function (val, p, rec)
    115                 {
    116                     return PartKeepr.getApplication().formatCurrency(rec.get("price") * rec.get("packagingUnit"), rec.get("currency"));
    117                 }
    118             }, {
    119                 header: i18n("SKU"),
    120                 dataIndex: 'sku',
    121                 flex: 1,
    122                 editor: {
    123                     xtype: 'urltextfield',
    124                     allowBlank: this.isOptional("sku"),
    125                     triggerCls: 'x-form-trigger-link',
    126 
    127                     getUrl: function ()
    128                     {
    129                         var distributor = this.ownerCt.context.record.getDistributor();
    130 
    131                         if (distributor !== null) {
    132                             var skuurl = distributor.get("skuurl");
    133 
    134                             if (skuurl) {
    135                                 skuurl = skuurl.replace("%s", this.value);
    136                                 return skuurl;
    137                             }
    138                         }
    139 
    140                         return false;
    141                     }
    142                 }
    143             }, {
    144                 header: i18n("Pricing"),
    145                 dataIndex: 'distributor.enabledForReports',
    146                 width: 80,
    147                 renderers: [{
    148                     rtype: 'icon',
    149                     rendererConfig: {
    150                         iconCls: 'web-icon fugue-icon money-bag-dollar',
    151                         title: i18n("Distributor is used for price calculations")
    152                     }
    153                 }]
    154             }, {
    155                 header: i18n("Ignore"),
    156                 dataIndex: 'ignoreForReports',
    157                 tooltip: i18n("Ignore this entry for price calculations"),
    158                 width: 80,
    159                 xtype: 'checkcolumn'
    160             }
    161         ];
    162 
    163         this.callParent();
    164 
    165         this.getSelectionModel().on('selectionchange',
    166             this.onSelectChange,
    167             this);
    168     },
    169     onAddClick: function ()
    170     {
    171         this.editing.cancelEdit();
    172 
    173         var rec = Ext.create("PartKeepr.PartBundle.Entity.PartDistributor", {
    174             packagingUnit: 1
    175         });
    176 
    177         this.store.insert(0, rec);
    178 
    179         this.editing.startEdit(0, 0);
    180     },
    181     onDeleteClick: function ()
    182     {
    183         this.store.remove(this.getView().getSelectionModel().getSelection());
    184     },
    185     onSelectChange: function (selModel, selections)
    186     {
    187         this.deleteButton.setDisabled(selections.length === 0);
    188     },
    189     isOptional: function (field)
    190     {
    191         var fields = PartKeepr.getApplication().getSystemPreference("partkeepr.partDistributor.requiredFields", []);
    192 
    193         return !Ext.Array.contains(fields, field);
    194     }
    195 });