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 () {
273 $(document).unbind("keydown");
276 $(document).unbind("keydown").keydown(function(e) {
277 if (e.keyCode == 27) {
283 $("#newfeature_button").val(SypStrings.Cancel);
284 $("#newfeature_button").unbind("click").click(cancel);
286 $("#instructions").text(SypStrings.AddHowto);
287 this.selFeatureControl.deactivate();
288 this.addFeatureControl.activate();
292 cancelCurrentFeature: function() {
293 if (AjaxMgr.running) {
296 var feature = this.currentFeature;
299 FeatureMgr.move (feature, this.currentFeatureLocation);
301 this.dataLayer.removeFeatures([feature]);
308 reloadLayer: function (layer) {
309 layer.destroyFeatures();
310 layer.loaded = false;
315 /* minimum bounds rectangle containing all feature locations.
316 * FIXME: if two features are close, but separated by 180th meridian,
317 * their mbr will span the whole earth. Actually, 179° lon and -170°
318 * lon are considerated very near.
320 mbr: function (layer) {
324 var mapProj = map.getProjectionObject();
325 var sypOrigProj = new OpenLayers.Projection("EPSG:4326");
327 for (var i =0; i < layer.features.length; i++) {
328 if (layer.features[i].cluster) {
329 features = features.concat(layer.features[i].cluster);
331 features = features.concat(layer.features);
340 if (features.length == 0) {
341 // keep default values
342 } else if (features.length == 1) {
343 // in case there's only one feature, we show an area of at least
345 var pos = features[0].geometry.getBounds().getCenterLonLat().clone();
346 var lonlat = pos.transform(mapProj, sypOrigProj);
348 minlon = Math.max (lonlat.lon - 2, -180);
349 maxlon = Math.min (lonlat.lon + 2, 180);
350 minlat = Math.max (lonlat.lat - 2, -90);
351 maxlat = Math.min (lonlat.lat + 2, 90);
353 for (var i = 0; i < features.length; i++) {
354 var pos = features[i].geometry.getBounds().getCenterLonLat().clone();
355 var lonlat = pos.transform(mapProj, sypOrigProj);
356 minlon = Math.min (lonlat.lon, minlon);
357 minlat = Math.min (lonlat.lat, minlat);
358 maxlon = Math.max (lonlat.lon, maxlon);
359 maxlat = Math.max (lonlat.lat, maxlat);
363 return [minlon, minlat, maxlon, maxlat];
368 escapeHTML: function (str) {
373 replace(/&/gm, '&').
374 replace(/'/gm, ''').
375 replace(/"/gm, '"').
376 replace(/>/gm, '>').
377 replace(/</gm, '<');
380 startsWith: function (str, prefix) {
381 return (str.slice(0, prefix.length) == prefix);
384 indexOf: function (array, item) {
385 if (array.indexOf !== undefined) {
386 return array.indexOf(item);
388 return OpenLayers.Util.indexOf(array, item);
400 alert (SypStrings.DisabledForDemo);
401 $(document).unbind("keydown");
405 var pos = map.getLonLatFromViewPortPx(evt.xy);
406 feature = this.update (null, pos, "", "", "");
407 Admin.addFeatureControl.deactivate();
408 Admin.selFeatureControl.select(feature);
411 move: function (feature, aLocation) {
412 if (!feature || !aLocation) {
415 var curLoc = feature.geometry;
416 feature.geometry.move(aLocation.x - curLoc.x, aLocation.y - curLoc.y);
417 feature.layer.drawFeature(feature);
420 update: function(feature, lonlat, imgurl, title, description) {
421 var point = new OpenLayers.Geometry.Point(lonlat.lon, lonlat.lat);
423 feature = new OpenLayers.Feature.Vector(point);
424 Admin.dataLayer.addFeatures([feature]);
426 this.move (feature, point);
428 feature.attributes.name = title;
429 feature.attributes.description = "<p>" + Admin.Utils.escapeHTML(description) + "</p>"
430 + "<img src=\"" + imgurl + "\">"
434 del: function (feature) {
435 alert (SypStrings.DisabledForDemo);
437 var form = $("#feature_delete");
438 form.find('input[name="fid"]').val(feature.fid);
441 oncomplete: OpenLayers.Function.bind(this.ajaxReply, this),
442 throbberid: "editor_throbber"
446 save: function (feature) {
447 var x = feature.geometry.x;
448 var y = feature.geometry.y;
450 var mapProj = feature.layer.map.getProjectionObject();
451 var lonlat = new OpenLayers.LonLat(x, y).
453 new OpenLayers.Projection("EPSG:4326"));
454 var form = $("#feature_update");
455 form.find('input[name="lon"]').val(lonlat.lon);
456 form.find('input[name="lat"]').val(lonlat.lat);
457 form.find('input[name="fid"]').val(feature.fid);
458 form.find('input[name="keep_img"]').val(
459 $("#img").attr("src") ? "yes": "no"
463 form.find('input[name="request"]').val("update");
465 form.find('input[name="request"]').val("add");
469 oncomplete: OpenLayers.Function.bind(this.ajaxReply, this),
470 throbberid: "editor_throbber"
474 ajaxReply: function (data) {
476 this.commError(SypStrings.ServerError);
480 var xml = new OpenLayers.Format.XML().read(data);
481 if (!xml.documentElement) {
482 this.commError(SypStrings.UnconsistentError);
487 switch (xml.documentElement.nodeName.toLowerCase()) {
489 switch (xml.documentElement.getAttribute("reason")) {
492 $("#cookie_warning").show();
494 Admin.cancelCurrentFeature();
499 this.commError(SypStrings.ServerError);
503 this.commError(SypStrings.UnreferencedError);
504 Admin.reloadLayer(Admin.dataLayer);
508 this.commError(SypStrings.NochangeError);
512 this.commError(SypStrings.RequestError);
516 this.commError(SypStrings.ToobigError);
517 $("#image_file").parent().html($("#image_file").parent().html());
518 $("#image_file").focus();
521 this.commError(SypStrings.NotimageError);
522 $("#image_file").parent().html($("#image_file").parent().html());
523 $("#image_file").focus();
526 this.commError(SypStrings.UnconsistentError);
532 switch (xml.documentElement.getAttribute("request")) {
534 this.commSuccess(SypStrings.DelSucces);
535 var someFeature = false;
537 $.each($(xml).find("FEATURE,feature"), function () {
539 var id = parseFloat($(this).find("ID:first,id:first").text());
540 if ((id === null) || isNaN (id)) {
543 var features = Admin.dataLayer.features;
544 for (var idx = 0; idx < features.length; idx++) {
545 if (features[idx].fid == id) {
546 Admin.dataLayer.removeFeatures([features[idx]]);
550 if (someFeature == false) {
551 this.commError(SypStrings.UnconsistentError);
558 var someFeature = false;
560 $.each($(xml).find("FEATURE,feature"), function () {
562 var id = parseFloat($(this).find("ID:first,id:first").text());
563 if ((id === null) || isNaN (id)) {
567 var lon = parseFloat($(this).find("LON:first,lon:first").text());
568 if ((typeof (lon) != "number") || isNaN (lon) ||
569 (lon < -180) || (lon > 180)) {
573 var lat = parseFloat($(this).find("LAT:first,lat:first").text());
574 if ((typeof (lat) != "number") || isNaN (lat) ||
575 (lat < -90) || (lat > 90)) {
579 var mapProj = Admin.map.getProjectionObject();
580 var lonlat = new OpenLayers.LonLat (lon, lat).
581 transform( new OpenLayers.Projection("EPSG:4326"), mapProj);
583 var imgurl = $(this).find("IMGURL:first,imgurl:first").text();
584 var title = $(this).find("HEADING:first,heading:first").text();
585 var description = $(this).find("DESCRIPTION:first,description:first").text();
587 feature = self.update (Admin.currentFeature, lonlat, imgurl, title, description);
591 if (someFeature == false) {
592 this.commError(SypStrings.UnconsistentError);
594 this.commSuccess(SypStrings.UpdateSucces);
600 this.commError(SypStrings.UnconsistentError);
605 this.commError(SypStrings.UnconsistentError);
610 commSuccess: function (message) {
611 $("#server_comm").text(message);
612 $("#server_comm").removeClass("error success").addClass("success");
615 commError: function (message) {
616 $("#server_comm").text(message);
617 $("#server_comm").removeClass("error success").addClass("error");
621 /* maintains a queue of ajax queries, so I'm sure they all execute in the same
622 * order they were defined */
628 add: function(query) {
629 this._queue.push(query);
630 if (this._queue.length > 1) {
633 this._runQuery(query);
637 _runQuery: function(query) {
639 $('#api_frame').one("load", function() {
640 self.running = false;
642 if (query.throbberid) {
643 $("#" + query.throbberid).css("visibility", "hidden");
645 if (typeof (query.oncomplete) == "function") {
648 if (this.contentDocument) {
649 body = this.contentDocument.body;
650 } else if (this.contentWindow) {
651 body = this.contentWindow.document.body;
653 body = document.frames[this.id].document.body;
657 query.oncomplete(body.innerHTML);
659 query.oncomplete(null);
663 query.form.attr("action", "api.php");
664 query.form.attr("target", "api_frame");
665 query.form.attr("method", "post");
667 query.form.get(0).submit();
668 if (query.throbberid) {
669 $("#" + query.throbberid).css("visibility", "visible");
671 if (typeof (query.onsend) == "function") {
676 _reqEnd: function() {
678 if (this._queue.length > 0) {
679 this._reqEnd(this._queue[0]);
687 $("#login_form").submit(this.submit);
688 $("#user").focus().select();
693 $("#login_area").show();
694 $("#password").val("");
695 $("#user").val(sypSettings.loggedUser).focus().select();
698 submit: function () {
700 pwdMgr.commError("");
702 form: $("#login_form"),
703 throbberid: "pwd_throbber",
705 $("#login_error").hide();
707 // we need a timeout; otherwise those fields will not be submitted
708 window.setTimeout(function() {
709 // removes focus from #password before disabling it. Otherwise, opera
710 // prevents re-focusing it after re-enabling it.
711 $("#user, #password").blur();
712 $("#login_submit, #user, #password").attr("disabled", "disabled");
715 oncomplete: OpenLayers.Function.bind(pwdMgr.ajaxReply, pwdMgr)
722 ajaxReply: function (data) {
723 // here, we need a timeout because onsend timeout sometimes has not been triggered yet
724 window.setTimeout(function() {
725 $("#login_submit, #user, #password").removeAttr("disabled");
729 this.commError(SypStrings.ServerError);
730 $("#login_error").show();
731 window.setTimeout(function() {
732 $("#user").focus().select();
737 var xml = new OpenLayers.Format.XML().read(data);
738 if (!xml.documentElement) {
739 this.commError(SypStrings.UnconsistentError);
740 $("#login_error").show();
741 window.setTimeout(function() {
742 $("#user").focus().select();
746 switch (xml.documentElement.nodeName.toLowerCase()) {
748 switch (xml.documentElement.getAttribute("reason")) {
750 this.commError(SypStrings.ServerError);
753 this.commError(SypStrings.UnauthorizedError);
756 this.commError(SypStrings.RequestError);
759 this.commError(SypStrings.UnconsistentError);
762 $("#login_error").show();
763 window.setTimeout(function() {
764 $("#user").focus().select();
768 $("#login_area").hide();
770 user = $(xml).find("USER,user").text();
771 sypSettings.loggedUser = user;
773 if (sypSettings.loggedUser == "admin") {
777 if (Admin.selFeatureControl) {
778 Admin.selFeatureControl.destroy();
780 if (Admin.moveFeatureControl) {
781 Admin.moveFeatureControl.destroy();
783 if (Admin.addFeatureControl) {
784 Admin.addFeatureControl.destroy();
786 if (Admin.dataLayer) {
787 Admin.dataLayer.destroy();
790 Admin.dataLayer = Admin.createDataLayer(user);
791 Admin.map.addLayer(Admin.dataLayer);
796 this.commError(SypStrings.UnconsistentError);
801 commError: function (message) {
802 $("#login_error").text(message);
804 $("#login_error").show();
806 $("#login_error").hide();
812 _adduserDisplayed: false,
813 _changepassDisplayed: false,
816 $("#user_close").unbind("click").click(function () {
820 $("#change_pass").unbind("click").click(function() {
821 userMgr.toggleChangePass();
824 $("#changepass").unbind("submit").submit(function() {
826 userMgr.changepass();
831 if (sypSettings.loggedUser != "admin") {
835 $("#add_user").show();
836 $("#add_user").unbind("click").click(function () {
837 userMgr.toggleAddUser();
840 $("#newuser").unbind("submit").submit(function() {
849 disableForms: function() {
850 $("#newuser_name, #newuser_password, #newuser_password_confirm, #newuser_submit").attr("disabled", "disabled");
851 $("#pass_current, #pass_new, #pass_new_confirm, #pass_submit").attr("disabled", "disabled");
854 enableForms: function() {
855 $("#newuser_name, #newuser_password, #newuser_password_confirm, #newuser_submit").removeAttr("disabled");
856 $("#pass_current, #pass_new, #pass_new_confirm, #pass_submit").removeAttr("disabled");
859 resetForms: function() {
860 $("#newuser_name, #newuser_password, #newuser_password_confirm").val("");
861 $("#pass_current, #pass_new, #pass_new_confirm").val("");
866 $("#add_user").unbind("click");
867 $("#add_user").hide();
868 $("#change_pass").unbind("click");
869 $("#user_close").unbind("click");
870 $("#newuser").unbind("submit");
871 $("#changepass").unbind("submit");
875 this.closeChangePass();
879 toggleChangePass: function() {
880 if (this._changepassDisplayed) {
881 this.closeChangePass();
883 this.showChangePass();
887 showChangePass: function() {
888 if (!Admin.cancelCurrentFeature()) {
893 $(document).unbind("keydown").keydown(function(e) {
894 if (e.keyCode == 27) {
895 userMgr.closeChangePass()
902 $("#user_area, #changepass").show();
905 // XXX: setTimeout needed because otherwise, map becomes hidden in IE. Why ??
906 window.setTimeout(function() {
907 $("#pass_current").focus();
910 this._changepassDisplayed = true;
913 closeChangePass: function() {
914 if (!this._changepassDisplayed) {
917 $("#user_area, #changepass").hide();
918 $(document).unbind("keydown");
919 this._changepassDisplayed = false;
922 changepass: function() {
923 var newpass = $("#pass_new").val();
924 var newpass_confirm = $("#pass_new_confirm").val();
925 if (newpass != newpass_confirm) {
926 this.commError(SypStrings.userPasswordmatchError);
927 $("#pass_new").focus().select();
932 this.commError(SypStrings.emptyPasswordError);
933 $("#pass_new").focus().select();
937 var curpass = $("#pass_current").val();
938 if (newpass == curpass) {
939 this.commError(SypStrings.changeSamePass);
940 $("#pass_new").focus().select();
947 alert (SypStrings.DisabledForDemo);
951 form: $("#changepass"),
952 oncomplete: OpenLayers.Function.bind(this.ajaxReply, this),
953 throbberid: "user_throbber",
955 // we need a timeout; otherwise those fields will not be submitted
956 window.setTimeout(function() {
957 // removes focus from #password before disabling it. Otherwise, opera
958 // prevents re-focusing it after re-enabling it.
959 $("#pass_current, #pass_new, #pass_new_confirm").blur();
960 userMgr.disableForms();
966 toggleAddUser: function() {
967 if (this._adduserDisplayed) {
974 showAddUser: function() {
975 if (!Admin.cancelCurrentFeature()) {
979 this.closeChangePass();
981 $(document).unbind("keydown").keydown(function(e) {
982 if (e.keyCode == 27) {
983 userMgr.closeAddUser()
988 $("#user_area, #newuser").show();
993 // XXX: setTimeout needed because otherwise, map becomes hidden in IE. Why ??
994 window.setTimeout(function() {
995 $("#newuser_name").focus();
998 this._adduserDisplayed = true;
1001 closeAddUser: function() {
1002 if (!this._adduserDisplayed) {
1005 $("#user_area, #newuser").hide();
1006 $(document).unbind("keydown");
1007 this._adduserDisplayed = false;
1011 var newuser_name = $("#newuser_name").val();
1012 if (!newuser_name) {
1013 this.commError(SypStrings.newUserNonameError);
1014 $("#newuser_name").focus();
1018 var newuser_pass = $("#newuser_password").val();
1019 var newuser_pass_confirm = $("#newuser_password_confirm").val();
1020 if (newuser_pass != newuser_pass_confirm) {
1021 this.commError(SypStrings.userPasswordmatchError);
1022 $("#newuser_password").focus().select();
1026 if (!newuser_pass) {
1027 this.commError(SypStrings.emptyPasswordError);
1028 $("#pass_new").focus().select();
1033 this.disableForms();
1034 alert (SypStrings.DisabledForDemo);
1038 form: $("#newuser"),
1039 oncomplete: OpenLayers.Function.bind(this.ajaxReply, this),
1040 throbberid: "user_throbber",
1041 onsend: function() {
1042 // we need a timeout; otherwise those fields will not be submitted
1043 window.setTimeout(function() {
1044 // removes focus from #password before disabling it. Otherwise, opera
1045 // prevents re-focusing it after re-enabling it.
1046 $("#newuser_name, #newuser_password, #newuser_password_confirm").blur();
1047 userMgr.disableForms();
1053 ajaxReply: function (data) {
1055 // here, we need a timeout because onsend timeout sometimes has not been triggered yet
1057 window.setTimeout(function() {
1060 this.commError(SypStrings.ServerError);
1064 var xml = new OpenLayers.Format.XML().read(data);
1065 if (!xml.documentElement) {
1066 // here, we need a timeout because onsend timeout sometimes has not been triggered yet
1068 window.setTimeout(function() {
1071 this.commError(SypStrings.UnconsistentError);
1075 var needFormEnabling = true;
1078 switch (xml.documentElement.nodeName.toLowerCase()) {
1080 switch (xml.documentElement.getAttribute("reason")) {
1081 case "unauthorized":
1083 $("#cookie_warning").show();
1088 this.commError(SypStrings.ServerError);
1089 if (this._adduserDisplayed) {
1090 focusEl = $("#newuser_name");
1091 } else if (this._changepassDisplayed) {
1092 focusEl = $("#pass_current");
1096 this.commError(SypStrings.RequestError);
1097 if (this._adduserDisplayed) {
1098 focusEl = $("#newuser_name");
1099 } else if (this._changepassDisplayed) {
1100 focusEl = $("#pass_current");
1104 this.commError(SypStrings.changePassBadPass);
1105 focusEl = $("#pass_current");
1107 case "newuser_exists":
1108 this.commError(SypStrings.newUserExistsError);
1109 focusEl = $("#newuser_name");
1112 this.commError(SypStrings.UnconsistentError);
1113 if (this._adduserDisplayed) {
1114 focusEl = $("#newuser_name");
1115 } else if (this._changepassDisplayed) {
1116 focusEl = $("#pass_current");
1122 switch (xml.documentElement.getAttribute("request")) {
1124 this.commSuccess(SypStrings.newUserSuccess);
1125 needFormEnabling = false;
1128 this.commSuccess(SypStrings.changePassSuccess);
1129 needFormEnabling = false;
1132 this.commError(SypStrings.UnconsistentError);
1133 focusEl = $("newuser_name");
1138 this.commError(SypStrings.UnconsistentError);
1139 focusEl = $("newuser_name");
1143 if (needFormEnabling) {
1144 // here, we need a timeout because onsend timeout sometimes has not been triggered yet
1146 window.setTimeout(function() {
1149 focusEl.select().focus();
1154 focusEl.focus().select();
1160 commSuccess: function (message) {
1161 $("#user_comm").text(message);
1162 $("#user_comm").removeClass("error success").addClass("success");
1165 commError: function (message) {
1166 $("#user_comm").text(message);
1167 $("#user_comm").removeClass("error success").addClass("error");
1171 $(window).load(function () {
1172 // if using .ready, ie triggers an error when trying to access
1173 // document.namespaces
1175 $("#newfeature_button").click(function () {
1176 Admin.addNewFeature();
1178 $("#editor_close").click(function () {
1179 Admin.cancelCurrentFeature()
1181 $("#feature_update").submit(function() {
1183 FeatureMgr.save(Admin.currentFeature);
1187 $("#feature_delete").submit(function() {
1189 FeatureMgr.del(Admin.currentFeature);
1193 $("#image_delete").click(function() {
1194 alert (SypStrings.DisabledForDemo);
1196 $("#img").removeAttr('src');
1197 // needs to rebuild element otherwise some browsers still
1199 $("#img").parent().html($("#img").parent().html());
1200 $("#img").parent().hide();
1201 $("#image_delete").hide();
1202 $("#image_file").parent().show();