diff --git a/vendor/built_in_modules/announcement/app/controllers/panel/announcement/back_end/bulletins_controller.rb b/vendor/built_in_modules/announcement/app/controllers/panel/announcement/back_end/bulletins_controller.rb index ee95a91ce..f78e2c349 100644 --- a/vendor/built_in_modules/announcement/app/controllers/panel/announcement/back_end/bulletins_controller.rb +++ b/vendor/built_in_modules/announcement/app/controllers/panel/announcement/back_end/bulletins_controller.rb @@ -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 diff --git a/vendor/built_in_modules/announcement/app/models/bulletin.rb b/vendor/built_in_modules/announcement/app/models/bulletin.rb index 510950042..e75385cd4 100644 --- a/vendor/built_in_modules/announcement/app/models/bulletin.rb +++ b/vendor/built_in_modules/announcement/app/models/bulletin.rb @@ -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| diff --git a/vendor/built_in_modules/announcement/app/views/panel/announcement/back_end/bulletins/_form.html.erb b/vendor/built_in_modules/announcement/app/views/panel/announcement/back_end/bulletins/_form.html.erb index b840a60b0..419a27ef4 100644 --- a/vendor/built_in_modules/announcement/app/views/panel/announcement/back_end/bulletins/_form.html.erb +++ b/vendor/built_in_modules/announcement/app/views/panel/announcement/back_end/bulletins/_form.html.erb @@ -22,8 +22,8 @@
<%= 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 %> |