add announcemet search & set top
This commit is contained in:
parent
4b838b5ef5
commit
7e7fc69a37
|
@ -4,15 +4,19 @@ class Panel::Announcement::BackEnd::BulletinsController < ApplicationController
|
|||
|
||||
before_filter :authenticate_user!
|
||||
before_filter :is_admin?
|
||||
|
||||
|
||||
def index
|
||||
# @bulletins = Bulletin.all
|
||||
# @bulletins = Bulletin.desc("postdate desc")
|
||||
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.desc("postdate")
|
||||
|
||||
|
||||
if params[:search]
|
||||
@bulletins = Bulletin.search(params[:search])
|
||||
else
|
||||
@bulletins = Bulletin.desc( :is_top, :postdate)
|
||||
end
|
||||
|
||||
respond_to do |format|
|
||||
format.html # index.html.erb
|
||||
|
@ -102,6 +106,7 @@ class Panel::Announcement::BackEnd::BulletinsController < ApplicationController
|
|||
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_bulletins_url, :notice => t('bulletin.update_bulletin_success')) }
|
||||
format.js { render 'toggle_enable' }
|
||||
format.xml { head :ok }
|
||||
else
|
||||
format.html { render :action => "edit" }
|
||||
|
@ -122,7 +127,16 @@ class Panel::Announcement::BackEnd::BulletinsController < ApplicationController
|
|||
format.xml { head :ok }
|
||||
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
|
||||
|
|
|
@ -7,7 +7,7 @@ class Bulletin
|
|||
|
||||
# field :category_id, :type => Integer
|
||||
field :title
|
||||
field :summary
|
||||
field :subtitle
|
||||
field :text
|
||||
field :postdate , :type => Date
|
||||
field :deadline , :type => Date
|
||||
|
@ -15,6 +15,8 @@ class Bulletin
|
|||
field :create_user_id
|
||||
field :update_user_id
|
||||
|
||||
field :is_top, :type => Boolean, :default => false
|
||||
|
||||
mount_uploader :image, ImageUploader
|
||||
|
||||
belongs_to :bulletin_category
|
||||
|
@ -29,7 +31,18 @@ class Bulletin
|
|||
validates_presence_of :title
|
||||
|
||||
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
|
||||
self.bulletin_files.each do |t|
|
||||
|
|
|
@ -22,8 +22,8 @@
|
|||
</div>
|
||||
|
||||
<div class="field">
|
||||
<%= f.label :summary %><br />
|
||||
<%= f.text_area :summary, :rows => 10, :cols => 40 %>
|
||||
<%= f.label :subtitle %><br />
|
||||
<%= f.text_area :subtitle, :rows => 10, :cols => 40 %>
|
||||
</div>
|
||||
|
||||
<div class="field">
|
||||
|
|
|
@ -13,12 +13,33 @@
|
|||
|
||||
<%= 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>
|
||||
<br />
|
||||
<br />
|
||||
<br />
|
||||
<br />
|
||||
<br />
|
||||
|
||||
|
||||
|
||||
<table>
|
||||
<tr>
|
||||
|
@ -41,7 +62,11 @@
|
|||
</td>
|
||||
<td>
|
||||
<%= 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>
|
||||
</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 %>
|
||||
</li>
|
||||
<li>
|
||||
<b><%= t('announcement.summary') %></b>
|
||||
<%= @bulletin.summary %>
|
||||
<b><%= t('announcement.subtitle') %></b>
|
||||
<%= @bulletin.subtitle %>
|
||||
</li>
|
||||
<li>
|
||||
<b><%= t('announcement.text') %></b>
|
||||
|
|
|
@ -0,0 +1,3 @@
|
|||
$("#enable_<%= @bulletin.id %>").toggle();
|
||||
$("#disable_<%= @bulletin.id %>").toggle();
|
||||
$("#bulletin_<%= @bulletin.id %>").toggleClass('disable');
|
Loading…
Reference in New Issue