changeset 945:023e622f9551

Added the ability to work with "StatusWerten" which are delivered by the lada-server. To enable the uses of StatusWerte, the controller for the status grid, needed to be extended. In addition, the form and grid views of Messung and Status were updated.
author Dustin Demuth <dustin@intevation.de>
date Tue, 27 Oct 2015 16:46:58 +0100
parents 1f1467713c3f
children 71e2acb1cdd6
files app/controller/grid/Status.js app/model/Messung.js app/model/Status.js app/store/Status.js app/store/StatusWerte.js app/view/form/Messung.js app/view/grid/Messung.js app/view/grid/Status.js resources/i18n/Lada_de-DE.properties
diffstat 9 files changed, 198 insertions(+), 62 deletions(-) [+]
line wrap: on
line diff
--- a/app/controller/grid/Status.js	Fri Oct 16 08:15:36 2015 +0200
+++ b/app/controller/grid/Status.js	Tue Oct 27 16:46:58 2015 +0100
@@ -20,7 +20,8 @@
         this.control({
             'statusgrid': {
                 edit: this.gridSave,
-                canceledit: this.cancelEdit
+                canceledit: this.cancelEdit,
+                select: this.toggleAllowedPermissions
             },
             'statusgrid button[action=add]': {
                 click: this.add
@@ -81,8 +82,9 @@
         var record = Ext.create('Lada.model.Status', {
             messungsId: button.up('statusgrid').recordId
         });
-        button.up('statusgrid').store.insert(0, record);
-        button.up('statusgrid').rowEditing.startEdit(0, 1);
+        var lastrow = button.up('statusgrid').store.count()
+        button.up('statusgrid').store.insert(lastrow, record);
+        button.up('statusgrid').rowEditing.startEdit(lastrow, 1);
     },
 
     /**
@@ -121,5 +123,43 @@
             }
         });
         grid.down('button[action=delete]').disable();
+    },
+
+    /**
+     * When a row in a grid is selected,
+     * this function checks if the row may be edited,
+     * or if the row can be removed
+     */
+    toggleAllowedPermissions: function(context, record, index){
+
+        //retrieve the readOnly parameters
+        var readonlyWin = context.view.up('window').record.get('readonly');
+
+        var readonlyRec = record.get('readonly');
+        var grid = context.view.up('grid');
+
+        //retrieve the last record of the store
+        var lastRecord = context.getStore().last()
+        //Check if remove is allowed
+        if (lastRecord == record &&
+            readonlyWin == false  &&
+            readonlyRec == false) {
+            grid.down('button[action=delete]').enable();
+        }
+        else {
+            grid.down('button[action=delete]').disable();
+        }
+
+
+        //Check if edit is allowed
+        if (lastRecord == record &&
+            readonlyWin == false  &&
+            readonlyRec == false) {
+            grid.getPlugin('rowedit').enable()
+        }
+        else {
+            grid.getPlugin('rowedit').disable()
+        }
     }
+
 });
--- a/app/model/Messung.js	Fri Oct 16 08:15:36 2015 +0200
+++ b/app/model/Messung.js	Tue Oct 27 16:46:58 2015 +0100
@@ -39,6 +39,8 @@
         },
         defaultValue: new Date()
     }, {
+        name: 'status',
+    }, {
         name: 'fertig',
         type: 'boolean'
     }, {
--- a/app/model/Status.js	Fri Oct 16 08:15:36 2015 +0200
+++ b/app/model/Status.js	Tue Oct 27 16:46:58 2015 +0100
@@ -15,20 +15,40 @@
     fields: [{
         name: 'id'
     }, {
-        name: 'owner',
-        type: 'boolean'
-    }, {
         name: 'readonly',
         type: 'boolean',
         persist: false
     }, {
+        name: 'owner',
+        type: 'boolean',
+    }, {
         name: 'messungsId'
     }, {
         name: 'erzeuger'
     }, {
-        name: 'status'
+        name: 'statusStufe',
+        type: 'int'
     }, {
-        name: 'sdatum',
+        name: 'statusWert',
+        type: 'int'
+    }, {
+        name: 'treeModified',
+        serialize: function(value) {
+            if (value === '') {
+               return null;
+           }
+           return value;
+        }
+    }, {
+       name: 'parentModified',
+       serialize: function(value) {
+           if (value === '') {
+               return null;
+           }
+           return value;
+       }
+    }, {
+        name: 'datum',
         type: 'date',
         convert: function(v) {
             if (!v) {
@@ -38,23 +58,7 @@
         },
         defaultValue: new Date()
     }, {
-        name: 'skommentar'
-    }, {
-        name: 'treeModified',
-        serialize: function(value) {
-            if (value === '') {
-                return null;
-            }
-            return value;
-        }
-    }, {
-        name: 'parentModified',
-        serialize: function(value) {
-            if (value === '') {
-                return null;
-            }
-            return value;
-        }
+        name: 'text'
     }],
 
     idProperty: 'id',
--- a/app/store/Status.js	Fri Oct 16 08:15:36 2015 +0200
+++ b/app/store/Status.js	Tue Oct 27 16:46:58 2015 +0100
@@ -11,5 +11,6 @@
  */
 Ext.define('Lada.store.Status', {
     extend: 'Ext.data.Store',
-    model: 'Lada.model.Status'
+    model: 'Lada.model.Status',
+    storeId: 'Status'
 });
--- a/app/store/StatusWerte.js	Fri Oct 16 08:15:36 2015 +0200
+++ b/app/store/StatusWerte.js	Tue Oct 27 16:46:58 2015 +0100
@@ -8,20 +8,10 @@
 
 /**
  * Store for Status-Werte
- * TODO i18n
  */
 Ext.define('Lada.store.StatusWerte', {
     extend: 'Ext.data.Store',
-    fields: ['display', 'id'],
-    data: [{
-            display: 'unbekannt', id: 0
-        }, {
-            display: 'nicht vergeben', id: 1
-        }, {
-            display: 'plausibel', id: 2
-        }, {
-            display: 'nicht repräsentativ', id: 3
-        }, {
-            display: 'nicht plausibel', id: 4
-        }]
+    model: 'Lada.model.StatusWerte',
+    autoLoad: true,
+    storeId: 'StatusWerte'
 });
--- a/app/view/form/Messung.js	Fri Oct 16 08:15:36 2015 +0200
+++ b/app/view/form/Messung.js	Tue Oct 27 16:46:58 2015 +0100
@@ -113,6 +113,22 @@
                     fieldLabel: 'Geplant',
                     width: 300,
                     labelWidth: 100
+                }, {
+                    xtype: 'textfield',
+                    name: 'status',
+                    readOnly: true,
+                    isFormField: false,
+                    maxLength: 10,
+                    margin: '0, 10, 5, 0',
+                    fieldLabel: 'Status',
+                    width: 300,
+                    labelWidth: 100,
+                    submitValue: false,
+                    isFormField: false,
+                    preventMark: true, //Do not display error msg.
+                    validateValue: function() {
+                        return true; //this field is always valid
+                    },
                 }]
             }]
         }];
@@ -121,6 +137,57 @@
 
     setRecord: function(record) {
         this.getForm().loadRecord(record);
+        this.retrieveStatus(record.id, record.get('status'));
+    },
+
+    retrieveStatus: function(messungsId, statusId) {
+        var i18n = Lada.getApplication().bundle;
+        var msg = i18n.getMsg('load.statuswert');
+        var textfield = this.down('[name=status]');
+
+        textfield.setRawValue(msg);
+
+        var sStore = Ext.StoreManager.lookup('Status');
+        if (!sStore) {
+            sStore = Ext.create('Lada.store.Status');
+        }
+        sStore.on('load',
+            function(records, operation, success) {
+                var ret;
+                var i18n = Lada.getApplication().bundle;
+                if (sStore.getTotalCount() === 0) {
+                    ret = 0;
+                }
+                else {
+                    ret = sStore.getById(statusId).get('statusWert');
+                }
+                this.setStatusWert(ret);
+            },
+            this);
+        sStore.load({
+            params: {
+                messungsId: messungsId
+            }
+        });
+    },
+
+    setStatusWert: function(value){
+        var swStore = Ext.StoreManager.lookup('StatusWerte');
+        if (!swStore) {
+            var swStore = Ext.create('Lada.store.StatusWerte');
+        }
+        swStore.on('load',
+            function(records, operation, success) {
+                var i18n = Lada.getApplication().bundle;
+                var msg = i18n.getMsg('load.statuswert.error');
+                var textfield = this.down('[name=status]');
+                if (success) {
+                    msg = swStore.getById(value).get('wert');
+                }
+                textfield.setRawValue(msg);
+            },
+            this);
+        swStore.load();
     },
 
     setMessages: function(errors, warnings) {
--- a/app/view/grid/Messung.js	Fri Oct 16 08:15:36 2015 +0200
+++ b/app/view/grid/Messung.js	Tue Oct 27 16:46:58 2015 +0100
@@ -83,9 +83,10 @@
             flex: 1,
             dataIndex: 'id',
             renderer: function(value) {
-                var id = 'messung-status-item' + value;
-                this.updateStatus(value, id);
-                return '<div id="' + id + '">Lade...</div>';
+                var statusId = this.store.getById(value).get('status');
+                var divId = 'messung-status-item' + value;
+                this.updateStatus(value, divId, statusId);
+                return '<div id="' + divId + '">Lade...</div>';
             }
         }, {
             header: 'OK-Flag',
@@ -147,12 +148,16 @@
         });
     },
 
-    updateStatus: function(value, divId) {
+    /**
+     * Load the statusstore,
+     * afterwards: retrieve the statusid
+     */
+    updateStatus: function(value, divId, statusId) {
         var statusStore = Ext.create('Lada.store.Status');
         statusStore.on('load',
             this.updateStatusColumn,
             this,
-            {divId: divId});
+            {divId: divId, statusId: statusId});
         statusStore.load({
             params: {
                 messungsId: value
@@ -197,18 +202,36 @@
         Ext.fly(opts.divId).update(value);
     },
 
+    /**
+     * Retrieve Statuswert and update the column
+     */
     updateStatusColumn: function(sstore, record, success, opts) {
-        var value;
+        var value = 0;
         if (sstore.getTotalCount() === 0) {
             value = 0;
         }
         else {
-            value = sstore.last().get('status');
+            value = sstore.getById(opts.statusId).get('statusWert');
         }
         if (Ext.fly(opts.divId)) {
-            var sta = Ext.create('Lada.store.StatusWerte');
-            var val = sta.getById(value).get('display');
-            Ext.fly(opts.divId).update(val);
+            var sta = Ext.StoreManager.lookup('StatusWerte');
+            if (!sta) {
+                var sta = Ext.create('Lada.store.StatusWerte');
+            }
+            var val = 'error';
+            sta.load({
+                scope: this,
+                callback: function(records, operation, success) {
+                    if (success) {
+                        try {
+                            val = sta.getById(value).get('wert');
+                        }
+                        catch (e) {
+                        }
+                    }
+                    Ext.fly(opts.divId).update(val);
+                }
+            });
         }
     },
 
--- a/app/view/grid/Status.js	Fri Oct 16 08:15:36 2015 +0200
+++ b/app/view/grid/Status.js	Tue Oct 27 16:46:58 2015 +0100
@@ -28,14 +28,14 @@
         this.rowEditing = Ext.create('Ext.grid.plugin.RowEditing', {
             clicksToMoveEditor: 1,
             autoCancel: false,
-            disabled: false,
+            disabled: true,
             pluginId: 'rowedit',
             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 readonlywin = o.grid.up('window').record.get('readonly');
                     var readonlygrid = o.record.get('readonly');
                     if (readonlywin == true || readonlygrid == true || this.disabled)  {
                         return false;
@@ -43,10 +43,11 @@
                     return true;
                 }
             }
-         });
+        });
         this.plugins = [this.rowEditing];
 
         var statusStore = Ext.create('Lada.store.StatusWerte');
+        statusStore.load();
         this.dockedItems = [{
             xtype: 'toolbar',
             dock: 'bottom',
@@ -64,10 +65,11 @@
         }];
         this.columns = [{
             header: 'erstellt',
-            dataIndex: 'sdatum',
+            dataIndex: 'datum',
             xtype: 'datecolumn',
             format: 'd.m.Y H:i',
             width: 110,
+            sortable: false,
         }, {
             header: 'Erzeuger',
             dataIndex: 'erzeuger',
@@ -85,33 +87,36 @@
                 valueField: 'id',
                 allowBlank: false,
                 editable: false
-            }
+            },
+            sortable: false,
         }, {
             header: 'Status',
-            dataIndex: 'status',
+            dataIndex: 'statusWert',
             renderer: function(value) {
                 if (!value || value === '') {
                     return '';
                 }
-                return statusStore.getById(value).get('display');
+                return statusStore.getById(value).get('wert');
             },
             editor: {
                 xtype: 'combobox',
                 store: statusStore,
-                displayField: 'display',
+                displayField: 'wert',
                 valueField: 'id',
                 allowBlank: false,
                 editable: false
-            }
+            },
+            sortable: false,
         }, {
             header: 'Text',
-            dataIndex: 'skommentar',
+            dataIndex: 'text',
             flex: 1,
             editor: {
                 allowBlank: true,
                 maxLength: 1000,
                 enforceMaxLength: true
-            }
+            },
+            sortable: false,
         }];
         this.listeners = {
            select: {
@@ -160,7 +165,7 @@
         }
     },
     /**
-     * Activate the Remove Button
+     * Activate the "Remove Button"
      */
     activateRemoveButton: function(selection, record) {
         var grid = this;
@@ -170,7 +175,7 @@
         }
     },
     /**
-     * Activate the Remove Button
+     * Deactivate the "Remove Button"
      */
     deactivateRemoveButton: function(selection, record) {
         var grid = this;
--- a/resources/i18n/Lada_de-DE.properties	Fri Oct 16 08:15:36 2015 +0200
+++ b/resources/i18n/Lada_de-DE.properties	Tue Oct 27 16:46:58 2015 +0100
@@ -99,6 +99,10 @@
 about.window.text.serverversion:Serverversion:
 about.window.text.clientversion:Clientversion:
 
+
+load.statuswert:Lade aktuellen Statuswert...
+load.statuswert.error:Fehler beim auflösen der Statuswerte
+
 # Actions
 add:Hinzufügen
 delete:Löschen

http://lada.wald.intevation.org