aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--data/assets/js/admin/tabs/posts.js23
-rw-r--r--data/assets/js/dropdown.js29
-rw-r--r--src/guff.cr28
-rw-r--r--src/views/admin-page.ecr41
-rw-r--r--src/views/dropdown/menu.ecr2
5 files changed, 88 insertions, 35 deletions
diff --git a/data/assets/js/admin/tabs/posts.js b/data/assets/js/admin/tabs/posts.js
index 6fc0afd..5b27cf6 100644
--- a/data/assets/js/admin/tabs/posts.js
+++ b/data/assets/js/admin/tabs/posts.js
@@ -30,9 +30,10 @@ jQuery(function($) {
.find('.loading').toggleClass('hidden');
send('post/get_posts', {
- post_type: $('#posts-filter-type li.active a').data('id'),
- q: $('#posts-q').data('q'),
- page: 1,
+ type: $('#posts-filter-type li.active a').data('id'),
+ state: $('#posts-filter-state li.active a').data('id'),
+ q: $('#posts-q').data('q'),
+ page: 1,
}).always(function() {
$('#posts-reload').removeClass('disabled')
.find('.loading').toggleClass('hidden');
@@ -99,21 +100,7 @@ jQuery(function($) {
reload();
});
- $('.posts-filter-menu').on('click', 'a', function() {
- var data = $(this).data(),
- ul = $(this).parents('ul'),
- is_default = (data.id == ul.data('default'));
-
- ul.find('li').removeClass('active');
- $(this).parents('li').addClass('active');
- ul.prev('a')
- .toggleClass('btn-default', is_default)
- .toggleClass('btn-primary', !is_default)
- .find('span').text(data.text);
-
- // hide dropdown
- $('body').trigger('click');
-
+ $('.posts-filter-menu').on('guff.choose', function() {
// reload posts
reload();
diff --git a/data/assets/js/dropdown.js b/data/assets/js/dropdown.js
new file mode 100644
index 0000000..1ab5785
--- /dev/null
+++ b/data/assets/js/dropdown.js
@@ -0,0 +1,29 @@
+jQuery(function($) {
+ "use strict";
+
+ $('.guff-dropdown').on('click', 'a', function() {
+ var data = $(this).data(),
+ ul = $(this).parents('ul'),
+ is_default = (data.id == ul.data('default'));
+
+ // update ui
+ ul.find('li').removeClass('active');
+ $(this).parents('li').addClass('active');
+ ul.prev('a')
+ .toggleClass('btn-default', is_default)
+ .toggleClass('btn-primary', !is_default)
+ .find('span').text(data.name);
+
+ // hide dropdown
+ $('body').trigger('click');
+
+ // trigger choose
+ $(this).trigger({
+ type: 'guff.choose',
+ item: $(this).data(),
+ });
+
+ // stop event
+ return false;
+ });
+});
diff --git a/src/guff.cr b/src/guff.cr
index 121f150..d3817d0 100644
--- a/src/guff.cr
+++ b/src/guff.cr
@@ -460,11 +460,11 @@ module Guff
LIMIT = 50
def get_posts(
- site_id : Int64? = nil,
- post_type : String? = nil,
- state : String? = nil,
- q : String? = nil,
- page : Int32 = 1,
+ site_id : Int64? = nil,
+ type : String? = nil,
+ state : String? = nil,
+ q : String? = nil,
+ page : Int32 = 1,
)
filters = %w{1}
args = [] of String
@@ -478,9 +478,9 @@ module Guff
args << site_id.to_s
end
- if post_type
+ if type
# add type filter
- filters << case post_type
+ filters << case type
when "blog"
"x.post_id IS NOT NULL"
when "page"
@@ -491,11 +491,11 @@ module Guff
# allow "all"
"1"
else
- raise "unknown post type: #{post_type}"
+ raise "unknown post type: #{type}"
end
end
- if state
+ if state && state != "default"
# add state filter
filters << "b.state = ?"
args << state
@@ -1450,11 +1450,11 @@ module Guff
module PostAPI
def do_post_get_posts(params : HTTP::Params)
@context.models.post.get_posts(
- site_id: params["site_id"]? ? params["site_id"].to_i64 : nil,
- state: params["state"]?,
- post_type: params["post_type"]?,
- q: params["q"]?,
- page: params["page"].to_i32,
+ site_id: params["site_id"]? ? params["site_id"].to_i64 : nil,
+ state: params["state"]?,
+ type: params["type"]?,
+ q: params["q"]?,
+ page: params["page"].to_i32,
)
end
end
diff --git a/src/views/admin-page.ecr b/src/views/admin-page.ecr
index eedc41c..ad8d429 100644
--- a/src/views/admin-page.ecr
+++ b/src/views/admin-page.ecr
@@ -87,11 +87,14 @@
<div class='btn-group btn-group-sm'><%=
dropdown(
id: "posts-filter-type",
- name: "Type",
css: "posts-filter-menu",
- text: "Filter by type.",
+
+ name: "Type",
+ text: "Filter posts by type.",
+
icon: "",
default: "all",
+
items: [{
id: "all",
name: "All",
@@ -114,6 +117,39 @@
)
%></div><!-- btn-group -->
+ <div class='btn-group btn-group-sm'><%=
+ dropdown(
+ id: "posts-filter-state",
+ css: "posts-filter-menu",
+
+ name: "State",
+ text: "Filter by post state.",
+
+ icon: "",
+ default: "default",
+
+ items: [{
+ id: "default",
+ name: "Default",
+ text: "Show drafts and posted items.",
+ }, {
+ type: "divider",
+ }, {
+ id: "draft",
+ name: "Draft",
+ text: "Show draft items.",
+ }, {
+ id: "posted",
+ name: "Posted",
+ text: "Show posted items.",
+ }, {
+ id: "deleted",
+ name: "Deleted",
+ text: "Show deleted items.",
+ }],
+ )
+ %></div><!-- btn-group -->
+
<div class='btn-group btn-group-sm pull-right'>
<a
href='#'
@@ -1050,6 +1086,7 @@
assets/bootstrap-3.3.6/js/bootstrap.min.js
assets/ckeditor-4.5.8-custom/ckeditor.js
assets/js/search-field.js
+ assets/js/dropdown.js
assets/js/admin/tabs/users.js
assets/js/admin/tabs/posts.js
assets/js/admin/dialogs/user-add.js
diff --git a/src/views/dropdown/menu.ecr b/src/views/dropdown/menu.ecr
index ca39c1e..df17ba2 100644
--- a/src/views/dropdown/menu.ecr
+++ b/src/views/dropdown/menu.ecr
@@ -12,7 +12,7 @@
<ul
id='<%= h(@id) %>'
- class='dropdown-menu <%= h(@css) %>'
+ class='dropdown-menu guff-dropdown <%= h(@css) %>'
data-default='<%= h(@default) %>'
><%=
items