Created
April 29, 2014 00:33
-
-
Save michaelorionmcmanus/11387942 to your computer and use it in GitHub Desktop.
Revisions
-
michaelorionmcmanus created this gist
Apr 29, 2014 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,49 @@ export default Ember.Mixin.create({ // Register all the query parameters that the controller needs to know about. queryParams: ['_start', '_limit'], // Store our values. _start: 0, _limit: 10, nextStart: 0, previousStart: null, hasPrevious: false, hasNext: true, nextStartObserver: function() { var start = (+this.get('_start')) + (+this.get('_limit')); this.set('nextStart', start); }.observes('_limit', '_start', 'resourceTotal'), hasNextObserver: function() { var refreshing = this.get('refreshing'); if(this.get('resourceTotal') - this.get('_start') > this.get('_limit')) { this.set('hasNext', true); } else { this.set('hasNext', false); } }.observes('_limit', '_start', 'resourceTotal'), hasPreviousObserver: function() { if(this.get('_start') >= this.get('_limit')) { this.set('hasPrevious', true); } else { this.set('hasPrevious', false); } }.observes('_limit', '_start', 'resourceTotal'), previousStartObserver: function() { var start = (+this.get('_start')) - (+this.get('_limit')); this.set('previousStart', start); }.observes('_limit', '_start', 'resourceTotal'), disableNext: function() { return !this.get('hasNext'); }.property('hasNext'), disablePrevious: function() { return !this.get('hasPrevious'); }.property('hasPrevious') }); This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,28 @@ export default Ember.Route.extend({ model: function(params) { return this.store.find('collection', { '_relations': 'page[id]', '_start': this.get('param1'), '_limit': params._limit || 10, '_sorts': 'id;desc' }); }, afterModel: function() { // TODO: Should be querying for only the pages related to this collection. return this.store.find('page'); }, setupController: function(controller, model) { var resourceTotal = this.store.metadataFor('collection').total; controller.set('resourceTotal', resourceTotal); this._super(controller, model); }, actions: { queryParamsDidChange: function() { this.refresh(); } } });