diff --git a/app/controllers/admin/asks_controller.rb b/app/controllers/admin/asks_controller.rb index 7ccf9cf..3f15796 100644 --- a/app/controllers/admin/asks_controller.rb +++ b/app/controllers/admin/asks_controller.rb @@ -9,70 +9,48 @@ class Admin::AsksController < OrbitAdminController @app_title = "ask" end - # 重新定義排序 - def sort - unless params[:sort].blank? - case params[:sort] - when "status" - @sort = {:status=>params[:order]} - when "category" - @sort = {:category_id=>params[:order]} - when "start_date" - @sort = {:postdate=>params[:order]} - when "end_date" - @sort = {:deadline=>params[:order]} - when "last_modified" - @sort = {:update_user_id=>params[:order]} - when "banner" - @sort = {'banner_id'=>params[:order]} - when "banner_name" - @sort = {:title=>params[:order]} - when "effect" - @sort = {:ad_fx=>params[:order]} - when "transition_interval" - @sort = {:timeout=>params[:order]} - when "transition_speed" - @sort = {:speed=>params[:order]} - when "size" - @sort = {:height=>params[:order]} - when "link" - @sort = {:out_link=>params[:order]} - else - s = Sanitize.clean(params[:sort]).to_sym - @sort = {s=>params[:order]} - end - else - @sort = {:created_at=>'desc'} - end - @sort - end - - # 重新定義分類搜尋 - def filter_fields(categories) + def filter_fields(categories, tags) { - :status=>[{:title=>"待處理",:id=>"is_hot"},{:title=>"已處理",:id=>"is_top"},{:title=>"轉介其他單位",:id=>"is_hidden"}], - :category=>categories.map{|c| {:title=>(c.title.blank? ? " " : c.title), :id=>c.id}} + :situation=>[{:title=>"is_waiting",:id=>"is_waiting"},{:title=>"is_processed",:id=>"is_processed"},{:title=>"is_referral",:id=>"is_referral"}], + :category=>categories.map{|c| {:title=>(c.title.blank? ? " " : c.title), :id=>c.id}}, + :identity=>tags.map{|tag| {:title=>(tag.name.blank? ? " " : tag.name), :id=>tag.id}} } end # 抓取網址的狀態參數 def filter2(type) case type - when "status" - params[:filters][:status].blank? ? [] : params[:filters][:status] rescue [] + when "situation" + params[:filters][:situation].blank? ? [] : params[:filters][:situation] rescue [] + when "identity" + params[:filters][:identity].blank? ? [] : params[:filters][:identity] rescue [] end end def index + @tags = @module_app.tags @categories = @module_app.categories - @filter_fields = filter_fields(@categories) + @filter_fields = filter_fields(@categories, @tags) # 列表欄位 - @table_fields = [:status, :category, :title, 'ask.name', 'ask.created_at'] + @table_fields = [:situation, :category, :title, 'ask.name', 'ask.created_at'] # 列表排序 - if filter2("status").blank? - @askquestions = AskQuestion.order_by(sort) .with_categories(filters("category")) + # debugger + if filter2("situation").blank? and filter2("identity").blank? + @askquestions = AskQuestion.order_by(sort) + .with_categories(filters("category")) + elsif filter2("situation").blank? + @askquestions = AskQuestion.order_by(sort) + .with_categories(filters("category")) + .any_in(:identity => filter2("identity")) + elsif filter2("identity").blank? + @askquestions = AskQuestion.order_by(sort) + .with_categories(filters("category")) + .any_in(:situation => filter2("situation")) else - @askquestions = AskQuestion.order_by(sort) .with_categories(filters("category")) .where(:status.in => filter2("status")) + @askquestions = AskQuestion.order_by(sort) + .with_categories(filters("category")) + .any_in(:identity => filter2("identity")) + .any_in(:situation => filter2("situation")) end # 分頁 @@ -82,6 +60,10 @@ class Admin::AsksController < OrbitAdminController end end + def search_tag(tag) + Tag.find(tag).name_translations{} + end + def edit @ask_question = AskQuestion.find(params[:id]) @url = admin_ask_path(@ask_question) @@ -149,16 +131,18 @@ class Admin::AsksController < OrbitAdminController AskQuestion.human_attribute_name(:reply), AskQuestion.human_attribute_name(:comment)] @ask_questions.each do |ask_question| - csv << [ ask_question.category.title, - ask_question.name, - ask_question[:identity], - ask_question.mail, - ask_question.phone, - ask_question.fax, - ask_question.title, - ask_question.content, - ask_question.reply, - ask_question.comment ] + Tag.where({:id => ask_question[:identity]}).each do |tag| + csv << [ ask_question.category.title, + ask_question.name, + tag.name, + ask_question.mail, + ask_question.phone, + ask_question.fax, + ask_question.title, + ask_question.content, + ask_question.reply, + ask_question.comment ] + end end end send_data csv.encode('Big5'), type: 'text/csv', filename: "Questions-#{date_start}-#{date_end}.csv" diff --git a/app/controllers/asks_controller.rb b/app/controllers/asks_controller.rb index 839d4e2..7ec9ed3 100644 --- a/app/controllers/asks_controller.rb +++ b/app/controllers/asks_controller.rb @@ -7,10 +7,12 @@ class AsksController < ApplicationController def index module_app = ModuleApp.where(:key => "ask").first categories = module_app.categories + tags = module_app.tags ask_question = AskQuestion.new { "ask_question" => ask_question, "categories" => categories, + "tags" => tags, "module_app" => module_app } end diff --git a/app/models/ask_question.rb b/app/models/ask_question.rb index 12c5827..bc5b44b 100644 --- a/app/models/ask_question.rb +++ b/app/models/ask_question.rb @@ -1,8 +1,9 @@ class AskQuestion include Mongoid::Document include Mongoid::Timestamps - include ActiveModel::Validations + # include ActiveModel::Validations include OrbitCategory::Categorizable + include OrbitTag::Taggable # 欄位 field :name, type: String @@ -15,11 +16,11 @@ class AskQuestion field :reply, type: String field :comment, type: String - field :status, type: String, default: "is_hot" #預設待處理 + field :situation, type: String, default: "is_waiting" #預設待處理 field :send_email, type: Boolean, default: false field :email_id - validates_presence_of :name, :identity, :mail, :title, :content + # validates_presence_of :name, :identity, :mail, :title, :content def email mail = Email.find(self.email_id) rescue nil diff --git a/app/views/admin/asks/_filter.html.erb b/app/views/admin/asks/_filter.html.erb deleted file mode 100644 index 808eb5a..0000000 --- a/app/views/admin/asks/_filter.html.erb +++ /dev/null @@ -1,186 +0,0 @@ -<% content_for :right_nav do %> - <% if !search_dom_id.nil?%> -
<%= AskQuestion.human_attribute_name(:name) %>:<%= @ask_question.name %> | -<%= AskQuestion.human_attribute_name(:identity) %>:<%= @ask_question[:identity] %> | +<%= AskQuestion.human_attribute_name(:identity) %>: + <% Tag.where({:id => @ask_question[:identity]}).each do |tag| %> + <%= tag.name %> + <% end %> + | <%= AskQuestion.human_attribute_name(:mail) %>:<%= @ask_question.mail %> | <%= AskQuestion.human_attribute_name(:phone) %>:<%= @ask_question.phone %> | <%= AskQuestion.human_attribute_name(:fax) %>:<%= @ask_question.fax %> | @@ -20,7 +24,7 @@<%= AskQuestion.human_attribute_name(:title) %>:<%= @ask_question.title %> | |||||||||||||||
<%= AskQuestion.human_attribute_name(:content) %>: <%= @ask_question.content %> |
+ <%= AskQuestion.human_attribute_name(:content) %>: <%= @ask_question.content.gsub(/[(\n)(\r)]/, "\n" => " ", "\r" => "" ).html_safe %> |
||||||||||||||||||||
<%= f.label :status %> <%= f.select :status, [ - ['待處理', 'is_hot'], - ['已處理', 'is_top'], - ['轉介其他單位', 'is_hidden'] + | <%= f.label t('situation') %> <%= f.select :situation, [ + [t('is_waiting'), 'is_waiting'], + [t('is_processed'), 'is_processed'], + [t('is_referral'), 'is_referral'] ] %> | ||||||||||||||||||||
- <% if b.status == 'is_hot' %> - <%= t('待處理') %> - <% elsif b.status == 'is_top' %> - <%= t('已處理') %> - <% elsif b.status == 'is_hidden' %> - <%= t('轉介其他單位') %> + <% if b.situation == 'is_waiting' %> + <%= t('is_waiting') %> + <% elsif b.situation == 'is_processed' %> + <%= t('is_processed') %> + <% elsif b.situation == 'is_referral' %> + <%= t('is_referral') %> <% end %> | <%= b.category.title %> | diff --git a/app/views/admin/asks/email.html.erb b/app/views/admin/asks/email.html.erb index f16b23e..3684920 100644 --- a/app/views/admin/asks/email.html.erb +++ b/app/views/admin/asks/email.html.erb @@ -5,7 +5,7 @@
<%= AskQuestion.human_attribute_name(:name) %>: | +<%= AskQuestion.human_attribute_name(:name) %>: | <%= @data['name'] %> | |
---|---|---|---|
<%= AskQuestion.human_attribute_name(:identity) %>: | -<%= @data['identity'] %> | +<%= AskQuestion.human_attribute_name(:identity) %>: | ++ <% Tag.where({:id => @data['identity']}).each do |tag| %> + <%= tag.name %> + <% end %> + |
<%= AskQuestion.human_attribute_name(:mail) %>: | +<%= AskQuestion.human_attribute_name(:mail) %>: | <%= @data['mail'] %> | |
<%= AskQuestion.human_attribute_name(:phone) %>: | +<%= AskQuestion.human_attribute_name(:phone) %>: | <%= @data['phone'] %> | |
<%= AskQuestion.human_attribute_name(:fax) %>: | +<%= AskQuestion.human_attribute_name(:fax) %>: | <%= @data['fax'] %> | |
<%= AskQuestion.human_attribute_name(:content) %>: | -<%= @data['content'] %> | +<%= AskQuestion.human_attribute_name(:content) %>: | +<%= @data['content'].gsub(/[(\n)(\r)]/, "\n" => " ", "\r" => "" ).html_safe %> |
此為系統自動發信,請勿直接回覆
diff --git a/app/views/asks/index.html.erb b/app/views/asks/index.html.erb index 6e7a8f3..8d70228 100644 --- a/app/views/asks/index.html.erb +++ b/app/views/asks/index.html.erb @@ -1,6 +1,7 @@ <% data = action_data @ask_question = data["ask_question"] @categories = data["categories"] + @tags = data["tags"] @module_app = data["module_app"] %> @@ -23,14 +24,10 @@ -