]> dev.renevier.net Git - syj.git/blob - public/js/list.js
update translations
[syj.git] / public / js / list.js
1 var WGS84 = new OpenLayers.Projection("EPSG:4326");
2 var Mercator = new OpenLayers.Projection("EPSG:900913");
3
4
5 document.observe("dom:loaded", function() {
6     $("message").hide();
7     $$(".map").each(function(elt) {
8         var geom = elt.getAttribute('data-geom'),
9             baseLayer = new OpenLayers.Layer.OSM("OSM"),
10             map = new OpenLayers.Map(elt, { controls: [], theme: null}),
11             layerOptions = {format:     OpenLayers.Format.WKT,
12                             projection: WGS84,
13                             styleMap:   new OpenLayers.StyleMap({
14                                             "default": new OpenLayers.Style({
15                                                 strokeColor: "blue",
16                                                 strokeWidth: 5,
17                                                 strokeOpacity: 0.7
18                                             })
19                                          })},
20             wkt = new OpenLayers.Format.WKT({ internalProjection: Mercator, externalProjection: WGS84 }),
21             viewLayer = new OpenLayers.Layer.Vector("View Layer", layerOptions),
22             extent;
23
24         map.addLayers([baseLayer, viewLayer]);
25         viewLayer.addFeatures([wkt.read(geom)]);
26         map.zoomToExtent(viewLayer.getDataExtent());
27     });
28
29     $$(".item").each(function(elt) {
30         new item(elt);
31     });
32 });
33
34 function item(elt) {
35     this.deleteHandler = elt.on('click', '.delete-link', this.remove.bindAsEventListener(this));
36     this.elt = elt;
37 }
38 item.prototype = {
39     deleteSuccess: function() {
40         this.elt.down('.title').update();
41         this.elt.down('.geom').update().setStyle({backgroundColor: 'gray'});
42         this.deleteHandler.stop();
43         this.elt.on('click', 'a', function(evt) { evt.stop(); });
44         this.elt.select('a').invoke('setStyle', {textDecoration: 'line-through'});
45         $("message").setMessage(SyjStrings.deleteSuccess, "success");
46     },
47
48     deleteFailure: function(transport) {
49         var httpCode = 0, message = "";
50         if (transport) {
51             httpCode = transport.getStatus();
52         }
53         switch (httpCode) {
54             case 0:
55                 message = SyjStrings.notReachedError;
56             break;
57             case 400:
58             case 403:
59                 location = loginlink();
60                 return;
61             break;
62             case 404:
63                  message = SyjStrings.requestError;
64             break;
65             case 410:
66                 message = SyjStrings.gonePathError;
67             break;
68             case 500:
69                 message = SyjStrings.serverError;
70             break;
71             default:
72                 message = SyjStrings.unknownError;
73             break;
74         }
75         $("message").setMessage(message, "error");
76     },
77
78     remove: function(evt) {
79         evt.stop();
80         if (!confirm(SyjStrings.confirmDelete)) {
81             return;
82         }
83         var id = this.elt.getAttribute('data-id');
84
85         $("message").hide();
86         new Ajax.Request('path/' + id.toString() + '/delete', {
87             method: 'post',
88             onSuccess: this.deleteSuccess.bind(this),
89             onFailure: this.deleteFailure.bind(this)
90         });
91     }
92 };
93
94 function loginlink() {
95     var lang;
96     if (location.search && location.search.length && location.search[0] === '?') {
97         lang = location.search.slice(1).split('&').find(function(str) {
98             return str.startsWith('lang=');
99         });
100         if (lang) {
101             lang = lang.slice('lang='.length);
102         }
103     }
104     return 'login?redirect=' + encodeURIComponent(location.pathname + location.search) + ((lang) ? '&lang=' + lang: "");
105 }