finish widget
This commit is contained in:
1 parent
5ca7593a05
commit
b44b181fc7
22 files changed
+588
-101
No files matched your search
@@ -1,4 +1,5 @@
|
||||
class Admin::AskAcknowledgementsController < OrbitAdminController
|
||||
helper Admin::AsksHelper
|
||||
def initialize
|
||||
super
|
||||
@app_title = 'ask_acknowledgement'
|
||||
|
||||
@@ -14,7 +14,7 @@ class Admin::AsksController < OrbitAdminController
|
||||
|
||||
def filter_fields(categories, tags)
|
||||
{
|
||||
:situation=>[{:title=>"is_waiting",:id=>"is_waiting"},{:title=>"is_processed",:id=>"is_processed"},{:title=>"is_referral",:id=>"is_referral"}],
|
||||
:situation=>[{:title=>"ask.is_waiting",:id=>"is_waiting"},{:title=>"ask.is_processed",:id=>"is_processed"},{:title=>"ask.is_referral",:id=>"is_referral"},{:title=>"ask.is_published",:id=>"is_published"}],
|
||||
: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}}
|
||||
}
|
||||
@@ -48,11 +48,13 @@ class Admin::AsksController < OrbitAdminController
|
||||
render :json => {key: ask_setting_index.key.to_i}
|
||||
end
|
||||
def index
|
||||
@ask_setting = AskSetting.first
|
||||
@ask_setting = AskSetting.create() if @ask_setting.nil?
|
||||
@tags = @module_app.tags
|
||||
@categories = @module_app.categories
|
||||
@filter_fields = filter_fields(@categories, @tags)
|
||||
# 列表欄位
|
||||
@table_fields = [:situation, :category, 'ask.name', 'ask.phone', 'ask.appointment']
|
||||
@table_fields = [:situation, :category, 'title' , 'ask.name', 'ask.phone', 'ask.appointment']
|
||||
# 列表排序
|
||||
# debugger
|
||||
if filter2("situation").blank? and filter2("identity").blank?
|
||||
|
||||
@@ -1,22 +1,163 @@
|
||||
class AsksController < ApplicationController
|
||||
class AsksController < ActionController::Base
|
||||
helper Admin::AsksHelper
|
||||
include Admin::AsksHelper
|
||||
include ActionView::Helpers::FormHelper
|
||||
include ActionView::Helpers::FormOptionsHelper
|
||||
helper ActionView::Helpers::UrlHelper
|
||||
include ActionController::RequestForgeryProtection
|
||||
def widget
|
||||
subpart = OrbitHelper.get_current_widget
|
||||
case subpart.widget_type
|
||||
when /.*_form/
|
||||
module_app = ModuleApp.where(:key => "ask").first
|
||||
categories = Array(Category.find(OrbitHelper.page_categories)) rescue ['all']
|
||||
categories = module_app.categories if categories.include? 'all'
|
||||
tags = module_app.tags
|
||||
ask_question = AskQuestion.new
|
||||
locale = I18n.locale
|
||||
ask_setting = AskSetting.first
|
||||
ask_setting = AskSetting.create() if ask_setting.nil?
|
||||
categories = Array(Category.find(OrbitHelper.widget_categories)) rescue ['all']
|
||||
categories = module_app.categories if categories.include? 'all'
|
||||
tmp = 'mongoid.attributes.ask_question'
|
||||
defalt_fields = [{'label'=>ask_label(t('title'),'true'),'content'=>text_field_tag('ask_question[title]',nil,placeholder: t('title'),required: true)}]
|
||||
if ask_setting.default_setting['ask_category_id']
|
||||
if categories.count > 1
|
||||
defalt_fields = defalt_fields + [{'label'=>ask_label(t("#{tmp}.ask_category_id"),'true'),'content'=>select_tag('ask_question[category_id]', options_for_select(categories.collect{|t| [ t.title, t.id ]}))}]
|
||||
else
|
||||
defalt_fields = defalt_fields + [{'label'=>ask_label(t("#{tmp}.ask_category_id"),'true'),'content'=>"<span>#{@categories[0].title rescue ''}</span>"+hidden_field_tag('ask_question[category_id]', (categories[0].id.to_s rescue ''))}]
|
||||
end
|
||||
else
|
||||
defalt_fields = defalt_fields + [{'label'=>'','content'=>hidden_field_tag('ask_question[category_id]', (categories[0].id.to_s rescue ''))}]
|
||||
end
|
||||
defalt_fields = defalt_fields + ['name','sex','mail','phone','appointment'].select{|v| ask_setting.default_setting[v]}.collect do |field|
|
||||
required = ['phone','appointment'].exclude?(field) ? 'true' : 'false'
|
||||
f1 = {'label'=>ask_label(t("#{tmp}.#{field}"),required)}
|
||||
field_name = "ask_question[#{field}]"
|
||||
case field
|
||||
when 'name'
|
||||
f1['content'] = text_field_tag(field_name,nil,data: {"fv-validation" => "required;", "fv-messages" => "必填欄位;"},required: true,placeholder:t("#{tmp}.#{field}"))
|
||||
when 'sex'
|
||||
f1['content'] = "<label class=\"radio-inline\">
|
||||
#{radio_button(field_name,'male')}#{I18n.t('users.male')}
|
||||
</label>
|
||||
<label class=\"radio-inline\">
|
||||
#{radio_button(field_name,'female')}#{I18n.t('users.female')}
|
||||
</label>"
|
||||
when 'mail'
|
||||
f1['content'] = text_field_tag(field_name,nil,data: {"fv-validation" => "required;check_email;", "fv-messages" => "必填欄位;Email不正確;"},required: true,placeholder:t("#{tmp}.#{field}"))
|
||||
when 'phone'
|
||||
f1['content'] = text_field_tag(field_name,nil,placeholder:t("#{tmp}.#{field}"))
|
||||
when 'appointment'
|
||||
f1['content'] = "<div class=\"default_picker\">#{text_field_tag(field_name,placeholder:t("#{tmp}.#{field}"))}</div>"
|
||||
end
|
||||
f1
|
||||
end
|
||||
defalt_fields = defalt_fields + ask_setting.custom_fields.collect{|k,v| {'label'=>ask_label(v['field'][I18n.locale],v['required']),'content'=>show_on_front(k,v)}}
|
||||
defalt_fields << {'label'=>ask_label(t("#{tmp}.agree_show")),'content'=>check_box_tag('ask_question[agree_show]')}
|
||||
request = OrbitHelper.request
|
||||
csrf_value = OrbitHelper.request.session[:_csrf_token] || SecureRandom.base64(32)
|
||||
{
|
||||
'fields' => defalt_fields,
|
||||
'extras'=>{
|
||||
'token_tag' => hidden_field_tag('authenticity_token',csrf_value),
|
||||
'form_url' => "/#{I18n.locale.to_s}/asks",
|
||||
'submit_tag' => submit_tag(t('submit'), :class=> 'btn btn-primary', :id => 'button-mail'),
|
||||
'close_tag' => button_tag(t('cancel'), type: 'reset', :class=> 'btn'),
|
||||
'referer_url' => ''
|
||||
}
|
||||
}
|
||||
else
|
||||
data_count = OrbitHelper.widget_data_count.to_i
|
||||
if data_count != 0
|
||||
ask_questions = AskQuestion.where(situation: 'is_published').page(1).per(data_count)
|
||||
else
|
||||
ask_questions = AskQuestion.where(situation: 'is_published')
|
||||
end
|
||||
ask_index_page = Page.where(:module=>'ask').first.url rescue nil
|
||||
ask_questions = ask_questions.collect do |v|
|
||||
url = ((ask_index_page+"?item=#{v.id}") rescue "javascript:alert('#{t('ask.no_index_page')}')")
|
||||
{'td'=> [
|
||||
{'content' =>v.category.title},
|
||||
{'content' => link_to(v.title,"#{url}",title: v.title)}
|
||||
]
|
||||
}
|
||||
end
|
||||
{
|
||||
'ask_questions' => ask_questions,
|
||||
'th'=>[{'td'=>t('categories')},{'td'=>t('title')}]
|
||||
}
|
||||
end
|
||||
end
|
||||
def get_layout_type
|
||||
@params = OrbitHelper.params
|
||||
page = Page.where(url:@params['url']).first
|
||||
@layout_type = 'index'
|
||||
if page.methods.include? 'select_option_items'.to_sym
|
||||
ModuleApp.all.select{|tmp| tmp.key.to_s=='ask'}.each do |modile_app|
|
||||
@show_option_items = modile_app.show_option_items rescue nil
|
||||
end
|
||||
page.select_option_items.each do |select_option_item|
|
||||
if !(@show_option_items.nil?) && select_option_item.field_name == @show_option_items.keys.first.to_s
|
||||
value = YAML.load(select_option_item.value)
|
||||
locale = I18n.default_locale
|
||||
I18n.with_locale(locale) do
|
||||
if value[locale] == t('ask.widget.index')
|
||||
@layout_type = 'index'
|
||||
elsif value[locale] == t('ask.is_published')
|
||||
@layout_type = 'published_index'
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
def initialize
|
||||
super
|
||||
@app_title = 'ask'
|
||||
end
|
||||
|
||||
def show
|
||||
ask_question = AskQuestion.where(id: @params['item']).first
|
||||
puts ask_question.inspect
|
||||
{'ask_question' => ask_question,'layout_type'=>'show'}
|
||||
end
|
||||
def index
|
||||
module_app = ModuleApp.where(:key => "ask").first
|
||||
categories = Array(Category.find(OrbitHelper.page_categories)) rescue ['all']
|
||||
categories = module_app.categories if categories.include? 'all'
|
||||
tags = module_app.tags
|
||||
ask_question = AskQuestion.new
|
||||
{
|
||||
"ask_question" => ask_question,
|
||||
"categories" => categories,
|
||||
"tags" => tags,
|
||||
"module_app" => module_app
|
||||
}
|
||||
@params = OrbitHelper.params
|
||||
if @params['item'].to_s.empty?
|
||||
get_layout_type
|
||||
else
|
||||
@layout_type = 'show'
|
||||
end
|
||||
if @layout_type == 'index'
|
||||
module_app = ModuleApp.where(:key => "ask").first
|
||||
categories = Array(Category.find(OrbitHelper.page_categories)) rescue ['all']
|
||||
categories = module_app.categories if categories.include? 'all'
|
||||
tags = module_app.tags
|
||||
ask_question = AskQuestion.new
|
||||
{
|
||||
'layout_type' => 'index',
|
||||
'ask_question' => ask_question,
|
||||
'categories' => categories,
|
||||
'tags' => tags,
|
||||
'module_app' => module_app
|
||||
}
|
||||
elsif @layout_type == 'published_index'
|
||||
page_number = OrbitHelper.page_number.to_i
|
||||
page_number = 1 if page_number == 0
|
||||
page_data_count = OrbitHelper.page_data_count.to_i
|
||||
if page_data_count != 0
|
||||
ask_questions = AskQuestion.where(situation: 'is_published').page(page_number).per(page_data_count)
|
||||
else
|
||||
ask_questions = AskQuestion.where(situation: 'is_published')
|
||||
end
|
||||
{
|
||||
'layout_type' => 'published_index',
|
||||
'ask_questions' => ask_questions,
|
||||
'url' => @params['url']
|
||||
}
|
||||
else
|
||||
show
|
||||
end
|
||||
end
|
||||
|
||||
def create
|
||||
@@ -41,38 +182,37 @@ class AsksController < ApplicationController
|
||||
end
|
||||
|
||||
def build_email(email_er)
|
||||
email = Email.new
|
||||
email.save
|
||||
email_er.email_id = email.id
|
||||
email_er.save
|
||||
email = Email.new
|
||||
email.save
|
||||
email_er.email_id = email.id
|
||||
email_er.save
|
||||
|
||||
@group_mail = email_er.email_address
|
||||
@mail_sentdate = DateTime.now
|
||||
@group_mail = email_er.email_address
|
||||
@mail_sentdate = DateTime.now
|
||||
|
||||
email_er.email.update_attributes(
|
||||
:create_user=>current_user,
|
||||
:mail_sentdate=>@mail_sentdate,
|
||||
:module_app=>@module_app,
|
||||
:mail_to=>@group_mail,
|
||||
:mail_subject=>Site.first.title_translations["zh_tw"]+" #{t('ask.new_question')}:",
|
||||
:template=>'asks/email',
|
||||
:template_data=>{
|
||||
# "title" => email_er.title,
|
||||
"name" => email_er.name,
|
||||
"identity" => email_er[:identity],
|
||||
"mail" => email_er.mail,
|
||||
"phone" => email_er.phone,
|
||||
# "fax" => email_er.fax,
|
||||
# "content" => email_er.content
|
||||
"appointment" => email_er.appointment
|
||||
}
|
||||
)
|
||||
email_er.email.update_attributes(
|
||||
:create_user=>(current_user rescue nil),
|
||||
:mail_sentdate=>@mail_sentdate,
|
||||
:module_app=>@module_app,
|
||||
:mail_to=>@group_mail,
|
||||
:mail_subject=>Site.first.title_translations["zh_tw"]+" #{t('ask.new_question')}:",
|
||||
:template=>'asks/email',
|
||||
:template_data=>{
|
||||
# "title" => email_er.title,
|
||||
"name" => email_er.name,
|
||||
"identity" => email_er[:identity],
|
||||
"mail" => email_er.mail,
|
||||
"phone" => email_er.phone,
|
||||
# "fax" => email_er.fax,
|
||||
# "content" => email_er.content
|
||||
"appointment" => email_er.appointment
|
||||
}
|
||||
)
|
||||
|
||||
OrbitMailer.set_mail(email_er.email).deliver
|
||||
OrbitMailer.set_mail(email_er.email).deliver
|
||||
end
|
||||
|
||||
def create_params
|
||||
params.require(:ask_question).permit!
|
||||
end
|
||||
|
||||
end
|
||||
Reference in new issue
Block a user