updates for Junyi
This commit is contained in:
parent
428ef10e06
commit
40722b7070
|
|
@ -398,6 +398,17 @@ class Admin::AsksController < OrbitAdminController
|
|||
build_email(@ask_question)
|
||||
end
|
||||
|
||||
# 取得同一 ask_question 的所有歷史紀錄,依時間排序
|
||||
histories = AskStatusHistory.where(ask_question_id: @ask_question.id).order_by(:created_at.asc)
|
||||
|
||||
# 比對相鄰兩筆
|
||||
histories.each_cons(2) do |h1, h2|
|
||||
# 判斷是否為重複:同一狀態,且時間差小於 1 秒
|
||||
if h2.status == h1.status && (h2.created_at - h1.created_at).abs < 1.second
|
||||
h2.destroy
|
||||
end
|
||||
end
|
||||
|
||||
redirect_to admin_asks_path(:locale=>locale), notice: t('ask.reply_success')
|
||||
end
|
||||
|
||||
|
|
@ -413,7 +424,7 @@ class Admin::AsksController < OrbitAdminController
|
|||
@mail_sentdate = DateTime.now
|
||||
|
||||
site = Site.first
|
||||
mail_from = site.title_translations[site.default_locale]
|
||||
mail_from = site.title_translations[site['default_locale']]
|
||||
|
||||
new_history = email_er.new_history
|
||||
host_url = Site.first.root_url rescue "http://"
|
||||
|
|
@ -422,12 +433,12 @@ class Admin::AsksController < OrbitAdminController
|
|||
end
|
||||
|
||||
email_er.email.update_attributes(
|
||||
:mail_lang=> site.default_locale,
|
||||
: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('ask.reply')}:" rescue "#{t('ask.reply')}:"),
|
||||
:mail_subject=>mail_from+" #{t('ask.reply')}:",
|
||||
:template=>'admin/asks/email',
|
||||
:template_data=>{
|
||||
"host_url" => host_url,
|
||||
|
|
|
|||
|
|
@ -479,7 +479,7 @@ class AsksController < ApplicationController
|
|||
build_email(@ask_question)
|
||||
end
|
||||
if @must_verify_email
|
||||
redirect_to "#{params[:referer_url]}?method=see_email"
|
||||
redirect_to "#{params[:referer_url]}?method=see_email&email=#{@ask_question.mail}"
|
||||
else
|
||||
redirect_to "#{params[:referer_url]}?method=thank&category=#{params['ask_question']['category_id']}"
|
||||
end
|
||||
|
|
|
|||
|
|
@ -235,3 +235,64 @@
|
|||
<%= f.submit t('submit'), class: 'btn btn-primary' %>
|
||||
<%= link_to t('cancel'),cancel_href,title: t('cancel'),:class=> 'btn' %>
|
||||
</div>
|
||||
<script type="text/javascript">
|
||||
document.addEventListener("DOMContentLoaded", function() {
|
||||
const form = document.querySelector("form.main-forms");
|
||||
if (!form) return;
|
||||
|
||||
const submitButton = form.querySelector('input[type="submit"], button[type="submit"]');
|
||||
|
||||
// 取得目前欄位值
|
||||
function getFormValues(form) {
|
||||
const values = {};
|
||||
form.querySelectorAll("input, select, textarea").forEach(el => {
|
||||
if (el.type === "radio") {
|
||||
if (el.checked) values[el.name] = el.value;
|
||||
} else if (el.type === "checkbox") {
|
||||
values[el.name] = el.checked;
|
||||
} else {
|
||||
values[el.name] = el.value;
|
||||
}
|
||||
});
|
||||
return values;
|
||||
}
|
||||
|
||||
// 恢復欄位值
|
||||
function setFormValues(form, values) {
|
||||
form.querySelectorAll("input, select, textarea").forEach(el => {
|
||||
if (el.type === "radio") {
|
||||
el.checked = (values[el.name] === el.value);
|
||||
} else if (el.type === "checkbox") {
|
||||
el.checked = values[el.name] || false;
|
||||
} else {
|
||||
el.value = values[el.name] || "";
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
form.addEventListener("submit", function handler(e) {
|
||||
const systemEmailRadio = form.querySelector('input[name="ask_question[send_email]"][value="1"]');
|
||||
if (systemEmailRadio && systemEmailRadio.checked) {
|
||||
e.preventDefault();
|
||||
|
||||
// 儲存目前表單值
|
||||
const formValues = getFormValues(form);
|
||||
|
||||
if (confirm("將透過系統信箱發信 ; Email will be sent by the system")) {
|
||||
// 點 Yes → 移除 handler,送出表單
|
||||
form.removeEventListener("submit", handler);
|
||||
form.submit();
|
||||
} else {
|
||||
// 點 Cancel → 恢復欄位值 & 按鈕
|
||||
setFormValues(form, formValues);
|
||||
if (submitButton) {
|
||||
submitButton.disabled = false;
|
||||
submitButton.removeAttribute("disabled");
|
||||
submitButton.removeAttribute("data-disable-with");
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
</script>
|
||||
|
||||
|
|
|
|||
|
|
@ -1,9 +1,10 @@
|
|||
<link href="/assets/ask/ask.css" media="screen" rel="stylesheet">
|
||||
<div class="form-horizontal">
|
||||
<h2>
|
||||
<%= t('ask.see_email') %>
|
||||
<h2>
|
||||
請確認email驗證信 (<%= params[:email] %>) ,以開始填寫表單。
|
||||
|
||||
<div class="form-actions">
|
||||
<a class="btn" href="<%= OrbitHelper.request.path_info %>"><%=t('ask.go_back')%></a>
|
||||
<a class="btn" href="<%= OrbitHelper.request.path_info %>"><%= t('ask.go_back') %></a>
|
||||
</div>
|
||||
</h2>
|
||||
</div>
|
||||
Loading…
Reference in New Issue