-enyo.kind({
- name: "blerg.Blerg",
- kind: "Control",
- lastHash: null,
- handlers: {
- onStartSignup: "showSignupDialog",
- onTryLogin: "tryLogin",
- onSetTitle: "setTitle"
- },
- components: [
- {classes: "blerg-header", components: [
- {kind: "blerg.Title"},
- {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"}
- ],
- 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);
-
- this.lastHash = location.hash;
- this.urlSwitch();
+// Listen for onsubmit events
+enyo.dispatcher.listen(document, "submit");
- //setInterval(this.hashCheck.bind(this), 250);
+enyo.kind({
+ name: "blerg.Blerg",
+ kind: "Control",
+ lastHash: null,
+ pathHandlers: [ blerg.User, blerg.Tag, blerg.Feed, blerg.ExternalURLPost, blerg.Welcome, blerg.AccountCenter, blerg.Recovery, blerg.EmailVerify ],
+ handlers: {
+ onStartSignup: "showSignupDialog",
+ onTryLogin: "tryLogin",
+ onTryLogout: "tryLogout",
+ onSetTitle: "setTitle",
+ onPostVisibility: "postVisibilityUpdate",
+ onReload: "sendReload",
+ onShowChangePassword: "showChangePassword",
+ onAuthFailure: "authFailure"
+ },
+ 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: "api", kind: "blerg.API",
+ onLoginSuccessful: "loginSuccessful",
+ onLoginFailed: "loginFailed",
+ onLogoutSuccessful: "logout"}
+ ],
+ rendered: function() {
+ this.inherited(arguments);
- 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;
+ this.lastHash = location.hash;
+ this.urlSwitch();
- 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"}
+ setInterval(this.hashCheck.bind(this), 250);
- this.$.main.updateView(objdef);
- },
- showSignupDialog: function() {
- this.$.signupDialog.show();
- },
- setTitle: function(inSender, inEvent) {
- if (inEvent.section != undefined)
- this.$.title.setSection(inEvent.section);
+ document.body.addEventListener('keyup', function(event) {
+ if (event.shiftKey && event.keyCode == 32) {
+ this.waterfall('onPostVisibility', {showing: true});
+ event.stopPropagation();
+ }
+ }.bind(this), false);
+ },
+ hashCheck: function() {
+ if (location.hash != this.lastHash) {
+ this.lastHash = location.hash;
+ this.urlSwitch();
+ }
+ },
+ urlSwitch: function() {
+ var m;
+ var objdef = null;
- if (inEvent.subscribed != undefined)
- this.$.title.setSubscribed(inEvent.subscribed);
+ 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"}
- if (inEvent.showControls)
- this.$.title.showControls()
- else
- this.$.title.hideControls();
- },
- tryLogin: function(inSender, 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.waterfall('onShowForgotPasswordLink');
+ 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);
+ },
+ sendReload: function() {
+ this.$.main.waterfall('onReload');
+ },
+ authFailure: function(inSender, inEvent) {
+ this.logout();
+ }
});