# HG changeset patch # User casties # Date 1290535378 -3600 # Node ID 825a92d0ab10687b90b79980f6818b5e8d8f4bcc # Parent 6f7f8dee6cd24fbd8e84188ed98d23707c5d5f3a fixed potential closure problem diff -r 6f7f8dee6cd2 -r 825a92d0ab10 gis_gui/blocks/map.js --- a/gis_gui/blocks/map.js Tue Nov 23 17:23:10 2010 +0100 +++ b/gis_gui/blocks/map.js Tue Nov 23 19:02:58 2010 +0100 @@ -59,31 +59,52 @@ return this.params; }; +guiBlocks.Block.prototype.deleteMapLayer = function (idx) { + // remove layer from this map + var layers = this.params.map_layers; + layers.splice(idx,1); + // update indexes + for (var i = 0; i < layers.length; i++) { + layers[i].idx = i; + } + return this.params; +}; + guiBlocks.Block.prototype.showMapParams = function (elem, params) { // create html with layer parameters from params - var i, layers, tmpl, lp, idx; + var i, layers, $tmpl, lp, idx; + var block = this; if (elem == null) { elem = this.element; } if (params == null) { params = this.params; } - $(elem).find(".map_name").val(params.name); + var $elem = $(elem); + $elem.find(".map_name").val(params.name); layers = params.map_layers; // remove old info $(elem).find(".map_layer_table .layer_info").remove(); // write new info if (layers.length > 0) { - tmpl = $(elem).find(".layer_info_tmpl").tmpl(layers); - $(elem).find(".map_layer_header").after(tmpl); + $tmpl = $elem.find(".layer_info_tmpl").tmpl(layers); + $elem.find(".map_layer_header").after($tmpl); // arm edit and delete buttons for (i = 0; i < layers.length; ++i) { lp = layers[i].layer; idx = layers[i].idx; console.debug("showmapparams lp=", lp, " idx=", idx); - tmpl.find(".layer_edit_"+idx).click(function () { + $tmpl.find(".layer_edit_"+idx).click(function () { + var param = lp; console.debug("open layer ",idx); - blocks.addLayerBlock("blocks/layer.html?table="+escape(lp.table),"layer", lp); + blocks.addLayerBlock("blocks/layer.html?table="+escape(lp.table),"layer", param); + }); + $tmpl.find(".layer_delete_"+idx).click(function () { + var layerIdx = idx; + console.debug("del layer ",layerIdx); + params = block.deleteMapLayer(layerIdx); + block.showMapParams(elem, params); + block.updateMap(elem, params); }); } } @@ -142,7 +163,7 @@ paramstr += "&connect_line="+params.connect_line; } var layerurl = "../db/RESTdb/db/public/" + escape(params.table) + "?" + paramstr; - jQuery.get(layerurl, function(data, textStatus, XMLHttpRequest) { + jQuery.get(layerurl, function (data, textStatus, XMLHttpRequest) { // function after load kml url finished console.debug("kml url loaded! this=", this, " data=", data, " ("+typeof(data)+")"); if (typeof(data) == "string") { diff -r 6f7f8dee6cd2 -r 825a92d0ab10 gis_gui/lib/blocks.js --- a/gis_gui/lib/blocks.js Tue Nov 23 17:23:10 2010 +0100 +++ b/gis_gui/lib/blocks.js Tue Nov 23 19:02:58 2010 +0100 @@ -14,6 +14,18 @@ return (typeof arguments[0] !== "undefined"); } +function randomString() { + var chars = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXTZabcdefghiklmnopqrstuvwxyz"; + var string_length = 8; + var randomstring = ''; + for (var i=0; i