1 /* This file is part of Syj, Copyright (c) 2010 Arnaud Renevier,
2 and is published under the AGPL license. */
4 // avoid openlayers alerts
5 OpenLayers.Console.userError = function(error) {
6 SYJView.messenger.setMessage(error, "error");
13 $("geom_title").observe('contentchange', this.enableSubmit.bindAsEventListener(this));
18 if (this.status === "enabled") {
22 $("geom_title").disabled = false;
23 $("geom_title").activate();
24 $$("#geom_accept_container, #geom_title_container").invoke('removeClassName', "disabled");
25 this.status = "enabled";
30 if (this.status === "disabled") {
34 $("geom_title").blur();
35 $("geom_title").disabled = true;
36 $$("#geom_accept_container, #geom_title_container").invoke('addClassName', "disabled");
37 this.status = "disabled";
41 enableSubmit: function() {
42 $("geom_submit").disabled = false;
43 $("geom_accept").disabled = false;
44 this.status = "partial";
48 disableSubmit: function() {
49 $("geom_submit").blur();
50 $("geom_submit").disabled = true;
51 $("geom_accept").blur();
52 $("geom_accept").disabled = true;
53 this.status = "partial";
58 var SYJPathLength = (function(){
61 var pathLength = 0, unit;
62 if (SYJView.mode === 'view') {
63 if (SYJView.viewLayer.features.length) {
64 pathLength = SYJView.viewLayer.features[0].geometry.getGeodesicLength(Mercator);
67 pathLength = SYJView.editControl.handler.line.geometry.getGeodesicLength(Mercator);
70 if (pathLength === 0) {
71 $("path-length").hide();
74 $("path-length").show();
76 if (pathLength < 1000) {
78 pathLength = Math.round(pathLength * 100) / 100;
82 pathLength = Math.round(pathLength) / 1000;
85 $("path-length-content").update(pathLength + ' ' + unit);
90 var SYJDataUi = (function() {
93 getdeck = function() {
95 deck = new Deck("data_controls");
99 getinfotoggler = function() {
101 infotoggler = new Toggler('path-infos-content');
102 $("path-infos-toggler").insert({bottom: infotoggler.element});
103 $("path-infos-anchor").observe('click', function(evt) {
105 infotoggler.toggle(evt);
107 document.observe('toggler:open', function(evt) {
108 if (evt.memo === infotoggler) {
109 // XXX: update informations
116 viewmode: function() {
117 getdeck().setIndex(0);
118 if ($("path-infos")) {
120 getinfotoggler().close();
121 $("path-infos").show();
124 editmode: function() {
125 getdeck().setIndex(1);
126 if ($("path-infos")) {
127 $("path-infos").hide();
133 OpenLayers.Handler.SyjModifiablePath = OpenLayers.Class(OpenLayers.Handler.ModifiablePath, {
134 mouseup: function(evt) {
135 // do not add a point when navigating
136 var mapControls = this.control.map.controls, idx, ctrl;
138 for (idx = mapControls.length; idx-->0; ) {
139 ctrl = mapControls[idx];
140 if (this.isCtrlNavigationActive(ctrl, evt)) {
144 return OpenLayers.Handler.ModifiablePath.prototype.mouseup.apply(this, arguments);
147 addPoints: function(pixel) {
148 // redraw before last point. As we have a special style for last point, we
149 // need to redraw before last point after adding a new point (otherwise, it
150 // keeps special style forever)
151 var oldpoint = this.point;
152 OpenLayers.Handler.ModifiablePath.prototype.addPoints.apply(this, arguments);
153 this.layer.drawFeature(oldpoint);
156 isCtrlNavigationActive: function(ctrl, evt) {
157 var tolerance = 4, xDiff, yDiff;
159 if (!(ctrl instanceof OpenLayers.Control.Navigation)) {
164 ctrl.zoomBox.active &&
165 ctrl.zoomBox.handler &&
166 ctrl.zoomBox.handler.active &&
167 ctrl.zoomBox.handler.dragHandler &&
168 ctrl.zoomBox.handler.dragHandler.start) {
173 !ctrl.dragPan.active ||
174 !ctrl.dragPan.handler ||
175 !ctrl.dragPan.handler.started ||
176 !ctrl.dragPan.handler.start) {
180 // if mouse moved 4 or less pixels, consider it has not moved.
183 xDiff = evt.xy.x - ctrl.dragPan.handler.start.x;
184 yDiff = evt.xy.y - ctrl.dragPan.handler.start.y;
186 if (Math.sqrt(Math.pow(xDiff,2) + Math.pow(yDiff,2)) <= tolerance) {
192 finalize: function(cancel) {
193 // do nothing. We don't want to finalize path
198 edit: new OpenLayers.StyleMap({
199 "default": new OpenLayers.Style({
200 pointRadius: "${radius}", // sized according to type attribute
201 fillColor: "#ffcc66",
202 strokeColor: "#ff9933",
204 strokeOpacity: "${opacity}",
205 fillOpacity: "${opacity}"
209 radius: function(feature) {
212 if (!(feature.geometry instanceof OpenLayers.Geometry.Point)) {
215 if (feature.type === "middle") {
218 features = feature.layer.features;
219 if (OpenLayers.Util.indexOf(features, feature) === 0) {
221 } else if (OpenLayers.Util.indexOf(features, feature) === features.length - 1) {
226 opacity: function (feature) {
227 if (feature.type === "middle") {
236 "select": new OpenLayers.Style({
237 externalGraphic: "icons/delete.png",
241 "select_for_canvas": new OpenLayers.Style({
243 fillColor: "lightblue"
248 view: new OpenLayers.StyleMap({
249 "default": new OpenLayers.Style({
257 var WGS84 = new OpenLayers.Projection("EPSG:4326");
258 var Mercator = new OpenLayers.Projection("EPSG:900913");
264 wkt: new OpenLayers.Format.WKT({ internalProjection: Mercator, externalProjection: WGS84 }),
265 needsFormResubmit: false,
270 var externalGraphic, baseURL, baseLayer, layerOptions, hidemessenger;
272 // is svg context, opera does not resolve links with base element is svg context
273 externalGraphic = styleMap.edit.styles.select.defaultStyle.externalGraphic;
274 baseURL = document.getElementsByTagName("base")[0].href;
275 styleMap.edit.styles.select.defaultStyle.externalGraphic = baseURL + externalGraphic;
277 this.map = new OpenLayers.Map('map', {
279 new OpenLayers.Control.Navigation(),
280 new OpenLayers.Control.PanZoom(),
281 new OpenLayers.Control.Attribution()
286 baseLayer = new OpenLayers.Layer.OSM("OSM", null, { wrapDateLine: true , attribution: SyjStrings.osmAttribution });
288 layerOptions = {format: OpenLayers.Format.WKT,
290 styleMap: styleMap.view,
291 attribution: SyjStrings.geomAttribution };
293 this.viewLayer = new OpenLayers.Layer.Vector("View Layer", layerOptions);
294 this.map.addLayers([baseLayer, this.viewLayer]);
297 $("edit-btn").observe('click', function() {
298 $("geom_submit").value = SyjStrings.editAction;
299 this.messenger.hide();
305 if ($("create-btn")) {
306 $("create-btn").observe('click', function() {
307 $("geom_submit").value = SyjStrings.createAction;
308 this.messenger.hide();
310 this.mode = 'create';
314 if ($("clone-btn")) {
315 $("clone-btn").observe('click', function() {
316 $("geom_submit").value = SyjStrings.cloneAction;
317 $("geom_title").value = "";
318 this.messenger.hide();
320 this.mode = 'create';
324 $("geomform").ajaxize({
325 presubmit: this.prepareForm.bind(this),
326 onSuccess: this.saveSuccess.bind(this),
327 onFailure: this.saveFailure.bind(this)
331 this.messenger = $('message');
332 hidemessenger = this.messenger.empty();
333 new CloseBtn(this.messenger, {
339 this.messenger.hide();
342 if (typeof gInitialGeom !== "undefined" && typeof gInitialGeom.data !== "undefined") {
343 this.viewLayer.addFeatures([this.wkt.read(gInitialGeom.data)]);
344 // XXX: ie has not guessed height of map main div yet during map
345 // initialisation. Now, it will read it correctly.
346 this.map.updateSize();
347 this.map.zoomToExtent(this.viewLayer.getDataExtent());
349 this.initMaPos(gInitialPos);
352 $("map-overlay").hide();
353 $("geom_upload").observe('change', function(evt) {
354 var file = null, reader = null, readerror = null;
355 if (window.FileList && window.FileReader) {
356 file = evt.target.files[0];
357 reader = new FileReader();
358 readerror = function() {
359 this.messenger.setMessage(SyjStrings.uploadFileError, "warn");
361 reader.onload = function(evt) {
362 var data = null, results = null, engine = null, vector = null, i = 0, formats = ['KML', 'GPX', 'GeoJSON'];
364 $("geom_upload_container").removeClassName("disabled");
365 $("geom_upload").disabled = false;
370 data = evt.target.result;
372 for (i = 0; i < formats.length; i++) {
373 engine = new OpenLayers.Format[formats[i]]({ internalProjection: Mercator, externalProjection: WGS84 });
375 results = engine.read(data);
378 if (results && results.length) {
382 if (!results || !results.length) {
388 if (vector.geometry.CLASS_NAME !== "OpenLayers.Geometry.LineString") {
392 this.viewLayer.addFeatures([vector]);
393 this.map.zoomToExtent(this.viewLayer.getDataExtent());
396 $("edit-btn").click();
397 } else if ($("create-btn")) {
398 $("create-btn").click();
401 if (this.editControl.handler.realPoints.length < 2) {
407 if (vector.data && vector.data.name) {
408 $("geom_title").value = vector.data.name;
411 $("geom_upload_container").addClassName("disabled");
412 $("geom_upload").disabled = true;
413 reader.readAsText(file);
416 $("map-overlay").show();
418 this.editControl.deactivate();
421 document.observe('simplebox:shown', this.observer.bindAsEventListener(this));
422 SYJPathLength.update();
425 initMaPos: function (aPos) {
426 var extent = null, center = null, zoom = 0;
428 if (aPos.hasOwnProperty('lon') && aPos.hasOwnProperty('lat') && aPos.hasOwnProperty('zoom')) {
429 center = new OpenLayers.LonLat(parseFloat(aPos.lon), parseFloat(aPos.lat)).transform(WGS84, Mercator);
430 zoom = parseInt(aPos.zoom, 10);
431 } else if (aPos.hasOwnProperty('minlon') && aPos.hasOwnProperty('minlat')
432 && aPos.hasOwnProperty('maxlon') && aPos.hasOwnProperty('maxlat')) {
433 extent = new OpenLayers.Bounds(aPos.minlon, aPos.minlat, aPos.maxlon, aPos.maxlat)
434 .transform(WGS84, Mercator);
436 extent = new OpenLayers.Bounds(-160, -70, 160, 70).transform(WGS84, Mercator);
440 this.map.zoomToExtent(extent);
442 this.map.setCenter(center, zoom);
446 observer: function(evt) {
447 if (evt.eventName === "simplebox:shown" && evt.memo.element !== $("termsofusearea")) {
448 this.messenger.hide();
452 prepareForm: function(form) {
453 if (!LoginMgr.logged && !$("geom_accept").checked) {
454 this.messenger.setMessage(SyjStrings.acceptTermsofuseWarn, "warn");
455 $("geom_accept_container").highlight('#F08080');
456 $("geom_accept").activate();
460 var line, realPoints, idx;
462 line = new OpenLayers.Geometry.LineString();
463 realPoints = this.editControl.handler.realPoints;
464 for (idx = 0; idx < realPoints.length; idx++) {
465 line.addComponent(realPoints[idx].geometry.clone());
467 this.viewLayer.addFeatures(new OpenLayers.Feature.Vector(line));
471 if (line.components.length) {
472 $("geom_data").value = this.wkt.write(new OpenLayers.Feature.Vector(line));
474 $("geom_data").value = "";
477 if (this.mode === "edit" && typeof gLoggedInfo.pathid !== "undefined") {
478 $("geomform").setAttribute("action", "path/" + gLoggedInfo.pathid.toString() + '/update');
480 $("geomform").setAttribute("action", "path");
482 this.needsFormResubmit = false;
483 SyjSaveUI.disable.bind(SyjSaveUI).defer();
484 this.messenger.hide();
488 viewMode: function() {
489 var handler = this.editControl.handler;
490 OpenLayers.Handler.ModifiablePath.prototype.finalize.apply(handler, arguments);
491 // we need to recreate them on next createFeature; otherwise
492 // they'll reference destroyed features
493 delete(handler.handlers.drag);
494 delete(handler.handlers.feature);
495 this.editControl.deactivate();
498 editMode: function() {
499 var components, point0, point, pixels, pixel, idx;
501 this.initEditControl();
503 this.editControl.activate();
504 if (this.viewLayer.features.length) {
505 components = this.viewLayer.features[0].geometry.components;
506 point0 = components[0];
508 pixel = this.map.getPixelFromLonLat(new OpenLayers.LonLat(point0.x, point0.y));
509 this.editControl.handler.createFeature(pixel);
510 this.editControl.handler.lastUp = pixel;
512 for (idx = 1; idx < components.length; idx++) {
513 point = components[idx];
514 pixels.push(this.map.getPixelFromLonLat(new OpenLayers.LonLat(point.x, point.y)));
516 this.editControl.handler.addPoints(pixels);
518 this.unsavedRoute = {
519 features: this.viewLayer.features.invoke('clone'),
520 title: $("geom_title").value
524 this.viewLayer.destroyFeatures();
526 SYJDataUi.editmode();
527 if (this.editControl.handler.realPoints && this.editControl.handler.realPoints.length >= 2) {
528 SyjSaveUI.disableSubmit();
534 initEditControl: function() {
537 if (this.editControl) {
541 this.editControl = new OpenLayers.Control.DrawFeature(new OpenLayers.Layer.Vector(), OpenLayers.Handler.SyjModifiablePath, {
543 modify: function(f, line) {
544 SYJPathLength.update();
546 var npoints = this.handler.realPoints.length;
548 $("geom_upload_container").show();
549 SYJView.unsavedRoute = null;
551 if (!SYJView.unsavedRoute) {
552 SYJView.unsavedRoute = {};
562 create: function(f, line) {
563 this.messenger.hide();
564 $("geom_upload_container").hide();
570 styleMap: styleMap.edit
574 this.map.addControl(this.editControl);
575 if (this.editControl.layer.renderer instanceof OpenLayers.Renderer.Canvas) {
576 // using externalGraphic with canvas renderer is definitively too buggy
577 styles = this.editControl.handler.layerOptions.styleMap.styles;
578 styles.select = styles.select_for_canvas;
582 saveSuccess: function(transport) {
583 // server sends and empty response on success. If we get a response, that
584 // probably means an error or warning has been printed by server.
585 if (!transport.responseJSON && transport.responseText.length) {
586 this.saveFailure(null, 500);
590 this.unsavedRoute = null;
591 if (transport.responseJSON && (typeof transport.responseJSON.redirect === "string")) {
592 location = transport.responseJSON.redirect;
596 this.messenger.setMessage(SyjStrings.saveSuccess, "success");
597 SYJDataUi.viewmode();
598 document.title = $('geom_title').value;
601 saveFailure: function(transport, httpCode) {
603 if (typeof httpCode === "undefined") {
604 httpCode = transport? transport.getStatus(): 0;
609 message = SyjStrings.notReachedError;
613 message = SyjStrings.requestError;
614 if (transport.responseJSON) {
615 switch (transport.responseJSON.message) {
617 message = SyjStrings.uniquePathError;
626 SYJLogin.messenger.setMessage(SyjStrings.loginNeeded, "warn");
627 SYJLogin.modalbox.show();
628 this.needsFormResubmit = true;
631 message = SyjStrings.gonePathError;
634 message = SyjStrings.serverError;
635 this.needsFormResubmit = true;
638 message = SyjStrings.unknownError;
643 // is some cases, we let the user resubmit, in some other cases, he
644 // needs to modify the path before submitting again
645 if (this.needsFormResubmit) {
649 this.messenger.setMessage(message, "error");
653 var SYJModalClass = Class.create({
657 this.area = $(this.type + '_area');
658 this.messenger = $(this.type + "_message");
659 this.modalbox = new SimpleBox(this.area, {
660 closeMethods: ["onescapekey", "onouterclick", "onbutton"]
663 $(this.type + "_control_anchor").observe("click", function(evt) {
664 this.modalbox.show();
666 }.bindAsEventListener(this));
668 document.observe('simplebox:shown', this.observer.bindAsEventListener(this));
669 document.observe('simplebox:hidden', this.observer.bindAsEventListener(this));
671 $(this.type + "form").ajaxize({
672 presubmit: this.presubmit.bind(this),
673 onSuccess: this.success.bind(this),
674 onFailure: this.failure.bind(this)
678 checkNotEmpty: function(input, message) {
679 if ($(input).value.strip().empty()) {
680 this.messenger.setMessage(message, "warn");
681 $(input).highlight('#F08080').activate();
687 observer: function(evt) {
688 var simplebox, input;
690 if (evt.eventName === "simplebox:shown" && evt.memo.element !== $("termsofusearea")) {
691 simplebox = evt.memo;
692 if (simplebox === this.modalbox) {
693 input = this.area.select('input[type="text"]')[0];
698 this.modalbox.hide();
701 } else if (evt.eventName === "simplebox:hidden" && evt.memo.element !== $("termsofusearea")) {
702 simplebox = evt.memo;
703 if (simplebox === this.modalbox) {
709 failure: function(transport) {
710 var httpCode = 0, message = SyjStrings.unknownError, input; // default message error
713 httpCode = transport.getStatus();
718 message = SyjStrings.notReachedError;
723 message = SyjStrings.requestError;
726 message = SyjStrings.serverError;
730 this.messenger.setMessage(message, "error");
731 input = this.area.select('input[type="text"]')[0];
732 input.highlight('#F08080').activate();
736 this.messenger.hide();
737 this.area.select('.message').invoke('setMessageStatus', null);
741 var SYJUserClass = Class.create(SYJModalClass, {
745 init: function($super) {
747 $("termsofusearea").hide();
749 $$("#user_termsofuse_anchor, #geom_termsofuse_anchor").invoke('observe', "click", function(evt) {
751 this.toubox = new SimpleBox($("termsofusearea"), {
752 closeMethods: ["onescapekey", "onouterclick", "onbutton"]
756 if (!$("termsofuseiframe").getAttribute("src")) {
757 $("termsofusearea").show();
758 $("termsofuseiframe").setAttribute("src", evt.target.href);
761 }.bindAsEventListener(this));
763 $$("#login_area_create > a").invoke('observe', 'click',
765 this.modalbox.show();
767 }.bindAsEventListener(this));
769 $("user_pseudo-desc").hide();
770 $("user_pseudo").observe('contentchange', function(evt) {
771 var value = evt.target.value;
772 PseudoChecker.reset();
773 if (value && !(value.match(/^[a-zA-Z0-9_.]+$/))) {
774 $("user_pseudo-desc").show().setMessageStatus("warn");
776 $("user_pseudo-desc").hide();
778 }).timedobserve(function() {
779 PseudoChecker.check();
782 $("user_password").observe('contentchange', function(evt) {
783 if (evt.target.value.length < 6) {
784 $("user_password-desc").setMessageStatus("warn");
786 $("user_password-desc").setMessageStatus("success");
788 }.bindAsEventListener(this));
790 $('account-create-anchor').insert({after: new Toggler('account-info').element});
793 presubmit: function() {
794 this.messenger.hide();
795 PseudoChecker.reset();
796 if (!(this.checkNotEmpty("user_pseudo", SyjStrings.userEmptyWarn))) {
800 if (!($("user_pseudo").value.match(/^[a-zA-Z0-9_.]+$/))) {
801 $("user_pseudo-desc").show().setMessageStatus("warn");
802 $("user_pseudo").highlight('#F08080').activate();
806 if (PseudoChecker.exists[$("user_pseudo").value]) {
807 PseudoChecker.availableMessage(false);
808 $("user_pseudo").highlight('#F08080').activate();
812 if (!(this.checkNotEmpty("user_password", SyjStrings.passwordEmptyWarn))) {
816 if ($("user_password").value.length < 6) {
817 $("user_password-desc").setMessageStatus("warn");
818 $("user_password").highlight('#F08080').activate();
822 if ($("user_password").value !== $("user_password_confirm").value) {
823 this.messenger.setMessage(SyjStrings.passwordNoMatchWarn, "warn");
824 $("user_password").highlight('#F08080').activate();
828 if (!(this.checkNotEmpty("user_email", SyjStrings.emailEmptyWarn))) {
832 if (!$("user_accept").checked) {
833 this.messenger.setMessage(SyjStrings.acceptTermsofuseWarn, "warn");
834 $("user_accept_container").highlight('#F08080');
835 $("user_accept").activate();
843 success: function(transport) {
844 if (!transport.responseJSON ||
845 typeof transport.responseJSON.pseudo !== "string"
847 this.messenger.setMessage(SyjStrings.unknownError, "error");
851 LoginMgr.login(transport.responseJSON.pseudo);
852 SYJView.messenger.setMessage(SyjStrings.userSuccess, "success");
853 this.modalbox.hide();
854 if (SYJView.needsFormResubmit) {
855 SYJView.messenger.addMessage(SyjStrings.canResubmit);
856 $("geom_submit").activate();
860 failure: function($super, transport) {
861 var httpCode = 0, focusInput = null, message = "";
864 httpCode = transport.getStatus();
872 if (transport.responseJSON) {
873 switch (transport.responseJSON.message) {
875 message = SyjStrings.emailInvalidWarn;
876 focusInput = $("user_email");
879 PseudoChecker.availableMessage(false);
880 focusInput = $("user_pseudo");
883 message = SyjStrings.uniqueEmailError;
884 focusInput = $("user_email");
893 this.messenger.setMessage(message, "error");
895 focusInput.highlight('#F08080').activate();
902 var SYJUser = new SYJUserClass();
904 var SYJLoginClass = Class.create(SYJModalClass, {
907 init: function($super) {
911 presubmit: function() {
912 this.messenger.hide();
913 if (!(this.checkNotEmpty("login_user", SyjStrings.userEmptyWarn))) {
921 success: function(transport) {
922 if (!transport.responseJSON ||
923 typeof transport.responseJSON.iscreator !== "boolean" ||
924 typeof transport.responseJSON.pseudo !== "string"
926 this.messenger.setMessage(SyjStrings.unknownError, "error");
929 LoginMgr.login(transport.responseJSON.pseudo, transport.responseJSON.iscreator);
931 SYJView.messenger.setMessage(SyjStrings.loginSuccess, "success");
932 this.modalbox.hide();
933 if (SYJView.needsFormResubmit) {
934 SYJView.messenger.addMessage(SyjStrings.canResubmit);
935 $("geom_submit").activate();
939 failure: function($super, transport) {
940 var httpCode = 0, focusInput = null, message = "";
943 httpCode = transport.getStatus();
951 message = SyjStrings.loginFailure;
952 focusInput = $("login_user");
957 this.messenger.setMessage(message, "error");
959 focusInput.highlight('#F08080').activate();
967 var SYJLogin = new SYJLoginClass();
969 var SYJNewpwdClass = Class.create(SYJModalClass, {
972 presubmit: function() {
973 if (!(this.checkNotEmpty("newpwd_email", SyjStrings.emailEmptyWarn))) {
979 success: function(transport) {
980 SYJView.messenger.setMessage(SyjStrings.newpwdSuccess, "success");
981 this.modalbox.hide();
985 var SYJNewpwd = new SYJNewpwdClass();
987 var LoginMgr = Object.extend(gLoggedInfo, {
990 updateUI: function() {
991 if (!this.controlsdeck) {
992 this.controlsdeck = new Deck("login_controls");
995 this.controlsdeck.setIndex(1);
996 $$(".logged-hide").invoke('hide');
997 $$(".logged-show").invoke('show');
999 this.controlsdeck.setIndex(0);
1000 $$(".logged-hide").invoke('show');
1001 $$(".logged-show").invoke('hide');
1004 if ($("edit-btn")) {
1005 if (this.iscreator && SYJView.mode === 'view') {
1006 $("edit-btn").show();
1008 $("edit-btn").hide();
1013 login: function(aPseudo, aIsCreator) {
1014 if (typeof aIsCreator === "boolean") {
1015 this.iscreator = aIsCreator;
1018 $$('.logged-pseudo').each(function(elt) {
1019 $A(elt.childNodes).filter(function(node) {
1020 return (node.nodeType === 3 || node.tagName.toLowerCase() === 'br');
1021 }).each(function(node) {
1022 node.nodeValue = node.nodeValue.replace('%s', aPseudo);
1029 var PseudoChecker = {
1036 message: function(str, status, throbber) {
1038 if (!this.messageelt) {
1039 row = new Element('tr');
1040 // we can't use row.update('<td></td><td><div></div></td>')
1041 // because gecko would mangle the <td>s
1042 row.insert(new Element('td'))
1043 .insert((new Element('td')).update(new Element('div')));
1045 $("user_pseudo").up('tr').insert({after: row});
1046 this.messageelt = new Element('span');
1047 this.throbber = new Element("img", { src: "icons/throbber.gif"});
1048 row.down('div').insert(this.throbber).insert(this.messageelt);
1051 this.throbber.show();
1053 this.throbber.hide();
1055 this.messageelt.up().setStyle({visibility: ''});
1056 this.messageelt.className = status;
1057 this.messageelt.update(str);
1060 availableMessage: function(available) {
1061 var message = available ? SyjStrings.availablePseudo: SyjStrings.unavailablePseudo,
1062 status = available ? "success": "warn";
1063 this.message(message, status, false);
1069 this.req = this.currentvalue = null;
1071 if (this.messageelt) {
1072 this.messageelt.up().setStyle({visibility: 'hidden'});
1077 var pseudo = $("user_pseudo").value;
1081 if (!pseudo || !(pseudo.match(/^[a-zA-Z0-9_.]+$/))) {
1085 if (typeof this.exists[pseudo] === "boolean") {
1087 this.availableMessage(!this.exists[pseudo]);
1091 this.message(SyjStrings.pseudoChecking, "", true);
1093 this.currentvalue = pseudo;
1094 this.req = new Ajax.TimedRequest('userexists/' + encodeURIComponent(pseudo), 20, {
1095 onFailure: this.failure.bind(this),
1096 onSuccess: this.success.bind(this)
1100 failure: function(transport) {
1101 var httpCode = 0, value = this.currentvalue;
1104 httpCode = transport.getStatus();
1107 if (httpCode === 404) {
1108 this.exists[value] = false;
1109 this.availableMessage(true);
1114 success: function(transport) {
1115 var httpCode = transport.getStatus(), value = this.currentvalue;
1117 this.exists[value] = true;
1118 this.availableMessage(false);
1122 var Nominatim = (function() {
1123 var presubmit = function() {
1124 var input = $("nominatim-search");
1125 if (input.value.strip().empty()) {
1126 $("nominatim-message").setMessage(SyjStrings.notEmptyField, "warn");
1130 $("nominatim-suggestions").hide();
1131 $("nominatim-message").hide();
1132 $("nominatim-throbber").show();
1136 var zoomToExtent = function(bounds) { // we must call map.setCenter with forceZoomChange to true. See ol#2798
1137 var center = bounds.getCenterLonLat();
1138 if (this.baseLayer.wrapDateLine) {
1139 var maxExtent = this.getMaxExtent();
1140 bounds = bounds.clone();
1141 while (bounds.right < bounds.left) {
1142 bounds.right += maxExtent.getWidth();
1144 center = bounds.getCenterLonLat().wrapDateLine(maxExtent);
1146 this.setCenter(center, this.getZoomForExtent(bounds), false, true);
1149 var success = function(transport) {
1150 $("nominatim-throbber").hide();
1152 if (!transport.responseJSON || !transport.responseJSON.length) {
1153 $("nominatim-message").setMessage(SyjStrings.noResult, 'error');
1154 $("nominatim-search").activate();
1158 var place = transport.responseJSON[0],
1159 bbox = place.boundingbox;
1161 if (!bbox || bbox.length !== 4) {
1162 $("nominatim-message").setMessage(SyjStrings.requestError, 'error');
1166 extent = new OpenLayers.Bounds(bbox[2], bbox[1], bbox[3], bbox[0]).transform(WGS84, Mercator);
1167 zoomToExtent.call(SYJView.map, extent);
1169 $("nominatim-suggestions-list").update();
1171 var clickhandler = function(bbox) {
1172 return function(evt) {
1174 var extent = new OpenLayers.Bounds(bbox[2], bbox[1], bbox[3], bbox[0]).transform(WGS84, Mercator);
1175 $("nominatim-suggestions-list").select("li").invoke('removeClassName', 'current');
1176 evt.target.up('li').addClassName('current');
1177 SYJView.map.zoomToExtent(extent);
1182 for (i = 0; i < transport.responseJSON.length; i++) {
1183 var item = transport.responseJSON[i];
1184 if (item.display_name && item.boundingbox && item.boundingbox.length === 4) {
1185 var li = new Element("li");
1186 var anchor = new Element("a", {
1188 className: "nominatim-suggestions-link"
1191 anchor.observe('click', clickhandler(item.boundingbox));
1192 Element.text(anchor, item.display_name);
1194 var icon = new Element("img", {
1195 className: "nominatim-suggestions-icon",
1196 src: item.icon || 'icons/world.png'
1198 li.insert(icon).insert(anchor);
1199 $("nominatim-suggestions-list").insert(li);
1200 if ($("nominatim-suggestions-list").childNodes.length >= 6) {
1206 if ($("nominatim-suggestions-list").childNodes.length > 1) {
1207 var bottomOffset = $('data_controls').measure('height') + 3;
1208 $("nominatim-suggestions").setStyle({
1209 bottom: (document.viewport.getHeight() - $('data_controls').cumulativeOffset().top + 3).toString() + 'px'
1211 $("nominatim-suggestions-list").select("li:first-child")[0].addClassName('current');
1213 $("nominatim-suggestions").hide();
1218 var failure = function(transport) {
1219 $("nominatim-throbber").hide();
1221 var httpCode = 0, message = SyjStrings.unknownError, input; // default message error
1224 httpCode = transport.getStatus();
1229 message = SyjStrings.notReachedError;
1233 message = SyjStrings.requestError;
1236 message = SyjStrings.serverError;
1240 $("nominatim-message").setMessage(message, 'error');
1245 if (!$("nominatim-form")) {
1248 $("nominatim-controls").hide();
1249 $("nominatim-label").observe('click', function(evt) {
1250 $("nominatim-controls").show();
1251 $("nominatim-search").activate();
1255 $("nominatim-form").ajaxize({
1256 presubmit: presubmit,
1260 new CloseBtn($("nominatim-suggestions"));
1262 $$("#nominatim-message, #nominatim-suggestions, #nominatim-throbber").invoke('hide');
1267 document.observe("dom:loaded", function() {
1270 SYJDataUi.viewmode();
1273 LoginMgr.updateUI();
1277 window.onbeforeunload = function() {
1278 if (SYJView.unsavedRoute) {
1279 return SyjStrings.unsavedConfirmExit;