Refine code
This commit is contained in:
parent
ee69221b8f
commit
a4db1fcd2f
|
@ -361,9 +361,9 @@ class AsksController < ApplicationController
|
||||||
email_er.email_id = email.id
|
email_er.email_id = email.id
|
||||||
email_er.save
|
email_er.save
|
||||||
|
|
||||||
@group_mail = email_er.mail
|
group_mail = email_er.mail
|
||||||
@manager_emails = email_er.reviewer_emails
|
manager_emails = email_er.reviewer_emails
|
||||||
@mail_sentdate = DateTime.now
|
mail_sentdate = DateTime.now
|
||||||
|
|
||||||
site = current_site rescue Site.first
|
site = current_site rescue Site.first
|
||||||
mail_from = site.title_translations[site.default_locale]
|
mail_from = site.title_translations[site.default_locale]
|
||||||
|
@ -375,9 +375,9 @@ class AsksController < ApplicationController
|
||||||
email_er.email.update_attributes(
|
email_er.email.update_attributes(
|
||||||
:mail_lang=> site.default_locale,
|
:mail_lang=> site.default_locale,
|
||||||
:create_user=>(current_user rescue nil),
|
:create_user=>(current_user rescue nil),
|
||||||
:mail_sentdate=>@mail_sentdate,
|
:mail_sentdate=>mail_sentdate,
|
||||||
:module_app=>@module_app,
|
:module_app=>@module_app,
|
||||||
:mail_to=>@group_mail,
|
:mail_to=>group_mail,
|
||||||
:mail_subject=>mail_subject,
|
:mail_subject=>mail_subject,
|
||||||
:template=>'asks/email',
|
:template=>'asks/email',
|
||||||
:template_data=>{
|
:template_data=>{
|
||||||
|
@ -394,16 +394,16 @@ class AsksController < ApplicationController
|
||||||
"site_host" => host_url,
|
"site_host" => host_url,
|
||||||
"usage_rule" => @usage_rule
|
"usage_rule" => @usage_rule
|
||||||
},
|
},
|
||||||
:mail_reply_to => (@manager_emails.empty? ? nil : @manager_emails)
|
:mail_reply_to => (manager_emails.empty? ? nil : manager_emails)
|
||||||
)
|
)
|
||||||
if !@manager_emails.empty?
|
if !manager_emails.empty?
|
||||||
Email.new(
|
Email.new(
|
||||||
:mail_lang=> site.default_locale,
|
:mail_lang=> site.default_locale,
|
||||||
:create_user=>(current_user rescue nil),
|
:create_user=>(current_user rescue nil),
|
||||||
:mail_sentdate=>@mail_sentdate,
|
:mail_sentdate=>mail_sentdate,
|
||||||
:module_app=>@module_app,
|
:module_app=>@module_app,
|
||||||
:mail_to=>@manager_emails,
|
:mail_to=>manager_emails,
|
||||||
:mail_subject=>mail_subject+" #{@group_mail}",
|
:mail_subject=>mail_subject+" #{group_mail}",
|
||||||
:template=>'asks/email',
|
:template=>'asks/email',
|
||||||
:template_data=>{
|
:template_data=>{
|
||||||
# "title" => email_er.title,
|
# "title" => email_er.title,
|
||||||
|
|
|
@ -155,15 +155,18 @@ class AskCategorySetting
|
||||||
field :default_setting_required, type: Hash,default: {title:true,ask_category_id: true,name: true,sex: true,mail: true,phone: false,appointment: false,recaptcha: true,agree_show: false,agree_usage: true}
|
field :default_setting_required, type: Hash,default: {title:true,ask_category_id: true,name: true,sex: true,mail: true,phone: false,appointment: false,recaptcha: true,agree_show: false,agree_usage: true}
|
||||||
field :default_setting_field_name, type: Hash,default: {}
|
field :default_setting_field_name, type: Hash,default: {}
|
||||||
field :default_setting_prompt_word, type: Hash,default: {}
|
field :default_setting_prompt_word, type: Hash,default: {}
|
||||||
field :use_default, type: Boolean, default: false
|
|
||||||
field :custom_fields, type: Hash,default: {}
|
field :custom_fields, type: Hash,default: {}
|
||||||
field :usage_rule, type: String, default: ''
|
field :usage_rule, type: String, default: ''
|
||||||
field :category_id, type: String
|
|
||||||
field :title_layout, type: Integer, default: 0
|
field :title_layout, type: Integer, default: 0
|
||||||
|
|
||||||
field :need_check_customs, type: Array, default: [] #From AskSetting
|
field :need_check_customs, type: Array, default: [] #From AskSetting
|
||||||
field :reject_customs, type: Array, default: [] #From AskSetting
|
field :reject_customs, type: Array, default: [] #From AskSetting
|
||||||
field :agree_customs, type: Array, default: [] #From AskSetting
|
field :agree_customs, type: Array, default: [] #From AskSetting
|
||||||
|
|
||||||
|
field :category_id, type: String
|
||||||
|
field :use_default, type: Boolean, default: false
|
||||||
|
|
||||||
scope :enabled, ->{any_of([{:use_default.ne=>true}, {:use_default=>true, :default_sort_number.nin=>[nil, {}]}])}
|
scope :enabled, ->{any_of([{:use_default.ne=>true}, {:use_default=>true, :default_sort_number.nin=>[nil, {}]}])}
|
||||||
scope :custom_enabled, ->{where({:use_default.ne=>true})}
|
scope :custom_enabled, ->{where({:use_default.ne=>true})}
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
class AskFile
|
class AskFile
|
||||||
include Mongoid::Document
|
include Mongoid::Document
|
||||||
include Mongoid::Timestamps
|
include Mongoid::Timestamps
|
||||||
|
|
||||||
mount_uploader :file, AssetUploader
|
mount_uploader :file, AssetUploader
|
||||||
field :ask_question_id
|
field :ask_question_id
|
||||||
end
|
end
|
|
@ -5,7 +5,7 @@ class AskQuestion
|
||||||
include OrbitCategory::Categorizable
|
include OrbitCategory::Categorizable
|
||||||
# include OrbitTag::Taggable
|
# include OrbitTag::Taggable
|
||||||
|
|
||||||
# 欄位
|
# 欄位定義
|
||||||
field :serial_number, type: Integer
|
field :serial_number, type: Integer
|
||||||
field :ip, type: String
|
field :ip, type: String
|
||||||
field :name, type: String
|
field :name, type: String
|
||||||
|
@ -15,7 +15,7 @@ class AskQuestion
|
||||||
field :fax, type: String
|
field :fax, type: String
|
||||||
field :title, type: String
|
field :title, type: String
|
||||||
field :content, type: String
|
field :content, type: String
|
||||||
field :appointment, type:DateTime
|
field :appointment, type: DateTime
|
||||||
field :sex
|
field :sex
|
||||||
|
|
||||||
field :reply, type: String
|
field :reply, type: String
|
||||||
|
@ -29,9 +29,8 @@ class AskQuestion
|
||||||
field :agree_usage, type: Boolean, default: false
|
field :agree_usage, type: Boolean, default: false
|
||||||
|
|
||||||
field :review_time, type: DateTime
|
field :review_time, type: DateTime
|
||||||
belongs_to :reviewer , :class_name=>"MemberProfile", :foreign_key => :reviewer_id
|
belongs_to :reviewer, class_name: "MemberProfile", foreign_key: :reviewer_id
|
||||||
|
|
||||||
# validates_presence_of :name, :identity, :mail, :title, :content
|
|
||||||
before_create do
|
before_create do
|
||||||
last_serial_number = AskSetting.update_last_serial_number
|
last_serial_number = AskSetting.update_last_serial_number
|
||||||
self.serial_number = last_serial_number
|
self.serial_number = last_serial_number
|
||||||
|
@ -43,9 +42,10 @@ class AskQuestion
|
||||||
def verify_email
|
def verify_email
|
||||||
verify_email = Email.where(:id=>self.verify_email_id).first
|
verify_email = Email.where(:id=>self.verify_email_id).first
|
||||||
end
|
end
|
||||||
|
|
||||||
def reviewer_emails
|
def reviewer_emails
|
||||||
email_address = AskAdmin.or(:category_ids.in => [self.category_id, [], nil]).pluck(:email).select{|s| s.present?}.uniq rescue []
|
email_address = AskAdmin.or(:category_ids.in => [self.category_id, [], nil]).pluck(:email).select { |s| s.present? }.uniq rescue []
|
||||||
authorizes = Authorization.where(:module_app_id=>ModuleApp.where(:key=>'ask').first.id).to_a rescue []
|
authorizes = Authorization.where(module_app_id: ModuleApp.where(key: 'ask').first.id).to_a rescue []
|
||||||
authorizes.each do |a|
|
authorizes.each do |a|
|
||||||
if a.category_id
|
if a.category_id
|
||||||
next if a.category_id != self.category_id
|
next if a.category_id != self.category_id
|
||||||
|
@ -54,7 +54,7 @@ class AskQuestion
|
||||||
u = a.user
|
u = a.user
|
||||||
email_address << u.email if u && u.email
|
email_address << u.email if u && u.email
|
||||||
elsif a.role_id
|
elsif a.role_id
|
||||||
email_address = email_address + MemberProfile.where(:role_ids=>a.role_id).pluck(:email).select{|s| s.present?}.uniq
|
email_address = email_address + MemberProfile.where(role_ids: a.role_id).pluck(:email).select { |s| s.present? }.uniq
|
||||||
else
|
else
|
||||||
a.destroy
|
a.destroy
|
||||||
end
|
end
|
||||||
|
@ -62,6 +62,7 @@ class AskQuestion
|
||||||
email_address = email_address.flatten
|
email_address = email_address.flatten
|
||||||
email_address.uniq
|
email_address.uniq
|
||||||
end
|
end
|
||||||
|
|
||||||
def get_serial_number(last_serial_number=nil, display_length=nil)
|
def get_serial_number(last_serial_number=nil, display_length=nil)
|
||||||
if display_length.nil? && last_serial_number.nil?
|
if display_length.nil? && last_serial_number.nil?
|
||||||
can_update_shared_hash = (defined?(OrbitHelper::SharedHash) && OrbitHelper::SharedHash)
|
can_update_shared_hash = (defined?(OrbitHelper::SharedHash) && OrbitHelper::SharedHash)
|
||||||
|
@ -70,7 +71,9 @@ class AskQuestion
|
||||||
display_length = [last_serial_number.to_s.length + 1, 4].max if display_length.nil?
|
display_length = [last_serial_number.to_s.length + 1, 4].max if display_length.nil?
|
||||||
display_format_string(self.serial_number, display_length)
|
display_format_string(self.serial_number, display_length)
|
||||||
end
|
end
|
||||||
|
|
||||||
def display_format_string(num, str_length)
|
def display_format_string(num, str_length)
|
||||||
return format("%0#{str_length}d", num)
|
format("%0#{str_length}d", num)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -182,7 +182,6 @@
|
||||||
situation_class_relation = {
|
situation_class_relation = {
|
||||||
"is_waiting"=>"label-important",
|
"is_waiting"=>"label-important",
|
||||||
"is_processed"=>"label-warning",
|
"is_processed"=>"label-warning",
|
||||||
"is_referral"=>"",
|
|
||||||
"is_published"=>"label-success"
|
"is_published"=>"label-success"
|
||||||
}
|
}
|
||||||
situation_trans = AskTicketStatus.all.map{|a| [a.key, a.title]}.to_h
|
situation_trans = AskTicketStatus.all.map{|a| [a.key, a.title]}.to_h
|
||||||
|
@ -203,7 +202,7 @@
|
||||||
<% when 'serial_number' %>
|
<% when 'serial_number' %>
|
||||||
<%= b.get_serial_number(last_serial_number, display_length) %>
|
<%= b.get_serial_number(last_serial_number, display_length) %>
|
||||||
<% when 'situation' %>
|
<% when 'situation' %>
|
||||||
<span class='label <%=situation_class_relation[b.situation]%>'><%= situation_trans[b.situation] %></span>
|
<span class='label <%= situation_class_relation[b.situation].to_s %>'><%= situation_trans[b.situation] %></span>
|
||||||
<% when 'ask_category_id' %>
|
<% when 'ask_category_id' %>
|
||||||
<%= b.category.title rescue 'category not set' %>
|
<%= b.category.title rescue 'category not set' %>
|
||||||
<% when 'sex' %>
|
<% when 'sex' %>
|
||||||
|
|
|
@ -8,6 +8,6 @@
|
||||||
<%= @data['reply'].to_s.gsub(/[(\n)(\r)]/, "\n" => "<br/>", "\r" => "" ).html_safe %>
|
<%= @data['reply'].to_s.gsub(/[(\n)(\r)]/, "\n" => "<br/>", "\r" => "" ).html_safe %>
|
||||||
</p>
|
</p>
|
||||||
<br />
|
<br />
|
||||||
<p>此為系統自動發信,請勿直接回覆</p>
|
<p><%= t('ask.email_automation_hint') %></p>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
Loading…
Reference in New Issue