diff options
Diffstat (limited to 'data/stuff/test')
-rw-r--r-- | data/stuff/test/auth.js | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/data/stuff/test/auth.js b/data/stuff/test/auth.js index 0776bfd..3960da6 100644 --- a/data/stuff/test/auth.js +++ b/data/stuff/test/auth.js @@ -7,6 +7,7 @@ jQuery(function($) { "class='list-group-item %{css|h}' ", "title='Edit user \"%{user_name|h}\".' ", "data-row='%{row|json|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>", @@ -34,6 +35,27 @@ jQuery(function($) { ], }); + function filter() { + var qs = $('#filter-q').val().replace(/^\s+|\s+$/g, '').toLowerCase().split(/\s+/); + + if (qs.length > 0) { + // hide all users + $('#users .list-group-item').addClass('hidden'); + + // show matching users + $($.grep($('#users .list-group-item'), function(el) { + var eq = $(el).data('q'); + + return ($.grep(qs, function(q) { + return eq.indexOf(q) !== -1; + }).length == qs.length); + })).removeClass('hidden'); + } else { + // show all users + $('#users .list-group-item').removeClass('hidden'); + } + } + function reload() { var btn = $('#reload'), list = $('#users'); @@ -51,9 +73,13 @@ jQuery(function($) { }).done(function(r) { list.html($.map(r.users, function(row) { return TEMPLATES.run('user', $.extend({}, row, { + q: [row.user_id, row.user_name, row.email, row.role_name].join(' ').toLowerCase(), row: row, })); }).join('')); + + // refresh filters + filter(); }); // stop event @@ -70,6 +96,10 @@ jQuery(function($) { }); } + $('#filter-q').on('search-update', function() { + filter(); + }); + $('#users').on('click', 'a.list-group-item', function() { var me = $(this); |