This commit is contained in:
Manson Wang 2014-02-11 14:27:01 +08:00
parent 893734b8d1
commit daf62e1542
11 changed files with 249 additions and 23 deletions

View File

@ -0,0 +1,45 @@
# encoding: utf-8
class Panel::Ask::BackEnd::AskRequestsController < OrbitBackendController
include AdminHelper
#include OrbitControllerLib::DivisionForDisable
#before_filter :for_app_manager
skip_before_filter :verify_authenticity_token
open_for_visitor :only => [:transferred_request]
def transferred_request
app_title = request.fullpath.split('/')[2]
module_app ||= ModuleApp.first(conditions: {:key => app_title} )
if request.headers["HTTP_X_AUTH_TOKEN"] == '3kjlfksjDFJ'
if !module_app.categories.where("title.en" => "Transferred Question").any?
ask_category = module_app.categories.build
ask_category.title_translations = { "zh_tw" => "轉介的問題", "en" => "Transferred Question" }
ask_category.save!
end
module_app.categories.enabled
category = module_app.categories.where("title.en" => "Transferred Question").first
@transferred_question = AskQuestion.new(
name: params['name'],
identity: params['identity'],
email: params['email'],
phone: params['phone'],
tax: params['tax'],
title: params['title'],
content: params['content'],
category_id: category.id)
@transferred_question.ask_reply = AskReply.new
@transferred_question.ask_reply.update_attributes(status: "待處理 (轉)")
@transferred_question.save
render :nothing => true
else
render :status => 500
end
end
end

View File

@ -1,13 +1,14 @@
class Panel::Ask::BackEnd::AskAcknowledgementsController < OrbitBackendController
include AdminHelper
include OrbitControllerLib::DivisionForDisable
#include AdminHelper
#include OrbitControllerLib::DivisionForDisable
before_filter :for_app_manager
#before_filter :for_app_manager
open_for_manager
def initialize
super
@app_title = 'ask_acknowledgement'
end
#def initialize
# super
# @app_title = 'ask_acknowledgement'
#end
def index
@ask_acknowledgement = AskAcknowledgement.first || AskAcknowledgement.create

View File

@ -1,14 +1,15 @@
class Panel::Ask::BackEnd::AskAdminsController < OrbitBackendController
include AdminHelper
include OrbitControllerLib::DivisionForDisable
#include AdminHelper
#include OrbitControllerLib::DivisionForDisable
before_filter :for_app_manager
#before_filter :for_app_manager
open_for_manager
def initialize
super
@app_title = 'ask_admins'
end
#def initialize
# super
# @app_title = 'ask_admins'
#end
def index
@ask_admins = AskAdmin.all

View File

@ -1,11 +1,11 @@
require 'csv'
class Panel::Ask::BackEnd::AskQuestionsController < OrbitBackendController
def initialize
super
@app_title = 'ask_questions'
end
require 'csv'
# def initialize
# super
# @app_title = 'ask_questions'
# end
def index
@ask_questions = AskQuestion.all
@ -53,10 +53,12 @@ class Panel::Ask::BackEnd::AskQuestionsController < OrbitBackendController
Rails.application.config.mongoid.use_activesupport_time_zone = true
date_start = "#{params[:export]['start(1i)']}-#{params[:export]['start(2i)']}-#{params[:export]['start(3i)']}"
date_end = "#{params[:export]['end(1i)']}-#{params[:export]['end(2i)']}-#{params[:export]['end(3i)']}"
@ask_questions = AskQuestion.includes(:ask_category).includes(:ask_reply).where(:created_at.gte => date_start, :created_at.lte => date_end)
#@ask_questions = AskQuestion.includes(:ask_category).includes(:ask_reply).where(:created_at.gte => date_start, :created_at.lte => date_end)
@ask_questions = AskQuestion.where(:created_at.gte => date_start, :created_at.lte => date_end)
csv = CSV.generate do |csv|
csv << [ t('category'),
csv << [ t('status'),
t('category'),
AskQuestion.human_attribute_name(:name),
AskQuestion.human_attribute_name(:identity),
AskQuestion.human_attribute_name(:email),
@ -68,7 +70,8 @@ class Panel::Ask::BackEnd::AskQuestionsController < OrbitBackendController
AskReply.human_attribute_name(:comment)]
@ask_questions.each do |ask_question|
ask_question.ask_reply ||= AskReply.new
csv << [ ask_question.ask_category.name,
csv << [ ask_question.ask_reply.status,
ask_question.category.title,
ask_question.name,
ask_question.identity,
ask_question.email,

View File

@ -1,3 +1,4 @@
# encoding: utf-8
class Panel::Ask::BackEnd::AskRepliesController < OrbitBackendController
include AdminHelper
@ -13,19 +14,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[:ask_reply][:depts].each do |dns|
# host = dns.split(":").first # local test
begin
status_stack << send_request(dns, @ask_reply.ask_question, @ask_reply) # local test, switch host to dns if on server
rescue
status_stack << "fail"
end
end if params[:ask_reply][:status] == "轉介其他單位"
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_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[:ask_reply][:depts].each do |dns|
# host = dns.split(":").first # local test
begin
status_stack << send_request(dns, @ask_reply.ask_question, @ask_reply) # local test, switch host to dns if on server
rescue
status_stack << "fail"
end
end if params[:ask_reply][:status] == "轉介其他單位"
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
private
def send_request(dep_dns, current_question, current_reply)
require 'net/http'
require 'uri'
require 'json'
uri_path = "/panel/ask/back_end/ask_requests/transferred_request"
http = Net::HTTP.new(dep_dns, 80) # port 4000 for local test, switch to port 80 for deployment
req = Net::HTTP::Post.new(uri_path)
body = {
'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
}
status = ""
req.set_form_data(body)
req.add_field 'X-Auth-Token', '3kjlfksjDFJ'
response = http.request(req)
if response.code == "200"
status = "success"
else
status = "fail"
end
return status
end
end

View File

@ -6,6 +6,7 @@ class AskReply
field :comment, type: String
field :status, type: String
field :send_email, type: Boolean, detault: false
field :depts, :type => Array
belongs_to :ask_question
end

View File

@ -1,3 +1,45 @@
<script type="text/javascript">
var local_host = "<%= request.host %>";
// var local_host = "<%= request.host_with_port %>"; // local test
if (local_host[0] == "g" && local_host[1] == "a") {
local_host = "www." + local_host;
}
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() {
$('.dept_options').hide();
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>
<div id="ask_question_reply">
<%= form_for @ask_reply, url: @url, method: @method do |f| %>
<table class="table">
@ -32,6 +74,26 @@
['轉介其他單位', '轉介其他單位']
] %></td>
</tr>
<tr>
<td colspan="5" class="dept_options">
<div class="checkbox">
<!-- <%= 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("ask_reply", "depts", {:multiple => true}, "www.ga.ntu.edu.tw", nil) %><%= label_tag("www.ga.ntu.edu.tw", "總務處") %>
<%= check_box("ask_reply", "depts", {:multiple => true}, "sec.ga.ntu.edu.tw", nil) %><%= label_tag("sec.ga.ntu.edu.tw", "總務長室暨總務處秘書室") %>
<%= check_box("ask_reply", "depts", {:multiple => true}, "doc.ga.ntu.edu.tw", nil) %><%= label_tag("doc.ga.ntu.edu.tw", "文書組") %>
<%= check_box("ask_reply", "depts", {:multiple => true}, "general.ga.ntu.edu.tw", nil) %><%= label_tag("general.ga.ntu.edu.tw", "事務組") %>
<%= check_box("ask_reply", "depts", {:multiple => true}, "property.ga.ntu.edu.tw", nil) %><%= label_tag("property.ga.ntu.edu.tw", "保管組") %>
<%= check_box("ask_reply", "depts", {:multiple => true}, "construction.ga.ntu.edu.tw", nil) %><%= label_tag("construction.ga.ntu.edu.tw", "營繕組") %>
<%= check_box("ask_reply", "depts", {:multiple => true}, "cashier.ga.ntu.edu.tw", nil) %><%= label_tag("cashier.ga.ntu.edu.tw", "出納組") %>
<%= check_box("ask_reply", "depts", {:multiple => true}, "procurement.ga.ntu.edu.tw", nil) %><%= label_tag("procurement.ga.ntu.edu.tw", "採購組") %>
<%= check_box("ask_reply", "depts", {:multiple => true}, "fss.ga.ntu.edu.tw", nil) %><%= label_tag("fss.ga.ntu.edu.tw", "經營管理組") %>
<%= check_box("ask_reply", "depts", {:multiple => true}, "police.ga.ntu.edu.tw", nil) %><%= label_tag("police.ga.ntu.edu.tw", "駐警隊") %>
<%= check_box("ask_reply", "depts", {:multiple => true}, "social.ga.ntu.edu.tw", nil) %><%= label_tag("social.ga.ntu.edu.tw", "社科院總務分處") %>
<%= check_box("ask_reply", "depts", {:multiple => true}, "medicine.ga.ntu.edu.tw", nil) %><%= label_tag("medicine.ga.ntu.edu.tw", "醫學院總務分處") %>
</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

@ -84,8 +84,11 @@ $(document).ready(function(){
<%= f.text_area :content, rows: 8, class: 'input-xlarge' %>
</div>
</div>
<div class="control-group">
<%= f.label t('ask.validate_code'), class: 'control-label required' %>
<div class="controls">
<label><%= t('ask.validate_code_note') %></label>
<%= gotcha_error %>
<%= gotcha%>
</div>

View File

@ -17,6 +17,8 @@ en:
admin: Administrator
new_question: New question
pending: Pending
validate_code: Verification code
validate_code_note: Please answer the following verification questions.
mongoid:
attributes:
ask_question:

View File

@ -22,6 +22,8 @@ zh_tw:
admin: 管理者
new_question: 新的發問
pending: 待處理
validate_code: 驗證碼
validate_code_note: 請回答下列驗證問句。
mongoid:
attributes:
ask_question:

View File

@ -15,6 +15,8 @@ Rails.application.routes.draw do
resources :ask_categories
resources :ask_acknowledgements
resources :ask_admins
match "ask_requests/transferred_request" => "ask_requests#transferred_request", :as => 'transferred_request', :via => :post
end
namespace :front_end do