changeset 1289:bfdc00c24baf

Ortszuordnung for messprogramm and probe using same form
author Maximilian Krambach <mkrambach@intevation.de>
date Wed, 01 Feb 2017 14:52:51 +0100
parents 08085b7d1d0b
children d17501b967f2
files app/controller/form/Messprogramm.js app/controller/form/Ortszuordnung.js app/controller/grid/Ortszuordnung.js app/model/Messprogramm.js app/model/Ort.js app/model/Ortszuordnung.js app/model/OrtszuordnungMp.js app/view/form/Messprogramm.js app/view/form/OrtInfo.js app/view/form/Ortserstellung.js app/view/form/Ortszuordnung.js app/view/grid/Ortszuordnung.js app/view/panel/Map.js app/view/widget/Staat.js app/view/widget/Verwaltungseinheit.js app/view/widget/base/TextField.js app/view/window/Messprogramm.js app/view/window/Ortserstellung.js app/view/window/Ortszuordnung.js
diffstat 19 files changed, 382 insertions(+), 268 deletions(-) [+]
line wrap: on
line diff
--- a/app/controller/form/Messprogramm.js	Fri Jan 27 13:25:14 2017 +0100
+++ b/app/controller/form/Messprogramm.js	Wed Feb 01 14:52:51 2017 +0100
@@ -12,9 +12,6 @@
 Ext.define('Lada.controller.form.Messprogramm', {
     extend: 'Ext.app.Controller',
 
-    requires: [
-        'Lada.view.window.MessprogrammOrt'
-    ],
 
     /**
      * Initialize the Controller
@@ -27,18 +24,12 @@
             'messprogrammform button[action=discard]': {
                 click: this.discard
             },
-            'messprogrammform button[action=ort]': {
-                click: this.editOrtWindow
-            },
             'messprogrammform': {
                 dirtychange: this.dirtyForm
             },
             'messprogrammform messstellelabor combobox': {
                 select: this.setNetzbetreiber
             },
-            'messprogrammform location combobox': {
-                select: this.syncOrtWindow
-            },
             'messprogrammform numfield numberfield': {
                 change: this.checkPeriod
             },
@@ -121,44 +112,6 @@
     },
 
     /**
-     * The function will open a new Window to edit the Ort of a Messprogramm
-     */
-    editOrtWindow: function(button) {
-        var formPanel = button.up('form');
-        //Only Open if the WIndow does not exist, else focus
-        if (!formPanel.ortWindow) {
-            var data = formPanel.getForm().getFieldValues(true);
-            formPanel.ortWindow = Ext.create('Lada.view.window.MessprogrammOrt', {
-                record: formPanel.getRecord(),
-                parentWindow: formPanel.up('window')
-            });
-            formPanel.ortWindow.show();
-            formPanel.ortWindow.initData();
-       }
-       else {
-            formPanel.ortWindow.focus();
-            formPanel.ortWindow.setActive(true);
-       }
-    },
-
-    /**
-     * When a OrtWindow exist, and the value of the location combobox is changed, update the window.
-     */
-    syncOrtWindow: function(combo, record){
-        var formPanel = combo.up('messprogrammform');
-        if (formPanel.ortWindow) {
-            var ortwindowlocation = formPanel
-                .ortWindow.down('location')
-            var ortwindowcombo = ortwindowlocation
-                .down('combobox');
-
-            ortwindowcombo.select(combo.getValue());
-            ortwindowlocation.fireEvent('select',
-                ortwindowcombo, ortwindowcombo.record);
-       }
-    },
-
-    /**
      * When the Slider was used,
      * update the Value of the Teilintervallfields
      */
@@ -202,14 +155,9 @@
         var formPanel = button.up('form');
         var data = formPanel.getForm().getFieldValues();
         var orte = Ext.data.StoreManager.get('orte');
-        var gemId;
-        if (data['ortId'] !== null && data['ortId'] !== '') {
-            gemId = orte.getById(data['ortId']).get('gemId');
-        }
         for (var key in data) {
             formPanel.getForm().getRecord().set(key, data[key]);
         }
-        formPanel.getForm().getRecord().set('gemId', gemId);
         if (!formPanel.getForm().getRecord().get('letzteAenderung')) {
             formPanel.getForm().getRecord().data.letzteAenderung = new Date();
         }
@@ -402,5 +350,4 @@
         }
     }
 
-    
 });
--- a/app/controller/form/Ortszuordnung.js	Fri Jan 27 13:25:14 2017 +0100
+++ b/app/controller/form/Ortszuordnung.js	Wed Feb 01 14:52:51 2017 +0100
@@ -48,14 +48,25 @@
         }
         catch (e) {
         }
-
-        var data = formPanel.getForm().getFieldValues(true);
+        var data = formPanel.getForm().getFieldValues(false);
         var i18n = Lada.getApplication().bundle;
-        for (var key in data) {
-            formPanel.getForm().getRecord().set(key, data[key]);
+        //TODO: the forms seem not to submit anything into record.
+        var recordData = formPanel.getForm().getRecord().data;
+        if (recordData['probeId'] !== undefined) {
+            // TODO: as model.ort.ortId and model.ortszuordnung.ortId coexist,
+            // but mean different things, data.ortId is an array here, of
+            // which we need the first entry
+            recordData.ortId = data.ortId[0];
+            recordData.ortszuordnungTyp = data.ortszuordnungTyp;
+        } else { //messprogramm
+            recordData.ortsTyp = data.ortsTyp;
+            recordData.ort = data.ort;
         }
-        if (!formPanel.getForm().getRecord().get('letzteAenderung')) {
-            formPanel.getForm().getRecord().data.letzteAenderung = new Date();
+        recordData.ortszusatztext = data.ortszusatztext;
+        if (!data.letzteAenderung) {
+            recordData.letzteAenderung = new Date();
+        } else {
+            recordData.letzteAenderung = data.letzteAenderung;
         }
         formPanel.getForm().getRecord().save({
             success: function(record, response) {
@@ -116,7 +127,11 @@
         var record = formPanel.getForm().getRecord();
         formPanel.getForm().loadRecord(record);
         try {
-            formPanel.refreshOrt(record.get('ortId'));
+            if (record.get('ortId') !== undefined) {
+                formPanel.setOrt(record.get('ortId'));
+            } else {
+                formPanel.setOrt(record.get('ort'));
+            }
             formPanel.down('button[action=setOrt]').toggle(false);
         }
         catch (e) {
@@ -127,7 +142,6 @@
      * When the button is Active, a Record can be selected.
      * If the Record was selected from a grid this function
      * sets the ortzuordnung.
-     * TODO: Check if the selected Record is a ORT
      */
     chooseLocation: function(button, pressed, opts) {
         var i18n = Lada.getApplication().bundle;
@@ -135,6 +149,7 @@
         var gridPanel = win.down('panel[name=ortgrid]');
         var osg = win.down('ortstammdatengrid');
         var oForm = button.up('form');
+        osg.addListener('select',oForm.setOrt, oForm);
         if (pressed) {
             win.setHeight(Ext.getBody().getViewSize().height - 50);
             button.setText(i18n.getMsg('ortszuordnung.form.setOrt.pressed'));
@@ -160,14 +175,25 @@
     validityChange: function(form, valid) {
         if (form.isDirty()) {
             form.owner.down('button[action=discard]').setDisabled(false);
-            if ( valid && form.getValues().ortId !== ''
-                && /[UEZA]/.test(form.getValues().ortszuordnungTyp)
-            ) {
-                form.owner.down('button[action=save]').setDisabled(false);
+            if (valid) {
+                if (form.getValues().ortId !== ''
+                    && /[UEZA]/.test(form.getValues().ortszuordnungTyp)) {
+                    // valid ortzuordnung(Probe)
+                        form.owner.down('button[action=save]').setDisabled(false);
+                } else if (form.getValues().ort !== ''
+                    && /[UEZA]/.test(form.getValues().ortsTyp)) {
+                    // valid ortzuordnung(messprogramm)
+                    form.owner.down('button[action=save]').setDisabled(false);
+                } else {
+                    form.owner.down('button[action=save]').setDisabled(true);
+                }
             } else {
+                //invalid
                 form.owner.down('button[action=save]').setDisabled(true);
             }
         } else {
+            //not dirty
+            form.owner.down('button[action=save]').setDisabled(true);
             form.owner.down('button[action=discard]').setDisabled(true);
         }
     }
--- a/app/controller/grid/Ortszuordnung.js	Fri Jan 27 13:25:14 2017 +0100
+++ b/app/controller/grid/Ortszuordnung.js	Wed Feb 01 14:52:51 2017 +0100
@@ -62,13 +62,20 @@
 
     /**
      * When open is called, a {@link Lada.view.window.Ortszuordnung}
-     * is created which allows to edit the Orte
+     * is created which allows to edit the Orte. record is an ortszuordnung
+     * or ortzuordnungMp
      */
     open: function(grid, record) {
-        var probe = grid.up('window').record;
+        var parent = grid.up('window').record;
+        // parent is either probe or messprogramm.
+        var parentisMp = false;
+        if (parent.data.hauptprobenNr === undefined) {
+            parentisMp = true;
+        }
         var win = Ext.create('Lada.view.window.Ortszuordnung', {
             parentWindow: grid.up('window'),
-            probe: probe,
+            probe: parentisMp ? null: parent,
+            messprogramm: parentisMp ? parent: null,
             record: record,
             grid: grid
         });
@@ -80,10 +87,15 @@
      * This function adds a new row to add an Ort
      */
     add: function(button) {
-        var probe = button.up('window').record;
+        var parent = button.up('window').record;
+        var parentisMp = false;
+        if (parent.data.hauptprobenNr === undefined) {
+            parentisMp = true;
+        }
         var win = Ext.create('Lada.view.window.Ortszuordnung', {
             parentWindow: button.up('window'),
-            probe: probe,
+            probe: parentisMp ? null: parent,
+            messprogramm: parentisMp ? parent: null,
             record: null,
             grid: button.up('ortszuordnung')
         });
@@ -240,7 +252,8 @@
             this.resultPanel = Ext.create('Lada.view.window.OrtFilter', {
                 x: 500,
                 y: 500,
-                alwaysOnTop: true
+                alwaysOnTop: true,
+                parentWindow: this
             });
         }
         this.resultPanel.show();
@@ -260,22 +273,26 @@
 
     selectedVerwaltungseinheit: function(grid, record) {
         var win = grid.up('window');
+        var panel = this.searchField.up('panel').up('window');
         win.hide();
         this.searchField.reset();
         Ext.create('Lada.view.window.Ortserstellung', {
-            record: Ext.create('Lada.model.Ort', record.data),
-            parentWindow: grid.up('ortszuordnungwindow')
+            record: Ext.create('Lada.model.Ort', {
+                gemId: record.get('id')
+            }),
+            parentWindow: panel
         }).show();
     },
 
     selectedStaat: function(grid, record) {
         var win = grid.up('window');
-        console.log(grid.up('ortszuordnungwindow'));
         win.hide();
+        this.searchField.reset();
         Ext.create('Lada.view.window.Ortserstellung', {
-            record: Ext.create('Lada.model.Ort', record.data),
-            parentWindow: grid.up('ortszuordnungwindow')
+            record: Ext.create('Lada.model.Ort', {
+                staatId: record.get('id')
+            }),
+            parentWindow: win
         }).show();
-        this.searchField.reset();
     }
 });
--- a/app/model/Messprogramm.js	Fri Jan 27 13:25:14 2017 +0100
+++ b/app/model/Messprogramm.js	Wed Feb 01 14:52:51 2017 +0100
@@ -31,10 +31,6 @@
     },{
         name: 'baId'
     }, {
-        name: 'gemId'
-    }, {
-        name: 'ortId'
-    }, {
         name: 'mediaDesk',
         serialize: function(value) {
             if (value === '') {
--- a/app/model/Ort.js	Fri Jan 27 13:25:14 2017 +0100
+++ b/app/model/Ort.js	Wed Feb 01 14:52:51 2017 +0100
@@ -25,9 +25,21 @@
     }, {
         name: 'netzbetreiberId'
     }, {
-        name: 'gemId'
+        name: 'gemId',
+        convert: function(v) {
+            if (v === '') {
+                return null;
+            }
+            return v;
+        }
     }, {
-        name: 'staatId'
+        name: 'staatId',
+        convert: function(v) {
+            if (v === '') {
+                return null;
+            }
+            return v;
+        }
     }, {
         name: 'kdaId',
         convert: function(v) {
--- a/app/model/Ortszuordnung.js	Fri Jan 27 13:25:14 2017 +0100
+++ b/app/model/Ortszuordnung.js	Wed Feb 01 14:52:51 2017 +0100
@@ -7,7 +7,7 @@
  */
 
 /**
- * Model class for Ortszuorndung
+ * Model class for Ortszuordnung of probe
  */
 Ext.define('Lada.model.Ortszuordnung', {
     extend: 'Ext.data.Model',
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/app/model/OrtszuordnungMp.js	Wed Feb 01 14:52:51 2017 +0100
@@ -0,0 +1,70 @@
+/* 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 Ortszuordnung of Messprogramme
+ */
+Ext.define('Lada.model.OrtszuordnungMp', {
+    extend: 'Ext.data.Model',
+
+    fields: [{
+        name: 'id'
+    }, {
+        name: 'owner',
+        type: 'boolean'
+    }, {
+        name: 'readonly',
+        type: 'boolean',
+        persist: false
+    }, {
+        name: 'ort'
+    }, {
+        name: 'messprogrammId'
+    }, {
+        name: 'ortsTyp'
+    }, {
+        name: 'ortszusatztext'
+    }, {
+        name: 'letzteAenderung',
+        type: 'date',
+        convert: function(v) {
+            if (!v) {
+                return v;
+            }
+            return new Date(v);
+        }
+    }, {
+        name: 'treeModified',
+        serialize: function(value) {
+            if (value === '') {
+                return null;
+            }
+            return value;
+        }
+    }, {
+        name: 'parentModified',
+        serialize: function(value) {
+            if (value === '') {
+                return null;
+            }
+            return value;
+        }
+    }],
+
+    idProperty: 'id',
+
+    proxy: {
+        type: 'rest',
+        url: 'lada-server/rest/ortszuordnungmp',
+        reader: {
+            type: 'json',
+            root: 'data'
+        }
+    }
+});
+
--- a/app/view/form/Messprogramm.js	Fri Jan 27 13:25:14 2017 +0100
+++ b/app/view/form/Messprogramm.js	Wed Feb 01 14:52:51 2017 +0100
@@ -38,7 +38,6 @@
     border: 0,
 
     recordId: null,
-    ortWindow: null,
 
     trackResetOnLoad: true,
 
@@ -360,32 +359,6 @@
                         }]
                     }]
                 }, {
-                    // Ort
-                    xtype: 'fieldset',
-                    title: 'Ort',
-                    layout: {
-                        type: 'hbox',
-                        align: 'stretch'
-                    },
-                    width: '100%',
-                    items: [{
-                        xtype: 'location',
-                        name: 'ortId',
-                        fieldLabel: i18n.getMsg('ortId'),
-                        labelWidth: 80,
-                        allowBlank: false,
-                        forceSelection: true,
-                        editable: false,
-                        columnWidth: '0.75'
-                    }, {
-                        xtype: 'button',
-                        name: 'ortIdButton',
-                        margin: '0 0 0 5',
-                        text: i18n.getMsg('messprogrammort.button.title'),
-                        action: 'ort',
-                        columnWidth: '0.25'
-                    }]
-                }, {
                     xtype: 'probenehmer',
                     name: 'probeNehmerId',
                     fieldLabel: i18n.getMsg('probeNehmerId'),
@@ -465,7 +438,7 @@
                 intervall, 0, false, false, true);
 
         if (intrec) { // in cases when a new messprogramm is
-        // created and the discard function is used, intrec will be null
+        // created and the discard function is used, intrec will be null && edit is allowed
         // consequently the assertion below will fail.
             min = intrec.get('periodstart');
             max = intrec.get('periodend');
@@ -672,7 +645,6 @@
         //no clear for probeNehmerId
         // Deskriptoren are missing
         this.down('cbox[name=umwId]').clearWarningOrError();
-        this.down('cbox[name=ortId]').clearWarningOrError();
     },
 
     setReadOnly: function(value) {
--- a/app/view/form/OrtInfo.js	Fri Jan 27 13:25:14 2017 +0100
+++ b/app/view/form/OrtInfo.js	Wed Feb 01 14:52:51 2017 +0100
@@ -23,50 +23,34 @@
             layout: 'vbox',
             flex: 1,
             border: 0,
-            items: [{
+            defaults: {
                 xtype: 'displayfield',
                 labelWidth: 125,
+                submitValue: false
+            },
+            items: [{
                 fieldLabel: i18n.getMsg('orte.ortId'),
                 name: 'ortId'
             },
             {
-                xtype: 'displayfield',
-                labelWidth: 125,
                 fieldLabel: i18n.getMsg('orte.kurztext'),
                 name: 'kurztext'
             }, {
-                xtype: 'displayfield',
-                labelWidth: 125,
                 fieldLabel: i18n.getMsg('orte.langtext'),
                 name: 'langtext'
             }, {
-                xtype: 'displayfield',
-                labelWidth: 125,
                 fieldLabel: i18n.getMsg('staat'),
                 name: 'staatISO'
             }, {
-                xtype: 'displayfield',
-                labelWidth: 125,
-                fieldLabel: i18n.getMsg('orte.gemeinde'),
-                name: 'gemeinde'
-            }, {
-                xtype: 'displayfield',
-                labelWidth: 125,
                 fieldLabel: i18n.getMsg('orte.gemeindename'),
                 name: 'gemeinde'
             }, {
-                xtype: 'displayfield',
-                labelWidth: 125,
                 fieldLabel: i18n.getMsg('orte.kda'),
                 name: 'kdaId'
             }, {
-                xtype: 'displayfield',
-                labelWidth: 125,
                 fieldLabel: i18n.getMsg('orte.koordx'),
                 name: 'koordXExtern'
             }, {
-                xtype: 'displayfield',
-                labelWidth: 125,
                 fieldLabel: i18n.getMsg('orte.koordy'),
                 name: 'koordYExtern'
             }]
--- a/app/view/form/Ortserstellung.js	Fri Jan 27 13:25:14 2017 +0100
+++ b/app/view/form/Ortserstellung.js	Wed Feb 01 14:52:51 2017 +0100
@@ -18,6 +18,8 @@
     ],
     model: null,
 
+    margin: 5,
+
     record: null,
 
     initComponent: function() {
@@ -28,28 +30,20 @@
             editable: false,
             readOnly: true,
             submitValue: true,
+            border: 0,
             fieldLabel: i18n.getMsg('netzbetreiberId'),
-            margin : '0, 5, 5, 5',
-            labelWidth: 80,
-            width: 150,
+            labelWidth: 125,
             value: Lada.netzbetreiber[0]
             }, {
             xtype: 'checkbox',
             name: 'aktiv',
             fieldLabel: 'aktiv:'
-        }, {
-            xtype: 'displayfield',
-            align: 'right',
-            value: 'D',
-            labelWidth: 125,
-            maxLength: 1,
-            name: 'messpunktart',
-            fieldLabel: 'Art des Messpunktes:'
         },{
             xtype: 'staat',
             labelWidth: 125,
             fieldLabel: i18n.getMsg('staat'),
             name: 'staatId',
+           forceSelection: true,
             listeners: {
                 change: {
                     fn: function() { me.checkCommitEnabled() }
@@ -59,6 +53,7 @@
             xtype: 'verwaltungseinheit',
             labelWidth: 125,
             fieldLabel: i18n.getMsg('orte.gemeinde'),
+            forceSelection: true,
             name: 'gemId',
             listeners: {
                 change: {
@@ -106,7 +101,7 @@
         }, {
             xtype: 'numfield',
             labelWidth: 125,
-            fieldLabel: 'Höhe:',
+            fieldLabel: i18n.getMsg('orte.hoeheLand'),
             name: 'hoeheLand',
             maxLength: 10,
             allowDecimals: true
@@ -115,7 +110,7 @@
             labelWidth: 125,
             maxLength: 100,
             name: 'kurztext',
-            fieldLabel: i18n.getMsg('orte.kurztext'),
+            fieldLabel: i18n.getMsg('orte.kurztext')
         },{
             xtype: 'tfield',
             labelWidth: 125,
@@ -124,9 +119,58 @@
         },{
             xtype: 'tfield',
             labelWidth: 125,
-            fieldLabel: 'Berichtstext:',
+            fieldLabel: i18n.getMsg('orte.berichtstext'),
             name: 'berichtstext'
+        }, {
+            xtype: 'tfield',
+            labelWidth: 125,
+            maxLength: 100,
+            name: 'anlageId',
+            fieldLabel: i18n.getMsg('orte.anlageId')
+        }, {
+            xtype: 'tfield',
+            labelWidth: 125,
+            maxLength: 100,
+            name: 'zone',
+            fieldLabel: i18n.getMsg('orte.zone')
+        },{
+            xtype: 'tfield',
+            labelWidth: 125,
+            maxLength: 100,
+            name: 'sektor',
+            fieldLabel: i18n.getMsg('orte.sektor')
+        },{
+            xtype: 'tfield',
+            labelWidth: 125,
+            maxLength: 100,
+            name: 'ortTyp',
+            fieldLabel: i18n.getMsg('orte.ortTyp')
+        },{
+            xtype: 'tfield',
+            labelWidth: 125,
+            maxLength: 100,
+            name: 'zustaendigkeit',
+            fieldLabel: i18n.getMsg('orte.zustaendigkeit')
+        },{
+            xtype: 'tfield',
+            labelWidth: 125,
+            maxLength: 100,
+            name: 'mpArt',
+            fieldLabel: i18n.getMsg('orte.mpArt')
+        },{
+            xtype: 'tfield',
+            labelWidth: 125,
+            maxLength: 100,
+            name: 'nutsCode',
+            fieldLabel: i18n.getMsg('orte.nutsCode')
+        },{
+            xtype: 'tfield',
+            labelWidth: 125,
+            maxLength: 100,
+            name: 'ozId',
+            fieldLabel: i18n.getMsg('orte.ozId')
         }];
+
         this.dockedItems = [{
             xtype: 'toolbar',
             dock: 'bottom',
@@ -150,44 +194,29 @@
             }]
         }];
 
-//TODO:
-//               'Anlage:'?
-//               zone
-//               sektor
-//               zustaendigkeit
-//               Messregime (mpArt)
-//               'Prog.-Punkt:', ?
-//               nutsCode
-//               Ortszusatz-ID (ozId)
         this.callParent(arguments);
         this.getForm().loadRecord(this.record);
     },
 
     /**
-     * checks Messpunktart and if the Messpunkt can be committed.
+     * checks if the Messpunkt can be committed.
      * Disables the save button if false
      */
-     // TODO messpunktart is not yet finally defined
     checkCommitEnabled: function() {
         var savebutton =  this.down('toolbar').down('button[action=save]');
         var form = this.getForm();
-        if (this.getForm().findField('kdaId').getValue() ||
-            this.getForm().findField('koordYExtern').getValue() ||
-            this.getForm().findField('koordXExtern').getValue()) {
+        if (form.findField('kdaId').getValue() ||
+            form.findField('koordYExtern').getValue() ||
+            form.findField('koordXExtern').getValue()) {
             if (this.checkCoordinates()) {
-                form.findField('messpunktart').setValue('D');
                 savebutton.setDisabled(false);
             } else {
                 savebutton.setDisabled(true);
             }
-        } else if (form.findField('gemId').getValue()) {
-            form.findField('messpunktart').setValue('V');
-            savebutton.setDisabled(false);
-        } else if (form.findField('staatId').getValue()) {
-            form.findField('messpunktart').setValue('S');
+        } else if (form.findField('gemId').getValue() ||
+            form.findField('staatId').getValue() >= 0 ) {
             savebutton.setDisabled(false);
         } else {
-            form.findField('messpunktart').setValue('D');
             savebutton.setDisabled(true);
         }
     },
@@ -240,29 +269,29 @@
         this_panel.record.save({
             success: function(record, response) {
                 var newOrtId;
-                Ext.Msg.show({
-                    title: Lada.getApplication().bundle.getMsg('success'),
-                    autoScroll: true,
-                    msg: 'Ort erfolgreich angelegt!',
-                    buttons: Ext.Msg.OK
-                });
                 var ozw = this_panel.up().parentWindow;
                 ozw.ortstore.load({
                     callback: function(records, operation, success) {
                         ozw.down('map').addLocations(ozw.ortstore);
-                        ozw.down('ortstammdatengrid').setStore(ozw.ortstore);
+                        var osg = ozw.down('ortstammdatengrid');
+                        osg.setStore(ozw.ortstore);
                         var id = Ext.decode(response.response.responseText).data.id;
-                        var record = ozw.down('ortstammdatengrid').store.getById(id);
-                        var selectionmodel = ozw.down('ortstammdatengrid').getSelectionModel();
-                        console.log(record);
-                        selectionmodel.select(record);
+                        var record = osg.store.getById(id);
+                        var selmod = osg.getView().getSelectionModel();
+                        selmod.select(record);
+                        Ext.Msg.show({
+                            title: Lada.getApplication().bundle.getMsg('success'),
+                            autoScroll: true,
+                            msg: 'Ort erfolgreich angelegt!',
+                            buttons: Ext.Msg.OK
+                        });
                         this_panel.close();
                     },
                     scope: this
                 });
+
             },
             failure: function(record, response) {
-                // TODO check
                 var json = Ext.decode(response.response.responseText);
                 if (json) {
                     if(json.errors.totalCount > 0 || json.warnings.totalCount > 0){
--- a/app/view/form/Ortszuordnung.js	Fri Jan 27 13:25:14 2017 +0100
+++ b/app/view/form/Ortszuordnung.js	Wed Feb 01 14:52:51 2017 +0100
@@ -13,8 +13,6 @@
     extend: 'Ext.form.Panel',
     alias: 'widget.ortszuordnungform',
 
-    model: 'Lada.model.Ortszuordnung',
-
     requires: [
         'Lada.view.form.OrtInfo',
         'Lada.view.widget.Verwaltungseinheit',
@@ -25,6 +23,13 @@
     margin: '5, 5, 0, 5',
     border: 0,
 
+    /**
+     * @cfg: the type of the record to be passed. Should be either 'probe' or 'mpr'.
+     * Variable naming of these differ slightly (see function initComponent and the
+     * two lada.data.model.ortszuordnung* )
+     */
+    type: null,
+
     record: null,
 
     trackResetOnLoad: true,
@@ -32,6 +37,13 @@
     initComponent: function() {
         var i18n = Lada.getApplication().bundle;
         var me = this;
+        if (this.type == 'probe') {
+            this.ortIdName = 'ortId';
+            this.typName = 'ortszuordnungTyp';
+        } else if (this.type == 'mpr') {
+            this.ortIdName = 'ort';
+            this.typName = 'ortsTyp';
+        }
         this.items = [{
             xtype: 'fieldset',
             title: i18n.getMsg('ortszuordnung.form.fset.title'),
@@ -91,9 +103,11 @@
                             allowBlank: false,
                             regex: /[UEZA]{1}/,
                             activeError: 'U, E, Z oder A eingeben',
-                            name: 'ortszuordnungTyp',
+                            name: this.typName,
                             fieldLabel: i18n.getMsg('ortszuordnung.form.field.ortszuordnungtyp'),
-
+                            listeners: {
+                                change: me.changed
+                            }
                         }, {
                             // this field is hidden because the user doesn't
                             // need to know the internal ortID
@@ -103,15 +117,13 @@
                             regex: /^[0-9]{1,45}$/,
                             submitValue: true,
                             hidden: true,
-                            name: 'ortId',
+                            name: this.ortIdName,
                             listeners: {
-                                change: me.changedOrt
+                                change: me.changed
                             }
                         }]
                     },
-                    Ext.create('Lada.view.form.OrtInfo', {
-                            record: me.record
-                    })
+                    Ext.create('Lada.view.form.OrtInfo')
                     ]
                 }]
             }]
@@ -128,28 +140,6 @@
         else {
             this.setReadOnly(true);
         }
-        var ortId = this.getRecord().get('ortId');
-        this.refreshOrt(ortId);
-    },
-
-    refreshOrt: function(ortId) {
-        var orteStore = Ext.StoreManager.get('orte');
-        var ort = orteStore.getById(ortId);
-        if (!ort) {
-            return;
-        }
-        var verwStore = Ext.StoreManager.get('verwaltungseinheiten');
-        var verw = verwStore.getById(ort.get('gemId'));
-        var staatStore = Ext.StoreManager.get('staaten');
-        var staat = staatStore.getById(ort.get('staatId'));
-        var ortinfo = this.down('ortinfo')
-        ortinfo.loadRecord(ort);
-        ortinfo.getForm().setValues({
-            gemeinde: verw.get('bezeichnung'),
-            staat: staat.get('staatIso'),
-            lon: ort.get('longitude'),
-            lat: ort.get('latitude')
-        });
     },
 
     /**
@@ -158,16 +148,31 @@
      */
     setOrt: function(row, selRecord, index, opts) {
         var newOrtId = selRecord.get('id');
-        var r = this.getRecord();
         if (newOrtId) {
-            if (newOrtId != r.get('ortId')) {
-                r.set('ortId', newOrtId);
+            if (this.type == 'probe') {
                 this.getForm().setValues({ortId: newOrtId});
-                this.refreshOrt(newOrtId);
+            } else {
+                this.getForm().setValues({ort: newOrtId});
             }
+            this.setOrtInfo(selRecord);
         }
     },
 
+    setOrtInfo: function(ortrecord) {
+        var verwStore = Ext.StoreManager.get('verwaltungseinheiten');
+        var verw = verwStore.getById(ortrecord.get('gemId'));
+        var staatStore = Ext.StoreManager.get('staaten');
+        var staat = staatStore.getById(ortrecord.get('staatId'));
+        var ortinfo = this.down('ortinfo');
+        ortinfo.loadRecord(ortrecord);
+        ortinfo.getForm().setValues({
+            gemeinde: verw.get('bezeichnung'),
+            staat: staat.get('staatIso'),
+            lon: ortrecord.get('longitude'),
+            lat: ortrecord.get('latitude')
+        });
+    },
+
     setMessages: function(errors, warnings) {
         var key;
         var element;
@@ -209,18 +214,19 @@
 
     setReadOnly: function(value) {
         this.down('tfield[name=ortszusatztext]').setReadOnly(value);
-        this.down('textfield[name=ortszuordnungTyp]').setReadOnly(value);
+        var fieldId = 'textfield[name=' + this.typName +']';
+        this.down(fieldId).setReadOnly(value);
     },
 
     /**
-     * Helper to trigger the forms' validity check on change of ortID
+     * Helper to trigger the forms' validity check
      */
-    changedOrt: function() {
+    changed: function(newValue, oldValue) {
         var controller = Lada.app.getController(
             'Lada.controller.form.Ortszuordnung');
         var form = this.up('form').getForm();
+        var fields = form.getFields().items;
         controller.validityChange(form, form.isValid());
-
     }
 });
 
--- a/app/view/grid/Ortszuordnung.js	Fri Jan 27 13:25:14 2017 +0100
+++ b/app/view/grid/Ortszuordnung.js	Wed Feb 01 14:52:51 2017 +0100
@@ -25,6 +25,8 @@
 
     recordId: null,
 
+    isMessprogramm: false,
+
     warnings: null,
     errors: null,
     readOnly: true,
@@ -164,25 +166,29 @@
     },
 
     initData: function() {
-        this.store = Ext.create('Lada.store.Ortszuordnung');
-        this.store.load({
-            params: {
-                probeId: this.recordId
-            }
-        });
-        Ext.ClassManager.get('Lada.model.Probe').load(this.recordId, {
-            failure: function(record, action) {
-                // TODO
-            },
-            success: function(record, response) {
-                var json = Ext.decode(response.response.responseText);
-                if (json) {
-                    this.warnings = json.warnings;
-                    this.errors = json.errors;
+        if (this.isMessprogramm) {
+            //TODO
+        } else {
+            this.store = Ext.create('Lada.store.Ortszuordnung');
+            this.store.load({
+                params: {
+                    probeId: this.recordId
                 }
-            },
-            scope: this
-        });
+            });
+            Ext.ClassManager.get('Lada.model.Probe').load(this.recordId, {
+                failure: function(record, action) {
+                    // TODO
+                },
+                success: function(record, response) {
+                    var json = Ext.decode(response.response.responseText);
+                    if (json) {
+                        this.warnings = json.warnings;
+                        this.errors = json.errors;
+                    }
+                },
+                scope: this
+            });
+        }
     },
 
     setReadOnly: function(b) {
--- a/app/view/panel/Map.js	Fri Jan 27 13:25:14 2017 +0100
+++ b/app/view/panel/Map.js	Wed Feb 01 14:52:51 2017 +0100
@@ -89,6 +89,9 @@
         }
     },
 
+    /**
+     * Select a feature by record (a Lada.model.Ort) and zoom to this Ort
+     */
     selectFeature: function(model, record) {
         if (!record.get('id') || record.get('id') === '') {
             return;
@@ -97,16 +100,14 @@
         this.map.setCenter(
             new OpenLayers.LonLat(feature.geometry.x, feature.geometry.y));
         this.map.zoomTo(12);
-
         if (this.selectedFeatureLayer) {
-            if (this.selectedFeatureLayer.features.lenght > 0) {
-                this.featureLayer.addFeatures(this.selectedFeatureLayer.features);
-            }
-            this.selectedFeatureLayer.addFeatures([feature]);
+            this.selectControl.unselectAll();
+            this.selectedFeatureLayer.removeAllFeatures();
+            this.selectedFeatureLayer.addFeatures(feature);
         } else {
+            this.selectControl.unselectAll();
             this.selectControl.select(feature);
         }
-        //TODO: the text of new features is still drawn on top of the old feature's text
     },
 
     activateDraw: function(record) {
@@ -163,7 +164,7 @@
                     }, OpenLayers.Feature.Vector.style['default'])),
                     'select': new OpenLayers.Style({
                         externalGraphic: 'resources/lib/OpenLayers/img/marker-blue.png',
-                        pointRadius: 15,
+                        pointRadius: 12,
                         label: '${bez}',
                         labelAlign: 'rt',
                         fontColor: 'blue',
@@ -211,7 +212,6 @@
      * Forward OpenlayersEvent to EXT
      */
     selectedFeature: function(feature) {
-        this.selectControl.unselectAll({except:feature});
         this.fireEvent('featureselected', this, arguments);
     },
 
--- a/app/view/widget/Staat.js	Fri Jan 27 13:25:14 2017 +0100
+++ b/app/view/widget/Staat.js	Wed Feb 01 14:52:51 2017 +0100
@@ -22,6 +22,7 @@
     triggerAction: 'all',
     typeAhead: false,
     minChars: 0,
+    forceSelection: this.forceSelection || false,
 
     initComponent: function() {
         this.store = Ext.data.StoreManager.get('staaten');
--- a/app/view/widget/Verwaltungseinheit.js	Fri Jan 27 13:25:14 2017 +0100
+++ b/app/view/widget/Verwaltungseinheit.js	Wed Feb 01 14:52:51 2017 +0100
@@ -19,10 +19,11 @@
     hideTrigger: true,
     // Enable filtering of comboboxes
     autoSelect: false,
-    queryMode: 'remote',
+    queryMode: 'local',
     triggerAction: 'type',
     typeAhead: false,
     minChars: 2,
+    forceSelection: this.forceSelection || false,
 
     initComponent: function() {
         this.store = Ext.data.StoreManager.get('verwaltungseinheiten');
--- a/app/view/widget/base/TextField.js	Fri Jan 27 13:25:14 2017 +0100
+++ b/app/view/widget/base/TextField.js	Wed Feb 01 14:52:51 2017 +0100
@@ -29,7 +29,8 @@
             fieldLabel: this.fieldLabel,
             labelWidth: this.labelWidth,
             readOnly: this.readOnly || false,
-            listeners: this.listeners
+            listeners: this.listeners,
+            type: this.type
         }, {
             xtype: 'image',
             name: 'warnImg',
--- a/app/view/window/Messprogramm.js	Fri Jan 27 13:25:14 2017 +0100
+++ b/app/view/window/Messprogramm.js	Wed Feb 01 14:52:51 2017 +0100
@@ -94,6 +94,16 @@
                 xtype: 'messprogrammform',
                 recordId: this.record ? this.record.get('id') : null
             }, {
+                xtype: 'fset',
+                name: 'orte',
+                title: 'Ortsangaben',
+                padding: '5, 5',
+                margin: 5,
+                items: [{
+                    xtype: 'ortszuordnunggrid',
+                    recordId: me.record ? me.record.get('id') : null
+                }]
+            }, {
                 //Messmethoden
                 xtype: 'fieldset',
                 padding: '5, 5',
@@ -159,11 +169,11 @@
                     // If the Messprogramm is ReadOnly, disable Inputfields and grids
                     if (this.record.get('readonly') === true) {
                         this.down('messprogrammform').setReadOnly(true);
-                        //this.disableChildren();
+                        this.disableChildren();
                     }
                     else {
                         this.down('messprogrammform').setReadOnly(false);
-                        //this.enableChildren();
+                        this.enableChildren();
                     }
                     me.setLoading(false);
                 },
@@ -189,11 +199,11 @@
     */
 
     disableChildren: function() {
-        // there are no children....
+        this.down('fset[name=orte]').down('ortszuordnunggrid').setReadOnly(true);
     },
 
     enableChildren: function() {
-        // there are no children....
+        this.down('fset[name=orte]').down('ortszuordnunggrid').setReadOnly(false);
     },
 
     /**
--- a/app/view/window/Ortserstellung.js	Fri Jan 27 13:25:14 2017 +0100
+++ b/app/view/window/Ortserstellung.js	Wed Feb 01 14:52:51 2017 +0100
@@ -19,7 +19,9 @@
 
     minWidth: 350,
 
-    margin: 5,
+    margin: 10,
+
+    shadow: false,
 
     border: 0,
 
--- a/app/view/window/Ortszuordnung.js	Fri Jan 27 13:25:14 2017 +0100
+++ b/app/view/window/Ortszuordnung.js	Wed Feb 01 14:52:51 2017 +0100
@@ -7,13 +7,16 @@
  */
 
 /**
- * Window to create/edit the Ort / Probe Relation
+ * Window to create/edit the Ort/Probe or Ort/Messprogramm Relation
  */
+
 Ext.define('Lada.view.window.Ortszuordnung', {
     extend: 'Ext.window.Window',
     alias: 'widget.ortszuordnungwindow',
 
     requires: [
+        'Lada.model.Ortszuordnung',
+        'Lada.model.OrtszuordnungMp',
         'Lada.view.form.Ortszuordnung',
         'Lada.view.form.Ortserstellung',
         'Lada.view.panel.Map',
@@ -27,6 +30,7 @@
     constrain: true,
 
     probe: null,
+    messprogramm: null,
 
     parentWindow: null,
     record: null,
@@ -38,10 +42,11 @@
     initComponent: function() {
         var i18n = Lada.getApplication().bundle;
         this.title = i18n.getMsg('ortszuordnung.window.title');
-
-        if (this.record && this.probe) {
-            // A record be edited
-            this.title = i18n.getMsg('ortszuordnung.window.title')
+        var recordtype;
+        if (this.probe) {
+            if (this.record) {
+                // A probe record will be edited
+                this.title = i18n.getMsg('ortszuordnung.window.title')
                             + ' '
                             + i18n.getMsg('ortszuordnung.window.title2')
                             + ' '
@@ -50,10 +55,9 @@
                             + this.probe.get('hauptprobenNr')
                             + ' '
                             + i18n.getMsg('edit');
-        }
-        else if (this.probe) {
-            // A new record will be created
-            this.title = i18n.getMsg('ortszuordnung.window.title')
+            } else  {
+                // A new probe record will be created
+                this.title = i18n.getMsg('ortszuordnung.window.title')
                             + ' '
                             + i18n.getMsg('ortszuordnung.window.title2')
                             + ' '
@@ -62,7 +66,29 @@
                             + this.probe.get('hauptprobenNr')
                             + ' '
                             + i18n.getMsg('create');
+            }
+        } else if (this.messprogramm) {
+            if (this.record) {
+                // A messprogramm record will be edited
+                this.title = i18n.getMsg('ortszuordnung.window.title')
+                            + ' '
+                            + i18n.getMsg('ortszuordnung.window.title2')
+                            + ' '
+                            + i18n.getMsg('messprogramm')
+                            + ' '
+                            + i18n.getMsg('edit');
+            } else  {
+                // A new messprogramm record will be created
+                this.title = i18n.getMsg('ortszuordnung.window.title')
+                            + ' '
+                            + i18n.getMsg('ortszuordnung.window.title2')
+                            + ' '
+                            + i18n.getMsg('messprogramm')
+                            + ' '
+                            + i18n.getMsg('create');
+            }
         }
+
         this.buttons = [{
             text: i18n.getMsg('close'),
             scope: this,
@@ -97,6 +123,7 @@
                 xtype: 'ortszuordnungform',
                 region: 'east',
                 minHeight: 380,
+                type: this.probe? 'probe': 'mpr'
             }, {
                 region: 'south',
                 border: 0,
@@ -135,7 +162,6 @@
                 }]
             }]
         }];
-
         this.callParent(arguments);
     },
 
@@ -145,11 +171,16 @@
     initData: function() {
         var me = this;
         if (!this.record) {
-            this.record = Ext.create('Lada.model.Ortszuordnung');
+            if (this.probe) {
+                this.record = Ext.create('Lada.model.Ortszuordnung');
+                this.record.set('probeId', this.probe.get('id'));
+            } else {
+                this.record = Ext.create('Lada.model.OrtszuordnungMp');
+                this.record.set('messprogrammId', this.messprogramm.get('id'));
+            }
             if (!this.record.get('letzteAenderung')) {
                 this.record.data.letzteAenderung = new Date();
             }
-            this.record.set('probeId', this.probe.get('id'));
         }
         this.down('ortszuordnungform').setRecord(this.record);
         var map = this.down('map');
@@ -175,7 +206,7 @@
                             'gewählter Messpunkt', {
                                 styleMap: new OpenLayers.StyleMap({
                                     externalGraphic: 'resources/lib/OpenLayers/img/marker-blue.png',
-                                    pointRadius: 10,
+                                    pointRadius: 12,
                                     label: '${bez}',
                                     labelAlign: 'rt',
                                     fontColor: 'blue',
@@ -186,10 +217,13 @@
                             });
                         map.map.addLayer(map.selectedFeatureLayer);
                         map.selectedFeatureLayer.setZIndex(499);
-                        var ortId = me.record.get('ortId');
+                        var ortId = me.messprogramm? me.record.get('ort') : me.record.get('ortId');
                         if (ortId){
-                            var feat = map.featureLayer.getFeaturesByAttribute('id', ortId)[0];
-                            map.selectControl.select(feat);
+                            var feat = map.featureLayer.getFeaturesByAttribute('id', ortId);
+                            var ortrecord = this.findRecord('id', ortId);
+                            osg.selectOrt(map, feat);
+                            map.selectFeature(this.model, ortrecord);
+                            me.down('ortszuordnungform').setOrt(null,ortrecord);
                         }
                     }
                 }

http://lada.wald.intevation.org