aboutsummaryrefslogtreecommitdiff
path: root/data
diff options
context:
space:
mode:
Diffstat (limited to 'data')
-rw-r--r--data/assets/js/admin/tabs/users.js49
1 files changed, 32 insertions, 17 deletions
diff --git a/data/assets/js/admin/tabs/users.js b/data/assets/js/admin/tabs/users.js
index 22348e2..b74b8a1 100644
--- a/data/assets/js/admin/tabs/users.js
+++ b/data/assets/js/admin/tabs/users.js
@@ -6,17 +6,16 @@ jQuery(function($) {
"<a ",
"href='#' ",
"class='list-group-item %{css|h}' ",
- "title='Edit user \"%{user_name|h}\".' ",
- "data-row='%{row|json|h}' ",
+ "title='Edit user \"%{name|h}\".' ",
+ "data-user_id='%{user_id|h}' ",
"data-q='%{q|h}' ",
">",
- "<i class='fa fa-fw fa-spinner fa-spin hidden loading'></i>",
- "<i class='fa fa-fw fa-user loading'></i>",
+ "<i class='fa fa-fw fa-user'></i>",
" ",
- "%{user_name|h} (%{email|h})",
+ "%{name|h} (%{email|h})",
- "<span class='badge pull-right'>",
- "%{role_name|h}",
+ "<span class='%{badge_css} badge pull-right'>",
+ "%{role|h}",
"</span>",
"</a>",
],
@@ -33,7 +32,7 @@ jQuery(function($) {
"<span class='list-group-item list-group-item-danger disabled'>",
"<i class='fa fa-exclamation-triangle'></i>",
" ",
- "Error: %{responseText|h}",
+ "Error: %{error|h}",
"</span>",
],
});
@@ -59,6 +58,12 @@ jQuery(function($) {
}
}
+ var ROLE_BADGE_CSS = {
+ viewer: 'hidden',
+ editor: '',
+ admin: '',
+ };
+
function reload() {
var btn = $('#users-reload'),
list = $('#users');
@@ -67,17 +72,27 @@ jQuery(function($) {
btn.toggleClass('disabled').find('.loading').toggleClass('hidden');
list.html(TEMPLATES.run('loading'));
- send('test/get_users').always(function() {
+ send('user/get_users').always(function() {
btn.toggleClass('disabled').find('.loading').toggleClass('hidden');
list.html('');
}).fail(function(r) {
- console.log('get_users failed: ' + r.responseText);
- list.html(TEMPLATES.run('error', r));
+ var error = r.responseText;
+
+ try {
+ var data = $.parseJSON(r.responseText);
+ if (data.error)
+ error = data.error;
+ } catch (e) {}
+
+ list.html(TEMPLATES.run('error', {
+ error: error
+ }));
}).done(function(r) {
- list.html($.map(r.users, function(row) {
+ list.html($.map(r, function(row) {
return TEMPLATES.run('user', $.extend({}, row, {
+ css: (row.is_active == '1') ? '' : 'list-group-item-danger',
q: [row.user_id, row.user_name, row.email, row.role_name].join(' ').toLowerCase(),
- row: row,
+ badge_css: ROLE_BADGE_CSS[row.role],
}));
}).join(''));
@@ -94,13 +109,13 @@ jQuery(function($) {
});
$('#users').on('click', 'a.list-group-item', function() {
- var me = $(this);
+ var user_id = $(this).data('user_id');
// update highlight
$('#users .active').removeClass('active');
- me.addClass('active');
+ $(this).addClass('active');
- $('#user-edit-dialog').data('row', me.data('row')).modal('show');
+ $('#user-edit-dialog').data('user_id', user_id).modal('show');
// stop event
return false;
@@ -109,7 +124,7 @@ jQuery(function($) {
$('#users-reload').click(reload);
// load users
- $('#admin-tab-users').on('show.bs.tab', function() {
+ $('#settings-tab-users').on('show.bs.tab', function() {
reload();
});
});