changeset 776:da14e0f3e599

merged
author Dustin Demuth <dustin@intevation.de>
date Tue, 12 May 2015 16:26:05 +0200
parents 311c39a64064 (current diff) dd6925ef6028 (diff)
children 5a153d36ed4e
files
diffstat 6 files changed, 209 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/app/controller/form/Probe.js	Tue May 12 16:25:17 2015 +0200
+++ b/app/controller/form/Probe.js	Tue May 12 16:26:05 2015 +0200
@@ -29,6 +29,9 @@
             },
             'probeform [xtype="datetime"] field': {
                 blur: this.checkDate
+            },
+            'probeform panel[xtype="deskriptor] combobox': {
+                select: this.deskriptorSelect
             }
         });
     },
@@ -173,5 +176,52 @@
         if (w == 0 && e == 0) {
             field.up().clearWarningOrError();
         }
+    },
+
+    deskriptorSelect: function(field, records) {
+        var desk = field.up('deskriptor');
+        var media = field.up('probeform').down('textfield[name="mediaDesk"]');
+        var current = media.getValue().split(' ');
+        this.clearChildDesk(field.up('deskriptor'), current);
+        if (current.length < 13) {
+            for (var i = 0; i <= 12; i++) {
+                if (i === 0) {
+                    current.push('D:');
+                }
+                else if (i === desk.layer + 1) {
+                    var value;
+                    if (records[0].get('sn') < 10) {
+                        value = '0' + records[0].get('sn');
+                    }
+                    else {
+                        value = records[0].get('sn');
+                    }
+                    current.push(value);
+                }
+                else {
+                    current.push('00');
+                }
+            }
+        }
+        else {
+            var value;
+            if (records[0].get('sn') < 10) {
+                value = '0' + records[0].get('sn');
+            }
+            else {
+                value = records[0].get('sn');
+            }
+            current[desk.layer + 1] = value;
+        }
+        media.setValue(current.join(' ').trim());
+    },
+
+    clearChildDesk: function(field, media) {
+        var allS = field.up('fieldset').items.items;
+        for (var i = field.layer + 1; i < 12; i++) {
+            allS[i].clearValue();
+            media[i + 1] = '00';
+        }
     }
+
 });
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/app/model/Deskriptor.js	Tue May 12 16:26:05 2015 +0200
@@ -0,0 +1,36 @@
+/**
+ *
+ */
+Ext.define('Lada.model.Deskriptor', {
+    extend: 'Ext.data.Model',
+
+    /**
+     * Fields are:
+     *  - ...
+     */
+    fields: [{
+        name: 'bedeutung'
+    }, {
+        name: 'beschreibung'
+    }, {
+        name: 'ebene'
+    }, {
+        name: 'id'
+    }, {
+        name: 'sn'
+    }, {
+        name: 'sXx'
+    }],
+
+    idProperty: 'id',
+
+    proxy: {
+        type: 'rest',
+        url: 'lada-server/deskriptor',
+        reader: {
+            type: 'json',
+            root: 'data',
+            totalProperty: 'totalCount'
+        }
+    }
+});
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/app/store/Deskriptoren.js	Tue May 12 16:26:05 2015 +0200
@@ -0,0 +1,15 @@
+/* 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 Datenbasis
+ */
+Ext.define('Lada.store.Deskriptoren', {
+    extend: 'Ext.data.Store',
+    model: 'Lada.model.Deskriptor'
+});
--- a/app/view/form/Probe.js	Tue May 12 16:25:17 2015 +0200
+++ b/app/view/form/Probe.js	Tue May 12 16:26:05 2015 +0200
@@ -20,11 +20,12 @@
         'Lada.view.widget.Testdatensatz',
         'Lada.view.widget.Probenart',
         'Lada.view.widget.Umwelt',
+        'Lada.view.widget.Deskriptor',
         'Lada.view.widget.base.TextField',
         'Lada.view.widget.base.Datetime',
         'Lada.view.widget.base.FieldSet',
         'Lada.view.widget.base.DateField',
-        'Lada.model.Probe',
+        'Lada.model.Probe'
     ],
 
     model: 'Lada.model.Probe',
@@ -303,6 +304,42 @@
         this.getForm().loadRecord(record);
     },
 
+    setMediaDesk: function(record) {
+        var media = record.get('mediaDesk').split(' ');
+        this.setMediaSN(0, media);
+    },
+
+    setMediaSN: function(ndx, media) {
+        if (ndx >= 12) {
+            return;
+        }
+        var me = this;
+        var current = this.down('deskriptor[layer=' + ndx + ']');
+        var cbox = current.down('combobox');
+        if (ndx === 0) {
+            cbox.store.proxy.extraParams = {
+                'layer': ndx
+            };
+        }
+        else {
+            var parents = current.getParents(current.down('combobox'));
+            if (parents.length === 0) {
+                return;
+            }
+            cbox.store.proxy.extraParams = {
+                'layer': ndx,
+                'parents': parents
+            };
+        }
+        cbox.store.load(function(records, op, success) {
+            if (!success) {
+                return;
+            }
+            cbox.select(cbox.store.findRecord('sn', parseInt(media[ndx + 1], 10)));
+            me.setMediaSN(++ndx, media);
+        });
+    },
+
     setMessages: function(errors, warnings) {
         var key;
         var element;
@@ -386,9 +423,12 @@
         var fields = [];
         for (var i = 0; i < 12; i++) {
             fields[i] = {
+                xtype: 'deskriptor',
                 fieldLabel: 'S' + i,
                 name: 's' + i,
                 labelWidth: 25,
+                width: 190,
+                layer: i,
                 margin: '0, 10, 5, 0'
             };
         }
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/app/view/widget/Deskriptor.js	Tue May 12 16:26:05 2015 +0200
@@ -0,0 +1,64 @@
+/* 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.
+ */
+
+/**
+ * Combobox for Deskriptor
+ */
+Ext.define('Lada.view.widget.Deskriptor', {
+    extend: 'Lada.view.widget.base.ComboBox',
+    alias: 'widget.deskriptor',
+    displayField: 'beschreibung',
+    valueField: 'id',
+    // Enable filtering of comboboxes
+    triggerAction: 'all',
+    typeAhead: false,
+    layer: null,
+    queryMode: 'local',
+    listeners: {
+        expand: {
+            fn: function(field) {
+                if (field.up('deskriptor').layer === 0) {
+                    field.store.proxy.extraParams = {'layer': field.up('deskriptor').layer};
+                    field.store.load();
+                }
+                else {
+                    var parents = field.up('deskriptor').getParents(this);
+                    if (parents !== '') {
+                        field.store.proxy.extraParams = {
+                            'layer': field.up('deskriptor').layer,
+                            'parents': parents
+                        };
+                        field.store.load();
+                    }
+                }
+            }
+        }
+    },
+
+    initComponent: function() {
+        this.store = Ext.create('Lada.store.Deskriptoren');
+
+        this.callParent(arguments);
+    },
+
+    getParents: function(field) {
+        var set = field.up('fieldset');
+        var allS = set.items.items;
+        var p = '';
+
+        for (var i = 0; i < field.up('deskriptor').layer; i++) {
+            if (allS[i].getValue() > 0) {
+                p += allS[i].getValue();
+                if (i < field.up('deskriptor').layer - 1) {
+                    p += ', ';
+                }
+            }
+        }
+        return p;
+    }
+});
--- a/app/view/window/ProbeEdit.js	Tue May 12 16:25:17 2015 +0200
+++ b/app/view/window/ProbeEdit.js	Tue May 12 16:26:05 2015 +0200
@@ -141,6 +141,9 @@
                 var json = Ext.decode(response.response.responseText);
                 if (json) {
                     this.setMessages(json.errors, json.warnings);
+                    if (!json.warnings.mediaDesk) {
+                        this.down('probeform').setMediaDesk(record);
+                    }
                 }
                 // If the Probe is ReadOnly, disable Inputfields and grids
                 if (this.record.get('readonly') === true) {

http://lada.wald.intevation.org