Add external URL Post method
[blerg.git] / www / jssrc / blerg / Blerg.js
index a077b52..af0f688 100644 (file)
 enyo.kind({
-       name: "blerg.Blerg",
-       kind: "Control",
-       lastHash: null,
-       handlers: {
-               onStartSignup: "showSignupDialog",
-               onTryLogin: "tryLogin",
-               onTryLogout: "tryLogout",
-               onSetTitle: "setTitle",
-               onPostVisibility: "postVisibilityUpdate"
-       },
-       components: [
-               {classes: "blerg-header", components: [
-                       {name: "title", kind: "blerg.Title"},
-                       {name: "controls", kind: "blerg.Controls"},
-                       {style: "clear: both"},
-                       {name: "post", kind: "blerg.Post", showing: false},
-                       {name: "help", kind: "blerg.Help"}
-               ]},
-               {name: "main", kind: "blerg.Main"},
-               {name: "signupDialog", kind: "blerg.SignupDialog"},
-               {name: "passwdDialog", kind: "blerg.PasswdDialog"},
-               {name: "api", kind: "blerg.API",
-                onLoginSuccessful: "loginSuccessful",
-                onLoginFailed: "loginFailed",
-                onLogoutSuccessful: "logout"}
-       ],
-       urlmap: [
-               ['search', /^\?post\/([^/]+)\/(.+)/, "blerg.ExternalURLPost"],
-               ['hash',   /^#\/(ref|tag)\/([A-Za-z0-9_-]+)(?:\/p(\d+))?$/, "blerg.Tag"],
-               ['hash',   /^#\/feed(?:\/p(\d+))?$/, "blerg.Feed"],
-               ['hash',   /^#([A-Za-z0-9_-]+)(?:\/(p)?(\d+))?$/, "blerg.User"]
-       ],
-       pathHandlers: [ blerg.Welcome ],
-       rendered: function() {
-               this.inherited(arguments);
+    name: "blerg.Blerg",
+    kind: "Control",
+    lastHash: null,
+    pathHandlers: [ blerg.User, blerg.Tag, blerg.Feed, blerg.ExternalURLPost, blerg.Welcome ],
+    handlers: {
+        onStartSignup: "showSignupDialog",
+        onTryLogin: "tryLogin",
+        onTryLogout: "tryLogout",
+        onSetTitle: "setTitle",
+        onPostVisibility: "postVisibilityUpdate"
+    },
+    components: [
+        {classes: "blerg-header", components: [
+            {name: "title", kind: "blerg.Title"},
+            {name: "controls", kind: "blerg.Controls"},
+            {style: "clear: both"},
+            {name: "post", kind: "blerg.Post", showing: false},
+            {name: "help", kind: "blerg.Help"}
+        ]},
+        {name: "main", kind: "blerg.Main"},
+        {name: "signupDialog", kind: "blerg.SignupDialog"},
+        {name: "passwdDialog", kind: "blerg.PasswdDialog"},
+        {name: "api", kind: "blerg.API",
+         onLoginSuccessful: "loginSuccessful",
+         onLoginFailed: "loginFailed",
+         onLogoutSuccessful: "logout"}
+    ],
+    rendered: function() {
+        this.inherited(arguments);
 
-               this.lastHash = location.hash;
-               this.urlSwitch();
+        this.lastHash = location.hash;
+        this.urlSwitch();
 
-               setInterval(this.hashCheck.bind(this), 250);
+        setInterval(this.hashCheck.bind(this), 250);
 
-               document.body.addEventListener('keyup', function(event) {
-                       if (event.shiftKey && event.keyCode == 32) {
-                               this.$.post.show();
-                               event.stopPropagation();
-                       }
-               }, false);
-       },
-       hashCheck: function() {
-               if (location.hash != this.lastHash) {
-                       this.lastHash = location.hash;
-                       this.urlSwitch();
-               }
-       },
-       urlSwitch: function() {
-               var m;
-               var objdef = null;
+        document.body.addEventListener('keyup', function(event) {
+            if (event.shiftKey && event.keyCode == 32) {
+                this.$.post.show();
+                event.stopPropagation();
+            }
+        }, false);
+    },
+    hashCheck: function() {
+        if (location.hash != this.lastHash) {
+            this.lastHash = location.hash;
+            this.urlSwitch();
+        }
+    },
+    urlSwitch: function() {
+        var m;
+        var objdef = null;
 
-               for (var i = 0; i < this.pathHandlers.length; i++) {
-                       var handler = this.pathHandlers[i];
-                       objdef = handler.locationDetect(window.location);
-                       if (objdef)
-                               break;
-               }
-               if (!objdef)
-                       objdef = {classes: "blerg-error", content: "No handler found"}
+        for (var i = 0; i < this.pathHandlers.length; i++) {
+            var handler = this.pathHandlers[i];
+            objdef = handler.locationDetect(window.location);
+            if (objdef)
+                break;
+        }
+        if (!objdef)
+            objdef = {classes: "blerg-error", content: "No handler found"}
 
-               this.$.main.updateView(objdef);
-       },
-       showSignupDialog: function() {
-               this.$.signupDialog.show();
-       },
-       setTitle: function(inSender, inEvent) {
-               this.$.title.waterfall('onSetTitle', inEvent);
-       },
-       tryLogin: function(inSender, inEvent) {
-               this.$.api.login(inEvent.username, inEvent.password);
-       },
-       tryLogout: function(inSender, inEvent) {
-               this.$.api.logout();
-       },
-       loginSuccessful: function(inSender, inEvent) {
-               this.$.api.requestFeedStatus();
-               this.feedStatusUpdateInterval = setInterval(function() {
-                       this.$.api.requestFeedStatus();
-               }.bind(this), 900000);
-               this.waterfall('onLogin', inEvent);
-       },
-       loginFailed: function(inSender, inEvent) {
-               alert('Login failed');
-               this.logout();
-       },
-       logout: function(inSender, inEvent) {
-               clearInterval(this.feedStatusUpdateInterval);
-               this.waterfall('onLogout');
-       },
-       postVisibilityUpdate: function(inSender, inEvent) {
-               this.$.post.waterfall('onPostVisibility', inEvent);
-               this.$.controls.waterfall('onPostVisibility', inEvent);
-       }
+        this.$.main.updateView(objdef);
+    },
+    showSignupDialog: function() {
+        this.$.signupDialog.show();
+    },
+    setTitle: function(inSender, inEvent) {
+        this.$.title.waterfall('onSetTitle', inEvent);
+    },
+    tryLogin: function(inSender, inEvent) {
+        this.$.api.login(inEvent.username, inEvent.password);
+    },
+    tryLogout: function(inSender, inEvent) {
+        this.$.api.logout();
+    },
+    loginSuccessful: function(inSender, inEvent) {
+        this.waterfall('onLogin', inEvent);
+    },
+    loginFailed: function(inSender, inEvent) {
+        alert('Login failed');
+        this.logout();
+    },
+    logout: function(inSender, inEvent) {
+        clearInterval(this.feedStatusUpdateInterval);
+        this.waterfall('onLogout');
+    },
+    postVisibilityUpdate: function(inSender, inEvent) {
+        this.$.post.waterfall('onPostVisibility', inEvent);
+        this.$.controls.waterfall('onPostVisibility', inEvent);
+    }
 });