1 /* Copyright (c) 2009 Arnaud Renevier, Inc, published under the modified BSD
4 // drag feature with tolerance
5 OpenLayers.Control.SypDragFeature = OpenLayers.Class (OpenLayers.Control.DragFeature, {
11 downFeature: function(pixel) {
12 OpenLayers.Control.DragFeature.prototype.downFeature.apply(this, arguments);
13 this.dragStart = (new Date()).getTime();
14 this.startPixel = pixel;
17 doneDragging: function(pixel) {
18 OpenLayers.Control.DragFeature.prototype.doneDragging.apply(this, arguments);
20 var passesTimeTolerance =
21 (new Date()).getTime() > this.dragStart + this.timeTolerance;
23 var xDiff = this.startPixel.x - pixel.x;
24 var yDiff = this.startPixel.y - pixel.y;
26 var passesPixelTolerance =
27 Math.sqrt(Math.pow(xDiff,2) + Math.pow(yDiff,2)) > this.pixelTolerance;
29 if(passesTimeTolerance && passesPixelTolerance){
30 this.onComplete(this.feature, pixel);
32 var feature = this.feature;
33 var res = this.map.getResolution();
34 this.feature.geometry.move(res * (this.startPixel.x - this.lastPixel.x),
35 res * (this.lastPixel.y - this.startPixel.y));
36 this.layer.drawFeature(this.feature);
38 this.layer.drawFeature(this.feature, "select");
41 moveFeature: function(pixel) {
42 OpenLayers.Control.DragFeature.prototype.moveFeature.apply(this, arguments);
43 this.layer.drawFeature(this.feature, "temporary");
46 overFeature: function (feature) {
47 // can only drag and drop currently selected feature
48 if (feature != Admin.currentFeature) {
51 OpenLayers.Control.DragFeature.prototype.overFeature.apply(this, arguments);
54 CLASS_NAME: "OpenLayers.Control.SypDragFeature"
59 ICON: "media/marker-normal.png",
60 SELECT_ICON: "media/marker-selected.png",
61 TEMPORARY_ICON: "media/marker-temp.png",
68 selFeatureControl: null,
69 moveFeatureControl: null,
70 addFeatureControl: null,
73 currentFeatureLocation: null,
76 this.map = new OpenLayers.Map ("map", {
78 new OpenLayers.Control.Navigation (),
79 new OpenLayers.Control.PanZoom ()
81 projection: new OpenLayers.Projection("EPSG:900913"),
82 displayProjection: new OpenLayers.Projection("EPSG:4326")
85 this.baseLayer = this.createBaseLayer ();
86 this.map.addLayer(this.baseLayer);
88 this.map.setCenter(new OpenLayers.LonLat(0, 0), 0);
89 if (sypSettings.loggedUser) {
90 this.dataLayer = this.createDataLayer (sypSettings.loggedUser);
91 this.map.addLayer(this.dataLayer);
97 this.addFeatureControl.deactivate();
98 this.moveFeatureControl.deactivate();
99 this.selFeatureControl.activate();
100 this.checkForFeatures();
101 $("#newfeature_button").show().val(SypStrings.AddItem);
102 $("#newfeature_button").unbind("click").click(function () {
103 Admin.addNewFeature();
107 createBaseLayer: function () {
108 return new OpenLayers.Layer.OSM("OSM");
111 createDataLayer: function (user) {
112 var styleMap = new OpenLayers.StyleMap (
114 externalGraphic: this.Markers.ICON,
115 graphicHeight: this.Markers.HEIGHT || 32
118 externalGraphic: this.Markers.TEMPORARY_ICON,
119 graphicHeight: this.Markers.HEIGHT || 32
122 externalGraphic: this.Markers.SELECT_ICON,
123 graphicHeight: this.Markers.HEIGHT || 32
126 var layer = new OpenLayers.Layer.GML("KML", "items.php?from_user=" + encodeURIComponent(user),
129 format: OpenLayers.Format.KML,
130 projection: this.map.displayProjection,
131 eventListeners: { scope: this,
132 loadend: this.dataLayerEndLoad
137 this.selFeatureControl = this.createSelectFeatureControl(layer)
138 this.map.addControl(this.selFeatureControl);
139 this.moveFeatureControl = this.createMoveFeatureControl(layer)
140 this.map.addControl(this.moveFeatureControl);
141 this.addFeatureControl = this.createNewfeatureControl();
142 this.map.addControl(this.addFeatureControl);
147 createMoveFeatureControl: function (layer) {
148 var control = new OpenLayers.Control.SypDragFeature(
154 createSelectFeatureControl: function (layer) {
155 var control = new OpenLayers.Control.SelectFeature(
157 onSelect: OpenLayers.Function.bind(this.onFeatureSelect, this)
162 createNewfeatureControl: function () {
163 var control = new OpenLayers.Control ();
164 var handler = new OpenLayers.Handler.Click(control, {
165 'click': OpenLayers.Function.bind(FeatureMgr.add, FeatureMgr)
167 control.handler = handler;
171 onFeatureSelect: function (feature) {
172 this.showEditor(feature);
174 this.selFeatureControl.deactivate();
175 this.moveFeatureControl.activate();
178 closeEditor: function() {
179 if ($("#editor").css("display") == "none") {
182 if (this.currentFeature && this.currentFeature.layer) {
183 this.selFeatureControl.unselect(this.currentFeature);
185 this.currentFeature = null;
186 this.currentFeatureLocation = null;
187 $("#img").removeAttr('src');
188 $("#img").parent().html($("#img").parent().html());
189 $("#img").parent().show();
190 $("#title, #description").val("");
192 // do it once before hidding and once after hidding to work in all cases
193 $("#title, #description").val("");
194 $("#image_file").parent().html($("#image_file").parent().html());
195 $(document).unbind("keydown");
196 this.checkForFeatures();
200 showEditor: function (feature) {
201 $("#newfeature_button").hide();
209 $(document).unbind("keydown").keydown(function(e) {
210 if (e.keyCode == 27) {
211 Admin.cancelCurrentFeature()
215 this.currentFeature = feature;
216 this.currentFeatureLocation = new OpenLayers.Pixel(feature.geometry.x, feature.geometry.y);
218 $("#instructions").text(SypStrings.DragDropHowto);
219 $("#title").val(feature.attributes.name);
220 var fullDesc = $(feature.attributes.description).parent();
221 $("#description").val(fullDesc.find('p').text());
222 var src = fullDesc.find('img').attr('src');
224 $("#img").parent().show();
225 $("#img").attr('src', src);
226 $("#image_file").parent().hide();
227 $("#image_delete").show();
229 $("#img").parent().hide();
230 $("#image_file").parent().show();
231 $("#image_delete").hide();
233 $("#title").select().focus();
236 dataLayerEndLoad: function() {
237 // only set zoom extent once
238 this.dataLayer.events.unregister('loadend', this, this.dataLayerEndLoad);
239 this.dataLayer.events.register('loadend', this, this.checkForFeatures);
241 if (!this.checkForFeatures()) {
246 var orig = this.Utils.mbr (this.dataLayer);
247 var centerBounds = new OpenLayers.Bounds();
249 var mapProj = map.getProjectionObject();
250 var sypOrigProj = new OpenLayers.Projection("EPSG:4326");
252 var bottomLeft = new OpenLayers.LonLat(orig[0],orig[1]);
253 bottomLeft = bottomLeft.transform(sypOrigProj, mapProj);
254 var topRight = new OpenLayers.LonLat(orig[2],orig[3])
255 topRight = topRight.transform(sypOrigProj, mapProj);
257 centerBounds.extend(bottomLeft);
258 centerBounds.extend(topRight);
259 map.zoomToExtent(centerBounds);
262 checkForFeatures: function () {
263 var features = this.dataLayer.features;
264 if (features.length != 0) {
265 $("#instructions").text(SypStrings.SelectHowto);
267 return !!features.length;
270 addNewFeature: function () {
271 alert (SypStrings.DisabledForDemo);
275 $(document).unbind("keydown");
278 $(document).unbind("keydown").keydown(function(e) {
279 if (e.keyCode == 27) {
285 $("#newfeature_button").val("annuler");
286 $("#newfeature_button").unbind("click").click(cancel);
288 $("#instructions").text(SypStrings.AddHowto);
289 this.selFeatureControl.deactivate();
290 this.addFeatureControl.activate();
294 cancelCurrentFeature: function() {
295 if (AjaxMgr.running) {
298 var feature = this.currentFeature;
301 FeatureMgr.move (feature, this.currentFeatureLocation);
303 this.dataLayer.removeFeatures([feature]);
310 reloadLayer: function (layer) {
311 layer.destroyFeatures();
312 layer.loaded = false;
317 /* minimum bounds rectangle containing all feature locations.
318 * FIXME: if two features are close, but separated by 180th meridian,
319 * their mbr will span the whole earth. Actually, 179° lon and -170°
320 * lon are considerated very near.
322 mbr: function (layer) {
326 var mapProj = map.getProjectionObject();
327 var sypOrigProj = new OpenLayers.Projection("EPSG:4326");
329 for (var i =0; i < layer.features.length; i++) {
330 if (layer.features[i].cluster) {
331 features = features.concat(layer.features[i].cluster);
333 features = features.concat(layer.features);
342 if (features.length == 0) {
343 // keep default values
344 } else if (features.length == 1) {
345 // in case there's only one feature, we show an area of at least
347 var pos = features[0].geometry.getBounds().getCenterLonLat().clone();
348 var lonlat = pos.transform(mapProj, sypOrigProj);
350 minlon = Math.max (lonlat.lon - 2, -180);
351 maxlon = Math.min (lonlat.lon + 2, 180);
352 minlat = Math.max (lonlat.lat - 2, -90);
353 maxlat = Math.min (lonlat.lat + 2, 90);
355 for (var i = 0; i < features.length; i++) {
356 var pos = features[i].geometry.getBounds().getCenterLonLat().clone();
357 var lonlat = pos.transform(mapProj, sypOrigProj);
358 minlon = Math.min (lonlat.lon, minlon);
359 minlat = Math.min (lonlat.lat, minlat);
360 maxlon = Math.max (lonlat.lon, maxlon);
361 maxlat = Math.max (lonlat.lat, maxlat);
365 return [minlon, minlat, maxlon, maxlat];
370 escapeHTML: function (str) {
375 replace(/&/gm, '&').
376 replace(/'/gm, ''').
377 replace(/"/gm, '"').
378 replace(/>/gm, '>').
379 replace(/</gm, '<');
382 startsWith: function (str, prefix) {
383 return (str.slice(0, prefix.length) == prefix);
386 indexOf: function (array, item) {
387 if (array.indexOf !== undefined) {
388 return array.indexOf(item);
390 return OpenLayers.Util.indexOf(array, item);
403 var pos = map.getLonLatFromViewPortPx(evt.xy);
404 feature = this.update (null, pos, "", "", "");
405 Admin.addFeatureControl.deactivate();
406 Admin.selFeatureControl.select(feature);
409 move: function (feature, aLocation) {
410 if (!feature || !aLocation) {
413 var curLoc = feature.geometry;
414 feature.geometry.move(aLocation.x - curLoc.x, aLocation.y - curLoc.y);
415 feature.layer.drawFeature(feature);
418 update: function(feature, lonlat, imgurl, title, description) {
419 var point = new OpenLayers.Geometry.Point(lonlat.lon, lonlat.lat);
421 feature = new OpenLayers.Feature.Vector(point);
422 Admin.dataLayer.addFeatures([feature]);
424 this.move (feature, point);
426 feature.attributes.name = title;
427 feature.attributes.description = "<p>" + Admin.Utils.escapeHTML(description) + "</p>"
428 + "<img src=\"" + imgurl + "\">"
432 del: function (feature) {
433 alert (SypStrings.DisabledForDemo);
435 var form = $("#feature_delete");
436 form.find('input[name="fid"]').val(feature.fid);
439 oncomplete: OpenLayers.Function.bind(this.ajaxReply, this),
440 throbberid: "editor_throbber"
444 save: function (feature) {
445 var x = feature.geometry.x;
446 var y = feature.geometry.y;
448 var mapProj = feature.layer.map.getProjectionObject();
449 var lonlat = new OpenLayers.LonLat(x, y).
451 new OpenLayers.Projection("EPSG:4326"));
452 var form = $("#feature_update");
453 form.find('input[name="lon"]').val(lonlat.lon);
454 form.find('input[name="lat"]').val(lonlat.lat);
455 form.find('input[name="fid"]').val(feature.fid);
456 form.find('input[name="keep_img"]').val(
457 $("#img").attr("src") ? "yes": "no"
461 form.find('input[name="request"]').val("update");
463 form.find('input[name="request"]').val("add");
467 oncomplete: OpenLayers.Function.bind(this.ajaxReply, this),
468 throbberid: "editor_throbber"
472 ajaxReply: function (data) {
474 this.commError(SypStrings.ServerError);
478 var xml = new OpenLayers.Format.XML().read(data);
479 if (!xml.documentElement) {
480 this.commError(SypStrings.UnconsistentError);
485 switch (xml.documentElement.nodeName.toLowerCase()) {
487 switch (xml.documentElement.getAttribute("reason")) {
490 $("#cookie_warning").show();
492 Admin.cancelCurrentFeature();
497 this.commError(SypStrings.ServerError);
501 this.commError(SypStrings.UnreferencedError);
502 Admin.reloadLayer(Admin.dataLayer);
506 this.commError(SypStrings.NochangeError);
510 this.commError(SypStrings.RequestError);
514 this.commError(SypStrings.ToobigError);
515 $("#image_file").parent().html($("#image_file").parent().html());
516 $("#image_file").focus();
519 this.commError(SypStrings.NotimageError);
520 $("#image_file").parent().html($("#image_file").parent().html());
521 $("#image_file").focus();
524 this.commError(SypStrings.UnconsistentError);
530 switch (xml.documentElement.getAttribute("request")) {
532 this.commSuccess(SypStrings.DelSucces);
533 var someFeature = false;
535 $.each($(xml).find("FEATURE,feature"), function () {
537 var id = parseFloat($(this).find("ID:first,id:first").text());
538 if ((id === null) || isNaN (id)) {
541 var features = Admin.dataLayer.features;
542 for (var idx = 0; idx < features.length; idx++) {
543 if (features[idx].fid == id) {
544 Admin.dataLayer.removeFeatures([features[idx]]);
548 if (someFeature == false) {
549 this.commError(SypStrings.UnconsistentError);
556 var someFeature = false;
558 $.each($(xml).find("FEATURE,feature"), function () {
560 var id = parseFloat($(this).find("ID:first,id:first").text());
561 if ((id === null) || isNaN (id)) {
565 var lon = parseFloat($(this).find("LON:first,lon:first").text());
566 if ((typeof (lon) != "number") || isNaN (lon) ||
567 (lon < -180) || (lon > 180)) {
571 var lat = parseFloat($(this).find("LAT:first,lat:first").text());
572 if ((typeof (lat) != "number") || isNaN (lat) ||
573 (lat < -90) || (lat > 90)) {
577 var mapProj = Admin.map.getProjectionObject();
578 var lonlat = new OpenLayers.LonLat (lon, lat).
579 transform( new OpenLayers.Projection("EPSG:4326"), mapProj);
581 var imgurl = $(this).find("IMGURL:first,imgurl:first").text();
582 var title = $(this).find("HEADING:first,heading:first").text();
583 var description = $(this).find("DESCRIPTION:first,description:first").text();
585 feature = self.update (Admin.currentFeature, lonlat, imgurl, title, description);
589 if (someFeature == false) {
590 this.commError(SypStrings.UnconsistentError);
592 this.commSuccess(SypStrings.UpdateSucces);
598 this.commError(SypStrings.UnconsistentError);
603 this.commError(SypStrings.UnconsistentError);
608 commSuccess: function (message) {
609 $("#server_comm").text(message);
610 $("#server_comm").removeClass("error success").addClass("success");
613 commError: function (message) {
614 $("#server_comm").text(message);
615 $("#server_comm").removeClass("error success").addClass("error");
619 /* maintains a queue of ajax queries, so I'm sure they all execute in the same
620 * order they were defined */
626 add: function(query) {
627 this._queue.push(query);
628 if (this._queue.length > 1) {
631 this._runQuery(query);
635 _runQuery: function(query) {
637 $('#api_frame').one("load", function() {
638 self.running = false;
640 if (query.throbberid) {
641 $("#" + query.throbberid).css("visibility", "hidden");
643 if (typeof (query.oncomplete) == "function") {
646 if (this.contentDocument) {
647 body = this.contentDocument.body;
648 } else if (this.contentWindow) {
649 body = this.contentWindow.document.body;
651 body = document.frames[this.id].document.body;
655 query.oncomplete(body.innerHTML);
657 query.oncomplete(null);
661 query.form.attr("action", "api.php");
662 query.form.attr("target", "api_frame");
663 query.form.attr("method", "post");
665 query.form.get(0).submit();
666 if (query.throbberid) {
667 $("#" + query.throbberid).css("visibility", "visible");
669 if (typeof (query.onsend) == "function") {
674 _reqEnd: function() {
676 if (this._queue.length > 0) {
677 this._reqEnd(this._queue[0]);
685 $("#login_form").submit(this.submit);
686 $("#user").focus().select();
691 $("#login_area").show();
692 $("#password").val("");
693 $("#user").val(sypSettings.loggedUser).focus().select();
696 submit: function () {
698 pwdMgr.commError("");
700 form: $("#login_form"),
701 throbberid: "pwd_throbber",
703 $("#login_error").hide();
705 // we need a timeout; otherwise those fields will not be submitted
706 window.setTimeout(function() {
707 // removes focus from #password before disabling it. Otherwise, opera
708 // prevents re-focusing it after re-enabling it.
709 $("#user, #password").blur();
710 $("#login_submit, #user, #password").attr("disabled", "disabled");
713 oncomplete: OpenLayers.Function.bind(pwdMgr.ajaxReply, pwdMgr)
720 ajaxReply: function (data) {
721 // here, we need a timeout because onsend timeout sometimes has not been triggered yet
722 window.setTimeout(function() {
723 $("#login_submit, #user, #password").removeAttr("disabled");
727 this.commError(SypStrings.ServerError);
728 $("#login_error").show();
729 window.setTimeout(function() {
730 $("#user").focus().select();
735 var xml = new OpenLayers.Format.XML().read(data);
736 if (!xml.documentElement) {
737 this.commError(SypStrings.UnconsistentError);
738 $("#login_error").show();
739 window.setTimeout(function() {
740 $("#user").focus().select();
744 switch (xml.documentElement.nodeName.toLowerCase()) {
746 switch (xml.documentElement.getAttribute("reason")) {
748 this.commError(SypStrings.ServerError);
751 this.commError(SypStrings.UnauthorizedError);
754 this.commError(SypStrings.RequestError);
757 this.commError(SypStrings.UnconsistentError);
760 $("#login_error").show();
761 window.setTimeout(function() {
762 $("#user").focus().select();
766 $("#login_area").hide();
768 user = $(xml).find("USER,user").text();
769 sypSettings.loggedUser = user;
771 if (sypSettings.loggedUser == "admin") {
775 if (Admin.selFeatureControl) {
776 Admin.selFeatureControl.destroy();
778 if (Admin.moveFeatureControl) {
779 Admin.moveFeatureControl.destroy();
781 if (Admin.addFeatureControl) {
782 Admin.addFeatureControl.destroy();
784 if (Admin.dataLayer) {
785 Admin.dataLayer.destroy();
788 Admin.dataLayer = Admin.createDataLayer(user);
789 Admin.map.addLayer(Admin.dataLayer);
794 this.commError(SypStrings.UnconsistentError);
799 commError: function (message) {
800 $("#login_error").text(message);
802 $("#login_error").show();
804 $("#login_error").hide();
810 _adduserDisplayed: false,
811 _changepassDisplayed: false,
814 $("#user_close").unbind("click").click(function () {
818 $("#change_pass").unbind("click").click(function() {
819 userMgr.toggleChangePass();
822 $("#changepass").unbind("submit").submit(function() {
824 userMgr.changepass();
829 if (sypSettings.loggedUser != "admin") {
833 $("#add_user").show();
834 $("#add_user").unbind("click").click(function () {
835 userMgr.toggleAddUser();
838 $("#newuser").unbind("submit").submit(function() {
847 disableForms: function() {
848 $("#newuser_name, #newuser_password, #newuser_password_confirm, #newuser_submit").attr("disabled", "disabled");
849 $("#pass_current, #pass_new, #pass_new_confirm, #pass_submit").attr("disabled", "disabled");
852 enableForms: function() {
853 $("#newuser_name, #newuser_password, #newuser_password_confirm, #newuser_submit").removeAttr("disabled");
854 $("#pass_current, #pass_new, #pass_new_confirm, #pass_submit").removeAttr("disabled");
857 resetForms: function() {
858 $("#newuser_name, #newuser_password, #newuser_password_confirm").val("");
859 $("#pass_current, #pass_new, #pass_new_confirm").val("");
864 $("#add_user").unbind("click");
865 $("#add_user").hide();
866 $("#change_pass").unbind("click");
867 $("#user_close").unbind("click");
868 $("#newuser").unbind("submit");
869 $("#changepass").unbind("submit");
873 this.closeChangePass();
877 toggleChangePass: function() {
878 if (this._changepassDisplayed) {
879 this.closeChangePass();
881 this.showChangePass();
885 showChangePass: function() {
886 if (!Admin.cancelCurrentFeature()) {
891 $(document).unbind("keydown").keydown(function(e) {
892 if (e.keyCode == 27) {
893 userMgr.closeChangePass()
900 $("#user_area, #changepass").show();
903 // XXX: setTimeout needed because otherwise, map becomes hidden in IE. Why ??
904 window.setTimeout(function() {
905 $("#pass_current").focus();
908 this._changepassDisplayed = true;
911 closeChangePass: function() {
912 if (!this._changepassDisplayed) {
915 $("#user_area, #changepass").hide();
916 $(document).unbind("keydown");
917 this._changepassDisplayed = false;
920 changepass: function() {
921 var newpass = $("#pass_new").val();
922 var newpass_confirm = $("#pass_new_confirm").val();
923 if (newpass != newpass_confirm) {
924 this.commError(SypStrings.userPasswordmatchError);
925 $("#pass_new").focus().select();
929 var curpass = $("#pass_current").val();
930 if (newpass == curpass) {
931 this.commError(SypStrings.changeSamePass);
932 $("#pass_new").focus().select();
939 alert (SypStrings.DisabledForDemo);
943 form: $("#changepass"),
944 oncomplete: OpenLayers.Function.bind(this.ajaxReply, this),
945 throbberid: "user_throbber",
947 // we need a timeout; otherwise those fields will not be submitted
948 window.setTimeout(function() {
949 // removes focus from #password before disabling it. Otherwise, opera
950 // prevents re-focusing it after re-enabling it.
951 $("#pass_current, #pass_new, #pass_new_confirm").blur();
952 userMgr.disableForms();
958 toggleAddUser: function() {
959 if (this._adduserDisplayed) {
966 showAddUser: function() {
967 if (!Admin.cancelCurrentFeature()) {
971 this.closeChangePass();
973 $(document).unbind("keydown").keydown(function(e) {
974 if (e.keyCode == 27) {
975 userMgr.closeAddUser()
980 $("#user_area, #newuser").show();
985 // XXX: setTimeout needed because otherwise, map becomes hidden in IE. Why ??
986 window.setTimeout(function() {
987 $("#newuser_name").focus();
990 this._adduserDisplayed = true;
993 closeAddUser: function() {
994 if (!this._adduserDisplayed) {
997 $("#user_area, #newuser").hide();
998 $(document).unbind("keydown");
999 this._adduserDisplayed = false;
1003 var newuser_name = $("#newuser_name").val();
1004 if (!newuser_name) {
1005 this.commError(SypStrings.newUserNonameError);
1006 $("#newuser_name").focus();
1010 var newuser_pass = $("#newuser_password").val();
1011 var newuser_pass_confirm = $("#newuser_password_confirm").val();
1012 if (newuser_pass != newuser_pass_confirm) {
1013 this.commError(SypStrings.userPasswordmatchError);
1014 $("#newuser_password").focus().select();
1019 this.disableForms();
1020 alert (SypStrings.DisabledForDemo);
1024 form: $("#newuser"),
1025 oncomplete: OpenLayers.Function.bind(this.ajaxReply, this),
1026 throbberid: "user_throbber",
1027 onsend: function() {
1028 // we need a timeout; otherwise those fields will not be submitted
1029 window.setTimeout(function() {
1030 // removes focus from #password before disabling it. Otherwise, opera
1031 // prevents re-focusing it after re-enabling it.
1032 $("#newuser_name, #newuser_password, #newuser_password_confirm").blur();
1033 userMgr.disableForms();
1039 ajaxReply: function (data) {
1041 // here, we need a timeout because onsend timeout sometimes has not been triggered yet
1043 window.setTimeout(function() {
1046 this.commError(SypStrings.ServerError);
1050 var xml = new OpenLayers.Format.XML().read(data);
1051 if (!xml.documentElement) {
1052 // here, we need a timeout because onsend timeout sometimes has not been triggered yet
1054 window.setTimeout(function() {
1057 this.commError(SypStrings.UnconsistentError);
1061 var needFormEnabling = true;
1064 switch (xml.documentElement.nodeName.toLowerCase()) {
1066 switch (xml.documentElement.getAttribute("reason")) {
1067 case "unauthorized":
1069 $("#cookie_warning").show();
1074 this.commError(SypStrings.ServerError);
1075 if (this._adduserDisplayed) {
1076 focusEl = $("#newuser_name");
1077 } else if (this._changepassDisplayed) {
1078 focusEl = $("#pass_current");
1082 this.commError(SypStrings.RequestError);
1083 if (this._adduserDisplayed) {
1084 focusEl = $("#newuser_name");
1085 } else if (this._changepassDisplayed) {
1086 focusEl = $("#pass_current");
1090 this.commError(SypStrings.changePassBadPass);
1091 focusEl = $("#pass_current");
1093 case "newuser_exists":
1094 this.commError(SypStrings.newUserExistsError);
1095 focusEl = $("#newuser_name");
1098 this.commError(SypStrings.UnconsistentError);
1099 if (this._adduserDisplayed) {
1100 focusEl = $("#newuser_name");
1101 } else if (this._changepassDisplayed) {
1102 focusEl = $("#pass_current");
1108 switch (xml.documentElement.getAttribute("request")) {
1110 this.commSuccess(SypStrings.newUserSuccess);
1111 needFormEnabling = false;
1114 this.commSuccess(SypStrings.changePassSuccess);
1115 needFormEnabling = false;
1118 this.commError(SypStrings.UnconsistentError);
1119 focusEl = $("newuser_name");
1124 this.commError(SypStrings.UnconsistentError);
1125 focusEl = $("newuser_name");
1129 if (needFormEnabling) {
1130 // here, we need a timeout because onsend timeout sometimes has not been triggered yet
1132 window.setTimeout(function() {
1135 focusEl.select().focus();
1140 focusEl.focus().select();
1146 commSuccess: function (message) {
1147 $("#user_comm").text(message);
1148 $("#user_comm").removeClass("error success").addClass("success");
1151 commError: function (message) {
1152 $("#user_comm").text(message);
1153 $("#user_comm").removeClass("error success").addClass("error");
1157 $(window).load(function () {
1158 // if using .ready, ie triggers an error when trying to access
1159 // document.namespaces
1161 $("#newfeature_button").click(function () {
1162 Admin.addNewFeature();
1164 $("#editor_close").click(function () {
1165 Admin.cancelCurrentFeature()
1167 $("#feature_update").submit(function() {
1169 FeatureMgr.save(Admin.currentFeature);
1173 $("#feature_delete").submit(function() {
1175 FeatureMgr.del(Admin.currentFeature);
1179 $("#image_delete").click(function() {
1180 alert (SypStrings.DisabledForDemo);
1182 $("#img").removeAttr('src');
1183 // needs to rebuild element otherwise some browsers still
1185 $("#img").parent().html($("#img").parent().html());
1186 $("#img").parent().hide();
1187 $("#image_delete").hide();
1188 $("#image_file").parent().show();