新增處理狀態和回覆功能

This commit is contained in:
邱博亞 2023-05-21 17:16:16 +08:00
parent b668ad1f36
commit 77d4af01f3
14 changed files with 335 additions and 20 deletions

View File

@ -39,26 +39,54 @@ class Admin::ApplicationFormSignupsController < OrbitAdminController
@application_form_signup = ApplicationFormSignup.find(params[:id])
@application_form_signup.update_attributes(application_form_signup_params)
if !params[:application_form_signup_values].nil?
params[:application_form_signup_values].each_with_index do |r,i|
field_value = r.last[:id].present?
@custom_field_value = ApplicationFormSignupValue.put_field_values(@application_form_signup, r.last, r.last[:id], field_value)
end
application_form_reviews = ApplicationFormReview.where(:application_form_main_id=>@application_form_signup.application_form_main_id).to_a
application_form_reviews.each{|sr| sr.save}
@application_form = @application_form_signup.application_form_main
unassigned_application_form_signup_ids = @application_form.application_form_signup_ids.map{|s| s.to_s}
@application_form.application_form_reviews.each do |sr|
unassigned_application_form_signup_ids = unassigned_application_form_signup_ids - sr.all_application_form_signup_ids
end
@application_form.unassigned_application_form_signup_ids = unassigned_application_form_signup_ids
@application_form.save
# if !params[:application_form_signup_values].nil?
# params[:application_form_signup_values].each_with_index do |r,i|
# field_value = r.last[:id].present?
# @custom_field_value = ApplicationFormSignupValue.put_field_values(@application_form_signup, r.last, r.last[:id], field_value)
# end
# application_form_reviews = ApplicationFormReview.where(:application_form_main_id=>@application_form_signup.application_form_main_id).to_a
# application_form_reviews.each{|sr| sr.save}
# @application_form = @application_form_signup.application_form_main
# unassigned_application_form_signup_ids = @application_form.application_form_signup_ids.map{|s| s.to_s}
# @application_form.application_form_reviews.each do |sr|
# unassigned_application_form_signup_ids = unassigned_application_form_signup_ids - sr.all_application_form_signup_ids
# end
# @application_form.unassigned_application_form_signup_ids = unassigned_application_form_signup_ids
# @application_form.save
# end
if @application_form_signup.finish_time
build_email(@application_form_signup)
end
redirect_to "/admin/application_forms/#{@application_form_signup.application_form_main_id}/application_form_signup"
end
def build_email(email_er)
@group_mail = email_er.email
@mail_sentdate = DateTime.now
site = Site.first
mail_from = site.title_translations[site['default_locale']]
Email.create(
:mail_lang=> site['default_locale'],
:create_user=>current_user,
:mail_sentdate=>@mail_sentdate,
:module_app=>@module_app,
:mail_to=>@group_mail,
:mail_subject=>mail_from+" #{t('application_form.reply')}",
:template=>'admin/application_forms/email',
:template_data=>{
situation_title: I18n.t('application_form.situation'),
finish_time_title: I18n.t('application_form.finish_time'),
situation: (ApplicationFormTicketStatus.where(key: email_er.situation).first.title rescue nil),
finish_time: email_er.finish_time.strftime("%Y/%m/%d"),
"reply" => email_er.reply
}
)
end
def destroy
@application_form_signup = ApplicationFormSignup.find(params[:id])

View File

@ -851,6 +851,36 @@ class Admin::ApplicationFormsController < OrbitAdminController
@print_text = process_format_text(@print_text,custom_fields)
@save_name = process_format_text(@save_name,custom_fields)
end
def ticket_status
@ticket_statuses = ApplicationFormTicketStatus.all
if request.xhr?
render 'ticket_status', :layout => false
end
end
def get_ticket_status
ticket_status = ApplicationFormTicketStatus.where(:id=>params[:id]).first
render :json => {
"id"=>params[:id],
"title_translations"=> (ticket_status ? ticket_status.get_title_translations : {})
}
end
def update_ticket_status
if params[:id].blank?
ticket_status = ApplicationFormTicketStatus.new
else
ticket_status = AskTicketStatus.where(:id=>params[:id]).first
end
ticket_status.update_attributes(params.require(:application_form_ticket_status).permit!)
render :json => {:success=>true}
end
def delete_ticket_status
ticket_status = ApplicationFormTicketStatus.where(:id=>params[:id]).first
unless ticket_status.is_default
ticket_status.destroy
end
render :json => {:success=>true}
end
private

View File

@ -37,7 +37,7 @@ class ApplicationFormMain
field :contribute_file_count, type: String
field :registration_status , :type => Array #C: 投稿者 G:一般
field :registration_status , :type => Array, default: [] #C: 投稿者 G:一般
field :create_user_id
field :update_user_id

View File

@ -4,6 +4,7 @@ class ApplicationFormSetting
field :reviewer_length, default: 3, :type=> Integer
field :last_serial_number, :type => Integer, :default => 0
field :last_ticket_key, type: Integer, default: 0
def self.get_one
s = self.first
s = self.create if s.nil?

View File

@ -27,6 +27,9 @@ class ApplicationFormSignup
field :reviewer_ids_list, type: Array, default: []
field :agree_reviewer_ids, type: Hash, default: {}
field :agree_reviewer_times, type: Hash, default: {}
field :reply, type: String
field :finish_time, type: DateTime
field :situation, type: String, default: "is_waiting" #預設待處理
def reviewer_ids_list
main = self.application_form_main
main.reviewer_enables.each_with_index.collect do |e,k|

View File

@ -0,0 +1,42 @@
class ApplicationFormTicketStatus
include Mongoid::Document
include Mongoid::Timestamps
DefaultKeys = ["is_waiting", "is_processed", "is_referral", "is_published"]
field :title, type: String, localize: true
field :is_default, type: Boolean, default: false # if true => cannot delete
field :key, type: String
before_create do
if self.key.blank?
can_update_shared_hash = (defined?(OrbitHelper::SharedHash) && OrbitHelper::SharedHash)
last_ticket_key = can_update_shared_hash ? OrbitHelper::SharedHash["application_form"][:last_ticket_key] : ApplicationFormSetting.pluck(:last_ticket_key)[0].to_i
self.key = last_ticket_key.to_s
ApplicationFormSetting.all.inc({'last_ticket_key'=>1})
if can_update_shared_hash
OrbitHelper::SharedHash["application_form"][:last_ticket_key] = last_ticket_key + 1
end
end
true
end
after_destroy do
# can_update_shared_hash = (defined?(OrbitHelper::SharedHash) && OrbitHelper::SharedHash)
# ApplicationFormSetting.all.inc({'last_ticket_key'=>-1})
# if can_update_shared_hash
# OrbitHelper::SharedHash["ask"][:last_ticket_key] = OrbitHelper::SharedHash["ask"][:last_ticket_key] - 1
# end
end
def title
tmp = super
if self.is_default
tmp = I18n.t("ask.#{self.key}") if tmp.blank?
end
tmp
end
def get_title_translations(locales=nil)
locales = I18n.available_locales if locales.nil?
trans = {}
locales.each do |locale|
trans[locale] = I18n.with_locale(locale){self.title}
end
trans
end
end

View File

@ -1,4 +1,5 @@
<fieldset class="form-horizontal main-forms">
<%= form_for @application_form_signup, url: admin_application_form_signup_path(@application_form_signup), html: { class: 'form-horizontal main-forms previewable',multipart: true } do |f| %>
<fieldset>
<% content_for :page_specific_css do %>
<%= stylesheet_link_tag "lib/main-forms" %>
<%= stylesheet_link_tag "lib/fileupload" %>
@ -48,10 +49,33 @@
</div>
<% end %>
<div class="control-group">
<div class="control-label muted"><%= t('application_form.situation') %></div>
<div class="controls">
<%= f.select :situation, ApplicationFormTicketStatus.all.map{|a| [a.title, a.key]} %>
</div>
</div>
<div class="control-group">
<div class="control-label muted"><%= t('application_form.finish_time') %></div>
<div class="controls">
<%= f.datetime_picker :finish_time, :format => "yyyy/MM/dd", :new_record => @application_form_signup.new_record? %>
</div>
</div>
<div class="control-group">
<div class="control-label muted"><%= t('application_form.reply') %></div>
<div class="controls">
<%= f.text_area :reply, rows: 10, style: 'width: 500px', :required => true %>
</div>
</div>
</div>
</div>
<div class="form-actions">
<%= link_to t('application_form.go_back'), "/admin/application_forms/#{@application_form.id}/application_form_signup", :class=>"btn" %>
<%= link_to t('application_form.go_back'), "/admin/application_forms/#{@application_form.id}/application_form_signup", :class=>"btn" %>
<%= f.submit t('submit'), class: 'btn btn-primary' %>
</div>
</fieldset>
</fieldset>
<% end %>

View File

@ -0,0 +1,21 @@
<!DOCTYPE html>
<html>
<head>
<meta content="text/html; charset=UTF-8" http-equiv="Content-Type" />
</head>
<body>
<p>
<%= @data['situation_title'] %>:
<%= @data['situation'] %>
</p>
<p>
<%= @data['finish_time_title'] %>:
<%= @data['finish_time'] %>
</p>
<p>
<%= @data['reply'].to_s.gsub(/[(\n)(\r)]/, "\n" => "<br/>", "\r" => "" ).html_safe %>
</p>
<br />
<p>此為系統自動發信,請勿直接回覆</p>
</body>
</html>

View File

@ -0,0 +1,115 @@
<div id="pageslide">
<div class="page-title clearfix">
<a class="pull-right" href="javascript:$.pageslide.close()">
<i class="icons-arrow-left-2"></i>
</a>
<span></span>
</div>
<div class="view-page">
<div class="nano">
<div class="content">
<%= form_for :application_form_ticket_status, url: update_ticket_status_admin_application_forms_path, remote: true, :html=>{id: "application_form_ticket_status_form"} do |f| %>
<fieldset>
<%= hidden_field_tag :id, "", {:id=>'hidden_id_field'} %>
<%= f.fields_for :title_translations do |f| %>
<% @site_in_use_locales.each do |locale| %>
<div class="control-group">
<label class="control-label"><%= "#{t('application_form.ticket_status')} (#{t(locale)})" %></label>
<div class="controls">
<input class="input-large" id="<%=locale%>" name="<%=f.object_name%>[<%=locale%>]" placeholder="<%=t('application_form.ticket_status')%>" type="text">
</div>
</div>
<% end %>
<% end %>
<div class="form-actions">
<a href="javascript:$.pageslide.close()" class="btn btn-small"><%= t(:cancel) %></a>
<%= f.submit t(:submit), class: 'btn btn-primary btn-small', id: "application_form_ticket_status_submit" %>
</div>
</fieldset>
<% end %>
</div>
</div>
</div>
</div>
<table class="table main-list" id="status_table">
<thead>
<tr>
<th><%= t('application_form.ticket_status') %></th>
<th><%= t('application_form.action') %></th>
</tr>
</thead>
<tbody>
<% @ticket_statuses.each do |ticket_status| %>
<tr>
<td><%= ticket_status.title %></td>
<td>
<a href="#" class="btn btn-primary edit_ticket open-slide" data-id="<%=ticket_status.id%>"><%= t(:edit) %></a>
<% unless ticket_status.is_default %>
<button class="btn btn-danger delete_ticket" data-id="<%=ticket_status.id%>"><%= t(:delete_) %></button>
<% end %>
</td>
</tr>
<% end %>
</tbody>
</table>
<a href="#" class="btn btn-primary new_ticket open-slide" data-title="<%=t("add")%>"><%= t(:add) %></a>
<script>
function reload_page(){
$.get(window.location.href).done(function(data){
$('#status_table').html($(data).filter('#status_table').html());
openSlide();
})
}
$(document).ready(function(){
openSlide();
$('form#application_form_ticket_status_form').bind('ajax:success', function(evt, data, status, xhr){
window.setTimeout(function(){
reload_page();
$.pageslide.close();
}, 500);
})
$.pageslide.closeCallback(function(pageslide, item) {
$('.filter-item').removeClass("active");
});
$.pageslide.loadComplete(function(pageslide, item) {
var id = item.data('id');
var form = pageslide.find('form');
$.post('<%= get_ticket_status_admin_application_forms_path %>', {id: id}).done(function(data){
form.find('#hidden_id_field').val(id);
Object.keys(data).forEach(function(k){
var v = data[k];
if(v instanceof Object){
console.log(v);
var tmp = Object.keys(v);
if(tmp.length){
tmp.forEach(function(kk){
form.find('[name*="application_form_ticket_status['+k+']['+kk+']"').val(v[kk]);
});
}else{
form.find('[name*="application_form_ticket_status['+k+']"').val('');
}
}else{
form.find('[name*="application_form_ticket_status['+k+']"').val(v);
}
})
})
});
$(document).on('click', '.delete_ticket', function(){
var id = $(this).data('id');
var tr = $(this).parents('tr');
var sure_text = "<%=t(:are_you_sure_to_delete)%>";
if(window.confirm(sure_text)){
if(window.confirm(sure_text)){
$.ajax({
url : '<%=delete_ticket_status_admin_application_forms_path%>',
type : 'DELETE',
data: {id: id},
success: function(){
tr.remove();
}
});
}
}
})
})
</script>

View File

@ -94,6 +94,10 @@ Gem::Specification.new do |s|
s.test_files = Dir["test/**/*"]
s.installed_by_version = "2.2.2" if s.respond_to? :installed_by_version
s.metadata = {
"_require" => "#{File.expand_path("../app/models/application_form_setting", __FILE__)}",
"global_hash" => "{last_ticket_key: (ApplicationFormSetting.pluck(:last_ticket_key)[0].to_i rescue 0), last_serial_number: (ApplicationFormSetting.pluck(:last_serial_number)[0].to_i rescue 0)}"
}
# s.add_dependency "custom_announcement"
# s.add_dependency "custom_gallery"
end

View File

@ -223,6 +223,16 @@ en:
frontend:
application_form: Semianr #線上申請表單前台
ticket_status: "Ticket Status"
action: Action
situation: Situation
is_waiting: Pending
is_processed: Processed
is_referral: Rreferral
is_published: Processed and Published
reply: Reply
finish_time: Finish Time
application_form_item:
new_item: New Item #新增項目
edit_item: Edit Item #編輯項目

View File

@ -224,6 +224,16 @@ zh_tw:
frontend:
application_form: 線上申請表單前台
ticket_status: "狀態設定"
action: "動作"
situation: 狀態
is_waiting: 待處理
is_processed: 已處理
is_referral: 轉介其他單位
is_published: 已處理
reply: 回覆
finish_time: 完成日期
application_form_item:
new_item: 新增項目
edit_item: 編輯項目

View File

@ -1,6 +1,22 @@
Rails.application.routes.draw do
locales = Site.first.in_use_locales rescue I18n.available_locales
if ENV['worker_num']=='0' && File.basename($0) != 'rake' && !Rails.const_defined?('Console')
Thread.new do
begin
default_keys = ApplicationFormTicketStatus::DefaultKeys
if ApplicationFormTicketStatus.count < default_keys.count
default_keys.each do |k|
ticket_status = ApplicationFormTicketStatus.where(:is_default=>true,:key=>k).first
if ticket_status.nil?
ApplicationFormTicketStatus.create(:is_default=>true,:key=>k, :title_translations=>locales.map{|l| [l.to_s, I18n.with_locale(l){I18n.t("ask.#{k}")}]}.to_h )
end
end
end
rescue => e
puts [e, e.backtrace]
end
end
end
Thread.new do
ApplicationFormEmailSet.where(:field_name=>nil).destroy
end
@ -15,6 +31,12 @@ Rails.application.routes.draw do
get ':application_form_id/print_setting' => "application_forms#print_setting"
post 'print_setting_save'
get 'ticket_status'
post 'get_ticket_status'
post 'update_ticket_status'
delete 'delete_ticket_status'
end
resources :application_forms do
member do
@ -51,7 +73,7 @@ Rails.application.routes.draw do
end
end
resources :application_form_agreements
resources :application_form_signups, except: [:edit, :update] do
resources :application_form_signups, except: [:edit] do
member do
get 'view'
end

View File

@ -54,6 +54,11 @@ module ApplicationForm
# :priority=>6,
# :active_for_action=>{'admin/application_forms'=>'enquiry_for_applicants'},
# :available_for => 'users'
context_link 'application_form.ticket_status',
:link_path=>"ticket_status_admin_application_forms_path" ,
:priority=>6,
:active_for_action=>{'admin/application_forms'=>'ticket_status'},
:available_for => 'managers'
context_link 'application_form.setting',
:link_path=>"setting_admin_application_forms_path" ,
:priority=>7,