From 0085ebfed447d3e7a828eb691a78c5ccc2c21a8c Mon Sep 17 00:00:00 2001 From: Chip Black Date: Sun, 17 Nov 2013 15:25:09 -0800 Subject: [PATCH] Handle empty responses and errors for tag listings --- www/jssrc/blerg/API.js | 12 ++++++++++-- www/jssrc/blerg/Pager.js | 14 +++++++++----- 2 files changed, 19 insertions(+), 7 deletions(-) diff --git a/www/jssrc/blerg/API.js b/www/jssrc/blerg/API.js index 908c213..986ac09 100644 --- a/www/jssrc/blerg/API.js +++ b/www/jssrc/blerg/API.js @@ -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() { diff --git a/www/jssrc/blerg/Pager.js b/www/jssrc/blerg/Pager.js index 92f6f4c..f311d1f 100644 --- a/www/jssrc/blerg/Pager.js +++ b/www/jssrc/blerg/Pager.js @@ -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(); -- 2.25.1