[Lada-commits] [PATCH 1 of 2] made window-panel recyclable, fwd openlayers events to ext

Wald Commits scm-commit at wald.intevation.org
Wed May 20 17:33:19 CEST 2015


# HG changeset patch
# User Dustin Demuth <dustin at intevation.de>
# Date 1432124352 -7200
# Node ID 7267bae1d43f9df13e275ac23cffe141e12723ef
# Parent  255568e97c961005d1eabb07616ff26b261692d7
made window-panel recyclable, fwd openlayers events to ext

diff -r 255568e97c96 -r 7267bae1d43f app/view/panel/Map.js
--- a/app/view/panel/Map.js	Mon May 18 17:04:32 2015 +0200
+++ b/app/view/panel/Map.js	Wed May 20 14:19:12 2015 +0200
@@ -32,7 +32,7 @@
      * Initialize the map panel.
      */
     initComponent: function() {
-        var id = this.record ? this.record.get('id') : Math.floor(Math.random() * 100);
+        var id = Ext.id();
         this.layers = [
             new OpenLayers.Layer.WMS(
                 'Standard' + id,
@@ -60,6 +60,7 @@
         this.bodyStyle = {background: '#fff'};
         this.initData();
         this.tbar = Ext.create('Lada.view.widget.MapToolbar');
+        this.addEvents('featureselected');
         this.callParent(arguments);
     },
 
@@ -92,6 +93,7 @@
         });
         this.featureLayer.addFeatures(this.locationFeatures);
         this.map.addLayer(this.featureLayer);
+
         this.selectControl = new OpenLayers.Control.SelectFeature(this.featureLayer, {
             clickout: false,
             toggle: false,
@@ -104,20 +106,6 @@
         this.selectControl.activate();
     },
 
-    selectedFeature: function(feature) {
-        if (feature.attributes.id &&
-            feature.attributes.id !== '') {
-            var record = Ext.data.StoreManager.get('locations').getById(feature.attributes.id);
-            this.up('window').down('locationform').setRecord(record);
-            this.up('window').down('locationform').setReadOnly(true);
-            this.up('window').down('ortform').down('combobox').setValue(record.id);
-        }
-        else {
-            this.up('window').down('locationform').setRecord(this.locationRecord);
-            this.up('window').down('locationform').setReadOnly(false);
-        }
-    },
-
     selectFeature: function(id) {
         var feature = this.featureLayer.getFeaturesByAttribute('id', id);
         this.map.setCenter(
@@ -153,16 +141,18 @@
      */
     afterRender: function() {
         this.superclass.afterRender.apply(this, arguments);
+
         this.map.render(this.body.dom);
         this.map.addControl(new OpenLayers.Control.Navigation());
         this.map.addControl(new OpenLayers.Control.PanZoomBar());
         this.map.addControl(new OpenLayers.Control.ScaleLine());
-        if (this.record) {
-            this.selectFeature(this.record.get('ort'));
-        }
-        else {
-            this.map.zoomToMaxExtent();
-        }
+    },
+
+    /**
+     * Forward OpenlayersEvent to EXT
+     */
+    selectedFeature: function() {
+        this.fireEvent('featureselected', this, arguments);
     },
 
     beforeDestroy: function() {
diff -r 255568e97c96 -r 7267bae1d43f app/view/window/OrtCreate.js
--- a/app/view/window/OrtCreate.js	Mon May 18 17:04:32 2015 +0200
+++ b/app/view/window/OrtCreate.js	Wed May 20 14:19:12 2015 +0200
@@ -6,8 +6,8 @@
  * the documentation coming with IMIS-Labordaten-Application for details.
  */
 
-/*
- * Window to edit a Messung
+/**
+ * Window to create a Ort
  */
 Ext.define('Lada.view.window.OrtCreate', {
     extend: 'Ext.window.Window',
@@ -78,7 +78,10 @@
                 bodyStyle: {
                     background: '#fff'
                 },
-                name: 'map'
+                name: 'map',
+                listeners: { //A listener which listens to the mappanels featureselected event
+                    featureselected: this.selectedFeature
+                }
             }]
         }];
         this.callParent(arguments);
@@ -91,6 +94,34 @@
         this.down('ortform').setRecord(ort);
     },
 
+    /**
+     * @private
+     * Override to display and update the map view in the panel.
+     */
+    afterRender: function(){
+        this.superclass.afterRender.apply(this, arguments);
+        var map = this.down('map');
+        map.map.zoomToMaxExtent();
+    },
+
+    /**
+     * This function is used by the MapPanel, when a Feature was selected
+     */
+    selectedFeature: function(context, args) {
+    var feature = args[0];
+        if (feature.attributes.id &&
+            feature.attributes.id !== '') {
+            var record = Ext.data.StoreManager.get('locations').getById(feature.attributes.id);
+            context.up('window').down('locationform').setRecord(record);
+            context.up('window').down('locationform').setReadOnly(true);
+            context.up('window').down('ortform').down('combobox').setValue(record.id);
+        }
+        else {
+            context.up('window').down('locationform').setRecord(this.locationRecord);
+            context.up('window').down('locationform').setReadOnly(false);
+        }
+    },
+
     setMessages: function(errors, warnings) {
         //todo this is a stub
     },
diff -r 255568e97c96 -r 7267bae1d43f app/view/window/OrtEdit.js
--- a/app/view/window/OrtEdit.js	Mon May 18 17:04:32 2015 +0200
+++ b/app/view/window/OrtEdit.js	Wed May 20 14:19:12 2015 +0200
@@ -6,8 +6,8 @@
  * the documentation coming with IMIS-Labordaten-Application for details.
  */
 
-/*
- * Window to edit a Messung
+/**
+ * Window to edit a Ort
  */
 Ext.define('Lada.view.window.OrtEdit', {
     extend: 'Ext.window.Window',
@@ -93,7 +93,10 @@
                 bodyStyle: {
                     background: '#fff'
                 },
-                name: 'map'
+                name: 'map',
+                listeners: { //A listener which listens to the mappanels featureselected event
+                    featureselected: this.selectedFeature
+                }
             }]
         }];
         this.callParent(arguments);
@@ -141,6 +144,39 @@
         });
     },
 
+    /**
+     * @private
+     * Override to display and update the map view in the panel.
+     */
+    afterRender: function(){
+        this.superclass.afterRender.apply(this, arguments);
+        var map = this.down('map');
+        if (this.record) {
+            map.selectFeature(this.record.get('ort'));
+        }
+        else {
+            map.map.zoomToMaxExtent();
+        }
+    },
+
+    /**
+     * This function is used by the MapPanel, when a Feature was selected
+     */
+    selectedFeature: function(context, args) {
+    var feature = args[0];
+        if (feature.attributes.id &&
+            feature.attributes.id !== '') {
+            var record = Ext.data.StoreManager.get('locations').getById(feature.attributes.id);
+            context.up('window').down('locationform').setRecord(record);
+            context.up('window').down('locationform').setReadOnly(true);
+            context.up('window').down('ortform').down('combobox').setValue(record.id);
+        }
+        else {
+            context.up('window').down('locationform').setRecord(this.locationRecord);
+            context.up('window').down('locationform').setReadOnly(false);
+        }
+    },
+
     setMessages: function(errors, warnings) {
         //todo this is a stub
     },


More information about the Lada-commits mailing list