Permalink
Browse files

Move editing javascript from GeoExplorer to view template

  • Loading branch information...
1 parent aa9655c commit 288e657d39358b6d002f1e8123bc10e3eeeb8a62 @mbertrand mbertrand committed Oct 31, 2012
Showing with 51 additions and 49 deletions.
  1. +0 −48 geonode-client/app/static/script/app/GeoExplorer.js
  2. +51 −1 geonode/maps/templates/maps/map_view.html
View
48 geonode-client/app/static/script/app/GeoExplorer.js
@@ -433,49 +433,6 @@ var GeoExplorer = Ext.extend(gxp.Viewer, {
});
GeoExplorer.superclass.loadConfig.apply(this, arguments);
},
-
- //Check permissions for selected layer and enable/disable feature edit buttons accordingly
- checkLayerPermissions:function (layerRecord) {
-
- var buttons = this.tools["gn_layer_editor"].actions;
-
- var toggleButtons = function(enabled) {
- for (var i = 0; i < buttons.length; i++) {
- enabled ? buttons[i].enable() : buttons[i].disable();
- }
- }
-
- //Disable if layer is null or selected layer in tree doesn't match input layer
- var tree_node = Ext.getCmp("treecontent").getSelectionModel().getSelectedNode();
- if (layerRecord == null) {
- toggleButtons(false);
- }
- else {
- //Proceed if this is a local queryable WMS layer
- var layer = layerRecord.getLayer();
- if (layer instanceof OpenLayers.Layer.WMS && (layer.url == "/geoserver/wms" ||
- layer.url.indexOf(this.localGeoServerBaseUrl.replace(this.urlPortRegEx, "$1/")) == 0)) {
- Ext.Ajax.request({
- url:"/layers/" + layer.params.LAYERS + "/edit-check",
- method:"POST",
- success:function (result, request) {
- if (result.status != 200) {
- toggleButtons(false);
- } else {
- layer.displayOutsideMaxExtent = true;
- toggleButtons(true);
- }
- },
- failure:function (result, request) {
- toggleButtons(false);
- }
- });
- } else {
- toggleButtons(false);
- }
- }
- },
-
initMapPanel: function() {
this.mapItems = [{
@@ -674,11 +631,6 @@ var GeoExplorer = Ext.extend(gxp.Viewer, {
}
}
];
-
- //Activate now, after layer has been autoselected in tree
- if ("gn_layer_editor" in this.tools) {
- this.tools["gn_layer_editor"].getFeatureManager().activate();
- }
GeoExplorer.superclass.initPortal.apply(this, arguments);
},
View
52 geonode/maps/templates/maps/map_view.html
@@ -35,7 +35,7 @@
autoLoadFeatures: true,
listeners: {
'layerchange': function(mgr, layer, schema) {
- app.checkLayerPermissions(layer);
+ checkLayerPermissions(layer);
}
}
},
@@ -61,8 +61,58 @@
authorizedRoles: "{{ user.is_authenticated|yesno:"ROLE_ADMINISTRATOR,ROLE_ANONYMOUS" }}"
}, {{ config }});
+
app = new GeoExplorer(config);
+ {% if user.is_authenticated and DB_DATASTORE %}
+ //Check permissions for selected layer and enable/disable feature edit buttons accordingly
+ var checkLayerPermissions = function (layerRecord) {
+
+ var buttons = app.tools["gn_layer_editor"].actions;
+
+ var toggleButtons = function(enabled) {
+ for (var i = 0; i < buttons.length; i++) {
+ enabled ? buttons[i].enable() : buttons[i].disable();
+ }
+ }
+
+ //Disable if layer is null or selected layer in tree doesn't match input layer
+ var tree_node = Ext.getCmp("treecontent").getSelectionModel().getSelectedNode();
+ if (layerRecord == null) {
+ toggleButtons(false);
+ }
+ else {
+ //Proceed if this is a local queryable WMS layer
+ var layer = layerRecord.getLayer();
+ if (layer instanceof OpenLayers.Layer.WMS && (layer.url == "/geoserver/wms" ||
+ layer.url.indexOf(app.localGeoServerBaseUrl.replace(app.urlPortRegEx, "$1/")) == 0)) {
+ Ext.Ajax.request({
+ url:"/layers/" + layer.params.LAYERS + "/edit-check",
+ method:"POST",
+ success:function (result, request) {
+ if (result.status != 200) {
+ toggleButtons(false);
+ } else {
+ layer.displayOutsideMaxExtent = true;
+ toggleButtons(true);
+ }
+ },
+ failure:function (result, request) {
+ toggleButtons(false);
+ }
+ });
+ } else {
+ toggleButtons(false);
+ }
+ }
+ };
+
+ //Activate the editing if a map is created with a layer already in the config
+ app.on('ready',function(){
+ app.tools["gn_layer_editor"].getFeatureManager().setLayer(app.selectedLayer);
+ });
+ {% endif %}
+
var permalinkTemplate = new Ext.Template("{protocol}//{host}/geonode/maps/{id}");
var permalink = function(id) {
return permalinkTemplate.apply({

0 comments on commit 288e657

Please sign in to comment.