add announcemet search & set top
This commit is contained in:
parent
4b838b5ef5
commit
7e7fc69a37
|
@ -11,8 +11,12 @@ class Panel::Announcement::BackEnd::BulletinsController < ApplicationController
|
||||||
get_categorys(params[:bulletin_category_id])
|
get_categorys(params[:bulletin_category_id])
|
||||||
|
|
||||||
# @bulletins = Bulletin.where("bulletin_category_id" => params[:bulletin_category_id]).desc("postdate") if params[:bulletin_category_id]
|
# @bulletins = Bulletin.where("bulletin_category_id" => params[:bulletin_category_id]).desc("postdate") if params[:bulletin_category_id]
|
||||||
@bulletins = Bulletin.desc("postdate")
|
|
||||||
|
|
||||||
|
if params[:search]
|
||||||
|
@bulletins = Bulletin.search(params[:search])
|
||||||
|
else
|
||||||
|
@bulletins = Bulletin.desc( :is_top, :postdate)
|
||||||
|
end
|
||||||
|
|
||||||
respond_to do |format|
|
respond_to do |format|
|
||||||
format.html # index.html.erb
|
format.html # index.html.erb
|
||||||
|
@ -102,6 +106,7 @@ class Panel::Announcement::BackEnd::BulletinsController < ApplicationController
|
||||||
if @bulletin.update_attributes(params[:bulletin])
|
if @bulletin.update_attributes(params[:bulletin])
|
||||||
# format.html { redirect_to(panel_announcement_back_end_bulletin_url(@bulletin), :notice => t('bulletin.update_bulletin_success')) }
|
# format.html { redirect_to(panel_announcement_back_end_bulletin_url(@bulletin), :notice => t('bulletin.update_bulletin_success')) }
|
||||||
format.html { redirect_to(panel_announcement_back_end_bulletins_url, :notice => t('bulletin.update_bulletin_success')) }
|
format.html { redirect_to(panel_announcement_back_end_bulletins_url, :notice => t('bulletin.update_bulletin_success')) }
|
||||||
|
format.js { render 'toggle_enable' }
|
||||||
format.xml { head :ok }
|
format.xml { head :ok }
|
||||||
else
|
else
|
||||||
format.html { render :action => "edit" }
|
format.html { render :action => "edit" }
|
||||||
|
@ -123,6 +128,15 @@ class Panel::Announcement::BackEnd::BulletinsController < ApplicationController
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def top_edit
|
||||||
|
|
||||||
|
Bulletin.where(id: params[:id]).update_all( is_top: true )
|
||||||
|
respond_to do |format|
|
||||||
|
format.html { redirect_to(panel_announcement_back_end_bulletins_url) }
|
||||||
|
format.xml { head :ok }
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
protected
|
protected
|
||||||
|
|
|
@ -7,7 +7,7 @@ class Bulletin
|
||||||
|
|
||||||
# field :category_id, :type => Integer
|
# field :category_id, :type => Integer
|
||||||
field :title
|
field :title
|
||||||
field :summary
|
field :subtitle
|
||||||
field :text
|
field :text
|
||||||
field :postdate , :type => Date
|
field :postdate , :type => Date
|
||||||
field :deadline , :type => Date
|
field :deadline , :type => Date
|
||||||
|
@ -15,6 +15,8 @@ class Bulletin
|
||||||
field :create_user_id
|
field :create_user_id
|
||||||
field :update_user_id
|
field :update_user_id
|
||||||
|
|
||||||
|
field :is_top, :type => Boolean, :default => false
|
||||||
|
|
||||||
mount_uploader :image, ImageUploader
|
mount_uploader :image, ImageUploader
|
||||||
|
|
||||||
belongs_to :bulletin_category
|
belongs_to :bulletin_category
|
||||||
|
@ -31,6 +33,17 @@ class Bulletin
|
||||||
after_save :save_bulletin_files
|
after_save :save_bulletin_files
|
||||||
|
|
||||||
|
|
||||||
|
def self.search(search)
|
||||||
|
|
||||||
|
find(:all, :conditions => {title: search}).desc( :is_top, :postdate)
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
def is_top?
|
||||||
|
self.is_top
|
||||||
|
end
|
||||||
|
|
||||||
def save_bulletin_files
|
def save_bulletin_files
|
||||||
self.bulletin_files.each do |t|
|
self.bulletin_files.each do |t|
|
||||||
if t.should_destroy
|
if t.should_destroy
|
||||||
|
|
|
@ -22,8 +22,8 @@
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="field">
|
<div class="field">
|
||||||
<%= f.label :summary %><br />
|
<%= f.label :subtitle %><br />
|
||||||
<%= f.text_area :summary, :rows => 10, :cols => 40 %>
|
<%= f.text_area :subtitle, :rows => 10, :cols => 40 %>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="field">
|
<div class="field">
|
||||||
|
|
|
@ -13,12 +13,33 @@
|
||||||
|
|
||||||
<%= flash_messages %>
|
<%= flash_messages %>
|
||||||
|
|
||||||
|
<br />
|
||||||
|
<br />
|
||||||
|
<br />
|
||||||
|
<br />
|
||||||
|
<br />
|
||||||
|
|
||||||
|
<fieldset><legend><%= t('bulletin.search') %></legend>
|
||||||
|
|
||||||
|
<%= form_for :bulletin, :action => 'search', :method => 'get', :url => panel_announcement_back_end_bulletins_path do |f| %>
|
||||||
|
|
||||||
|
Category <%= f.select :bulletin_category_id, @bulletin_categorys.collect {|t| [ t.i18n_variable[I18n.locale], t.id ] },{ :include_blank => t('bulletin.select') }%>
|
||||||
|
|
||||||
|
KeyWord <%= text_field_tag :search, params[:search], :id => 'search_field' %>
|
||||||
|
|
||||||
|
<%= submit_tag "Search", :name => nil %>
|
||||||
|
|
||||||
|
<% end %>
|
||||||
|
|
||||||
|
|
||||||
|
</fieldset>
|
||||||
|
|
||||||
|
<br />
|
||||||
|
<br />
|
||||||
|
|
||||||
<h1><%= t('bulletin.list_announcement') %></h1>
|
<h1><%= t('bulletin.list_announcement') %></h1>
|
||||||
<br />
|
|
||||||
<br />
|
|
||||||
<br />
|
|
||||||
<br />
|
|
||||||
<br />
|
|
||||||
|
|
||||||
<table>
|
<table>
|
||||||
<tr>
|
<tr>
|
||||||
|
@ -41,7 +62,11 @@
|
||||||
</td>
|
</td>
|
||||||
<td>
|
<td>
|
||||||
<%= link_to t('bulletin.edit'), edit_panel_announcement_back_end_bulletin_path(post) %> |
|
<%= link_to t('bulletin.edit'), edit_panel_announcement_back_end_bulletin_path(post) %> |
|
||||||
<%= link_to t('bulletin.delete'), panel_announcement_back_end_bulletin_path(post), :confirm => t('announcement.sure?'), :method => :delete, :confirm => 'Are you sure?' %>
|
|
||||||
|
<%= link_to t(:set_top), eval("panel_announcement_back_end_bulletin_path(post, :authenticity_token => form_authenticity_token, :bulletin => {:is_top => true})"), :remote => true, :method => :put, :id => "disable_#{post.id}", :style => "display:#{post.is_top? ? 'none' : ''}", :class => 'switch' %>
|
||||||
|
<%= link_to t(:cancel_top), eval("panel_announcement_back_end_bulletin_path(post, :authenticity_token => form_authenticity_token, :bulletin => {:is_top => false})"), :remote => true, :method => :put, :id => "enable_#{post.id}", :style => "display:#{post.is_top? ? '' : 'none'}", :class => 'switch' %>
|
||||||
|
|
||||||
|
| <%= link_to t('bulletin.delete'), panel_announcement_back_end_bulletin_path(post), :confirm => t('announcement.sure?'), :method => :delete %>
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
|
|
||||||
|
|
|
@ -24,8 +24,8 @@
|
||||||
<%= link_to image_tag(@bulletin.image.url, :size => "320x240"), @bulletin.image.url, {:target => '_blank', :title => @bulletin.image_filename} if @bulletin.image.file %>
|
<%= link_to image_tag(@bulletin.image.url, :size => "320x240"), @bulletin.image.url, {:target => '_blank', :title => @bulletin.image_filename} if @bulletin.image.file %>
|
||||||
</li>
|
</li>
|
||||||
<li>
|
<li>
|
||||||
<b><%= t('announcement.summary') %></b>
|
<b><%= t('announcement.subtitle') %></b>
|
||||||
<%= @bulletin.summary %>
|
<%= @bulletin.subtitle %>
|
||||||
</li>
|
</li>
|
||||||
<li>
|
<li>
|
||||||
<b><%= t('announcement.text') %></b>
|
<b><%= t('announcement.text') %></b>
|
||||||
|
|
|
@ -0,0 +1,3 @@
|
||||||
|
$("#enable_<%= @bulletin.id %>").toggle();
|
||||||
|
$("#disable_<%= @bulletin.id %>").toggle();
|
||||||
|
$("#bulletin_<%= @bulletin.id %>").toggleClass('disable');
|
Reference in New Issue