changeset 796:7267bae1d43f

made window-panel recyclable, fwd openlayers events to ext
author Dustin Demuth <dustin@intevation.de>
date Wed, 20 May 2015 14:19:12 +0200 (2015-05-20)
parents 255568e97c96
children b8fd43021c29
files app/view/panel/Map.js app/view/window/OrtCreate.js app/view/window/OrtEdit.js
diffstat 3 files changed, 84 insertions(+), 27 deletions(-) [+]
line wrap: on
line diff
--- 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() {
--- 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
     },
--- 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
     },

http://lada.wald.intevation.org