X-Git-Url: https://dev.renevier.net/?a=blobdiff_plain;f=public%2Fjs%2Fsyj.js;h=0572fce71c7099bcad3f054c04690bf43d194803;hb=95727eb231968e25b764f99d899bf2e044664ab4;hp=45ae794c5289fdfbcc533ac4b0f38ba7e7508fad;hpb=a8006c98d15c04f86427ef6b2f5537005978e7e5;p=syj.git diff --git a/public/js/syj.js b/public/js/syj.js index 45ae794..0572fce 100644 --- a/public/js/syj.js +++ b/public/js/syj.js @@ -14,18 +14,6 @@ var SyjSaveUI = { return this; }, - hide: function() { - $("geom_submit").blur(); - $("geom_title").blur(); - $("geomform").hide(); - return this; - }, - - show: function() { - $("geomform").show(); - return this; - }, - enable: function() { if (this.status === "enabled") { return this; @@ -52,6 +40,7 @@ var SyjSaveUI = { enableSubmit: function() { $("geom_submit").disabled = false; + $("geom_accept").disabled = false; this.status = "partial"; return this; }, @@ -59,23 +48,30 @@ var SyjSaveUI = { disableSubmit: function() { $("geom_submit").blur(); $("geom_submit").disabled = true; + $("geom_accept").blur(); + $("geom_accept").disabled = true; this.status = "partial"; return this; } }; -var SyjEditUI = { - hide: function() { - $("data_controls_btns").blur(); - $("data_controls_btns").hide(); - return this; - }, - - show: function() { - $("data_controls_btns").show(); - return this; - } -}; +var SYJDataUi = (function() { + var deck = null, + getdeck = function() { + if (!deck) { + deck = new Deck("data_controls"); + } + return deck; + }; + return { + viewmode: function() { + getdeck().setIndex(0); + }, + editmode: function() { + getdeck().setIndex(1); + } + }; +}()); OpenLayers.Handler.SyjModifiablePath = OpenLayers.Class(OpenLayers.Handler.ModifiablePath, { mouseup: function(evt) { @@ -234,41 +230,38 @@ var SYJView = { layerOptions = {format: OpenLayers.Format.WKT, projection: WGS84, - styleMap: styleMap.view}; - if (gLoggedInfo.creatorname) { - layerOptions.attribution = SyjStrings.routeBy + ' ' + '' + gLoggedInfo.creatorname + ''; - } + styleMap: styleMap.view, + attribution: SyjStrings.geomAttribution }; this.viewLayer = new OpenLayers.Layer.Vector("View Layer", layerOptions); this.map.addLayers([baseLayer, this.viewLayer]); if ($("edit-btn")) { - $("edit-btn").observe('click', (function() { + $("edit-btn").observe('click', function() { $("geom_submit").value = SyjStrings.editAction; this.messenger.hide(); this.editMode(); this.mode = 'edit'; - }).bind(this)); + }.bind(this)); } if ($("create-btn")) { - $("create-btn").observe('click', (function() { + $("create-btn").observe('click', function() { $("geom_submit").value = SyjStrings.createAction; this.messenger.hide(); this.editMode(); this.mode = 'create'; - }).bind(this)); + }.bind(this)); } if ($("clone-btn")) { - $("clone-btn").observe('click', (function() { + $("clone-btn").observe('click', function() { $("geom_submit").value = SyjStrings.cloneAction; $("geom_title").value = ""; this.messenger.hide(); this.editMode(); this.mode = 'create'; - SyjSaveUI.enableSubmit(); - }).bind(this)); + }.bind(this)); } $("geomform").ajaxize({ @@ -276,7 +269,7 @@ var SYJView = { onSuccess: this.saveSuccess.bind(this), onFailure: this.saveFailure.bind(this) }); - SyjSaveUI.init().hide(); + SyjSaveUI.init(); this.messenger = $('message'); hidemessenger = this.messenger.empty(); @@ -289,8 +282,8 @@ var SYJView = { this.messenger.hide(); } - if ($("geom_data").value) { - this.viewLayer.addFeatures([this.wkt.read($("geom_data").value)]); + if (typeof gInitialGeom !== "undefined" && typeof gInitialGeom.data !== "undefined") { + this.viewLayer.addFeatures([this.wkt.read(gInitialGeom.data)]); extent = this.viewLayer.getDataExtent(); // XXX: ie has not guessed height of map main div yet during map // initialisation. Now, it will read it correctly. @@ -378,12 +371,11 @@ var SYJView = { this.viewLayer.destroyFeatures(); - SyjEditUI.hide(); + SYJDataUi.editmode(); if (this.editControl.handler.realPoints && this.editControl.handler.realPoints.length >= 2) { - SyjSaveUI.show(); SyjSaveUI.disableSubmit(); } else { - SyjSaveUI.show().disable(); + SyjSaveUI.disable(); } }, @@ -394,17 +386,16 @@ var SYJView = { return; } - var self = this; this.editControl = new OpenLayers.Control.DrawFeature(new OpenLayers.Layer.Vector(), OpenLayers.Handler.SyjModifiablePath, { callbacks: { modify: function(f, line) { - if (!self.unsavedRoute) { - self.unsavedRoute = {}; + if (!SYJView.unsavedRoute) { + SYJView.unsavedRoute = {}; } if (this.handler.realPoints.length < 2) { - SyjSaveUI.show().disable(); + SyjSaveUI.disable(); } else { - SyjSaveUI.show().enable(); + SyjSaveUI.enable(); } } }, @@ -429,8 +420,7 @@ var SYJView = { callback: function(form) { this.viewMode(); this.mode = 'view'; - SyjSaveUI.hide(); - SyjEditUI.show(); + SYJDataUi.viewmode(); this.messenger.hide(); if (this.unsavedRoute && typeof this.unsavedRoute.features !== "undefined") { @@ -455,8 +445,7 @@ var SYJView = { } this.messenger.setMessage(SyjStrings.saveSuccess, "success"); - SyjSaveUI.hide(); - SyjEditUI.show(); + SYJDataUi.viewmode(); document.title = $('geom_title').value; }, @@ -610,13 +599,15 @@ var SYJUserClass = Class.create(SYJModalClass, { $$("#user_termsofuse_anchor, #geom_termsofuse_anchor").invoke('observe', "click", function(evt) { if (!this.toubox) { - $("termsofusearea").show(); - $("termsofuseiframe").setAttribute("src", evt.target.href); this.toubox = new SimpleBox($("termsofusearea"), { closeMethods: ["onescapekey", "onouterclick", "onbutton"] }); } this.toubox.show(); + if (!$("termsofuseiframe").getAttribute("src")) { + $("termsofusearea").show(); + $("termsofuseiframe").setAttribute("src", evt.target.href); + } evt.stop(); }.bindAsEventListener(this)); @@ -783,11 +774,21 @@ var SYJLoginClass = Class.create(SYJModalClass, { }, success: function(transport) { - if (transport.responseText === "1") { - LoginMgr.login(true); - } else { - LoginMgr.login(); + if (!transport.responseJSON || + typeof transport.responseJSON.iscreator !== "boolean" || + typeof transport.responseJSON.pseudo !== "string" + ) { + this.messenger.setMessage(SyjStrings.unknownError, "error"); + return; } + LoginMgr.login(transport.responseJSON.iscreator); + $$('.logged-pseudo').each(function(elt) { + $A(elt.childNodes).filter(function(node) { + return (node.nodeType === 3 || node.tagName.toLowerCase() === 'br'); + }).each(function(node) { + node.nodeValue = node.nodeValue.replace('%s', transport.responseJSON.pseudo); + }); + }); SYJView.messenger.setMessage(SyjStrings.loginSuccess, "success"); this.modalbox.hide(); if (SYJView.needsFormResubmit) { @@ -976,6 +977,7 @@ var PseudoChecker = { document.observe("dom:loaded", function() { SYJLogin.init(); SYJUser.init(); + SYJDataUi.viewmode(); SYJView.init(); SYJNewpwd.init(); LoginMgr.updateUI(); @@ -986,4 +988,4 @@ window.onbeforeunload = function() { } else { return undefined; } -} +};