From 3a502a504dfe88cac68f18304f593ac15f0495e2 Mon Sep 17 00:00:00 2001 From: Yves Fischer Date: Sun, 21 Dec 2014 23:47:49 +0100 Subject: pagination --- imdb-lookup/js/app.js | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) (limited to 'imdb-lookup/js/app.js') diff --git a/imdb-lookup/js/app.js b/imdb-lookup/js/app.js index 8cd5e76..d5f7c53 100644 --- a/imdb-lookup/js/app.js +++ b/imdb-lookup/js/app.js @@ -49,10 +49,33 @@ App.Movie = DS.Model.extend({ }); App.IndexController = Ember.ArrayController.extend({ + page: 1, + perPage: "10", + visiblePerPage: ["10", "20", "25", "50", "100", "250", "500"], + pages: function() { + var list = []; + for (var i = 1; i <= this.get("pagesCount"); i++) { + list.push(i); + } + return list; + }.property('page','perPage'), + paginatedContent: function() { + var page = this.get('page'); + var perPage = parseInt(this.get('perPage')); + var start = (page - 1 ) * perPage; + var end = page * perPage; + return this.get('arrangedContent').slice(start, end) + }.property('arrangedContent.[]', 'page', 'perPage'), + pagesCount: function() { + return Math.ceil(this.get("content.length") / parseInt(this.get("perPage"))) + }.property('content.[]', 'perPage'), actions: { sortBy: function(property) { this.set('sortProperties', [property]); this.set('sortAscending', !this.get('sortAscending')); + }, + setPage: function(property) { + this.set('page', property) } } }); -- cgit v1.2.1