Reload user when posting
[blerg.git] / www / jssrc / blerg / User.js
index ac4c24c..7871051 100644 (file)
@@ -4,7 +4,8 @@ enyo.kind({
     listKind: "blerg.Record",
     handlers: {
         onLogin: "getStalkStatus",
-        onLogout: "getStalkStatus"
+        onLogout: "getStalkStatus",
+        onReload: "usernameChanged"
     },
     published: {
         username: "",
@@ -23,9 +24,14 @@ enyo.kind({
             ]}
         ]},
         {name: "records"},
+        {name: "spinner", kind: "OldSchoolSpinner", showing: false},
+        {name: "emptyAccountMessage", showing: false, content: "Hey, there's nothing here!"},
+        {name: "userNotFoundMessage", classes: "blerg-error", showing: false, content: "User not found"},
         {name: "loadMoreButton", kind: "onyx.Button", onclick: "loadMore", content: "Load More"},
         {name: "api", kind: "blerg.API",
          onItemsLoaded: "itemsLoaded",
+         onUserNotFound: "userNotFound",
+         onAPIError: "apiError",
          onSubscriptionStatus: "gotStalkStatus"}
     ],
     statics: {
@@ -65,6 +71,7 @@ enyo.kind({
         this.$.api.loadUserRecords(this.username, from, to);
     },
     itemsLoaded: function(inSender, inEvent) {
+        this.$.userNotFoundMessage.hide();
         if (this.permalink) {
             this.$.loadMoreButton.hide();
         } else {
@@ -76,9 +83,22 @@ enyo.kind({
         }
 
         this.addItems(inEvent.entries);
-        if (this.lastRecord == 0)
+        if (this.lastRecord == 0 || inEvent.entries.length == 0)
             this.$.loadMoreButton.hide();
     },
+    addItems: function(items) {
+        this.$.emptyAccountMessage.setShowing(items.length == 0);
+        this.inherited(arguments);
+    },
+    userNotFound: function() {
+        this.addItems([]);
+        this.$.emptyAccountMessage.hide();
+        this.$.userNotFoundMessage.show();
+    },
+    apiError: function() {
+        this.addItems([]);
+        alert('Unknown API Error');
+    },
     getStalkStatus: function() {
         if (!blerg.API.loggedIn) {
             this.$.stalkLink.hide();