aboutsummaryrefslogtreecommitdiff
path: root/data/assets/js/admin/tabs
diff options
context:
space:
mode:
Diffstat (limited to 'data/assets/js/admin/tabs')
-rw-r--r--data/assets/js/admin/tabs/posts.js125
-rw-r--r--data/assets/js/admin/tabs/users.js115
2 files changed, 240 insertions, 0 deletions
diff --git a/data/assets/js/admin/tabs/posts.js b/data/assets/js/admin/tabs/posts.js
new file mode 100644
index 0000000..00117d6
--- /dev/null
+++ b/data/assets/js/admin/tabs/posts.js
@@ -0,0 +1,125 @@
+jQuery(function($) {
+ "use strict";
+
+ var TEMPLATES = new LuigiTemplate.Cache({
+ user: [
+ "<a ",
+ "href='#' ",
+ "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>",
+ " ",
+ "%{user_name|h} (%{email|h})",
+
+ "<span class='badge pull-right'>",
+ "%{role_name|h}",
+ "</span>",
+ "</a>",
+ ],
+
+ loading: [
+ "<span class='list-group-item disabled'>",
+ "<i class='fa fa-spinner fa-spin'></i>",
+ " ",
+ "Loading...",
+ "</span>",
+ ],
+
+ error: [
+ "<span class='list-group-item list-group-item-danger disabled'>",
+ "<i class='fa fa-exclamation-triangle'></i>",
+ " ",
+ "Error: %{responseText|h}",
+ "</span>",
+ ],
+ });
+
+ function update_slug(name, slug) {
+ if (slug.prop('disabled')) {
+ slug.val(
+ name.val().toLowerCase()
+ .replace(/[^a-z0-9_\.-]+/g, '-')
+ .replace(/^-+|-+$/g, '')
+ );
+ }
+ }
+
+ $.each(['blog', 'page', 'project'], function(i, id) {
+ var p = '#' + id + '-edit-';
+
+ $(p + 'dialog').one('shown.bs.modal', function() {
+ // lazy-init editor
+ CKEDITOR.replace(id + '-edit-body');
+ }).on('show.bs.modal', function() {
+ // reset close confirmation
+ $(this).data('close-dialog-confirmed', false);
+
+ // hide all bodies
+ $(this).find('.modal-body').addClass('hidden');
+ }).on('shown.bs.modal', function() {
+ $(p + 'name').focus();
+ }).on('hide.bs.modal', function() {
+ return (
+ $(this).data('close-dialog-confirmed') ||
+ confirm('Close without saving changes?')
+ );
+ }).find('button[data-dismiss="modal"]').click(function() {
+ // override close confirmation
+ // FIXME: should this only be on save?
+ $(p + 'dialog').data('close-dialog-confirmed', true);
+ });
+
+ $(p + 'confirm').click(function() {
+ if ($(this).hasClass('disabled'))
+ return false;
+
+ // TODO: see #user-add-confirm
+ alert('TODO: create');
+
+ // stop event
+ return false;
+ });
+ });
+
+ $('.post-name').keydown(function() {
+ var name = $(this),
+ slug = $(this).parents('.modal-body').find('.post-slug');
+
+ setTimeout(function() {
+ update_slug(name, slug);
+ }, 10);
+ });
+
+ $('.post-slug-lock').click(function() {
+ var modal_body = $(this).parents('.modal-body');
+
+ // toggle locked state
+ $(this).toggleClass('btn-default btn-primary')
+ .find('.fa').toggleClass('fa-lock fa-unlock');
+ var locked = $(this).hasClass('btn-default');
+
+ // update slug disabled state
+ var slug = modal_body.find('.post-slug');
+ slug.prop('disabled', locked ? 'disabled' : null);
+
+ if (locked) {
+ // auto-generate slug
+ update_slug(modal_body.find('.post-name'), slug);
+ }
+
+ // stop event
+ return false;
+ });
+
+ $('.state-buttons').on('a', 'click', function() {
+ $(this).parent().find('.btn-primary').toggleClass('btn-default btn-primary');
+ $(this).toggleClass('btn-default btn-primary');
+
+ // stop event
+ return false;
+ });
+});
diff --git a/data/assets/js/admin/tabs/users.js b/data/assets/js/admin/tabs/users.js
new file mode 100644
index 0000000..22348e2
--- /dev/null
+++ b/data/assets/js/admin/tabs/users.js
@@ -0,0 +1,115 @@
+jQuery(function($) {
+ "use strict";
+
+ var TEMPLATES = new LuigiTemplate.Cache({
+ user: [
+ "<a ",
+ "href='#' ",
+ "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>",
+ " ",
+ "%{user_name|h} (%{email|h})",
+
+ "<span class='badge pull-right'>",
+ "%{role_name|h}",
+ "</span>",
+ "</a>",
+ ],
+
+ loading: [
+ "<span class='list-group-item disabled'>",
+ "<i class='fa fa-spinner fa-spin'></i>",
+ " ",
+ "Loading...",
+ "</span>",
+ ],
+
+ error: [
+ "<span class='list-group-item list-group-item-danger disabled'>",
+ "<i class='fa fa-exclamation-triangle'></i>",
+ " ",
+ "Error: %{responseText|h}",
+ "</span>",
+ ],
+ });
+
+ function filter() {
+ var qs = $('#users-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 = $('#users-reload'),
+ list = $('#users');
+
+ // show loading
+ btn.toggleClass('disabled').find('.loading').toggleClass('hidden');
+ list.html(TEMPLATES.run('loading'));
+
+ send('test/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));
+ }).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
+ return false;
+ }
+
+ $('#users-q').on('search-update', function() {
+ filter();
+ });
+
+ $('#users').on('click', 'a.list-group-item', function() {
+ var me = $(this);
+
+ // update highlight
+ $('#users .active').removeClass('active');
+ me.addClass('active');
+
+ $('#user-edit-dialog').data('row', me.data('row')).modal('show');
+
+ // stop event
+ return false;
+ });
+
+ $('#users-reload').click(reload);
+
+ // load users
+ $('#admin-tab-users').on('show.bs.tab', function() {
+ reload();
+ });
+});