]> dev.renevier.net Git - syj.git/blobdiff - public/js/syj.js
general class for accout info toggler
[syj.git] / public / js / syj.js
index 4032cca7989f10060fcbd970f7528f016bedee82..39ecd4f90bdf86b8321054ead2e08f823a28612d 100644 (file)
@@ -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 + ' ' + '<strong>' + gLoggedInfo.creatorname + '</strong>';
-        }
+                        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();
@@ -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));
 
@@ -647,18 +638,7 @@ var SYJUserClass = Class.create(SYJModalClass, {
             }
         }.bindAsEventListener(this));
 
-        $("account-info").hide();
-        $("account-info-bullet").observe('click', function(evt) {
-            var elt = $("account-info");
-            if (elt.visible()) {
-                evt.target.src = "icons/bullet_arrow_right.png";
-                elt.hide();
-            } else {
-                evt.target.src = "icons/bullet_arrow_down.png";
-                elt.show();
-            }
-            evt.stop();
-        });
+        $('account-create-anchor').insert({after: new Toggler('account-info').element});
     },
 
     presubmit: function() {
@@ -783,11 +763,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 +966,7 @@ var PseudoChecker = {
 document.observe("dom:loaded", function() {
     SYJLogin.init();
     SYJUser.init();
+    SYJDataUi.viewmode();
     SYJView.init();
     SYJNewpwd.init();
     LoginMgr.updateUI();
@@ -986,4 +977,4 @@ window.onbeforeunload = function() {
     } else {
         return undefined;
     }
-}
+};