2014-08-31 23:22:56 +02:00
|
|
|
var App = App || {};
|
|
|
|
App.Presenters = App.Presenters || {};
|
|
|
|
|
2014-09-03 19:07:53 +02:00
|
|
|
App.Presenters.UserListPresenter = function(
|
2014-09-08 22:02:28 +02:00
|
|
|
_,
|
2014-09-03 19:07:53 +02:00
|
|
|
jQuery,
|
|
|
|
util,
|
2014-09-04 18:06:25 +02:00
|
|
|
promise,
|
2014-09-06 10:00:26 +02:00
|
|
|
auth,
|
2014-10-01 23:22:20 +02:00
|
|
|
pagerPresenter,
|
2014-10-01 23:43:39 +02:00
|
|
|
topNavigationPresenter) {
|
2014-08-31 23:22:56 +02:00
|
|
|
|
|
|
|
var $el = jQuery('#content');
|
2014-10-05 10:41:12 +02:00
|
|
|
var templates = {};
|
2014-10-09 21:41:46 +02:00
|
|
|
var params;
|
2014-08-31 23:22:56 +02:00
|
|
|
|
2014-10-09 21:41:46 +02:00
|
|
|
function init(params, loaded) {
|
2014-09-03 09:10:26 +02:00
|
|
|
topNavigationPresenter.select('users');
|
2014-09-11 13:59:12 +02:00
|
|
|
topNavigationPresenter.changeTitle('Users');
|
2014-09-03 19:07:53 +02:00
|
|
|
|
2014-10-02 00:30:25 +02:00
|
|
|
promise.wait(
|
2014-09-17 22:37:49 +02:00
|
|
|
util.promiseTemplate('user-list'),
|
|
|
|
util.promiseTemplate('user-list-item'))
|
2014-10-05 10:41:12 +02:00
|
|
|
.then(function(listTemplate, listItemTemplate) {
|
|
|
|
templates.list = listTemplate;
|
|
|
|
templates.listItem = listItemTemplate;
|
2014-09-17 22:37:49 +02:00
|
|
|
|
|
|
|
render();
|
2014-09-18 11:29:19 +02:00
|
|
|
loaded();
|
|
|
|
|
2014-10-01 23:22:20 +02:00
|
|
|
pagerPresenter.init({
|
2014-09-18 11:29:19 +02:00
|
|
|
baseUri: '#/users',
|
|
|
|
backendUri: '/users',
|
|
|
|
$target: $el.find('.pagination-target'),
|
|
|
|
updateCallback: function(data, clear) {
|
|
|
|
renderUsers(data.entities, clear);
|
|
|
|
},
|
|
|
|
},
|
|
|
|
function() {
|
2014-10-09 21:41:46 +02:00
|
|
|
reinit(params, function() {});
|
2014-09-18 11:29:19 +02:00
|
|
|
});
|
2014-09-17 22:37:49 +02:00
|
|
|
});
|
2014-09-02 23:07:50 +02:00
|
|
|
}
|
2014-08-31 23:22:56 +02:00
|
|
|
|
2014-10-09 21:41:46 +02:00
|
|
|
function reinit(_params, loaded) {
|
|
|
|
params = _params;
|
|
|
|
params.query = params.query || {};
|
|
|
|
params.query.order = params.query.order || 'name,asc';
|
|
|
|
updateActiveOrder(params.query.order);
|
2014-09-12 22:58:07 +02:00
|
|
|
|
2014-10-09 21:41:46 +02:00
|
|
|
pagerPresenter.reinit({query: params.query});
|
|
|
|
loaded();
|
2014-09-07 09:30:48 +02:00
|
|
|
}
|
|
|
|
|
2014-10-02 00:30:25 +02:00
|
|
|
function deinit() {
|
|
|
|
pagerPresenter.deinit();
|
|
|
|
}
|
|
|
|
|
2014-08-31 23:22:56 +02:00
|
|
|
function render() {
|
2014-10-05 10:41:12 +02:00
|
|
|
$el.html(templates.list());
|
2014-09-03 19:07:53 +02:00
|
|
|
$el.find('.order a').click(orderLinkClicked);
|
2014-09-12 22:58:07 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
function updateActiveOrder(activeOrder) {
|
2014-09-17 11:48:10 +02:00
|
|
|
$el.find('.order li a').removeClass('active');
|
|
|
|
$el.find('.order [data-order="' + activeOrder + '"]').addClass('active');
|
2014-09-12 22:58:07 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
function renderUsers(users, clear) {
|
|
|
|
var $target = $el.find('.users');
|
|
|
|
|
2014-10-04 14:06:44 +02:00
|
|
|
if (clear) {
|
|
|
|
$target.empty();
|
|
|
|
}
|
|
|
|
|
2014-09-12 22:58:07 +02:00
|
|
|
_.each(users, function(user) {
|
2014-10-05 11:05:34 +02:00
|
|
|
var $item = jQuery('<li>' + templates.listItem({
|
2014-09-12 22:58:07 +02:00
|
|
|
user: user,
|
|
|
|
formatRelativeTime: util.formatRelativeTime,
|
2014-10-05 11:05:34 +02:00
|
|
|
}) + '</li>');
|
|
|
|
util.loadImagesNicely($item.find('img'));
|
|
|
|
$target.append($item);
|
2014-09-12 22:58:07 +02:00
|
|
|
});
|
2014-09-08 22:02:28 +02:00
|
|
|
}
|
2014-08-31 23:22:56 +02:00
|
|
|
|
2014-09-07 09:57:01 +02:00
|
|
|
function orderLinkClicked(e) {
|
2014-09-03 19:07:53 +02:00
|
|
|
e.preventDefault();
|
|
|
|
var $orderLink = jQuery(this);
|
2014-09-12 22:58:07 +02:00
|
|
|
var activeSearchOrder = $orderLink.attr('data-order');
|
2014-10-09 21:41:46 +02:00
|
|
|
params.query.order = activeSearchOrder;
|
|
|
|
pagerPresenter.setQuery(params.query);
|
2014-09-03 19:07:53 +02:00
|
|
|
}
|
|
|
|
|
2014-08-31 23:22:56 +02:00
|
|
|
return {
|
2014-09-03 09:10:26 +02:00
|
|
|
init: init,
|
2014-09-12 22:58:07 +02:00
|
|
|
reinit: reinit,
|
2014-10-02 00:30:25 +02:00
|
|
|
deinit: deinit,
|
2014-09-12 22:58:07 +02:00
|
|
|
render: render,
|
2014-08-31 23:22:56 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
};
|
|
|
|
|
2014-10-01 23:43:39 +02:00
|
|
|
App.DI.register('userListPresenter', ['_', 'jQuery', 'util', 'promise', 'auth', 'pagerPresenter', 'topNavigationPresenter'], App.Presenters.UserListPresenter);
|