Widget for announcement and web_link with ajax reload and pagination
This commit is contained in:
parent
2989366fa4
commit
7d57b50e46
|
@ -7,6 +7,6 @@
|
||||||
"update_info": "Some info",
|
"update_info": "Some info",
|
||||||
"create_date": "11-11-2011",
|
"create_date": "11-11-2011",
|
||||||
"app_pages": ["bulletins"],
|
"app_pages": ["bulletins"],
|
||||||
"widgets": ["bulletins","bulletins_list"],
|
"widgets": ["bulletins","bulletins_list", "bulletins_and_web_links"],
|
||||||
"enable_frontend": true
|
"enable_frontend": true
|
||||||
}
|
}
|
||||||
|
|
|
@ -30,6 +30,23 @@ class Panel::Announcement::Widget::BulletinsController < ObitWidgetController
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def bulletins_and_web_links
|
||||||
|
@tags = AnnouncementTag.all
|
||||||
|
@selected_tag = AnnouncementTag.find(params[:id]) rescue @tags[0]
|
||||||
|
@bulletins = @selected_tag.get_visible_bulletins.page(params[:page]).per(1) rescue nil
|
||||||
|
@web_links = WebResourceTag.first(:conditions => {:en => @selected_tag[:en]}).get_visible_links.page(params[:page]).per(1) rescue nil
|
||||||
|
end
|
||||||
|
|
||||||
|
def reload_bulletins
|
||||||
|
@selected_tag = AnnouncementTag.find(params[:tag_id])
|
||||||
|
@bulletins = @selected_tag.get_visible_bulletins.page(params[:page]).per(1) rescue nil
|
||||||
|
end
|
||||||
|
|
||||||
|
def reload_web_links
|
||||||
|
@selected_tag = AnnouncementTag.find(params[:tag_id])
|
||||||
|
@web_links = WebResourceTag.first(:conditions => {:en => @selected_tag[:en]}).get_visible_links.page(params[:page]).per(1) rescue nil
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
protected
|
protected
|
||||||
|
|
||||||
|
|
|
@ -2,4 +2,9 @@ class AnnouncementTag < Tag
|
||||||
|
|
||||||
has_and_belongs_to_many :bulletins
|
has_and_belongs_to_many :bulletins
|
||||||
|
|
||||||
|
|
||||||
|
def get_visible_bulletins(sort = :name)
|
||||||
|
self.bulletins.where(:is_hidden => false).desc(:is_top, sort)
|
||||||
|
end
|
||||||
|
|
||||||
end
|
end
|
|
@ -0,0 +1,7 @@
|
||||||
|
<% @bulletins.each do |bulletin| %>
|
||||||
|
<li>
|
||||||
|
<%= bulletin.title[I18n.locale] %>
|
||||||
|
</li>
|
||||||
|
<% end %>
|
||||||
|
|
||||||
|
<%= paginate @bulletins, :params => {:controller => 'widget/bulletins', :action => 'reload_bulletins', :tag_id => @selected_tag.id}, :remote => true %>
|
|
@ -0,0 +1,4 @@
|
||||||
|
<li>
|
||||||
|
<%= link_to tag[I18n.locale], panel_announcement_widget_bulletins_and_web_links_path(:id => tag.id), :remote => true %>
|
||||||
|
<%= '-' if tag.eql?(@selected_tag) %>
|
||||||
|
</li>
|
|
@ -0,0 +1,7 @@
|
||||||
|
<% @web_links.each do |web_link| %>
|
||||||
|
<li>
|
||||||
|
<%= web_link.name[I18n.locale] %>
|
||||||
|
</li>
|
||||||
|
<% end %>
|
||||||
|
|
||||||
|
<%= paginate @web_links, :params => {:controller => 'widget/bulletins', :action => 'reload_web_links', :tag_id => @selected_tag.id}, :remote => true %>
|
|
@ -0,0 +1,17 @@
|
||||||
|
<div>
|
||||||
|
<ul id='bulletins_web_links_tags'>
|
||||||
|
<%= render :partial => 'tag', :collection => @tags %>
|
||||||
|
</ul>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div>
|
||||||
|
<ul id='bulletins_web_links_bulletins'>
|
||||||
|
<%= render 'bulletins' %>
|
||||||
|
</ul>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div>
|
||||||
|
<ul id='bulletins_web_links_web_links'>
|
||||||
|
<%= render 'web_links' %>
|
||||||
|
</ul>
|
||||||
|
</div>
|
|
@ -0,0 +1,3 @@
|
||||||
|
$('#bulletins_web_links_tags').html("<%= j render :partial => 'tag', :collection => @tags %>")
|
||||||
|
$('#bulletins_web_links_bulletins').html("<%= j render 'bulletins' %>")
|
||||||
|
$('#bulletins_web_links_web_links').html("<%= j render 'web_links' %>")
|
|
@ -0,0 +1 @@
|
||||||
|
$('#bulletins_web_links_bulletins').html("<%= j render 'bulletins' %>")
|
|
@ -0,0 +1 @@
|
||||||
|
$('#bulletins_web_links_web_links').html("<%= j render 'web_links' %>")
|
|
@ -16,6 +16,9 @@ Rails.application.routes.draw do
|
||||||
namespace :widget do
|
namespace :widget do
|
||||||
match "bulletins" => "bulletins#index"
|
match "bulletins" => "bulletins#index"
|
||||||
match "bulletins_list" => "bulletins#bulletins_list"
|
match "bulletins_list" => "bulletins#bulletins_list"
|
||||||
|
match "bulletins_and_web_links" => "bulletins#bulletins_and_web_links"
|
||||||
|
match "reload_bulletins" => "bulletins#reload_bulletins"
|
||||||
|
match "reload_web_links" => "bulletins#reload_web_links"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Reference in New Issue