Files
dss/static/js/app/views/user/userListView.js
2013-07-19 15:58:42 +01:00

86 lines
2.8 KiB
JavaScript
Executable File

// Generated by CoffeeScript 1.6.2
(function() {
var __bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; },
__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(['jquery', 'marionette', 'models/user/userCollection', 'views/user/userItemView', 'text!/tpl/UserListView', 'bootpag'], function($, Marionette, UserCollection, UserItemView, Template) {
var UserListView, _ref;
UserListView = (function(_super) {
__extends(UserListView, _super);
function UserListView() {
this.doSearch = __bind(this.doSearch, this);
this._fetchCollection = __bind(this._fetchCollection, this);
this.initialize = __bind(this.initialize, this); _ref = UserListView.__super__.constructor.apply(this, arguments);
return _ref;
}
UserListView.prototype.template = _.template(Template);
UserListView.prototype.events = {
"keyup #search-text": "doSearch"
};
UserListView.prototype.ui = {
searchText: "#search-text"
};
UserListView.prototype.itemView = UserItemView;
UserListView.prototype.itemViewContainer = "#user-table";
UserListView.prototype.initialize = function() {
console.log("UserListView: initialize");
this.collection = new UserCollection();
this._fetchCollection(this.options);
};
UserListView.prototype._fetchCollection = function(options) {
var _this = this;
this.collection.fetch({
data: options,
success: function() {
var pag;
console.log("UserListView: Collection fetched");
console.log(_this.collection);
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();
}
});
}
});
};
UserListView.prototype.doSearch = function() {
var query;
console.log("UserListView: doSearch");
query = this.ui.searchText.val();
if (query) {
return this._fetchCollection({
q: query
});
} else {
return this._fetchCollection(this.options);
}
};
return UserListView;
})(Marionette.CompositeView);
return UserListView;
});
}).call(this);