szurubooru/public_html/js/Presenters/UserListPresenter.js

68 lines
1.6 KiB
JavaScript
Raw Normal View History

2014-08-31 23:22:56 +02:00
var App = App || {};
App.Presenters = App.Presenters || {};
App.Presenters.UserListPresenter = function(
jQuery,
util,
2014-09-04 18:06:25 +02:00
promise,
2014-09-06 10:00:26 +02:00
auth,
router,
pagedCollectionPresenter,
2014-09-04 19:57:06 +02:00
topNavigationPresenter,
messagePresenter) {
2014-08-31 23:22:56 +02:00
var $el = jQuery('#content');
var template;
var userList = [];
var activeSearchOrder;
2014-08-31 23:22:56 +02:00
function init(args) {
topNavigationPresenter.select('users');
activeSearchOrder = util.parseComplexRouteArgs(args.searchArgs).order;
2014-09-04 18:06:25 +02:00
promise.wait(util.promiseTemplate('user-list')).then(function(html) {
template = _.template(html);
pagedCollectionPresenter.init({
searchArgs: args.searchArgs,
baseUri: '#/users',
backendUri: '/users',
renderCallback: function updateCollection(data) {
userList = data.entities;
render();
2014-09-04 19:57:06 +02:00
},
failCallback: function(response) {
$el.empty();
messagePresenter.showError($el, response.json && response.json.error || response);
}});
});
2014-09-02 23:07:50 +02:00
}
2014-08-31 23:22:56 +02:00
function render() {
$el.html(template({
userList: userList,
}));
$el.find('.order a').click(orderLinkClicked);
$el.find('.order [data-order="' + activeSearchOrder + '"]').parent('li').addClass('active');
var $pager = $el.find('.pager');
pagedCollectionPresenter.render($pager);
2014-08-31 23:22:56 +02:00
};
function orderLinkClicked(e)
{
e.preventDefault();
var $orderLink = jQuery(this);
activeSearchOrder = $orderLink.attr('data-order');
router.navigate(pagedCollectionPresenter.getSearchOrderChangeLink(activeSearchOrder));
}
2014-08-31 23:22:56 +02:00
return {
init: init,
2014-08-31 23:22:56 +02:00
render: render
};
};
App.DI.register('userListPresenter', App.Presenters.UserListPresenter);