aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaul Duncan <pabs@pablotron.org>2016-05-26 00:57:06 -0400
committerPaul Duncan <pabs@pablotron.org>2016-05-26 00:57:06 -0400
commit9e73b3b2bd571b5f7dd752db80bc86f27d2300dd (patch)
treea15ef6d318b19a48dbcbd6bf7981a5cc83f031c7
parenta5757765b0f5f17d7ab9916b6fe9c3127b41790b (diff)
downloadguff-9e73b3b2bd571b5f7dd752db80bc86f27d2300dd.tar.bz2
guff-9e73b3b2bd571b5f7dd752db80bc86f27d2300dd.zip
enable user list
-rw-r--r--data/assets/js/admin/tabs/users.js49
-rw-r--r--src/guff.cr5
2 files changed, 35 insertions, 19 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();
});
});
diff --git a/src/guff.cr b/src/guff.cr
index 7eb284a..6b842f8 100644
--- a/src/guff.cr
+++ b/src/guff.cr
@@ -1042,13 +1042,14 @@ module Guff
a.name,
a.email,
a.is_active,
- b.role
+ b.role,
+ b.name AS role_name
FROM users a
JOIN roles b
ON (b.role_id = a.role_id)
- ORDER BY LOWER(a.email)
+ ORDER BY LOWER(a.name)
",
}