[Lada-commits] [PATCH] Merge behaviour of Stammdaten panel and ortszuordnungs grid

Wald Commits scm-commit at wald.intevation.org
Tue Feb 7 19:50:39 CET 2017


# HG changeset patch
# User Maximilian Krambach <mkrambach at intevation.de>
# Date 1486493436 -3600
# Node ID 5c2d6812d85a1d12b46e403af345b1d99dabbb20
# Parent  d1dce50fa9a612ba0daf3c5dc8df645d415679fb
Merge behaviour of Stammdaten panel and ortszuordnungs grid

according to the recent changes in Ortszuordnung and Ortserstellung.

diff -r d1dce50fa9a6 -r 5c2d6812d85a app/controller/Ort.js
--- a/app/controller/Ort.js	Tue Feb 07 18:56:35 2017 +0100
+++ b/app/controller/Ort.js	Tue Feb 07 19:50:36 2017 +0100
@@ -55,16 +55,14 @@
     },
 
     addRecord: function(button) {
-        var record = Ext.create('Lada.model.Ort');
+        Ext.create('Lada.view.window.Ortserstellung',{
+            record: Ext.create('Lada.model.Ort', {ortTyp: 1}),
+            parentWindow: button.up('ortpanel')
+        }).show();
         var grid = button.up('ortpanel').down('ortstammdatengrid');
-        if (grid.getCollapsed()) {
-            grid.expand();
-        }
-        if (!record.get('letzteAenderung')) {
-            record.data.letzteAenderung = new Date();
-        }
-        grid.store.insert(0, record);
-        grid.rowEditing.startEdit(0, 1);
+        // if (grid.getCollapsed()) {
+        //    grid.expand();
+        // }
     },
 
     deleteItem: function(button) {
diff -r d1dce50fa9a6 -r 5c2d6812d85a app/controller/form/Ortserstellung.js
--- a/app/controller/form/Ortserstellung.js	Tue Feb 07 18:56:35 2017 +0100
+++ b/app/controller/form/Ortserstellung.js	Tue Feb 07 19:50:36 2017 +0100
@@ -46,8 +46,9 @@
     },
 
     save: function(button) {
-        var me = button.up('panel');
-        var form = me.getForm();
+        var me = this;
+        var formpanel = button.up('ortserstellungsform');
+        var form = formpanel.getForm();
         var record = form.getRecord();
         var data = form.getFieldValues(true);
         for (var key in data) {
@@ -58,45 +59,28 @@
         record.save({
             success: function(newrecord, response) {
                 form.loadRecord(newrecord);
-                me.down('verwaltungseinheit').store.clearFilter();
-                me.down('staat').store.clearFilter();
+                formpanel.down('verwaltungseinheit').store.clearFilter();
+                formpanel.down('staat').store.clearFilter();
                 button.setDisabled(true);
-                me.down('button[action=revert]').setDisabled(true);
+                formpanel.down('button[action=revert]').setDisabled(true);
                 button.hide();
-                var ozw = me.up('window').parentWindow;
+                var ozw = formpanel.up('panel').parentWindow;
                 var json = Ext.decode(response.response.responseText);
                 if (json) {
-                    me.clearMessages();
-                    me.setMessages(json.errors, json.warnings);
+                    formpanel.clearMessages();
+                    formpanel.setMessages(json.errors, json.warnings);
                 }
-                ozw.ortstore.load({
-                    callback: function(records, operation, success) {
-                        ozw.down('map').addLocations(ozw.ortstore);
-                        var osg = ozw.down('ortstammdatengrid');
-                        osg.setStore(ozw.ortstore);
-                        var id = Ext.decode(response.response.responseText).data.id;
-                        var record = osg.store.getById(id);
-                        var selmod = osg.getView().getSelectionModel();
-                        selmod.select(record);
-                        var resulttext;
-                        if (json) {
-                            if (json.message == '201') {
-                                resulttext = 'Dieser Ort existiert bereits!';
-                            }
-                            if (json.message == '200') {
-                                resulttext = 'Ort erfolgreich angelegt!';
-                            }
-                        }
-                        Ext.Msg.show({
-                            title: Lada.getApplication().bundle.getMsg('success'),
-                            autoScroll: true,
-                            msg: resulttext,
-                            buttons: Ext.Msg.OK
-                        });
-                    },
-                    scope: this
-                });
-
+                if (ozw.ortstore) {
+                    ozw.ortstore.load({
+                        callback: function(records, operation, success) {
+                            me.afterSave(formpanel, ozw.ortstore, json);
+                        },
+                        scope: this
+                    });
+                } else {
+                    ozw.setStore();
+                    me.afterSave(formpanel, ozw.getStore(), json);
+                }
             },
             failure: function(record, response) {
                 var json = response.request.scope.reader.jsonData;
@@ -119,6 +103,35 @@
         });
     },
 
+    /**
+     * Callbacks after a Ort has been saved and the store is reloaded
+     */
+    afterSave: function(form, store, json) {
+        var ozw = form.up('panel').parentWindow;
+        ozw.down('map').addLocations(ozw.ortstore);
+        var osg = ozw.down('ortstammdatengrid');
+        osg.setStore(ozw.ortstore);
+        var id = json.data.id;
+        var record = osg.store.getById(id);
+        var selmod = osg.getView().getSelectionModel();
+        selmod.select(record);
+        var resulttext;
+        if (json) {
+            if (json.message == '201') {
+                resulttext = 'Dieser Ort existiert bereits!';
+            }
+            if (json.message == '200') {
+                resulttext = 'Ort erfolgreich angelegt!';
+            }
+        }
+        Ext.Msg.show({
+            title: Lada.getApplication().bundle.getMsg('success'),
+                     autoScroll: true,
+                     msg: resulttext,
+                     buttons: Ext.Msg.OK
+        });
+    },
+
     discard: function(button) {
         button.up('panel').getForm().reset();
     },
diff -r d1dce50fa9a6 -r 5c2d6812d85a app/controller/grid/Ortszuordnung.js
--- a/app/controller/grid/Ortszuordnung.js	Tue Feb 07 18:56:35 2017 +0100
+++ b/app/controller/grid/Ortszuordnung.js	Tue Feb 07 19:50:36 2017 +0100
@@ -154,15 +154,12 @@
     },
 
     /**
-     *
-     * Creates an event listener for a map click
+     * Creates a new Ortrecord from map coordinates
      */
     frommap: function(button) {
         var map = button.up('ortszuordnungwindow').down('map');
-        map.getEl().setStyle('cursor', 'crosshair');
-        var me = this;
-        map.map.events.register('click', button, me.newOrtfromMapClick);
-        // TODO Deactivate event listener if button is destroyed
+        var record = Ext.create('Lada.model.Ort');
+        map.activateDraw(record);
     },
 
     /**
@@ -182,28 +179,6 @@
     },
 
     /**
-     * Gets the clicked map's coordinates and opens a new Messpunkt window with coordinates prefilled
-     */
-    newOrtfromMapClick: function(evt) {
-        var me = this; //this = button(action:frommap)
-        var map = this.up('ortszuordnungwindow').down('map').map;
-        this.up('ortszuordnungwindow').down('map').getEl().setStyle('cursor', 'auto');
-        var lonlat = map.getLonLatFromViewPortPx(evt.xy).transform(new OpenLayers.Projection('EPSG:3857'),
-                                                                   new OpenLayers.Projection('EPSG:4326'));
-        var controller = Lada.app.getController('Lada.controller.grid.Ortszuordnung');
-        map.events.unregister('click', this, controller.newOrtfromMapClick);
-        Ext.create('Lada.view.window.Ortserstellung', {
-            record: Ext.create('Lada.model.Ort',{
-                koordXExtern: lonlat.lon,
-                koordYExtern: lonlat.lat,
-                kdaId : 4,
-                ortTyp: 1
-            }),
-            parentWindow: this.up('ortszuordnungwindow')
-        }).show();
-    },
-
-    /**
      * Search triggered by textfield key event.
      */
     search: function(field, evt, opts) {
diff -r d1dce50fa9a6 -r 5c2d6812d85a app/view/panel/Map.js
--- a/app/view/panel/Map.js	Tue Feb 07 18:56:35 2017 +0100
+++ b/app/view/panel/Map.js	Tue Feb 07 19:50:36 2017 +0100
@@ -120,27 +120,30 @@
         }
     },
 
-    activateDraw: function(record) {
-        this.locationRecord = record;
+    activateDraw: function() {
         if (!this.drawPoint) {
             this.drawPoint = new OpenLayers.Control.DrawFeature(this.featureLayer,
                 OpenLayers.Handler.Point);
             this.map.addControl(this.drawPoint);
+            this.drawPoint.events.register('featureadded', this, this.featureAdded);
         }
         this.drawPoint.activate();
-        this.drawPoint.events.register('featureadded', this, this.featureAdded);
     },
 
     featureAdded: function(features) {
-        this.locationRecord.set('kdaId', 4);
         features.feature.geometry.transform(new OpenLayers.Projection('EPSG:3857'),
                                             new OpenLayers.Projection('EPSG:4326'));
-        this.locationRecord.set('koordYExtern', features.feature.geometry.y);
-        this.locationRecord.set('koordXExtern', features.feature.geometry.x);
+        var parent = this.up('ortszuordnungwindow') || this.up('ortpanel');
+        Ext.create('Lada.view.window.Ortserstellung', {
+            record: Ext.create('Lada.model.Ort',{
+                koordXExtern: features.feature.geometry.x,
+                koordYExtern: features.feature.geometry.y,
+                kdaId : 4,
+                ortTyp: 1
+            }),
+            parentWindow: parent
+        }).show();
         this.drawPoint.deactivate();
-        this.fireEvent('featureadded', this.locationRecord);
-    //    this.selectControl.unselectAll();
-    //    this.selectControl.select(features.feature);
     },
 
     addLocations: function(locationStore) {
diff -r d1dce50fa9a6 -r 5c2d6812d85a app/view/panel/Ort.js
--- a/app/view/panel/Ort.js	Tue Feb 07 18:56:35 2017 +0100
+++ b/app/view/panel/Ort.js	Tue Feb 07 19:50:36 2017 +0100
@@ -89,8 +89,12 @@
                 }
             }
         }];
-
         this.callParent(arguments);
+        var map = this.down('map');
+        var osg = this.down('ortstammdatengrid');
+        osg.setLoading(true);
+        map.setLoading(true);
+        this.setStore();
     },
 
     afterRender: function() {
@@ -102,41 +106,32 @@
         var me = this;
         var osg = this.down('ortstammdatengrid');
         var map = this.down('map');
+        osg.setLoading(true);
+        map.setLoading(true);
 
         if (!store) {
-            var ortstore = Ext.create('Lada.store.Orte', {
-                defaultPageSize: 0,
-                listeners: {
-                    beforeload: {
-                        fn: function() {
-                            osg.setLoading(true);
-                            map.setLoading(true);
-                        }
-                    },
-                    load: {
-                        fn: function() {
-                            osg.setLoading(false);
-                            map.setLoading(false);
-                            osg.setStore(ortstore);
-                            map.addLocations(ortstore);
-                        }
-                    }
-                }
-            });
+            this.ortstore = Ext.data.StoreManager.get('orte');
+            //this.ortstore.clearFilter(true);
+        } else {
+            this.ortstore = store;
         }
-        else {
-            store.clearFilter(true);
-            osg.setStore(store);
-            map.addLocations(store);
-        }
+        // store.clearFilter(true);
+        this.ortstore.load({
+            callback: function() {
+                osg.setStore(me.ortstore);
+                map.addLocations(me.ortstore);
+                osg.setLoading(false);
+                map.setLoading(false);
+            }
+        });
+        //enable buttons
+        this.down('toolbar button[action=add]').enable();
+        this.down('toolbar button[action=addMap]').enable();
         this.connectListeners();
-        //enable buttons
-        me.down('toolbar button[action=add]').enable();
-        me.down('toolbar button[action=addMap]').enable();
     },
 
     getStore: function() {
-        return this.down('grid').getStore();
+        return this.ortstore;
     },
 
     connectListeners: function() {


More information about the Lada-commits mailing list