From 9e73b3b2bd571b5f7dd752db80bc86f27d2300dd Mon Sep 17 00:00:00 2001 From: Paul Duncan Date: Thu, 26 May 2016 00:57:06 -0400 Subject: enable user list --- data/assets/js/admin/tabs/users.js | 49 +++++++++++++++++++++++++------------- 1 file changed, 32 insertions(+), 17 deletions(-) (limited to 'data/assets/js') 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($) { "", - "", - "", + "", " ", - "%{user_name|h} (%{email|h})", + "%{name|h} (%{email|h})", - "", - "%{role_name|h}", + "", + "%{role|h}", "", "", ], @@ -33,7 +32,7 @@ jQuery(function($) { "", "", " ", - "Error: %{responseText|h}", + "Error: %{error|h}", "", ], }); @@ -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(); }); }); -- cgit v1.2.3