[Lada-commits] [PATCH 1 of 3] enabled removal and creation of messgroessen for a messmethode

Wald Commits scm-commit at wald.intevation.org
Tue May 12 15:09:23 CEST 2015


# HG changeset patch
# User Dustin Demuth <dustin at intevation.de>
# Date 1431433481 -7200
# Node ID 31eaed998531e51ae562edb8c250720eeb148a1d
# Parent  62721a75d31db247a7e8944c276d29637b4deaff
enabled removal and creation of messgroessen for a messmethode

diff -r 62721a75d31d -r 31eaed998531 app/controller/grid/Messmethode.js
--- a/app/controller/grid/Messmethode.js	Fri May 08 16:12:01 2015 +0200
+++ b/app/controller/grid/Messmethode.js	Tue May 12 14:24:41 2015 +0200
@@ -11,6 +11,7 @@
  */
 Ext.define('Lada.controller.grid.Messmethode', {
     extend: 'Ext.app.Controller',
+    record: null,
 
     /**
      * Inhitialize the controller
@@ -28,6 +29,17 @@
             },
             'messmethodengrid button[action=delete]': {
                 click: this.remove
+            },
+            //Nuklidegrid
+            'nuklidegrid': {
+                edit: this.gridSaveNuklid,
+                canceledit: this.cancelEdit
+            },
+            'nuklidegrid button[action=add]': {
+                click: this.addNuklid
+            },
+            'nuklidegrid button[action=remove]': {
+                click: this.removeNuklid
             }
         });
     },
@@ -39,7 +51,6 @@
      * On failure it displays a message
      */
      gridSave: function(editor, context) {
-        console.log(context);
         context.record.save({
             success: function() {
                 context.grid.initData();
@@ -65,10 +76,23 @@
     },
 
     /**
+     * This function is called when the Nuklide-grids roweditor saves
+     * the record.
+     * It adds the nuklid to the messgroessen-array of the messmethode
+     * record.
+     * On success it refreshes the windows which contains the grid
+     * On failure it displays a message
+     */
+    gridSaveNuklid: function(editor, context) {
+        console.log(context);
+        this.syncArray(context.store);
+    },
+
+    /**
      * When the edit was canceled,
      * the empty row might have been created by the roweditor is removed
      */
-     cancelEdit: function(editor, context) {
+    cancelEdit: function(editor, context) {
         if (!context.record.get('id') ||
             context.record.get('id') === '') {
             editor.getCmp().store.remove(context.record);
@@ -82,25 +106,109 @@
      * Messmethod
      */
     selectRow: function(row, record, index) {
+        //save the record to this object. which makes it accessible
+        //for nuklideGrid releated functions.
+        this.record = record;
+        var nuklide = record.get('messgroessen');
+
         var ngrid = row.view.up('window').down('nuklidegrid');
-        var nuklide = record.get('messgroessen');
+
+        var mmtmessgroessenstore = this.buildNuklideStore(nuklide);
+        //Set Store
+        ngrid.setData(mmtmessgroessenstore);
+
+        //Enable Editing
+        ngrid.setReadOnly(false);
+    },
+
+    /**
+     * This function syncs the Messmethoden-Messgroessen Array
+     * With the Nuklide Store.
+     * It simply overwrites the Array
+     */
+    syncArray: function(store) {
+        var mg = new Array();
+        console.log('syncarray');
+        console.log(store);
+        var item;
+        for (item in store.data.items){
+            mg.push(store.data.items[item].get('id'));
+        }
+
+        // Ext.Array.contains(mg, id[i])
+        this.record.set('messgroessen', mg);
+        var me = this;
+        this.record.save({
+            success: function() {
+                console.log('Success');
+                console.log(me.record.get('messgroessen'));
+                console.log(mg);
+            },
+            failure: function(request, response) {
+                var json = response.request.scope.reader.jsonData;
+                if (json) {
+                    if (json.message){
+                        Ext.Msg.alert(Lada.getApplication().bundle.getMsg('err.msg.save.title')
+                            +' #'+json.message,
+                            Lada.getApplication().bundle.getMsg(json.message));
+                    } else {
+                        Ext.Msg.alert(Lada.getApplication().bundle.getMsg('err.msg.save.title'),
+                            Lada.getApplication().bundle.getMsg('err.msg.generic.body'));
+                    }
+                } else {
+                    Ext.Msg.alert(Lada.getApplication().bundle.getMsg('err.msg.save.title'),
+                        Lada.getApplication().bundle.getMsg('err.msg.response.body'));
+                }
+            }
+        });
+
+    },
+
+    /**
+     * Return a MessgroessenStore created from nuklide array
+     */
+    buildNuklideStore: function(nuklide) {
+        // Create a fully populated Messgroessen Store
         var store = Ext.data.StoreManager.get('messgroessen');
         if (!store) {
             store = Ext.create('Lada.store.Messgroessen');
         }
-        //get selection model
-        var selectedRecords = [];
-        //iterate store and slecet all records which are in nuklide array
-        store.each(function(record){
-            //TODO if(record.get('id') in nuklide){
-                selectedRecords.push(record);
-            //TODO}
+
+        //Create an empty Messgroessen Store which will be populated with the
+        //Messgroessen defined in the Messmethoden record.
+        var mmtmessgroessenstore = Ext.create('Ext.data.Store', {
+            model: 'Lada.model.Messgroesse',
         });
-        ngrid.setData(store);
 
-        var selModel = ngrid.getSelectionModel();
-        console.log(selModel);
-        selModel.select(selectedRecords, false, false);
+        // Copy every Record from Messgroessenstore to the empty Store
+        // which was defined in the messmethode record
+        for (n in nuklide) {
+            mmtmessgroessenstore.add(store.getById(nuklide[n]));
+        }
+        return mmtmessgroessenstore;
+    },
+
+    /**
+     * This function adds a new row in the NuklidGrid
+     */
+    addNuklid: function(button) {
+        var record = Ext.create('Lada.model.Messgroesse');
+        button.up('nuklidegrid').store.insert(0, record);
+        button.up('nuklidegrid').rowEditing.startEdit(0, 0);
+    },
+
+    /**
+     * A row can be removed from the Nuklidgrid with the remove
+     * function. It asks the user for confirmation
+     * If the removal was confirmed, it reloads the parent window on success,
+     * on failure, an error message is shown.
+     */
+    removeNuklid: function(button) {
+        var grid = button.up('grid');
+        var selection = grid.getView().getSelectionModel().getSelection()[0];
+        grid.getStore().remove(selection);
+        var store = grid.getStore();
+        this.syncArray(store);
     },
 
     /**
diff -r 62721a75d31d -r 31eaed998531 app/model/Messgroesse.js
--- a/app/model/Messgroesse.js	Fri May 08 16:12:01 2015 +0200
+++ b/app/model/Messgroesse.js	Tue May 12 14:24:41 2015 +0200
@@ -40,14 +40,7 @@
         name: 'kennungBvl'
     }],
 
-    idProperty: 'id',
-
-    proxy: {
-        type: 'rest',
-        url: 'lada-server/messgroesse',
-        reader: {
-            type: 'json',
-            root: 'data'
-        }
-    }
+    idProperty: 'id'
+    // other models contain the proxy-configuration at this point.
+    // we don't. You can find the Proxy in in the Store: Lada.store.Messgroessen
 });
diff -r 62721a75d31d -r 31eaed998531 app/store/Messgroessen.js
--- a/app/store/Messgroessen.js	Fri May 08 16:12:01 2015 +0200
+++ b/app/store/Messgroessen.js	Tue May 12 14:24:41 2015 +0200
@@ -22,5 +22,15 @@
             return '';
         }
     }],
-    autoLoad: true
+    autoLoad: true,
+
+    proxy: {
+        type: 'rest',
+        url: 'lada-server/messgroesse',
+        reader: {
+            type: 'json',
+            root: 'data'
+        }
+    }
+
 });
diff -r 62721a75d31d -r 31eaed998531 app/view/grid/Messmethoden.js
--- a/app/view/grid/Messmethoden.js	Fri May 08 16:12:01 2015 +0200
+++ b/app/view/grid/Messmethoden.js	Tue May 12 14:24:41 2015 +0200
@@ -34,7 +34,7 @@
             clicksToMoveEditor: 1,
             autoCancel: false,
             disabled: false,
-            pluginId: 'rowedit',
+            pluginId: 'mmtrowedit',
             listeners:{
                 // Make row ineditable when readonly is set to true
                 // Normally this would belong into a controller an not the view.
diff -r 62721a75d31d -r 31eaed998531 app/view/grid/Nuklide.js
--- a/app/view/grid/Nuklide.js	Fri May 08 16:12:01 2015 +0200
+++ b/app/view/grid/Nuklide.js	Tue May 12 14:24:41 2015 +0200
@@ -13,11 +13,6 @@
     extend: 'Ext.grid.Panel',
     alias: 'widget.nuklidegrid',
 
-    selType: 'checkboxmodel',
-    selModel: {
-        checkOnly: false,
-        injectCheckbox: 0
-    },
     requires: [
         'Lada.view.widget.Messgroesse'
     ],
@@ -39,16 +34,16 @@
             xtype: 'toolbar',
             dock: 'bottom',
             items: ['->', {
-                text: i18n.getMsg('save'),
-                qtip: i18n.getMsg('save.qtip'),
-                icon: 'resources/img/dialog-ok-apply.png',
-                action: 'save',
+                text: i18n.getMsg('add'),
+                qtip: i18n.getMsg('add.qtip'),
+                icon: 'resources/img/list-add.png',
+                action: 'add',
                 disabled: true
             }, {
-                text: i18n.getMsg('discard'),
-                qtip: i18n.getMsg('discard.qtip'),
-                icon: 'resources/img/dialog-cancel.png',
-                action: 'discard',
+                text: i18n.getMsg('delete'),
+                qtip: i18n.getMsg('delete.qtip'),
+                icon: 'resources/img/list-remove.png',
+                action: 'remove',
                 disabled: true
             }]
         }];
@@ -65,14 +60,56 @@
                     store = Ext.create('Lada.store.Messgroessen');
                 }
                 return store.findRecord('id', value, 0, false, false, true).get('messgroesse');
+            },
+            editor: {
+                xtype: 'combobox',
+                store: Ext.data.StoreManager.get('messgroessen'),
+                valueField: 'id',
+                allowBlank: false,
+                editable: true,
+                forceSelection: true,
+                autoSelect: true,
+                //multiSelect: true, // TODO
+                queryMode: 'local',
+                minChars: 0,
+                typeAhead: false,
+                triggerAction: 'all',
+                tpl: Ext.create("Ext.XTemplate",
+                    '<tpl for="."><div class="x-combo-list-item  x-boundlist-item" >' +
+                    '{messgroesse}</div></tpl>'),
+                displayTpl: Ext.create('Ext.XTemplate',
+                    '<tpl for=".">{messgroesse}</tpl>'),
             }
         }];
+
+        this.rowEditing = Ext.create('Ext.grid.plugin.RowEditing', {
+            clicksToMoveEditor: 1,
+            autoCancel: false,
+            disabled: false,
+            pluginId: 'nuklidrowedit',
+            listeners:{
+                // Make row ineditable when readonly is set to true
+                // Normally this would belong into a controller an not the view.
+                // But the RowEditPlugin is not handled there.
+                beforeedit: function(e, o) {
+                    var readonlywin = o.grid.up('window').record.get('readonly');
+                    var readonlygrid = o.record.get('readonly');
+                    if (readonlywin == true || readonlygrid == true || this.disabled)  {
+                        return false;
+                    }
+                    return true;
+                }
+            }
+        });
+
+        this.plugins = [this.rowEditing];
+
         this.initData();
         this.callParent(arguments);
     },
     initData: function() {
         if (this.store) {
-            this.store.removeAll();
+            this.store.reload();
         }
     },
     setData: function(store) {
@@ -86,15 +123,15 @@
             if (this.getPlugin('rowedit')){
                 this.getPlugin('rowedit').disable();
             }
-            this.down('button[action=discard]').disable();
-            this.down('button[action=save]').disable();
+            this.down('button[action=add]').disable();
+            this.down('button[action=remove]').disable();
         }else{
             //Writable
             if (this.getPlugin('rowedit')){
                 this.getPlugin('rowedit').enable();
             }
-            this.down('button[action=discard]').enable();
-            this.down('button[action=save]').enable();
+            this.down('button[action=add]').enable();
+            this.down('button[action=remove]').enable();
          }
     }
 });


More information about the Lada-commits mailing list