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 $("geomform").removeClassName("disabled");
25 this.status = "enabled";
30 if (this.status === "disabled") {
34 $("geom_title").blur();
35 $("geom_title").disabled = true;
36 $("geomform").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, extent, 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 extent = this.viewLayer.getDataExtent();
345 // XXX: ie has not guessed height of map main div yet during map
346 // initialisation. Now, it will read it correctly.
347 this.map.updateSize();
349 extent = new OpenLayers.Bounds(gMaxExtent.minlon, gMaxExtent.minlat, gMaxExtent.maxlon, gMaxExtent.maxlat)
350 .transform(WGS84, Mercator);
352 this.map.zoomToExtent(extent);
353 document.observe('simplebox:shown', this.observer.bindAsEventListener(this));
354 SYJPathLength.update();
357 observer: function(evt) {
358 if (evt.eventName === "simplebox:shown" && evt.memo.element !== $("termsofusearea")) {
359 this.messenger.hide();
363 prepareForm: function(form) {
364 if (!LoginMgr.logged && !$("geom_accept").checked) {
365 this.messenger.setMessage(SyjStrings.acceptTermsofuseWarn, "warn");
366 $("geom_accept_container").highlight('#F08080');
367 $("geom_accept").activate();
371 var line, realPoints, idx;
373 line = new OpenLayers.Geometry.LineString();
374 realPoints = this.editControl.handler.realPoints;
375 for (idx = 0; idx < realPoints.length; idx++) {
376 line.addComponent(realPoints[idx].geometry.clone());
378 this.viewLayer.addFeatures(new OpenLayers.Feature.Vector(line));
382 $("geom_data").value = this.wkt.write(new OpenLayers.Feature.Vector(line));
383 if (this.mode === "edit" && typeof gLoggedInfo.pathid !== "undefined") {
384 $("geomform").setAttribute("action", "path/" + gLoggedInfo.pathid.toString() + '/update');
386 $("geomform").setAttribute("action", "path");
388 this.needsFormResubmit = false;
389 SyjSaveUI.disable.bind(SyjSaveUI).defer();
390 this.messenger.hide();
394 viewMode: function() {
395 var handler = this.editControl.handler;
396 OpenLayers.Handler.ModifiablePath.prototype.finalize.apply(handler, arguments);
397 // we need to recreate them on next createFeature; otherwise
398 // they'll reference destroyed features
399 delete(handler.handlers.drag);
400 delete(handler.handlers.feature);
401 this.editControl.deactivate();
404 editMode: function() {
405 var components, point0, point, pixels, pixel, idx;
407 this.initEditControl();
409 this.editControl.activate();
410 if (this.viewLayer.features.length) {
411 components = this.viewLayer.features[0].geometry.components;
412 point0 = components[0];
414 pixel = this.map.getPixelFromLonLat(new OpenLayers.LonLat(point0.x, point0.y));
415 this.editControl.handler.createFeature(pixel);
416 this.editControl.handler.lastUp = pixel;
418 for (idx = 1; idx < components.length; idx++) {
419 point = components[idx];
420 pixels.push(this.map.getPixelFromLonLat(new OpenLayers.LonLat(point.x, point.y)));
422 this.editControl.handler.addPoints(pixels);
424 this.unsavedRoute = {
425 features: this.viewLayer.features.invoke('clone'),
426 title: $("geom_title").value
430 this.viewLayer.destroyFeatures();
432 SYJDataUi.editmode();
433 if (this.editControl.handler.realPoints && this.editControl.handler.realPoints.length >= 2) {
434 SyjSaveUI.disableSubmit();
440 initEditControl: function() {
443 if (this.editControl) {
447 this.editControl = new OpenLayers.Control.DrawFeature(new OpenLayers.Layer.Vector(), OpenLayers.Handler.SyjModifiablePath, {
449 modify: function(f, line) {
450 SYJPathLength.update();
451 if (!SYJView.unsavedRoute) {
452 SYJView.unsavedRoute = {};
454 if (this.handler.realPoints.length < 2) {
464 styleMap: styleMap.edit
468 this.map.addControl(this.editControl);
469 if (this.editControl.layer.renderer instanceof OpenLayers.Renderer.Canvas) {
470 // using externalGraphic with canvas renderer is definitively too buggy
471 styles = this.editControl.handler.layerOptions.styleMap.styles;
472 styles.select = styles.select_for_canvas;
474 new CloseBtn($("geomform"), {
476 marginRight: "-40px",
479 callback: function(form) {
482 SYJDataUi.viewmode();
483 this.messenger.hide();
485 if (this.unsavedRoute && typeof this.unsavedRoute.features !== "undefined") {
486 this.viewLayer.addFeatures(this.unsavedRoute.features);
488 if (this.unsavedRoute && typeof this.unsavedRoute.title !== "undefined") {
489 $("geom_title").value = this.unsavedRoute.title;
491 $("geom_title").value = "";
493 this.unsavedRoute = null;
498 saveSuccess: function(transport) {
499 this.unsavedRoute = null;
501 if (transport.responseJSON && (typeof transport.responseJSON.redirect === "string")) {
502 location = transport.responseJSON.redirect;
506 this.messenger.setMessage(SyjStrings.saveSuccess, "success");
507 SYJDataUi.viewmode();
508 document.title = $('geom_title').value;
511 saveFailure: function(transport) {
512 var httpCode = 0, message = "";
515 httpCode = transport.getStatus();
519 message = SyjStrings.notReachedError;
523 message = SyjStrings.requestError;
524 if (transport.responseJSON) {
525 switch (transport.responseJSON.message) {
527 message = SyjStrings.uniquePathError;
536 SYJLogin.messenger.setMessage(SyjStrings.loginNeeded, "warn");
537 SYJLogin.modalbox.show();
538 this.needsFormResubmit = true;
541 message = SyjStrings.gonePathError;
544 message = SyjStrings.serverError;
545 this.needsFormResubmit = true;
548 message = SyjStrings.unknownError;
553 // is some cases, we let the user resubmit, in some other cases, he
554 // needs to modify the path before submitting again
555 if (this.needsFormResubmit) {
559 this.messenger.setMessage(message, "error");
563 var SYJModalClass = Class.create({
567 this.area = $(this.type + '_area');
568 this.messenger = $(this.type + "_message");
569 this.modalbox = new SimpleBox(this.area, {
570 closeMethods: ["onescapekey", "onouterclick", "onbutton"]
573 $(this.type + "_control_anchor").observe("click", function(evt) {
574 this.modalbox.show();
576 }.bindAsEventListener(this));
578 document.observe('simplebox:shown', this.observer.bindAsEventListener(this));
579 document.observe('simplebox:hidden', this.observer.bindAsEventListener(this));
581 $(this.type + "form").ajaxize({
582 presubmit: this.presubmit.bind(this),
583 onSuccess: this.success.bind(this),
584 onFailure: this.failure.bind(this)
588 checkNotEmpty: function(input, message) {
589 if ($(input).value.strip().empty()) {
590 this.messenger.setMessage(message, "warn");
591 $(input).highlight('#F08080').activate();
597 observer: function(evt) {
598 var simplebox, input;
600 if (evt.eventName === "simplebox:shown" && evt.memo.element !== $("termsofusearea")) {
601 simplebox = evt.memo;
602 if (simplebox === this.modalbox) {
603 input = this.area.select('input[type="text"]')[0];
608 this.modalbox.hide();
611 } else if (evt.eventName === "simplebox:hidden" && evt.memo.element !== $("termsofusearea")) {
612 simplebox = evt.memo;
613 if (simplebox === this.modalbox) {
619 failure: function(transport) {
620 var httpCode = 0, message = SyjStrings.unknownError, input; // default message error
623 httpCode = transport.getStatus();
628 message = SyjStrings.notReachedError;
633 message = SyjStrings.requestError;
636 message = SyjStrings.serverError;
640 this.messenger.setMessage(message, "error");
641 input = this.area.select('input[type="text"]')[0];
642 input.highlight('#F08080').activate();
646 this.messenger.hide();
647 this.area.select('.message').invoke('setMessageStatus', null);
651 var SYJUserClass = Class.create(SYJModalClass, {
655 init: function($super) {
657 $("termsofusearea").hide();
659 $$("#user_termsofuse_anchor, #geom_termsofuse_anchor").invoke('observe', "click", function(evt) {
661 this.toubox = new SimpleBox($("termsofusearea"), {
662 closeMethods: ["onescapekey", "onouterclick", "onbutton"]
666 if (!$("termsofuseiframe").getAttribute("src")) {
667 $("termsofusearea").show();
668 $("termsofuseiframe").setAttribute("src", evt.target.href);
671 }.bindAsEventListener(this));
673 $$("#login_area_create > a").invoke('observe', 'click',
675 this.modalbox.show();
677 }.bindAsEventListener(this));
679 $("user_pseudo-desc").hide();
680 $("user_pseudo").observe('contentchange', function(evt) {
681 var value = evt.target.value;
682 PseudoChecker.reset();
683 if (value && !(value.match(/^[a-zA-Z0-9_.]+$/))) {
684 $("user_pseudo-desc").show().setMessageStatus("warn");
686 $("user_pseudo-desc").hide();
688 }).timedobserve(function() {
689 PseudoChecker.check();
692 $("user_password").observe('contentchange', function(evt) {
693 if (evt.target.value.length < 6) {
694 $("user_password-desc").setMessageStatus("warn");
696 $("user_password-desc").setMessageStatus("success");
698 }.bindAsEventListener(this));
700 $('account-create-anchor').insert({after: new Toggler('account-info').element});
703 presubmit: function() {
704 this.messenger.hide();
705 PseudoChecker.reset();
706 if (!(this.checkNotEmpty("user_pseudo", SyjStrings.userEmptyWarn))) {
710 if (!($("user_pseudo").value.match(/^[a-zA-Z0-9_.]+$/))) {
711 $("user_pseudo-desc").show().setMessageStatus("warn");
712 $("user_pseudo").highlight('#F08080').activate();
716 if (PseudoChecker.exists[$("user_pseudo").value]) {
717 PseudoChecker.availableMessage(false);
718 $("user_pseudo").highlight('#F08080').activate();
722 if (!(this.checkNotEmpty("user_password", SyjStrings.passwordEmptyWarn))) {
726 if ($("user_password").value.length < 6) {
727 $("user_password-desc").setMessageStatus("warn");
728 $("user_password").highlight('#F08080').activate();
732 if ($("user_password").value !== $("user_password_confirm").value) {
733 this.messenger.setMessage(SyjStrings.passwordNoMatchWarn, "warn");
734 $("user_password").highlight('#F08080').activate();
738 if (!(this.checkNotEmpty("user_email", SyjStrings.emailEmptyWarn))) {
742 if (!$("user_accept").checked) {
743 this.messenger.setMessage(SyjStrings.acceptTermsofuseWarn, "warn");
744 $("user_accept_container").highlight('#F08080');
745 $("user_accept").activate();
753 success: function(transport) {
755 SYJView.messenger.setMessage(SyjStrings.userSuccess, "success");
756 this.modalbox.hide();
757 if (SYJView.needsFormResubmit) {
758 SYJView.messenger.addMessage(SyjStrings.canResubmit);
759 $("geom_submit").activate();
763 failure: function($super, transport) {
764 var httpCode = 0, focusInput = null, message = "";
767 httpCode = transport.getStatus();
775 if (transport.responseJSON) {
776 switch (transport.responseJSON.message) {
778 message = SyjStrings.emailInvalidWarn;
779 focusInput = $("user_email");
782 PseudoChecker.availableMessage(false);
783 focusInput = $("user_pseudo");
786 message = SyjStrings.uniqueEmailError;
787 focusInput = $("user_email");
796 this.messenger.setMessage(message, "error");
798 focusInput.highlight('#F08080').activate();
805 var SYJUser = new SYJUserClass();
807 var SYJLoginClass = Class.create(SYJModalClass, {
810 init: function($super) {
814 presubmit: function() {
815 this.messenger.hide();
816 if (!(this.checkNotEmpty("login_user", SyjStrings.userEmptyWarn))) {
824 success: function(transport) {
825 if (!transport.responseJSON ||
826 typeof transport.responseJSON.iscreator !== "boolean" ||
827 typeof transport.responseJSON.pseudo !== "string"
829 this.messenger.setMessage(SyjStrings.unknownError, "error");
832 LoginMgr.login(transport.responseJSON.iscreator);
833 $$('.logged-pseudo').each(function(elt) {
834 $A(elt.childNodes).filter(function(node) {
835 return (node.nodeType === 3 || node.tagName.toLowerCase() === 'br');
836 }).each(function(node) {
837 node.nodeValue = node.nodeValue.replace('%s', transport.responseJSON.pseudo);
840 SYJView.messenger.setMessage(SyjStrings.loginSuccess, "success");
841 this.modalbox.hide();
842 if (SYJView.needsFormResubmit) {
843 SYJView.messenger.addMessage(SyjStrings.canResubmit);
844 $("geom_submit").activate();
848 failure: function($super, transport) {
849 var httpCode = 0, focusInput = null, message = "";
852 httpCode = transport.getStatus();
860 message = SyjStrings.loginFailure;
861 focusInput = $("login_user");
866 this.messenger.setMessage(message, "error");
868 focusInput.highlight('#F08080').activate();
876 var SYJLogin = new SYJLoginClass();
878 var SYJNewpwdClass = Class.create(SYJModalClass, {
881 presubmit: function() {
882 if (!(this.checkNotEmpty("newpwd_email", SyjStrings.emailEmptyWarn))) {
888 success: function(transport) {
889 SYJView.messenger.setMessage(SyjStrings.newpwdSuccess, "success");
890 this.modalbox.hide();
894 var SYJNewpwd = new SYJNewpwdClass();
896 var LoginMgr = Object.extend(gLoggedInfo, {
899 updateUI: function() {
900 if (!this.controlsdeck) {
901 this.controlsdeck = new Deck("login_controls");
904 this.controlsdeck.setIndex(1);
905 $$(".logged-hide").invoke('hide');
906 $$(".logged-show").invoke('show');
908 this.controlsdeck.setIndex(0);
909 $$(".logged-hide").invoke('show');
910 $$(".logged-show").invoke('hide');
914 if (this.iscreator && SYJView.mode === 'view') {
915 $("edit-btn").show();
917 $("edit-btn").hide();
922 login: function(aIsCreator) {
923 if (typeof aIsCreator === "boolean") {
924 this.iscreator = aIsCreator;
931 var PseudoChecker = {
938 message: function(str, status, throbber) {
940 if (!this.messageelt) {
941 row = new Element('tr');
942 // we can't use row.update('<td></td><td><div></div></td>')
943 // because gecko would mangle the <td>s
944 row.insert(new Element('td'))
945 .insert((new Element('td')).update(new Element('div')));
947 $("user_pseudo").up('tr').insert({after: row});
948 this.messageelt = new Element('span');
949 this.throbber = new Element("img", { src: "icons/throbber.gif"});
950 row.down('div').insert(this.throbber).insert(this.messageelt);
953 this.throbber.show();
955 this.throbber.hide();
957 this.messageelt.up().setStyle({visibility: ''});
958 this.messageelt.className = status;
959 this.messageelt.update(str);
962 availableMessage: function(available) {
963 var message = available ? SyjStrings.availablePseudo: SyjStrings.unavailablePseudo,
964 status = available ? "success": "warn";
965 this.message(message, status, false);
971 this.req = this.currentvalue = null;
973 if (this.messageelt) {
974 this.messageelt.up().setStyle({visibility: 'hidden'});
979 var pseudo = $("user_pseudo").value;
983 if (!pseudo || !(pseudo.match(/^[a-zA-Z0-9_.]+$/))) {
987 if (typeof this.exists[pseudo] === "boolean") {
989 this.availableMessage(!this.exists[pseudo]);
993 this.message(SyjStrings.pseudoChecking, "", true);
995 this.currentvalue = pseudo;
996 this.req = new Ajax.TimedRequest('userexists/' + encodeURIComponent(pseudo), 20, {
997 onFailure: this.failure.bind(this),
998 onSuccess: this.success.bind(this)
1002 failure: function(transport) {
1003 var httpCode = 0, value = this.currentvalue;
1006 httpCode = transport.getStatus();
1009 if (httpCode === 404) {
1010 this.exists[value] = false;
1011 this.availableMessage(true);
1016 success: function(transport) {
1017 var httpCode = transport.getStatus(), value = this.currentvalue;
1019 this.exists[value] = true;
1020 this.availableMessage(false);
1024 var Nominatim = (function() {
1025 var presubmit = function() {
1026 var input = $("nominatim-search");
1027 if (input.value.strip().empty()) {
1028 $("nominatim-message").setMessage(SyjStrings.notEmptyField, "warn");
1032 $("nominatim-suggestions").hide();
1033 $("nominatim-message").hide();
1034 $("nominatim-throbber").show();
1038 var zoomToExtent = function(bounds) { // we must call map.setCenter with forceZoomChange to true. See ol#2798
1039 var center = bounds.getCenterLonLat();
1040 if (this.baseLayer.wrapDateLine) {
1041 var maxExtent = this.getMaxExtent();
1042 bounds = bounds.clone();
1043 while (bounds.right < bounds.left) {
1044 bounds.right += maxExtent.getWidth();
1046 center = bounds.getCenterLonLat().wrapDateLine(maxExtent);
1048 this.setCenter(center, this.getZoomForExtent(bounds), false, true);
1051 var success = function(transport) {
1052 $("nominatim-throbber").hide();
1054 if (!transport.responseJSON || !transport.responseJSON.length) {
1055 $("nominatim-message").setMessage(SyjStrings.noResult, 'error');
1056 $("nominatim-search").activate();
1060 var place = transport.responseJSON[0],
1061 bbox = place.boundingbox;
1063 if (!bbox || bbox.length !== 4) {
1064 $("nominatim-message").setMessage(SyjStrings.requestError, 'error');
1068 extent = new OpenLayers.Bounds(bbox[2], bbox[1], bbox[3], bbox[0]).transform(WGS84, Mercator);
1069 zoomToExtent.call(SYJView.map, extent);
1071 $("nominatim-suggestions-list").update();
1073 var clickhandler = function(bbox) {
1074 return function(evt) {
1076 var extent = new OpenLayers.Bounds(bbox[2], bbox[1], bbox[3], bbox[0]).transform(WGS84, Mercator);
1077 $("nominatim-suggestions-list").select("li").invoke('removeClassName', 'current');
1078 evt.target.up('li').addClassName('current');
1079 SYJView.map.zoomToExtent(extent);
1083 for (var i = 0; i < transport.responseJSON.length; i++) {
1084 var item = transport.responseJSON[i];
1085 if (item.display_name && item.boundingbox && item.boundingbox.length === 4) {
1086 var li = new Element("li");
1087 var anchor = new Element("a", {
1089 className: "nominatim-suggestions-link"
1092 anchor.observe('click', clickhandler(item.boundingbox));
1094 var text = document.createTextNode(item.display_name);
1095 var icon = new Element("img", {
1096 className: "nominatim-suggestions-icon",
1097 src: item.icon || 'icons/world.png'
1099 anchor.appendChild(text); // insert does not work; see prototype #1125
1100 li.insert(icon).insert(anchor);
1101 $("nominatim-suggestions-list").insert(li);
1102 if ($("nominatim-suggestions-list").childNodes.length >= 6) {
1108 if ($("nominatim-suggestions-list").childNodes.length > 1) {
1109 var bottomOffset = $('data_controls').measure('height') + 3;
1110 $("nominatim-suggestions").setStyle({
1111 bottom: bottomOffset.toString() + 'px'
1113 $("nominatim-suggestions-list").select("li:first-child")[0].addClassName('current');
1115 $("nominatim-suggestions").hide();
1120 var failure = function(transport) {
1121 $("nominatim-throbber").hide();
1123 var httpCode = 0, message = SyjStrings.unknownError, input; // default message error
1126 httpCode = transport.getStatus();
1131 message = SyjStrings.notReachedError;
1135 message = SyjStrings.requestError;
1138 message = SyjStrings.serverError;
1142 $("nominatim-message").setMessage(message, 'error');
1147 if (!$("nominatim-form")) {
1150 $("nominatim-controls").hide();
1151 $("nominatim-label").observe('click', function(evt) {
1152 $("nominatim-controls").show();
1153 $("nominatim-search").activate();
1157 $("nominatim-form").ajaxize({
1158 presubmit: presubmit,
1162 new CloseBtn($("nominatim-suggestions"));
1164 $$("#nominatim-message, #nominatim-suggestions, #nominatim-throbber").invoke('hide');
1169 document.observe("dom:loaded", function() {
1172 SYJDataUi.viewmode();
1175 LoginMgr.updateUI();
1179 window.onbeforeunload = function() {
1180 if (SYJView.unsavedRoute) {
1181 return SyjStrings.unsavedConfirmExit;