Merge branch '0913_ntu_ga_co' into 0913_ntu_ga_primary

This commit is contained in:
Bernie Chiu 2013-10-11 11:30:01 +08:00
commit 9ed824d615
34 changed files with 253 additions and 16 deletions

View File

@ -12,7 +12,6 @@ development:
test:
<<: *defaults
database: test_site
# set these environment variables on your prod server
production:
# host: <%= ENV['MONGOID_HOST'] %>
@ -21,4 +20,4 @@ production:
# password: <%= ENV['MONGOID_PASSWORD'] %>
# database: <%= ENV['MONGOID_DATABASE'] %>
<<: *defaults
database: test_site
database: production_8

View File

@ -0,0 +1,15 @@
class Panel::Ask::BackEnd::AskCoordinationsController < OrbitWidgetController
include AdminHelper
include OrbitControllerLib::DivisionForDisable
before_filter :for_app_manager
def initialize
super
@app_title = 'ask_coordinations'
end
def index
end
end

View File

@ -1,5 +1,5 @@
# encoding: utf-8
class Panel::Ask::BackEnd::AskRepliesController < OrbitBackendController
include AdminHelper
include OrbitControllerLib::DivisionForDisable
@ -13,19 +13,122 @@ class Panel::Ask::BackEnd::AskRepliesController < OrbitBackendController
def create
@ask_question = AskQuestion.find(params[:ask_question_id])
@ask_question.ask_reply = AskReply.new(params[:ask_reply])
@ask_reply = @ask_question.ask_reply
@ask_question.save
if @ask_question.ask_reply.send_email?
Resque.enqueue(SendAskReplyMail, @ask_reply.ask_question.id)
end
status_stack = []
new_status = ""
params[:school][:depts].each do |dns|
begin
status_stack << send_request(dns, @ask_question, @ask_reply)
rescue
status_stack << "fail"
end
end unless params[:school].nil?
success_count = status_stack.count("success")
failed_count = status_stack.count("fail")
if failed_count == 0 && success_count > 0
new_status = "轉介其他單位"
elsif failed_count > 0 && success_count > 0
new_status = "部份轉介失敗"
elsif failed_count > 0 && success_count == 0
new_status = "轉介失敗"
elsif failed_count == 0 && success_count == 0 && @ask_reply.status == "待處理"
new_status = "待處理"
elsif failed_count == 0 && success_count == 0 && @ask_reply.status == "已處理"
new_status = "已處理"
elsif failed_count == 0 && success_count == 0 && @ask_reply.status == "轉介其他單位"
new_status = "轉介失敗"
end
@ask_reply.update_attributes(status: new_status)
redirect_to panel_ask_back_end_ask_questions_path, notice: t('ask.reply_success')
end
def update
@ask_question = AskQuestion.find(params[:ask_question_id])
@ask_reply = AskReply.find(params[:id])
@ask_reply.update_attributes(params[:ask_reply])
if @ask_reply.send_email?
Resque.enqueue(SendAskReplyMail, @ask_reply.ask_question.id)
end
status_stack = []
new_status = ""
params[:school][:depts].each do |dns|
begin
status_stack << send_request(dns, @ask_question, @ask_reply)
rescue
status_stack << "fail"
end
end unless params[:school].nil?
success_count = status_stack.count("success")
failed_count = status_stack.count("fail")
if failed_count == 0 && success_count > 0
new_status = "轉介其他單位"
elsif failed_count > 0 && success_count > 0
new_status = "部份轉介失敗"
elsif failed_count > 0 && success_count == 0
new_status = "轉介失敗"
elsif failed_count == 0 && success_count == 0 && @ask_reply.status == "待處理"
new_status = "待處理"
elsif failed_count == 0 && success_count == 0 && @ask_reply.status == "已處理"
new_status = "已處理"
elsif failed_count == 0 && success_count == 0 && @ask_reply.status == "轉介其他單位"
new_status = "轉介失敗"
end
@ask_reply.update_attributes(status: new_status)
redirect_to panel_ask_back_end_ask_questions_path, notice: t('ask.reply_success')
end
def send_request(dep_dns, current_question, current_reply)
require 'net/http'
require 'uri'
require 'json'
uri_path = "/panel/ask/back_end/ask_requests/transfer_request"
uri = URI.parse("http://" + dep_dns + uri_path)
http = Net::HTTP.new(uri.host, uri.port)
request = Net::HTTP::Post.new(uri.request_uri)
body = {
# 'auth_token' => '3kjlfksjDFJ',
'name' => current_question.name,
'title' => current_question.title,
'identity' => current_question.identity,
'email' => current_question.email,
'phone' => current_question.phone,
'tax' => current_question.tax,
'content' => current_question.content,
}
#binding.pry
status = ""
3.times do
request.set_form_data(body)
request.add_field 'X-Auth-Token', '3kjlfksjDFJ'
response = http.request(request)
if response.code == "200"
status = "success"
break
else
status = "fail"
end
end
return status
# puts "Response #{response.code} #{response.message}: #{response.body}"
# flash[:notice] = response.body
# flash[:notice] = "Response #{response.code} #{response.message}: #{response.body}"
end
end

View File

@ -0,0 +1,38 @@
# encoding: utf-8
class Panel::Ask::BackEnd::AskRequestsController < OrbitBackendController
include AdminHelper
include OrbitControllerLib::DivisionForDisable
skip_before_filter :verify_authenticity_token
def transfer_request
if request.headers["HTTP_X_AUTH_TOKEN"] == '3kjlfksjDFJ'
if !AskCategory.where(key: "transferred_question").any?
@ask_category = AskCategory.new(key: "transferred_question")
@ask_category.name_translations = { "zh_tw" => "轉介的問題", "en" => "Transferred Question" }
@ask_category.save!
end
category = AskCategory.where(key: "transferred_question")
@transfered_question = AskQuestion.new(
name: params['name'],
identity: params['identity'],
email: params['email'],
phone: params['phone'],
tax: params['tax'],
title: params['title'],
content: params['content'],
ask_category_id: category.first.id)
@transfered_question.ask_reply = AskReply.new
@transfered_question.ask_reply.update_attributes(status: "待處理 (轉)")
@transfered_question.save
render :nothing => true
else
render :status => 500
end
end
end

View File

@ -14,18 +14,22 @@ class Panel::Ask::FrontEnd::AskQuestionsController < OrbitWidgetController
def create
@ask_question = AskQuestion.new(params[:ask_question])
if gotcha_valid? && @ask_question.save
@acknowledgement = AskAcknowledgement.last
@acknowledgement = AskAcknowledgement.last
@ask_acknowledgement = AskAcknowledgement.first || AskAcknowlegement.new
#@ask_question.save
redirect_to root_path
AskAdmin.all.each do |ask_admin|
AskMailer.notice(ask_admin, @ask_question).deliver
Resque.enqueue(SendAskNoticeMail, ask_admin.id, @ask_question.id)
end
# redirect_to panel_ask_front_end_thank_you_path
# Render to create.js.erb
respond_to do |format|
format.js
# format.js { render :thank_you, notice: 'Your question has been successfully sent.' }
end
else
# Render to index.js.erb
respond_to do |format|
format.js { render :index }
end
end
end
@ -43,4 +47,7 @@ class Panel::Ask::FrontEnd::AskQuestionsController < OrbitWidgetController
end
@item = Page.find(params[:page_id]) rescue nil
end
def sorry
end
end

View File

@ -1,3 +1,47 @@
<script type="text/javascript">
var local_host = "<%= request.host %>:<%= request.port %>";
function hide_current_host_name(localhost) {
$('input[type=checkbox]').each(function() {
if ($(this).val() == local_host) {
$(this).addClass("hide");
$(this).next().addClass("hide");
}
});
}
$(document).ready(function() {
if ($("#ask_reply_status").val() == '轉介其他單位') {
hide_current_host_name(local_host);
$('.dept_options').show();
}
$("#ask_reply_status").change(function() {
hide_current_host_name(local_host);
$('.dept_options').slideUp();
if ($(this).find('option:selected').attr('value') == '轉介其他單位') {
$('.dept_options').slideDown();
}
});
});
</script>
<style type="text/css">
.dept_options {
display: none;
}
.hide {
display: none;
}
</style>
<div id="ask_question_reply">
<%= form_for @ask_reply, url: @url, method: @method do |f| %>
<table class="table">
@ -31,7 +75,29 @@
['已處理', '已處理'],
['轉介其他單位', '轉介其他單位']
] %></td>
<td id="XXX"></td>
</tr>
<tr>
<td colspan="5" class="dept_options">
<div class="dept_options">
<%= check_box("school", "depts", {:multiple => true}, 'ntu_ga_test_p.tp.rulingcom.com:80', nil) %><%= label_tag("ntu_ga_test_p.tp.rulingcom.com:80", "測試站總務處 (ntu_ga_test_p)") %>
<%= check_box("school", "depts", {:multiple => true}, 'ntu_ga_test.tp.rulingcom.com:80', nil) %><%= label_tag("ntu_ga_test.tp.rulingcom.com:80", "測試站總務處經管組 (ntu_ga_test)") %>
<!-- <%= check_box("school", "depts", {:multiple => true}, (request.host + ":3000"), nil) %><%= label_tag((request.host + ":3000"), "測試站3000") %>
<%= check_box("school", "depts", {:multiple => true}, (request.host + ":4000"), nil) %><%= label_tag((request.host + ":4000"), "測試站4000") %> -->
<%= check_box("school", "depts", {:multiple => true}, "", nil) %><%= label_tag(:dep1, "總務長室暨總務處秘書室") %>
<%= check_box("school", "depts", {:multiple => true}, "文書組", nil) %><%= label_tag(:dep2, "文書組") %>
<%= check_box("school", "depts", {:multiple => true}, "事務組", nil) %><%= label_tag(:dep3, "事務組") %>
<%= check_box("school", "depts", {:multiple => true}, "保管組", nil) %><%= label_tag(:dep4, "保管組") %>
<%= check_box("school", "depts", {:multiple => true}, "營繕組", nil) %><%= label_tag(:dep5, "營繕組") %>
<%= check_box("school", "depts", {:multiple => true}, "出納組", nil) %><%= label_tag(:dep6, "出納組") %>
<%= check_box("school", "depts", {:multiple => true}, "採購組", nil) %><%= label_tag(:dep7, "採購組") %>
<%= check_box("school", "depts", {:multiple => true}, "經營管理組", nil) %><%= label_tag(:dep8, "經營管理組") %>
<%= check_box("school", "depts", {:multiple => true}, "駐警隊", nil) %><%= label_tag(:dep9, "駐警隊") %>
<%= check_box("school", "depts", {:multiple => true}, "社科院總務分處", nil) %><%= label_tag(:dep10, "社科院總務分處") %>
<%= check_box("school", "depts", {:multiple => true}, "醫學院總務分處", nil) %><%= label_tag(:dep11, "醫學院總務分處") %>
</div>
</td>
</tr>
<tr>
<td colspan="5">
<%= f.label :send_email %><%= f.radio_button :send_email, 1, checked: @ask_reply.send_email? %><%= t('ask.yes') %>

View File

@ -1 +1 @@
window.location.href= "<%= panel_ask_front_end_thank_you_path %>"
window.location.href = "<%= panel_ask_front_end_thank_you_path %>";

View File

@ -21,9 +21,9 @@ $(document).ready(function(){
$(this).hide();
}).bind("ajaxError", function() {
$(this).hide();
// window.location.href = "<%= panel_ask_front_end_thank_you_path %>";
});
});
});
</script>
<div id="spinner" class="spinner" style="display:none;">
@ -31,11 +31,11 @@ $(document).ready(function(){
</div>
<div id="new-ask-question" class="ask-question">
<div id="acknowledgement"></div>
<%= form_for @ask_question, url: panel_ask_front_end_ask_questions_path(standalone: true), html: {class: 'form-horizontal'} do |f| %>
<%= form_for @ask_question, url: panel_ask_front_end_ask_questions_path(standalone: true), html: {class: 'form-horizontal'}, method: :post do |f| %>
<div class="control-group">
<%= f.label :ask_category_id, class: 'control-label required' %>
<div class="controls">
<%= f.collection_select :ask_category_id, AskCategory.all, :id, :name %>
<%= f.collection_select :ask_category_id, AskCategory.all.select { |c| c.key != 'transferred_question' }, :id, :name %>
</div>
</div>
<div class="control-group">

View File

@ -0,0 +1 @@
window.location.href = "<%= panel_ask_front_end_sorry_path %>";

View File

@ -0,0 +1 @@
<h3><%= t(:ask_fail, :scope => :ask) %> !</h3>

View File

@ -1,5 +1,6 @@
en:
ask:
ask_fail: Something went wrong
ask: Ask
export: Export
reply: Reply

View File

@ -3,6 +3,7 @@ zh_tw:
errors:
verification_failed: 驗證碼錯誤
ask:
ask_fail: 寄送失敗
ask: 發問
export: 匯出
reply: 回覆

View File

@ -11,14 +11,18 @@ Rails.application.routes.draw do
end
resources :ask_replies
end
resources :ask_categories
resources :ask_acknowledgements
resources :ask_admins
match "ask_requests/auth_request" => "ask_requests#auth_request", :as => 'auth_request'
match "ask_requests/transfer_request" => "ask_requests#transfer_request", :as => 'transfer_request'
end
namespace :front_end do
match "ask_questions/thank_you" => "ask_questions#thank_you", :as => 'thank_you'
match "ask_questions/sorry" => "ask_questions#sorry", :as => 'sorry'
resources :ask_questions
end
end

View File

@ -17,6 +17,6 @@
<div class="form-actions form-fixed pagination-right">
<%= link_to content_tag(:i, nil, :class => 'icon-plus icon-white') + t(:add), new_panel_faq_back_end_qa_path, :class => 'btn btn-primary pull-right' if (is_manager? rescue nil) %>
<div id="qa_pagination" class="paginationFixed">
<%= paginate @qas, :params => {:direction => params[:direction], :sort => params[:sort], :filter => @filter, :new_filter => nil} %>
<%= paginate @qas, :params => {:direction => params[:direction], :sort => params[:sort], :filter => @filter, :new_filter => nil} rescue nil %>
</div>
</div>

View File

@ -22,7 +22,8 @@ module Faq
default_widget do
enable ["typeA"]
query 'Survey.any_of( {:postdate.lte => Time.now} )'
link_field :title, {:method => 'panel_survey_front_end_survey_path',:args=>:self}
# link_field :title, {:method => 'panel_survey_front_end_survey_path',:args=>:self}
field :title
field :time_range
field :write
field :result