From 9679aa0d8f072a06f7c8af3b92c87fc3f23a804c Mon Sep 17 00:00:00 2001 From: Paul Duncan Date: Wed, 25 May 2016 01:19:52 -0400 Subject: populate posts table --- data/assets/css/admin.css | 3 + data/assets/js/admin/tabs/posts.js | 143 ++++++++++++++++++++++++++++++++----- 2 files changed, 128 insertions(+), 18 deletions(-) create mode 100644 data/assets/css/admin.css (limited to 'data') diff --git a/data/assets/css/admin.css b/data/assets/css/admin.css new file mode 100644 index 0000000..df2dda9 --- /dev/null +++ b/data/assets/css/admin.css @@ -0,0 +1,3 @@ +#posts tbody tr { + cursor: pointer; +} diff --git a/data/assets/js/admin/tabs/posts.js b/data/assets/js/admin/tabs/posts.js index 5b27cf6..6bd4c4c 100644 --- a/data/assets/js/admin/tabs/posts.js +++ b/data/assets/js/admin/tabs/posts.js @@ -3,28 +3,104 @@ jQuery(function($) { var TEMPLATES = new LuigiTemplate.Cache({ post: [ - "", - "%{name|h}", - " ", - "(slug = %{slug|h}, state = %{state|h}, type = %{post_type|h})", + "", + "", + "", + + "", + "%{name|h}", + " ", + "%{label}", + "", + + "", + "", + "%{user_name|h}", + "", + "", + + "", + // TODO: make editable + "%{site_name|h}", + "", + + "", + "%{post_url}", + "", + + "", + "%{created_at_text|h}", + "", + + "", + "%{posted_at_text|h}", + "", + "", + ], + + post_url: [ + "", + "%{post_url|h}", "", ], + post_slug: [ + "%{slug|h}", + ], + error: [ - "", - "", - " ", - "Error: %{error|h}", - "", + "", + "", + "", + " ", + "Error: %{error|h}", + "", + "", ], }); + var POST_TYPE_ICONS = { + blog: 'fa-sticky-note-o', + page: 'fa-bookmark-o', + project: 'fa-cube', + }; + + var POST_STATES = { + draft: { + css: 'bg-warning', + label: [ + " ", + "", + ].join(''), + }, + + deleted: { + css: 'bg-danger', + label: [ + " ", + "", + ].join(''), + }, + }; + function reload() { $('#posts-reload').addClass('disabled') .find('.loading').toggleClass('hidden'); @@ -46,14 +122,32 @@ jQuery(function($) { error = data.error; } catch (e) {} - $('#posts').html(TEMPLATES.run('error', { + $('#posts tbody').html(TEMPLATES.run('error', { error: error, })); }).done(function(r) { - console.log(r); - - $('#posts').html($.map(r.rows, function(row) { - return TEMPLATES.run('post', row); + $('#posts tbody').html($.map(r.rows, function(row) { + var css = '', + label = ''; + + if (POST_STATES[row.state]) { + css = POST_STATES[row.state].css; + label = POST_STATES[row.state].label; + } + + var post_url = 'n/a'; + if (row.post_url) { + post_url = TEMPLATES.run('post_url', row); + } else { + post_url = TEMPLATES.run('post_slug', row); + } + + return TEMPLATES.run('post', $.extend(row, { + css: css, + label: label, + icon: POST_TYPE_ICONS[row.post_type], + post_url: post_url, + })); }).join('')); }); } @@ -103,12 +197,25 @@ jQuery(function($) { $('.posts-filter-menu').on('guff.choose', function() { // reload posts reload(); + }); + + $('#posts').on('click', 'a.edit-user', function() { + var data = $(this).data(); + + $('#user-edit-dialog').data(data).modal('show'); + + // stop event + return false; + }); + + $('#posts').on('click', 'a.link', function() { + location.href = $(this).attr('href'); // stop event return false; }); - $('#posts').on('click', 'a', function() { + $('#posts').on('click', 'tbody tr[data-post_id]', function() { var data = $(this).data(); $('#' + data.post_type + '-edit-dialog') -- cgit v1.2.3