Handle empty responses and errors for tag listings
authorChip Black <bytex64@bytex64.net>
Sun, 17 Nov 2013 23:25:09 +0000 (15:25 -0800)
committerChip Black <bytex64@bytex64.net>
Sun, 17 Nov 2013 23:25:09 +0000 (15:25 -0800)
www/jssrc/blerg/API.js
www/jssrc/blerg/Pager.js

index 908c213..986ac09 100644 (file)
@@ -163,14 +163,22 @@ enyo.kind({
         var req = new enyo.Ajax({
             url: url
         });
-        req.response(function(inSender, inResponse) {
+        req.response(this, function(inSender, inResponse) {
             this.bubble('onItemsLoaded', {
                 type: 'tag',
                 tagType: type,
                 tag: tag,
                 entries: inResponse
             });
-        }.bind(this));
+        });
+        req.error(this, function() {
+            this.bubble('onItemsLoaded', {
+                type: 'tag',
+                tagType: type,
+                tag: tag,
+                entries: []
+            });
+        });
         req.go();
     },
     getFeedInfo: function() {
index 92f6f4c..f311d1f 100644 (file)
@@ -8,11 +8,15 @@ enyo.kind({
         {name: "spinner", kind: "OldSchoolSpinner", showing: false}
     ],
     addItems: function(items) {
-        this.$.records.createComponents(items, {kind: this.listKind});
-        for (var i = 0; i < items.length; i++) {
-            var r = parseInt(items[i].record);
-            if (r < this.lastRecord || this.lastRecord == null)
-                this.lastRecord = r;
+        if (items.length > 0) {
+            this.$.records.createComponents(items, {kind: this.listKind});
+            for (var i = 0; i < items.length; i++) {
+                var r = parseInt(items[i].record);
+                if (r < this.lastRecord || this.lastRecord == null)
+                    this.lastRecord = r;
+            }
+        } else {
+            this.$.records.createComponent({content: "No items"});
         }
         this.$.records.render();
         this.stopLoadAnimation();