From abd5263671e0738c93045a74fc74bebf3fd3f7d8 Mon Sep 17 00:00:00 2001 From: Vikhyat Korrapati Date: Sun, 18 May 2014 12:42:47 +0530 Subject: [PATCH] Load more users on badge pages using infinite scrolling instead of a button. --- .../discourse/controllers/badges/show.js.es6 | 10 ++++------ .../discourse/templates/badges/show.js.handlebars | 6 ++---- .../javascripts/discourse/views/badges_show_view.js | 11 +++++++++++ 3 files changed, 17 insertions(+), 10 deletions(-) create mode 100644 app/assets/javascripts/discourse/views/badges_show_view.js diff --git a/app/assets/javascripts/discourse/controllers/badges/show.js.es6 b/app/assets/javascripts/discourse/controllers/badges/show.js.es6 index 9ccd077be0d..27856754bdd 100644 --- a/app/assets/javascripts/discourse/controllers/badges/show.js.es6 +++ b/app/assets/javascripts/discourse/controllers/badges/show.js.es6 @@ -10,13 +10,11 @@ export default Discourse.ObjectController.extend({ grantDates: Em.computed.mapBy('userBadges', 'grantedAt'), minGrantedAt: Em.computed.min('grantDates'), - moreUserCount: function() { + canLoadMore: function() { if (this.get('userBadges')) { - return this.get('model.grant_count') - this.get('userBadges.length'); + return this.get('model.grant_count') > this.get('userBadges.length'); } else { - return 0; + return false; } - }.property('model.grant_count', 'userBadges.length'), - - showMoreUsers: Em.computed.gt('moreUserCount', 0) + }.property('model.grant_count', 'userBadges.length') }); diff --git a/app/assets/javascripts/discourse/templates/badges/show.js.handlebars b/app/assets/javascripts/discourse/templates/badges/show.js.handlebars index 5949c35d8b3..26f7a090611 100644 --- a/app/assets/javascripts/discourse/templates/badges/show.js.handlebars +++ b/app/assets/javascripts/discourse/templates/badges/show.js.handlebars @@ -27,10 +27,8 @@ {{/link-to}} {{/each}} - {{#if showMoreUsers}} - + {{#if canLoadMore}} +
{{i18n loading}}
{{/if}} {{else}} {{#unless userBadgesLoaded}} diff --git a/app/assets/javascripts/discourse/views/badges_show_view.js b/app/assets/javascripts/discourse/views/badges_show_view.js new file mode 100644 index 00000000000..7534e62bba2 --- /dev/null +++ b/app/assets/javascripts/discourse/views/badges_show_view.js @@ -0,0 +1,11 @@ +/** + View for showing a particular badge. + + @class BadgesShowView + @extends Discourse.View + @namespace Discourse + @module Discourse +**/ +Discourse.BadgesShowView = Discourse.View.extend(Discourse.LoadMore, { + eyelineSelector: '.badge-user' +});