From c1c4c03d394e8701cfd4640d8571afacc83d2ba2 Mon Sep 17 00:00:00 2001 From: Paul Duncan Date: Tue, 24 May 2016 13:30:11 -0400 Subject: enable post list --- data/assets/js/admin/tabs/posts.js | 78 ++++++++++++++++++++++++++++++++++++++ data/assets/js/search-field.js | 4 +- 2 files changed, 80 insertions(+), 2 deletions(-) (limited to 'data/assets/js') diff --git a/data/assets/js/admin/tabs/posts.js b/data/assets/js/admin/tabs/posts.js index 03f3483..83db403 100644 --- a/data/assets/js/admin/tabs/posts.js +++ b/data/assets/js/admin/tabs/posts.js @@ -2,6 +2,62 @@ jQuery(function($) { "use strict"; var TEMPLATES = new LuigiTemplate.Cache({ + post: [ + "", + "%{name|h}", + " ", + "(slug = %{slug|h}, state = %{state|h}, type = %{post_type|h})", + "", + ], + + error: [ + "", + "", + " ", + "Error: %{error|h}", + "", + ], + }); + + function reload() { + $('#posts-reload').addClass('disabled') + .find('.loading').toggleClass('hidden'); + + send('post/get_posts', { + q: $('#posts-q').data('q'), + page: 1, + }).always(function() { + $('#posts-reload').removeClass('disabled') + .find('.loading').toggleClass('hidden'); + }).fail(function(r) { + var error = r.responseText; + + try { + var data = $.parseJSON(r.responseText); + if (data.error) + error = data.error; + } catch (e) {} + + $('#posts').html(TEMPLATES.run('error', { + error: error, + })); + }).done(function(r) { + console.log(r); + + $('#posts').html($.map(r.rows, function(row) { + return TEMPLATES.run('post', row); + }).join('')); + }); + } + + $('#admin-tab-posts').on('show.bs.tab', function() { + $('#posts-reload').click(); }); $('.add-post').click(function() { @@ -30,4 +86,26 @@ jQuery(function($) { // stop event return false; }); + + $('#posts-reload').click(function() { + reload(); + + // stop event + return false; + }); + + $('#posts-q').on('search-update', function() { + reload(); + }); + + $('#posts').on('click', 'a', function() { + var data = $(this).data(); + + $('#' + data.post_type + '-edit-dialog') + .data('post_id', data.post_id) + .modal('show'); + + // stop event + return false; + }); }); diff --git a/data/assets/js/search-field.js b/data/assets/js/search-field.js index 76ff69f..3d6c494 100644 --- a/data/assets/js/search-field.js +++ b/data/assets/js/search-field.js @@ -61,10 +61,10 @@ jQuery(function($) { if (trigger == 'delay') { clear_delay(me); - setTimeout(function() { + me.data('search-interval', setTimeout(function() { clear_delay(me); trigger_search(me, me.val()); - }, me.data('search-delay') || 100); + }, me.data('search-delay') || 300)); } else if (trigger == 'enter') { if (ev.which == 13) { setTimeout(function() { -- cgit v1.2.3