partkeepr

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

ProjectEditor.js (3791B)


      1 /**
      2  * Represents the project editor view
      3  */
      4 Ext.define('PartKeepr.ProjectEditor', {
      5     extend: 'PartKeepr.Editor',
      6     alias: 'widget.ProjectEditor',
      7 
      8     // Various style configurations
      9     saveText: i18n("Save Project"),
     10     defaults: {
     11         anchor: '100%',
     12         labelWidth: 110
     13     },
     14     layout: {
     15         type: 'vbox',
     16         align: 'stretch',
     17         pack: 'start'
     18     },
     19 
     20     /**
     21      * Initializes the component
     22      */
     23     initComponent: function ()
     24     {
     25         /**
     26          * Due to an ExtJS issue, we need to delay the event
     27          * for a bit.
     28          *
     29          * @todo Fix this in a cleaner way
     30          */
     31         this.on("startEdit", this.onEditStart, this, {
     32             delay: 200
     33         });
     34 
     35         this.on("itemSaved", this._onItemSaved, this);
     36 
     37         var config = {};
     38 
     39         // Build the initial (empty) store for the project parts
     40         Ext.Object.merge(config, {
     41             autoLoad: false,
     42             model: "PartKeepr.ProjectBundle.Entity.ProjectPart",
     43             autoSync: false, // Do not change. If true, new (empty) records would be immediately committed to the database.
     44             remoteFilter: false,
     45             remoteSort: false
     46         });
     47 
     48         this.store = Ext.create('Ext.data.Store', config);
     49 
     50         this.partGrid = Ext.create("PartKeepr.ProjectPartGrid", {
     51             store: this.store,
     52             listeners: {
     53                 edit: this.onProjectGridEdit
     54             }
     55         });
     56 
     57         var container = Ext.create("Ext.form.FieldContainer", {
     58             fieldLabel: i18n("Project Parts"),
     59             labelWidth: 110,
     60             layout: 'fit',
     61             flex: 1,
     62             items: this.partGrid
     63         });
     64 
     65         this.attachmentGrid = Ext.create("PartKeepr.ProjectAttachmentGrid", {
     66             border: true
     67         });
     68 
     69         var container2 = Ext.create("Ext.form.FieldContainer", {
     70             fieldLabel: i18n("Attachments"),
     71             labelWidth: 110,
     72             layout: 'fit',
     73             flex: 1,
     74             items: this.attachmentGrid
     75         });
     76 
     77         this.items = [
     78             {
     79                 xtype: 'textfield',
     80                 name: 'name',
     81                 height: 20,
     82                 fieldLabel: i18n("Project Name")
     83             }, {
     84                 xtype: 'textarea',
     85                 name: 'description',
     86                 fieldLabel: i18n("Project Description"),
     87                 height: 70
     88             },
     89             container,
     90             container2
     91         ];
     92         this.callParent();
     93 
     94     },
     95     /**
     96      * Handle transparent setting of the part name after a value was selected from the combobox
     97      */
     98     onProjectGridEdit: function (editor, e)
     99     {
    100         if (e.field == "part_id") {
    101             /**
    102              * If the user cancelled the editing, set the field to the original value
    103              */
    104             if (e.value === null) {
    105                 e.record.set("part_id", e.originalValue);
    106             }
    107 
    108             /**
    109              * Inject the name into the record
    110              */
    111             var rec = e.column.getEditor().store.getById(e.value);
    112             if (rec) {
    113                 e.record.set("part_name", rec.get("name"));
    114             }
    115         }
    116     },
    117     /**
    118      * Re-bind the store after an item was saved
    119      */
    120     _onItemSaved: function (record)
    121     {
    122         this.partGrid.bindStore(record.parts());
    123         this.attachmentGrid.bindStore(record.attachments());
    124     },
    125     /**
    126      * Bind the store as soon as the view was rendered.
    127      *
    128      * @todo This is a hack, because invocation of this method is delayed.
    129      */
    130     onEditStart: function ()
    131     {
    132         var store = this.record.parts();
    133         this.partGrid.bindStore(store);
    134 
    135         var store2 = this.record.attachments();
    136         this.attachmentGrid.bindStore(store2);
    137     }
    138 });