diff --git a/static/js/app/models/user/userCollection.coffee b/static/js/app/models/user/userCollection.coffee index 3cd3ad0..9655e98 100755 --- a/static/js/app/models/user/userCollection.coffee +++ b/static/js/app/models/user/userCollection.coffee @@ -5,7 +5,7 @@ define ['backbone', 'models/user/userItem', 'app.lib/backbone.dss.model.collecti limit: 20 model: UserItem url: -> - com.podnoms.settings.urlRoot + "user/?limit=" + @limit + "&offset=" + @page * @limit + com.podnoms.settings.urlRoot + "user/?limit=" + @limit + "&offset=" + Math.max(@page-1, 0) * @limit UserCollection diff --git a/static/js/app/models/user/userCollection.js b/static/js/app/models/user/userCollection.js index 3f20d71..3959873 100755 --- a/static/js/app/models/user/userCollection.js +++ b/static/js/app/models/user/userCollection.js @@ -1,17 +1,16 @@ -// Generated by CoffeeScript 1.6.2 +// Generated by CoffeeScript 1.3.3 (function() { var __hasProp = {}.hasOwnProperty, __extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; }; define(['backbone', 'models/user/userItem', 'app.lib/backbone.dss.model.collection'], function(Backbone, UserItem, DssCollection) { - var UserCollection, _ref; - + var UserCollection; UserCollection = (function(_super) { + __extends(UserCollection, _super); function UserCollection() { - _ref = UserCollection.__super__.constructor.apply(this, arguments); - return _ref; + return UserCollection.__super__.constructor.apply(this, arguments); } UserCollection.prototype.page = 0; @@ -21,7 +20,7 @@ UserCollection.prototype.model = UserItem; UserCollection.prototype.url = function() { - return com.podnoms.settings.urlRoot + "user/?limit=" + this.limit + "&offset=" + this.page * this.limit; + return com.podnoms.settings.urlRoot + "user/?limit=" + this.limit + "&offset=" + Math.max(this.page - 1, 0) * this.limit; }; return UserCollection; diff --git a/static/js/app/views/user/userListView.coffee b/static/js/app/views/user/userListView.coffee index e9bb011..8790474 100755 --- a/static/js/app/views/user/userListView.coffee +++ b/static/js/app/views/user/userListView.coffee @@ -12,15 +12,6 @@ define ['jquery', 'marionette', 'models/user/userCollection', 'views/user/userIt itemView: UserItemView itemViewContainer: "tbody" - - pag = $("#page-selection").bootpag - total: 0 - - pag.on "page", (event, num) => # page number here - console.log "Paginating" - @collection.page = num # Load next page - @collection.fetch() - initialize: => console.log "UserListView: initialize" @collection = new UserCollection() @@ -33,11 +24,19 @@ define ['jquery', 'marionette', 'models/user/userCollection', 'views/user/userIt success: => console.log("UserListView: Collection fetched") console.log(@collection) - @pag = $("#page-selection").bootpag + pag = $("#page-selection").bootpag total: @collection.page_count + pag.off "page" + pag.on "page", (event, num) => # page number here + if num != @collection.page + console.log "Paginating" + @collection.page = num # Load next page + @collection.fetch() + return ) + return doSearch: => console.log("UserListView: doSearch") diff --git a/static/js/app/views/user/userListView.js b/static/js/app/views/user/userListView.js index 1ff53bd..c2d61ba 100755 --- a/static/js/app/views/user/userListView.js +++ b/static/js/app/views/user/userListView.js @@ -7,8 +7,6 @@ define(['jquery', 'marionette', 'models/user/userCollection', 'views/user/userItemView', 'text!/tpl/UserListView', 'libs/bootstrap/bootpag'], function($, Marionette, UserCollection, UserItemView, Template) { var UserListView; UserListView = (function(_super) { - var pag, - _this = this; __extends(UserListView, _super); @@ -35,16 +33,6 @@ UserListView.prototype.itemViewContainer = "tbody"; - pag = $("#page-selection").bootpag({ - total: 0 - }); - - pag.on("page", function(event, num) { - console.log("Paginating"); - UserListView.collection.page = num; - return UserListView.collection.fetch(); - }); - UserListView.prototype.initialize = function() { console.log("UserListView: initialize"); this.collection = new UserCollection(); @@ -53,14 +41,23 @@ UserListView.prototype._fetchCollection = function(options) { var _this = this; - return this.collection.fetch({ + this.collection.fetch({ data: options, success: function() { + var pag; console.log("UserListView: Collection fetched"); console.log(_this.collection); - _this.pag = $("#page-selection").bootpag({ + pag = $("#page-selection").bootpag({ total: _this.collection.page_count }); + pag.off("page"); + pag.on("page", function(event, num) { + if (num !== _this.collection.page) { + console.log("Paginating"); + _this.collection.page = num; + return _this.collection.fetch(); + } + }); } }); }; @@ -80,7 +77,7 @@ return UserListView; - }).call(this, Marionette.CompositeView); + })(Marionette.CompositeView); return UserListView; });