partkeepr

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

StorageLocationEditor.js (4697B)


      1 Ext.define('PartKeepr.StorageLocationEditor', {
      2     extend: 'PartKeepr.Editor',
      3     alias: 'widget.StorageLocationEditor',
      4     saveText: i18n("Save Storage Location"),
      5 
      6     layout: 'column',
      7     defaultListenerScope: true,
      8 
      9     initComponent: function ()
     10     {
     11         var config = {};
     12 
     13         Ext.Object.merge(config, {
     14             autoLoad: false,
     15             model: "PartKeepr.PartBundle.Entity.Part",
     16             autoSync: false, // Do not change. If true, new (empty) records would be immediately commited to the database.
     17             remoteFilter: true,
     18             remoteSort: true,
     19             pageSize: 15
     20         });
     21 
     22         this.store = Ext.create('Ext.data.Store', config);
     23 
     24         this.bottomToolbar = Ext.create("PartKeepr.PagingToolbar", {
     25             store: this.store,
     26             enableOverflow: true,
     27             dock: 'bottom',
     28             displayInfo: false
     29         });
     30 
     31         this.gridPanel = Ext.create("PartKeepr.BaseGrid", {
     32             store: this.store,
     33             columnLines: true,
     34             dockedItems: [this.bottomToolbar],
     35             columns: [
     36                 {
     37                     header: i18n("Name"),
     38                     dataIndex: 'name',
     39                     flex: 1,
     40                     minWidth: 200,
     41                     renderer: Ext.util.Format.htmlEncode
     42                 },
     43                 {
     44                     header: i18n("Qty"),
     45                     width: 50,
     46                     dataIndex: 'stockLevel'
     47                 }
     48             ]
     49         });
     50 
     51 	this.gridPanel.on("itemdblclick", this.onDoubleClick, this);
     52 
     53         var container = Ext.create("Ext.form.FieldContainer", {
     54             fieldLabel: i18n("Contained Parts"),
     55             labelWidth: 110,
     56             layout: 'fit',
     57             height: 246,
     58             itemId: 'containedParts',
     59             items: this.gridPanel
     60         });
     61 
     62 
     63         this.items = [
     64             {
     65                 columnWidth: 1,
     66                 minWidth: 500,
     67                 layout: 'anchor',
     68                 xtype: 'container',
     69                 margin: '0 5 0 0',
     70                 items: [
     71                     {
     72                         xtype: 'textfield',
     73                         name: 'name',
     74                         anchor: '100%',
     75                         labelWidth: 110,
     76                         fieldLabel: i18n("Storage Location")
     77                     },
     78                     container
     79                 ]
     80             }, {
     81                 width: 370,
     82                 height: 250,
     83                 xtype: 'fieldcontainer',
     84                 items: {
     85                     xtype: 'remoteimagefield',
     86                     itemId: 'image',
     87                     maxHeight: 256,
     88                     maxWidth: 256,
     89                     listeners: {
     90                         'fileUploaded': "onFileUploaded"
     91                     }
     92                 },
     93                 labelWidth: 75,
     94                 fieldLabel: i18n("Image")
     95             }
     96         ];
     97 
     98         this.on("startEdit", this.onStartEdit, this);
     99         this.callParent();
    100     },
    101     onFileUploaded: function (data)
    102     {
    103         var uploadedFile = Ext.create("PartKeepr.UploadedFileBundle.Entity.TempUploadedFile", data);
    104 
    105         if (this.record.getImage() === null) {
    106             this.record.setImage(data);
    107         } else {
    108             this.record.getImage().set("replacement", uploadedFile.getId());
    109         }
    110 
    111         this.down('#image').setValue(uploadedFile);
    112     },
    113     /**
    114      * Gets called as soon as storage location editing begins.
    115      */
    116     onStartEdit: function ()
    117     {
    118         if (!this.record.phantom) {
    119             this.down('#containedParts').setVisible(true);
    120             var filter = Ext.create("PartKeepr.util.Filter", {
    121                 property: "storageLocation",
    122                 operator: "=",
    123                 value: this.record.getId()
    124             });
    125 
    126             this.store.addFilter(filter);
    127             this.store.load();
    128         } else {
    129             this.down('#containedParts').setVisible(false);
    130         }
    131 
    132 
    133         this.down('#image').setValue(this.record.getImage());
    134     },
    135     onDoubleClick: function(view, record) {
    136         if (record) {
    137             this.onEditPart(record);
    138         }
    139     },
    140     onEditPart: function(part) {
    141         var editorWindow;
    142 
    143         if (part.get("metaPart") === true)
    144         {
    145             editorWindow = Ext.create("PartKeepr.Components.Part.Editor.MetaPartEditorWindow");
    146         } else
    147         {
    148             editorWindow = Ext.create("PartKeepr.PartEditorWindow");
    149         }
    150         editorWindow.on("partSaved", this.onPartSaved, this);
    151         editorWindow.editor.editItem(part);
    152         editorWindow.show();
    153     },
    154     onPartSaved: function() {
    155         this.grid.getStore().reload();
    156     }
    157 });