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() {
354 $("map-overlay").show();
356 this.editControl.deactivate();
359 document.observe('simplebox:shown', this.observer.bindAsEventListener(this));
360 SYJPathLength.update();
363 initMaPos: function (aPos) {
364 var extent = null, center = null, zoom = 0;
366 if (aPos.hasOwnProperty('lon') && aPos.hasOwnProperty('lat') && aPos.hasOwnProperty('zoom')) {
367 center = new OpenLayers.LonLat(parseFloat(aPos.lon), parseFloat(aPos.lat)).transform(WGS84, Mercator);
368 zoom = parseInt(aPos.zoom);
369 } else if (aPos.hasOwnProperty('minlon') && aPos.hasOwnProperty('minlat')
370 && aPos.hasOwnProperty('maxlon') && aPos.hasOwnProperty('maxlat')) {
371 extent = new OpenLayers.Bounds(aPos.minlon, aPos.minlat, aPos.maxlon, aPos.maxlat)
372 .transform(WGS84, Mercator);
374 extent = new OpenLayers.Bounds(-160, -70, 160, 70).transform(WGS84, Mercator);
378 this.map.zoomToExtent(extent);
380 this.map.setCenter(center, zoom);
384 observer: function(evt) {
385 if (evt.eventName === "simplebox:shown" && evt.memo.element !== $("termsofusearea")) {
386 this.messenger.hide();
390 prepareForm: function(form) {
391 if (!LoginMgr.logged && !$("geom_accept").checked) {
392 this.messenger.setMessage(SyjStrings.acceptTermsofuseWarn, "warn");
393 $("geom_accept_container").highlight('#F08080');
394 $("geom_accept").activate();
398 var line, realPoints, idx;
400 line = new OpenLayers.Geometry.LineString();
401 realPoints = this.editControl.handler.realPoints;
402 for (idx = 0; idx < realPoints.length; idx++) {
403 line.addComponent(realPoints[idx].geometry.clone());
405 this.viewLayer.addFeatures(new OpenLayers.Feature.Vector(line));
409 if (line.components.length) {
410 $("geom_data").value = this.wkt.write(new OpenLayers.Feature.Vector(line));
412 $("geom_data").value = "";
415 if (this.mode === "edit" && typeof gLoggedInfo.pathid !== "undefined") {
416 $("geomform").setAttribute("action", "path/" + gLoggedInfo.pathid.toString() + '/update');
418 $("geomform").setAttribute("action", "path");
420 this.needsFormResubmit = false;
421 SyjSaveUI.disable.bind(SyjSaveUI).defer();
422 this.messenger.hide();
426 viewMode: function() {
427 var handler = this.editControl.handler;
428 OpenLayers.Handler.ModifiablePath.prototype.finalize.apply(handler, arguments);
429 // we need to recreate them on next createFeature; otherwise
430 // they'll reference destroyed features
431 delete(handler.handlers.drag);
432 delete(handler.handlers.feature);
433 this.editControl.deactivate();
436 editMode: function() {
437 var components, point0, point, pixels, pixel, idx;
439 this.initEditControl();
441 this.editControl.activate();
442 if (this.viewLayer.features.length) {
443 components = this.viewLayer.features[0].geometry.components;
444 point0 = components[0];
446 pixel = this.map.getPixelFromLonLat(new OpenLayers.LonLat(point0.x, point0.y));
447 this.editControl.handler.createFeature(pixel);
448 this.editControl.handler.lastUp = pixel;
450 for (idx = 1; idx < components.length; idx++) {
451 point = components[idx];
452 pixels.push(this.map.getPixelFromLonLat(new OpenLayers.LonLat(point.x, point.y)));
454 this.editControl.handler.addPoints(pixels);
456 this.unsavedRoute = {
457 features: this.viewLayer.features.invoke('clone'),
458 title: $("geom_title").value
462 this.viewLayer.destroyFeatures();
464 SYJDataUi.editmode();
465 if (this.editControl.handler.realPoints && this.editControl.handler.realPoints.length >= 2) {
466 SyjSaveUI.disableSubmit();
472 initEditControl: function() {
475 if (this.editControl) {
479 this.editControl = new OpenLayers.Control.DrawFeature(new OpenLayers.Layer.Vector(), OpenLayers.Handler.SyjModifiablePath, {
481 modify: function(f, line) {
482 SYJPathLength.update();
484 var npoints = this.handler.realPoints.length;
486 $("geom_upload_container").show();
487 SYJView.unsavedRoute = null;
489 if (!SYJView.unsavedRoute) {
490 SYJView.unsavedRoute = {};
500 create: function(f, line) {
501 $("geom_upload_container").hide();
507 styleMap: styleMap.edit
511 this.map.addControl(this.editControl);
512 if (this.editControl.layer.renderer instanceof OpenLayers.Renderer.Canvas) {
513 // using externalGraphic with canvas renderer is definitively too buggy
514 styles = this.editControl.handler.layerOptions.styleMap.styles;
515 styles.select = styles.select_for_canvas;
519 saveSuccess: function(transport) {
520 this.unsavedRoute = null;
522 if (transport.responseJSON && (typeof transport.responseJSON.redirect === "string")) {
523 location = transport.responseJSON.redirect;
527 this.messenger.setMessage(SyjStrings.saveSuccess, "success");
528 SYJDataUi.viewmode();
529 document.title = $('geom_title').value;
532 saveFailure: function(transport) {
533 var httpCode = 0, message = "";
536 httpCode = transport.getStatus();
540 message = SyjStrings.notReachedError;
544 message = SyjStrings.requestError;
545 if (transport.responseJSON) {
546 switch (transport.responseJSON.message) {
548 message = SyjStrings.uniquePathError;
557 SYJLogin.messenger.setMessage(SyjStrings.loginNeeded, "warn");
558 SYJLogin.modalbox.show();
559 this.needsFormResubmit = true;
562 message = SyjStrings.gonePathError;
565 message = SyjStrings.serverError;
566 this.needsFormResubmit = true;
569 message = SyjStrings.unknownError;
574 // is some cases, we let the user resubmit, in some other cases, he
575 // needs to modify the path before submitting again
576 if (this.needsFormResubmit) {
580 this.messenger.setMessage(message, "error");
584 var SYJModalClass = Class.create({
588 this.area = $(this.type + '_area');
589 this.messenger = $(this.type + "_message");
590 this.modalbox = new SimpleBox(this.area, {
591 closeMethods: ["onescapekey", "onouterclick", "onbutton"]
594 $(this.type + "_control_anchor").observe("click", function(evt) {
595 this.modalbox.show();
597 }.bindAsEventListener(this));
599 document.observe('simplebox:shown', this.observer.bindAsEventListener(this));
600 document.observe('simplebox:hidden', this.observer.bindAsEventListener(this));
602 $(this.type + "form").ajaxize({
603 presubmit: this.presubmit.bind(this),
604 onSuccess: this.success.bind(this),
605 onFailure: this.failure.bind(this)
609 checkNotEmpty: function(input, message) {
610 if ($(input).value.strip().empty()) {
611 this.messenger.setMessage(message, "warn");
612 $(input).highlight('#F08080').activate();
618 observer: function(evt) {
619 var simplebox, input;
621 if (evt.eventName === "simplebox:shown" && evt.memo.element !== $("termsofusearea")) {
622 simplebox = evt.memo;
623 if (simplebox === this.modalbox) {
624 input = this.area.select('input[type="text"]')[0];
629 this.modalbox.hide();
632 } else if (evt.eventName === "simplebox:hidden" && evt.memo.element !== $("termsofusearea")) {
633 simplebox = evt.memo;
634 if (simplebox === this.modalbox) {
640 failure: function(transport) {
641 var httpCode = 0, message = SyjStrings.unknownError, input; // default message error
644 httpCode = transport.getStatus();
649 message = SyjStrings.notReachedError;
654 message = SyjStrings.requestError;
657 message = SyjStrings.serverError;
661 this.messenger.setMessage(message, "error");
662 input = this.area.select('input[type="text"]')[0];
663 input.highlight('#F08080').activate();
667 this.messenger.hide();
668 this.area.select('.message').invoke('setMessageStatus', null);
672 var SYJUserClass = Class.create(SYJModalClass, {
676 init: function($super) {
678 $("termsofusearea").hide();
680 $$("#user_termsofuse_anchor, #geom_termsofuse_anchor").invoke('observe', "click", function(evt) {
682 this.toubox = new SimpleBox($("termsofusearea"), {
683 closeMethods: ["onescapekey", "onouterclick", "onbutton"]
687 if (!$("termsofuseiframe").getAttribute("src")) {
688 $("termsofusearea").show();
689 $("termsofuseiframe").setAttribute("src", evt.target.href);
692 }.bindAsEventListener(this));
694 $$("#login_area_create > a").invoke('observe', 'click',
696 this.modalbox.show();
698 }.bindAsEventListener(this));
700 $("user_pseudo-desc").hide();
701 $("user_pseudo").observe('contentchange', function(evt) {
702 var value = evt.target.value;
703 PseudoChecker.reset();
704 if (value && !(value.match(/^[a-zA-Z0-9_.]+$/))) {
705 $("user_pseudo-desc").show().setMessageStatus("warn");
707 $("user_pseudo-desc").hide();
709 }).timedobserve(function() {
710 PseudoChecker.check();
713 $("user_password").observe('contentchange', function(evt) {
714 if (evt.target.value.length < 6) {
715 $("user_password-desc").setMessageStatus("warn");
717 $("user_password-desc").setMessageStatus("success");
719 }.bindAsEventListener(this));
721 $('account-create-anchor').insert({after: new Toggler('account-info').element});
724 presubmit: function() {
725 this.messenger.hide();
726 PseudoChecker.reset();
727 if (!(this.checkNotEmpty("user_pseudo", SyjStrings.userEmptyWarn))) {
731 if (!($("user_pseudo").value.match(/^[a-zA-Z0-9_.]+$/))) {
732 $("user_pseudo-desc").show().setMessageStatus("warn");
733 $("user_pseudo").highlight('#F08080').activate();
737 if (PseudoChecker.exists[$("user_pseudo").value]) {
738 PseudoChecker.availableMessage(false);
739 $("user_pseudo").highlight('#F08080').activate();
743 if (!(this.checkNotEmpty("user_password", SyjStrings.passwordEmptyWarn))) {
747 if ($("user_password").value.length < 6) {
748 $("user_password-desc").setMessageStatus("warn");
749 $("user_password").highlight('#F08080').activate();
753 if ($("user_password").value !== $("user_password_confirm").value) {
754 this.messenger.setMessage(SyjStrings.passwordNoMatchWarn, "warn");
755 $("user_password").highlight('#F08080').activate();
759 if (!(this.checkNotEmpty("user_email", SyjStrings.emailEmptyWarn))) {
763 if (!$("user_accept").checked) {
764 this.messenger.setMessage(SyjStrings.acceptTermsofuseWarn, "warn");
765 $("user_accept_container").highlight('#F08080');
766 $("user_accept").activate();
774 success: function(transport) {
775 if (!transport.responseJSON ||
776 typeof transport.responseJSON.pseudo !== "string"
778 this.messenger.setMessage(SyjStrings.unknownError, "error");
782 LoginMgr.login(transport.responseJSON.pseudo);
783 SYJView.messenger.setMessage(SyjStrings.userSuccess, "success");
784 this.modalbox.hide();
785 if (SYJView.needsFormResubmit) {
786 SYJView.messenger.addMessage(SyjStrings.canResubmit);
787 $("geom_submit").activate();
791 failure: function($super, transport) {
792 var httpCode = 0, focusInput = null, message = "";
795 httpCode = transport.getStatus();
803 if (transport.responseJSON) {
804 switch (transport.responseJSON.message) {
806 message = SyjStrings.emailInvalidWarn;
807 focusInput = $("user_email");
810 PseudoChecker.availableMessage(false);
811 focusInput = $("user_pseudo");
814 message = SyjStrings.uniqueEmailError;
815 focusInput = $("user_email");
824 this.messenger.setMessage(message, "error");
826 focusInput.highlight('#F08080').activate();
833 var SYJUser = new SYJUserClass();
835 var SYJLoginClass = Class.create(SYJModalClass, {
838 init: function($super) {
842 presubmit: function() {
843 this.messenger.hide();
844 if (!(this.checkNotEmpty("login_user", SyjStrings.userEmptyWarn))) {
852 success: function(transport) {
853 if (!transport.responseJSON ||
854 typeof transport.responseJSON.iscreator !== "boolean" ||
855 typeof transport.responseJSON.pseudo !== "string"
857 this.messenger.setMessage(SyjStrings.unknownError, "error");
860 LoginMgr.login(transport.responseJSON.pseudo, transport.responseJSON.iscreator);
862 SYJView.messenger.setMessage(SyjStrings.loginSuccess, "success");
863 this.modalbox.hide();
864 if (SYJView.needsFormResubmit) {
865 SYJView.messenger.addMessage(SyjStrings.canResubmit);
866 $("geom_submit").activate();
870 failure: function($super, transport) {
871 var httpCode = 0, focusInput = null, message = "";
874 httpCode = transport.getStatus();
882 message = SyjStrings.loginFailure;
883 focusInput = $("login_user");
888 this.messenger.setMessage(message, "error");
890 focusInput.highlight('#F08080').activate();
898 var SYJLogin = new SYJLoginClass();
900 var SYJNewpwdClass = Class.create(SYJModalClass, {
903 presubmit: function() {
904 if (!(this.checkNotEmpty("newpwd_email", SyjStrings.emailEmptyWarn))) {
910 success: function(transport) {
911 SYJView.messenger.setMessage(SyjStrings.newpwdSuccess, "success");
912 this.modalbox.hide();
916 var SYJNewpwd = new SYJNewpwdClass();
918 var LoginMgr = Object.extend(gLoggedInfo, {
921 updateUI: function() {
922 if (!this.controlsdeck) {
923 this.controlsdeck = new Deck("login_controls");
926 this.controlsdeck.setIndex(1);
927 $$(".logged-hide").invoke('hide');
928 $$(".logged-show").invoke('show');
930 this.controlsdeck.setIndex(0);
931 $$(".logged-hide").invoke('show');
932 $$(".logged-show").invoke('hide');
936 if (this.iscreator && SYJView.mode === 'view') {
937 $("edit-btn").show();
939 $("edit-btn").hide();
944 login: function(aPseudo, aIsCreator) {
945 if (typeof aIsCreator === "boolean") {
946 this.iscreator = aIsCreator;
949 $$('.logged-pseudo').each(function(elt) {
950 $A(elt.childNodes).filter(function(node) {
951 return (node.nodeType === 3 || node.tagName.toLowerCase() === 'br');
952 }).each(function(node) {
953 node.nodeValue = node.nodeValue.replace('%s', aPseudo);
960 var PseudoChecker = {
967 message: function(str, status, throbber) {
969 if (!this.messageelt) {
970 row = new Element('tr');
971 // we can't use row.update('<td></td><td><div></div></td>')
972 // because gecko would mangle the <td>s
973 row.insert(new Element('td'))
974 .insert((new Element('td')).update(new Element('div')));
976 $("user_pseudo").up('tr').insert({after: row});
977 this.messageelt = new Element('span');
978 this.throbber = new Element("img", { src: "icons/throbber.gif"});
979 row.down('div').insert(this.throbber).insert(this.messageelt);
982 this.throbber.show();
984 this.throbber.hide();
986 this.messageelt.up().setStyle({visibility: ''});
987 this.messageelt.className = status;
988 this.messageelt.update(str);
991 availableMessage: function(available) {
992 var message = available ? SyjStrings.availablePseudo: SyjStrings.unavailablePseudo,
993 status = available ? "success": "warn";
994 this.message(message, status, false);
1000 this.req = this.currentvalue = null;
1002 if (this.messageelt) {
1003 this.messageelt.up().setStyle({visibility: 'hidden'});
1008 var pseudo = $("user_pseudo").value;
1012 if (!pseudo || !(pseudo.match(/^[a-zA-Z0-9_.]+$/))) {
1016 if (typeof this.exists[pseudo] === "boolean") {
1018 this.availableMessage(!this.exists[pseudo]);
1022 this.message(SyjStrings.pseudoChecking, "", true);
1024 this.currentvalue = pseudo;
1025 this.req = new Ajax.TimedRequest('userexists/' + encodeURIComponent(pseudo), 20, {
1026 onFailure: this.failure.bind(this),
1027 onSuccess: this.success.bind(this)
1031 failure: function(transport) {
1032 var httpCode = 0, value = this.currentvalue;
1035 httpCode = transport.getStatus();
1038 if (httpCode === 404) {
1039 this.exists[value] = false;
1040 this.availableMessage(true);
1045 success: function(transport) {
1046 var httpCode = transport.getStatus(), value = this.currentvalue;
1048 this.exists[value] = true;
1049 this.availableMessage(false);
1053 var Nominatim = (function() {
1054 var presubmit = function() {
1055 var input = $("nominatim-search");
1056 if (input.value.strip().empty()) {
1057 $("nominatim-message").setMessage(SyjStrings.notEmptyField, "warn");
1061 $("nominatim-suggestions").hide();
1062 $("nominatim-message").hide();
1063 $("nominatim-throbber").show();
1067 var zoomToExtent = function(bounds) { // we must call map.setCenter with forceZoomChange to true. See ol#2798
1068 var center = bounds.getCenterLonLat();
1069 if (this.baseLayer.wrapDateLine) {
1070 var maxExtent = this.getMaxExtent();
1071 bounds = bounds.clone();
1072 while (bounds.right < bounds.left) {
1073 bounds.right += maxExtent.getWidth();
1075 center = bounds.getCenterLonLat().wrapDateLine(maxExtent);
1077 this.setCenter(center, this.getZoomForExtent(bounds), false, true);
1080 var success = function(transport) {
1081 $("nominatim-throbber").hide();
1083 if (!transport.responseJSON || !transport.responseJSON.length) {
1084 $("nominatim-message").setMessage(SyjStrings.noResult, 'error');
1085 $("nominatim-search").activate();
1089 var place = transport.responseJSON[0],
1090 bbox = place.boundingbox;
1092 if (!bbox || bbox.length !== 4) {
1093 $("nominatim-message").setMessage(SyjStrings.requestError, 'error');
1097 extent = new OpenLayers.Bounds(bbox[2], bbox[1], bbox[3], bbox[0]).transform(WGS84, Mercator);
1098 zoomToExtent.call(SYJView.map, extent);
1100 $("nominatim-suggestions-list").update();
1102 var clickhandler = function(bbox) {
1103 return function(evt) {
1105 var extent = new OpenLayers.Bounds(bbox[2], bbox[1], bbox[3], bbox[0]).transform(WGS84, Mercator);
1106 $("nominatim-suggestions-list").select("li").invoke('removeClassName', 'current');
1107 evt.target.up('li').addClassName('current');
1108 SYJView.map.zoomToExtent(extent);
1113 for (i = 0; i < transport.responseJSON.length; i++) {
1114 var item = transport.responseJSON[i];
1115 if (item.display_name && item.boundingbox && item.boundingbox.length === 4) {
1116 var li = new Element("li");
1117 var anchor = new Element("a", {
1119 className: "nominatim-suggestions-link"
1122 anchor.observe('click', clickhandler(item.boundingbox));
1123 Element.text(anchor, item.display_name);
1125 var icon = new Element("img", {
1126 className: "nominatim-suggestions-icon",
1127 src: item.icon || 'icons/world.png'
1129 li.insert(icon).insert(anchor);
1130 $("nominatim-suggestions-list").insert(li);
1131 if ($("nominatim-suggestions-list").childNodes.length >= 6) {
1137 if ($("nominatim-suggestions-list").childNodes.length > 1) {
1138 var bottomOffset = $('data_controls').measure('height') + 3;
1139 $("nominatim-suggestions").setStyle({
1140 bottom: (document.viewport.getHeight() - $('data_controls').cumulativeOffset().top + 3).toString() + 'px'
1142 $("nominatim-suggestions-list").select("li:first-child")[0].addClassName('current');
1144 $("nominatim-suggestions").hide();
1149 var failure = function(transport) {
1150 $("nominatim-throbber").hide();
1152 var httpCode = 0, message = SyjStrings.unknownError, input; // default message error
1155 httpCode = transport.getStatus();
1160 message = SyjStrings.notReachedError;
1164 message = SyjStrings.requestError;
1167 message = SyjStrings.serverError;
1171 $("nominatim-message").setMessage(message, 'error');
1176 if (!$("nominatim-form")) {
1179 $("nominatim-controls").hide();
1180 $("nominatim-label").observe('click', function(evt) {
1181 $("nominatim-controls").show();
1182 $("nominatim-search").activate();
1186 $("nominatim-form").ajaxize({
1187 presubmit: presubmit,
1191 new CloseBtn($("nominatim-suggestions"));
1193 $$("#nominatim-message, #nominatim-suggestions, #nominatim-throbber").invoke('hide');
1198 document.observe("dom:loaded", function() {
1201 SYJDataUi.viewmode();
1204 LoginMgr.updateUI();
1208 window.onbeforeunload = function() {
1209 if (SYJView.unsavedRoute) {
1210 return SyjStrings.unsavedConfirmExit;