Mercurial > hg > ChinaGisRestApi
changeset 72:825a92d0ab10
fixed potential closure problem
author | casties |
---|---|
date | Tue, 23 Nov 2010 19:02:58 +0100 |
parents | 6f7f8dee6cd2 |
children | 3779ad0ba9c7 |
files | gis_gui/blocks/map.js gis_gui/lib/blocks.js |
diffstat | 2 files changed, 43 insertions(+), 23 deletions(-) [+] |
line wrap: on
line diff
--- 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") {
--- 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<string_length; i++) { + var rnum = Math.floor(Math.random() * chars.length); + randomstring += chars.substring(rnum,rnum+1); + } + return randomstring; +} + + /* * guiBlocks base */ @@ -52,8 +64,8 @@ $(this).appendTo(container); // chain done function if (typeof(whenDone) == "function") { - // chain whenDone - whenDone(); + // chain whenDone (should we add parameters?) + whenDone.apply(this); } else { // default after load function $(this).fadeIn(); @@ -116,7 +128,7 @@ // collapse the block so that only its titlebar is visible function foldBlock(segment){ - if (! segment) { + if (segment == null) { return; } if(segment.hasClass("folded")){ @@ -157,16 +169,3 @@ }); } - - -function randomString() { - var chars = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXTZabcdefghiklmnopqrstuvwxyz"; - var string_length = 8; - var randomstring = ''; - for (var i=0; i<string_length; i++) { - var rnum = Math.floor(Math.random() * chars.length); - randomstring += chars.substring(rnum,rnum+1); - } - return randomstring; -} -