X-Git-Url: https://dev.renevier.net/?a=blobdiff_plain;f=public%2Fjs%2Flist.js;h=a51092772ccb6083583d6c01eb0c27feff7f5fd5;hb=24364d6ff0a0f73a41cf8df2bd17283f3355a59a;hp=62f7b068d82c186e5e3e41dc5bf9a01177fb5393;hpb=1d1b5940442782d78f796d8608e63328e2e8783b;p=syj.git diff --git a/public/js/list.js b/public/js/list.js index 62f7b06..a510927 100644 --- a/public/js/list.js +++ b/public/js/list.js @@ -1,10 +1,27 @@ +/* This file is part of Syj, Copyright (c) 2010-2011 Arnaud Renevier, + and is published under the AGPL license. */ + +"use strict"; + var WGS84 = new OpenLayers.Projection("EPSG:4326"); var Mercator = new OpenLayers.Projection("EPSG:900913"); document.observe("dom:loaded", function() { $("message").hide(); - $$(".map").each(function(elt) { + + $$(".item").each(function(elt) { + new item(elt); + }); +}); + +function item(elt) { + this.deleteHandler = elt.on('click', '.delete-link', this.remove.bindAsEventListener(this)); + this.elt = elt; + this.map = this.createmap(elt.down('.map')); +} +item.prototype = { + createmap: function(elt) { var geom = elt.getAttribute('data-geom'), baseLayer = new OpenLayers.Layer.OSM("OSM"), map = new OpenLayers.Map(elt, { controls: [], theme: null}), @@ -24,24 +41,16 @@ document.observe("dom:loaded", function() { map.addLayers([baseLayer, viewLayer]); viewLayer.addFeatures([wkt.read(geom)]); map.zoomToExtent(viewLayer.getDataExtent()); - }); - - $$(".item").each(function(elt) { - new item(elt); - }); -}); + return map; + }, -function item(elt) { - this.deleteHandler = elt.on('click', '.delete-link', this.remove.bindAsEventListener(this)); - this.elt = elt; -} -item.prototype = { deleteSuccess: function() { this.deactivate(); $("message").setMessage(SyjStrings.deleteSuccess, "success"); }, deactivate: function() { + this.map.destroy(); this.elt.down('.title').update(); this.elt.down('.geom').update().setStyle({backgroundColor: 'gray'}); this.deleteHandler.stop(); @@ -87,7 +96,7 @@ item.prototype = { } var id = this.elt.getAttribute('data-id'); - $("message").hide(); + $("message").clearMessages(); new Ajax.Request('path/' + id.toString() + '/delete', { method: 'post', onSuccess: this.deleteSuccess.bind(this),