Add tags filter for frontend
This commit is contained in:
parent
843dcef9f8
commit
fca37fdeb9
|
@ -1,7 +1,8 @@
|
|||
class AnnouncementsController < ApplicationController
|
||||
|
||||
def index
|
||||
announcements = Bulletin.where(:is_preview.in=>[false,nil]).can_display.order_by(:created_at=>'desc').filter_by_categories
|
||||
announcements = Bulletin.where(:is_preview.in=>[false,nil]).can_display.order_by(:created_at=>'desc').filter_by_categories.filter_by_tags(OrbitHelper.params['tags'])
|
||||
|
||||
anns = announcements.collect do |a|
|
||||
statuses = a.statuses_with_classname.collect do |status|
|
||||
{
|
||||
|
@ -16,19 +17,22 @@ class AnnouncementsController < ApplicationController
|
|||
"postdate" => a.postdate.strftime("%b %d, %Y at %I:%M %p"),
|
||||
"link_to_show" => OrbitHelper.url_to_show(a.to_param),
|
||||
"img_src" => a.image.thumb.url || "http://placehold.it/100x100",
|
||||
"more" => "More"
|
||||
"more" => t(:more_plus)
|
||||
}
|
||||
end
|
||||
{
|
||||
"announcements" => anns,
|
||||
"extras" => {"widget-title"=>"Announcements"},
|
||||
"extras" => {
|
||||
"widget-title"=>t('announcement.announcement')
|
||||
},
|
||||
"total_pages" => announcements.total_pages
|
||||
}
|
||||
|
||||
end
|
||||
|
||||
def widget
|
||||
announcements = Bulletin.where(:is_preview.in=>[false,nil]).can_display.order_by(:created_at=>'desc').filter_by_widget_categories
|
||||
announcements = Bulletin.where(:is_preview.in=>[false,nil]).can_display.order_by(:created_at=>'desc').filter_by_widget_categories.filter_by_tags(OrbitHelper.widget_tags)
|
||||
|
||||
anns = announcements.collect do |a|
|
||||
statuses = a.statuses_with_classname.collect do |status|
|
||||
{
|
||||
|
@ -47,7 +51,9 @@ class AnnouncementsController < ApplicationController
|
|||
end
|
||||
{
|
||||
"announcements" => anns,
|
||||
"extras" => {"widget-title"=>"Announcements","more_url"=>OrbitHelper.widget_more_url}
|
||||
"extras" => {
|
||||
"more_url"=>OrbitHelper.widget_more_url
|
||||
}
|
||||
}
|
||||
end
|
||||
|
||||
|
@ -57,7 +63,10 @@ class AnnouncementsController < ApplicationController
|
|||
|
||||
announcement = Bulletin.can_display.find_by(:uid=>params[:uid])
|
||||
|
||||
tags = announcement.tags.map{|tag| { "tag" => tag.name } } rescue []
|
||||
tags = announcement.tags.map{|tag| {
|
||||
"tag" => tag.name ,
|
||||
"url" => OrbitHelper.page_for_tag(tag)
|
||||
} } rescue []
|
||||
files = announcement.bulletin_files.map{|file| { "file_url" => file.file.url, "file_title" => (file.title.blank? ? File.basename(file.file.path) : file.title) } } rescue []
|
||||
links = announcement.bulletin_links.map{|link| { "link_url" => link.url, "link_title" => (link.title.blank? ? link.url : link.title) } } rescue []
|
||||
update_user = announcement.update_user.member_profile.name rescue ""
|
||||
|
|
|
@ -13,7 +13,7 @@
|
|||
<div class="accordion-body collapse" id="collapse-<%= field %>">
|
||||
<div class="accordion-inner pagination-right" data-toggle="buttons-checkbox">
|
||||
<% @filter_fields[field].each do |val| %>
|
||||
<%= link_to t(val[:title]), "#", :onclick => "filter.addFilter('filters[#{field}][]=#{val[:id]}')", :class => "btn btn-small #{is_filter_active?(field, val[:id])}" %>
|
||||
<%= link_to t(val[:title]), "#", :onclick => "filter.addFilter('filters[#{field}][]=#{val[:id]}')", :class => "btn btn-small #{is_filter_active?(field, val[:id])}", :id => "filter_#{val[:id]}" %>
|
||||
<% end %>
|
||||
</div>
|
||||
<div class="filter-clear">
|
||||
|
@ -31,6 +31,8 @@
|
|||
<%= render 'layouts/delete_modal', delete_options: @delete_options %>
|
||||
|
||||
<script type="text/javascript">
|
||||
var update = false;
|
||||
|
||||
var Filter = function(dom){
|
||||
var makeFilters = function(){
|
||||
return (window.location.search ? window.location.search.replace('?','').split('&') : []);
|
||||
|
@ -38,14 +40,18 @@
|
|||
var filters = makeFilters(),
|
||||
dom = $(dom),
|
||||
mainUrl = window.location.pathname;
|
||||
var updateTable = function(url){
|
||||
xurl = (url == null ? ( filters.length ? mainUrl + "?" + filters.join('&') : mainUrl ) : null);
|
||||
var updateTable = function(url, goback){
|
||||
update = true;
|
||||
xurl = (url == null ? ( filters.length ? mainUrl + "?" + filters.join('&') : mainUrl ) : url);
|
||||
$.ajax({
|
||||
url : xurl,
|
||||
type : "get",
|
||||
dataType : "html"
|
||||
}).done(function(data){
|
||||
history.pushState(null, null, decodeURIComponent(xurl));
|
||||
if(!goback){
|
||||
history.replaceState(null, null, decodeURIComponent(xurl));
|
||||
}
|
||||
|
||||
filters = makeFilters();
|
||||
dom.html(data);
|
||||
$(".pagination a").click(function(){
|
||||
|
@ -76,6 +82,17 @@
|
|||
updateTable();
|
||||
return false;
|
||||
}
|
||||
|
||||
window.onpopstate = function(event){
|
||||
if(!update){
|
||||
updateTable(document.location.href, true);
|
||||
$(".filter-group .btn-small").removeClass('active');
|
||||
$.each(document.location.search.split('&'),function(key,filter){
|
||||
$('#filter_'+filter.split('=')[1]).addClass('active');
|
||||
});
|
||||
}
|
||||
update = false;
|
||||
}
|
||||
}
|
||||
var filter = new Filter("#index_table");
|
||||
</script>
|
Loading…
Reference in New Issue