[Lada-commits] [PATCH 5 of 7] Updated client status workflow and model

Wald Commits scm-commit at wald.intevation.org
Wed Aug 31 16:25:07 CEST 2016


# HG changeset patch
# User Raimund Renkert <raimund.renkert at intevation.de>
# Date 1472651929 -7200
# Branch schema-update
# Node ID 90ae675a1224aed7c41e1f7f090f279ddcf38b36
# Parent  be720d0473f65e055c85eccaf8bdc5b7c369f9d3
Updated client status workflow and model.

diff -r be720d0473f6 -r 90ae675a1224 app/controller/grid/Status.js
--- a/app/controller/grid/Status.js	Wed Aug 31 15:58:19 2016 +0200
+++ b/app/controller/grid/Status.js	Wed Aug 31 15:58:49 2016 +0200
@@ -39,7 +39,18 @@
      * On failure it displays a message
      */
      gridSave: function(editor, context) {
-        context.record.set('sdatum', new Date());
+        context.record.set('datum', new Date());
+        var wert = editor.getEditor().down('combobox[displayField=wert]').value;
+        var stufe = editor.getEditor().down('combobox[displayField=stufe]').value;
+        var kombis = Ext.data.StoreManager.get('statuskombi');
+        var kombiNdx = kombis.findBy(function(record, id) {
+            if (record.raw.statusStufe.id === stufe &&
+                record.raw.statusWert.id === wert
+            ) {
+                return true;
+            }
+        });
+        context.record.set('statusKombi', kombis.getAt(kombiNdx).get('id'));
         context.record.save({
             success: function(response) {
                 var i18n = Lada.getApplication().bundle;
@@ -172,18 +183,27 @@
 
         var resetStatusValue = 8;
 
-        var s = button.up('window').down('messungform').getRecord().get('status');
+        var s = button.up('window').down('messungform').getCurrentStatus();
         var messId = button.up('window').down('messungform').getRecord().get('id');
-        var recentStatus = button.up('statusgrid').store.getById(s);
 
+        if(!s) {
+            Ext.Msg.alert(i18n.getMsg('err.msg.generic.title'),
+                i18n.getMsg('err.msg.generic.body'));
+            return;
+        }
         //Set Status to 'Resetted' (8)
-        if (recentStatus) {
-            var record = recentStatus.copy();
-            record.set('datum', new Date());
-            record.set('statusWert', resetStatusValue);
-            record.set('id', null);
-            record.set('text', i18n.getMsg('statusgrid.resetText'));
-        }
+        var kombis = Ext.data.StoreManager.get('statuskombi');
+        var stufe = kombis.getById(s.get('statusKombi')).raw.statusStufe.id;
+        var kombiNdx = kombis.findBy(function(record, id) {
+            if(record.raw.statusStufe.id === stufe && record.raw.statusWert.id === 8) {
+                return true;
+            }
+        });
+        var record = s.copy();
+        record.set('datum', new Date());
+        record.set('statusKombi', kombis.getAt(kombiNdx).get('id'));
+        record.set('id', null);
+        record.set('text', i18n.getMsg('statusgrid.resetText'));
 
         Ext.Ajax.request({
             url: 'lada-server/rest/status',
diff -r be720d0473f6 -r 90ae675a1224 app/model/StatusKombi.js
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/app/model/StatusKombi.js	Wed Aug 31 15:58:49 2016 +0200
@@ -0,0 +1,36 @@
+/* Copyright (C) 2013 by Bundesamt fuer Strahlenschutz
+ * Software engineering by Intevation GmbH
+ *
+ * This file is Free Software under the GNU GPL (v>=3)
+ * and comes with ABSOLUTELY NO WARRANTY! Check out
+ * the documentation coming with IMIS-Labordaten-Application for details.
+ */
+
+/**
+ * Model class for StatusKombi
+ */
+Ext.define('Lada.model.StatusKombi', {
+    extend: 'Ext.data.Model',
+
+    fields: [{
+        name: 'id'
+    }, {
+        name: 'stufeId',
+        type: 'int'
+    }, {
+        name: 'stufeId',
+        type: 'int'
+    }],
+
+    idProperty: 'id',
+
+    proxy: {
+        type: 'rest',
+        url: 'lada-server/rest/statuskombi',
+        reader: {
+            type: 'json',
+            root: 'data'
+        }
+    }
+});
+
diff -r be720d0473f6 -r 90ae675a1224 app/store/StatusKombi.js
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/app/store/StatusKombi.js	Wed Aug 31 15:58:49 2016 +0200
@@ -0,0 +1,17 @@
+/* Copyright (C) 2013 by Bundesamt fuer Strahlenschutz
+ * Software engineering by Intevation GmbH
+ *
+ * This file is Free Software under the GNU GPL (v>=3)
+ * and comes with ABSOLUTELY NO WARRANTY! Check out
+ * the documentation coming with IMIS-Labordaten-Application for details.
+ */
+
+/**
+ * Store for Status-Kombi
+ */
+Ext.define('Lada.store.StatusKombi', {
+    extend: 'Ext.data.Store',
+    model: 'Lada.model.StatusKombi',
+    autoLoad: false
+});
+
diff -r be720d0473f6 -r 90ae675a1224 app/view/form/Messung.js
--- a/app/view/form/Messung.js	Wed Aug 31 15:58:19 2016 +0200
+++ b/app/view/form/Messung.js	Wed Aug 31 15:58:49 2016 +0200
@@ -30,6 +30,8 @@
 
     trackResetOnLoad: true,
 
+    currentStatus: null,
+
     initComponent: function() {
         var me = this;
         var i18n = Lada.getApplication().bundle;
@@ -79,6 +81,7 @@
                     name: 'mmtId',
                     margin: '0, 10, 5, 0',
                     fieldLabel: 'Messmethode',
+                    allowBlank: false,
                     width: 300,
                     labelWidth: 100
                 }, {
@@ -126,7 +129,6 @@
                     width: 300,
                     labelWidth: 100,
                     submitValue: false,
-                    isFormField: false,
                     preventMark: true, //Do not display error msg.
                     validateValue: function() {
                         return true; //this field is always valid
@@ -168,6 +170,10 @@
         }
     },
 
+    getCurrentStatus: function() {
+        return this.currentStatus;
+    },
+
     retrieveStatus: function(messungsId, statusId) {
         var i18n = Lada.getApplication().bundle;
         var msg = i18n.getMsg('load.statuswert');
@@ -178,6 +184,7 @@
             textfield.setRawValue(msg);
         }
 
+        var me = this;
         var sStore = Ext.create('Lada.store.Status');
         sStore.load({
             params: {
@@ -190,9 +197,13 @@
                     sw = 0;
                 }
                 else {
-                    sw = sStore.getById(statusId).get('statusWert');
-                    ss = sStore.getById(statusId).get('statusStufe');
-                    se = sStore.getById(statusId).get('erzeuger');
+                    me.currentStatus = sStore.getById(statusId);
+                    sk = sStore.getById(statusId).get('statusKombi');
+                    se = sStore.getById(statusId).get('mstId');
+                    var kombis = Ext.data.StoreManager.get('statuskombi');
+                    var rec = kombis.getById(sk);
+                    sw = rec.raw.statusWert.id;
+                    ss = rec.raw.statusStufe.id;
                 }
                 this.setStatusWert(sw);
                 this.setStatusStufe(ss);
diff -r be720d0473f6 -r 90ae675a1224 app/view/grid/Messung.js
--- a/app/view/grid/Messung.js	Wed Aug 31 15:58:19 2016 +0200
+++ b/app/view/grid/Messung.js	Wed Aug 31 15:58:49 2016 +0200
@@ -75,36 +75,40 @@
         }, {
             header: 'Status',
             flex: 1,
-            dataIndex: 'statusWert',
+            dataIndex: 'statusKombi',
             renderer: function(value, meta, record, rNdx, cNdx) {
                 var statusId = record.get('status');
                 var mId = record.get('id');
                 //also fwd the record to the asynchronous loading of statuswerte
                 // in order to add the statuswert to the record,
                 // after the grid was rendered...
-                if (value === '') {
+                if (!value || value === '') {
                     this.updateStatus(mId, statusId, record);
                     return 'Lade...';
                 }
-                var sta = Ext.data.StoreManager.getByKey('statuswerte');
-                return sta.getById(value).get('wert');
+                var kombis = Ext.data.StoreManager.get('statuskombi');
+                var kombi = kombis.getById(value);
+                var st = kombi.raw.statusWert.wert
+                return st;
             }
         }, {
             header: 'Stufe',
             flex: 1,
-            dataIndex: 'statusStufe',
+            dataIndex: 'statusKombi',
             renderer: function(value, meta, record, rNdx, cNdx) {
                 var statusId = record.get('status');
                 var mId = record.get('id');
                 //also fwd the record to the asynchronous loading of statuswerte
                 // in order to add the statuswert to the record,
                 // after the grid was rendered...
-                if (value === '') {
+                if (!value || value === '') {
                     this.updateStatus(mId, statusId, record);
                     return 'Lade...';
                 }
-                var sta = Ext.data.StoreManager.getByKey('statusstufe');
-                return sta.getById(value).get('stufe');
+                var kombis = Ext.data.StoreManager.get('statuskombi');
+                var kombi = kombis.getById(value);
+                var st = kombi.raw.statusStufe.stufe
+                return st;
             }
         }, {
             header: 'OK-Flag',
@@ -252,14 +256,12 @@
         else {
             var rec = sstore.getById(opts.statusId);
             if (rec) {
-                value = rec.get('statusWert');
-                var stufe = rec.get('statusStufe');
+                value = rec.get('statusKombi');
                 //add the determined statuswert to the record.
                 // this is necessary to let the controller determine
                 // which actions are allowed.
                 opts.record.beginEdit();
-                opts.record.set('statusWert', value);
-                opts.record.set('statusStufe', stufe);
+                opts.record.set('statusKombi', value);
                 opts.record.endEdit();
             }
         }
diff -r be720d0473f6 -r 90ae675a1224 app/view/grid/Status.js
--- a/app/view/grid/Status.js	Wed Aug 31 15:58:19 2016 +0200
+++ b/app/view/grid/Status.js	Wed Aug 31 15:58:49 2016 +0200
@@ -23,6 +23,7 @@
     readOnly: true,
     allowDeselect: true,
     statusWerteStore: null,
+    statusStufeStore: null,
 
     initComponent: function() {
         var i18n = Lada.getApplication().bundle;
@@ -34,8 +35,8 @@
                 messungsId: this.recordId
             }
         });
-        var statusStufeStore = Ext.create('Lada.store.StatusStufe');
-        statusStufeStore.load();
+        this.statusStufeStore = Ext.create('Lada.store.StatusStufe');
+        this.statusStufeStore.load();
 
         this.rowEditing = Ext.create('Ext.grid.plugin.RowEditing', {
             clicksToMoveEditor: 1,
@@ -110,33 +111,37 @@
             sortable: false
         }, {
             header: i18n.getMsg('statusgrid.header.statusStufe'),
-            dataIndex: 'statusStufe',
+            dataIndex: 'statusKombi',
             renderer: function(value) {
-                var sta = Ext.data.StoreManager.get('statusstufe');
-                var r;
-                if (value===null || value === '') {
-                    r = i18n.getMsg('error');
-                }
-                var item = sta.getById(value);
+                var kombi = Ext.data.StoreManager.get('statuskombi');
+                var r = '';
+                var item = kombi.getById(value);
                 if (item) {
-                    r = item.get('stufe');
+                    r = item.raw.statusStufe.stufe;
                 }
                 return r;
             },
+            editor: {
+                xtype: 'combobox',
+                store: this.statusStufeStore,
+                queryMode: 'local',
+                displayField: 'stufe',
+                valueField: 'id',
+                allowBlank: false,
+                editable: false,
+                forceSelection: true
+            },
             sortable: false
         }, {
             header: i18n.getMsg('statusgrid.header.statusWert'),
-            dataIndex: 'statusWert',
+            dataIndex: 'statusKombi',
             renderer: function(value) {
-                var sta = Ext.data.StoreManager.get('statuswerte');
+                var kombi = Ext.data.StoreManager.get('statuskombi');
                 //This store is NOT used in the editor...
-                var r;
-                if (value===null || value === '') {
-                    r = i18n.getMsg('error');
-                }
-                var item = sta.getById(value);
+                var r = '';
+                var item = kombi.getById(value);
                 if (item) {
-                    r = item.get('wert');
+                    r = item.raw.statusWert.wert;
                 }
                 return r;
             },


More information about the Lada-commits mailing list