1 var WGS84 = new OpenLayers.Projection("EPSG:4326");
2 var Mercator = new OpenLayers.Projection("EPSG:900913");
5 document.observe("dom:loaded", function() {
8 $$(".item").each(function(elt) {
14 this.deleteHandler = elt.on('click', '.delete-link', this.remove.bindAsEventListener(this));
16 this.map = this.createmap(elt.down('.map'));
19 createmap: function(elt) {
20 var geom = elt.getAttribute('data-geom'),
21 baseLayer = new OpenLayers.Layer.OSM("OSM"),
22 map = new OpenLayers.Map(elt, { controls: [], theme: null}),
23 layerOptions = {format: OpenLayers.Format.WKT,
25 styleMap: new OpenLayers.StyleMap({
26 "default": new OpenLayers.Style({
32 wkt = new OpenLayers.Format.WKT({ internalProjection: Mercator, externalProjection: WGS84 }),
33 viewLayer = new OpenLayers.Layer.Vector("View Layer", layerOptions),
36 map.addLayers([baseLayer, viewLayer]);
37 viewLayer.addFeatures([wkt.read(geom)]);
38 map.zoomToExtent(viewLayer.getDataExtent());
42 deleteSuccess: function() {
44 $("message").setMessage(SyjStrings.deleteSuccess, "success");
47 deactivate: function() {
49 this.elt.down('.title').update();
50 this.elt.down('.geom').update().setStyle({backgroundColor: 'gray'});
51 this.deleteHandler.stop();
52 this.elt.on('click', 'a', function(evt) { evt.stop(); });
53 this.elt.select('a').invoke('setStyle', {textDecoration: 'line-through'});
56 deleteFailure: function(transport) {
57 var httpCode = 0, message = "";
59 httpCode = transport.getStatus();
63 message = SyjStrings.notReachedError;
67 location = loginlink();
71 message = SyjStrings.requestError;
75 message = SyjStrings.gonePathError;
78 message = SyjStrings.serverError;
81 message = SyjStrings.unknownError;
84 $("message").setMessage(message, "error");
87 remove: function(evt) {
89 if (!confirm(SyjStrings.confirmDelete)) {
92 var id = this.elt.getAttribute('data-id');
94 $("message").clearMessages();
95 new Ajax.Request('path/' + id.toString() + '/delete', {
97 onSuccess: this.deleteSuccess.bind(this),
98 onFailure: this.deleteFailure.bind(this)
103 function loginlink() {
105 if (location.search && location.search.length && location.search[0] === '?') {
106 lang = location.search.slice(1).split('&').find(function(str) {
107 return str.startsWith('lang=');
110 lang = lang.slice('lang='.length);
113 return 'login?redirect=' + encodeURIComponent(location.pathname + location.search) + ((lang) ? '&lang=' + lang: "");