Fixed double search call due to bootpag

This commit is contained in:
Fergal Moran
2013-07-02 22:24:08 +01:00
parent fbbb395c7f
commit 2bdb56474d
4 changed files with 25 additions and 21 deletions

View File

@@ -126,8 +126,7 @@ class UserResource(BackboneCompatibleResource):
if q is not None:
semi_filtered = semi_filtered.filter(
Q(first_name__icontains=q) |
Q(last_name__icontains=q) |
Q(username__icontains=q)
Q(last_name__icontains=q)
)
return semi_filtered

View File

@@ -2,7 +2,7 @@ define(['backbone'], function (Backbone) {
return Backbone.Collection.extend({
parse: function (response) {
this.meta = response.meta || {};
this.page_count = this.meta.total_count / this.meta.limit;
this.page_count = Math.ceil(this.meta.total_count / this.meta.limit);
return response.objects || response;
}
});

View File

@@ -13,7 +13,13 @@ define ['jquery', 'marionette', 'models/user/userCollection', 'views/user/userIt
itemView: UserItemView
itemViewContainer: "tbody"
isLoading = true
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"
@@ -27,18 +33,14 @@ 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.on "page", (event, num) => # page number here
console.log "Paginating"
@collection.page = num # Load next page
@collection.fetch()
@isLoading = false
return
)
doSearch: =>
console.clear()
console.log("UserListView: doSearch")
query = @ui.searchText.val()
if (query)

View File

@@ -7,7 +7,8 @@
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 isLoading;
var pag,
_this = this;
__extends(UserListView, _super);
@@ -34,7 +35,15 @@
UserListView.prototype.itemViewContainer = "tbody";
isLoading = true;
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");
@@ -47,24 +56,18 @@
return this.collection.fetch({
data: options,
success: function() {
var pag;
console.log("UserListView: Collection fetched");
console.log(_this.collection);
pag = $("#page-selection").bootpag({
_this.pag = $("#page-selection").bootpag({
total: _this.collection.page_count
});
pag.on("page", function(event, num) {
console.log("Paginating");
_this.collection.page = num;
return _this.collection.fetch();
});
_this.isLoading = false;
}
});
};
UserListView.prototype.doSearch = function() {
var query;
console.clear();
console.log("UserListView: doSearch");
query = this.ui.searchText.val();
if (query) {
@@ -78,7 +81,7 @@
return UserListView;
})(Marionette.CompositeView);
}).call(this, Marionette.CompositeView);
return UserListView;
});