2022-10-11 15:16:34 +00:00
|
|
|
<script>
|
|
|
|
if(document.querySelectorAll("#orbit-bar").length==0) location.reload();
|
|
|
|
if( Array.prototype.delete == undefined ){
|
|
|
|
Array.prototype.delete = function(v){
|
|
|
|
var idx = this.indexOf(v);
|
|
|
|
if(idx != -1){
|
|
|
|
return this.splice(idx, 1)[0];
|
|
|
|
}else{
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
function reload_tbody(url){
|
|
|
|
console.log("done");
|
|
|
|
if(url == undefined){
|
|
|
|
url = window.location.href;
|
|
|
|
}
|
|
|
|
$.get(url).done(function(data){
|
|
|
|
$('#index_table tbody').replaceWith($(data).find('tbody'));
|
|
|
|
if(window.scroll_top){
|
|
|
|
$(window).scrollTop(window.scroll_top);
|
|
|
|
}
|
|
|
|
window.batch_select_asks = [];
|
|
|
|
$(".delete_asks_btn, .batch_modify_status_btn").addClass('hide');
|
|
|
|
});
|
|
|
|
}
|
|
|
|
$(document).on("click", ".batch_select", function(){
|
|
|
|
var that = $(this);
|
|
|
|
var id = that.data("id");
|
|
|
|
if(window.batch_select_asks == undefined){
|
|
|
|
window.batch_select_asks = [];
|
|
|
|
}
|
|
|
|
if(that.prop("checked")){
|
|
|
|
window.batch_select_asks.push(id);
|
|
|
|
}else{
|
|
|
|
window.batch_select_asks.delete(id);
|
|
|
|
}
|
|
|
|
if(window.batch_select_asks.length == 0){
|
|
|
|
$(".delete_asks_btn, .batch_modify_status_btn").addClass('hide');
|
|
|
|
}else{
|
|
|
|
$(".delete_asks_btn, .batch_modify_status_btn").removeClass('hide');
|
|
|
|
}
|
|
|
|
})
|
|
|
|
function batch_delete_asks(){
|
|
|
|
if(!window.batch_select_asks || window.batch_select_asks.length == 0){
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
var data = new FormData();
|
|
|
|
var csrf_token = document
|
|
|
|
.querySelector("meta[name='csrf-token']")
|
|
|
|
.getAttribute("content");
|
|
|
|
var csrf_param = document
|
|
|
|
.querySelector("meta[name='csrf-param']")
|
|
|
|
.getAttribute("content");
|
|
|
|
if (csrf_token && csrf_param) {
|
|
|
|
data.append(csrf_param, csrf_token);
|
|
|
|
}
|
|
|
|
window.batch_select_asks.forEach(function(val){
|
|
|
|
data.append('ids[]', val);
|
|
|
|
});
|
|
|
|
$.ajax({
|
|
|
|
url: "<%=delete_admin_asks_path%>",
|
|
|
|
method: 'DELETE',
|
|
|
|
data: data,
|
|
|
|
headers: {
|
|
|
|
// 'Content-Type': 'multipart/form-data',
|
|
|
|
// 使用 multipart/form-data 在此不需要設定 Content-Type。
|
|
|
|
'X-Requested-With': 'XMLHttpRequest',
|
|
|
|
'Authorization': `Bearer ${ csrf_token }`,
|
|
|
|
},
|
|
|
|
contentType: false, //required
|
|
|
|
processData: false, // required
|
|
|
|
statusCode: {
|
|
|
|
204: reload_tbody,
|
|
|
|
403: function() {
|
|
|
|
alert( "Delete failed!" );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
function batch_edit_status_asks(){
|
|
|
|
if($('#dialog-batch-modify-status').length == 0){
|
|
|
|
var li_statuses = "";
|
|
|
|
<% AskTicketStatus.all.each do |s| %>
|
|
|
|
li_statuses += "<li style=\"list-style: none;\"><label><input type=\"radio\" name=\"status_key\" value=\"<%=s.key%>\"><%=s.title%></label></li>"
|
|
|
|
<% end%>
|
|
|
|
$("#main-wrap").before("<div id='dialog-batch-modify-status' title='"+"<%= t('ask.batch_modify_status') %>'>"+
|
|
|
|
"<div style='clear:both;'></div><div><ul>"+ li_statuses +"</ul></div>"+
|
|
|
|
"</div>");
|
|
|
|
}else{
|
|
|
|
$('[name="status_key"]').prop('checked',false);
|
|
|
|
}
|
|
|
|
$( "#dialog-batch-modify-status" ).dialog({
|
|
|
|
resizable: true,
|
|
|
|
minHeight: 100,
|
|
|
|
maxHeight: 400,
|
|
|
|
modal: true,
|
|
|
|
buttons: {
|
|
|
|
"<%= t(:confirm) %>": function(){
|
|
|
|
var status_key = $('[name="status_key"]:checked').val();
|
|
|
|
if(status_key){
|
|
|
|
if(window.confirm("<%=t(:sure?)%>")){
|
|
|
|
var data = new FormData();
|
|
|
|
var csrf_token = document
|
|
|
|
.querySelector("meta[name='csrf-token']")
|
|
|
|
.getAttribute("content");
|
|
|
|
var csrf_param = document
|
|
|
|
.querySelector("meta[name='csrf-param']")
|
|
|
|
.getAttribute("content");
|
|
|
|
if (csrf_token && csrf_param) {
|
|
|
|
data.append(csrf_param, csrf_token);
|
|
|
|
}
|
|
|
|
window.batch_select_asks.forEach(function(val){
|
|
|
|
data.append('ids[]', val);
|
|
|
|
});
|
|
|
|
data.append("status_key", status_key);
|
|
|
|
$.ajax({
|
|
|
|
url: "<%=batch_modify_status_admin_asks_path%>",
|
|
|
|
method: 'POST',
|
|
|
|
data: data,
|
|
|
|
headers: {
|
|
|
|
// 'Content-Type': 'multipart/form-data',
|
|
|
|
// 使用 multipart/form-data 在此不需要設定 Content-Type。
|
|
|
|
'X-Requested-With': 'XMLHttpRequest',
|
|
|
|
'Authorization': `Bearer ${ csrf_token }`,
|
|
|
|
},
|
|
|
|
contentType: false, //required
|
|
|
|
processData: false, // required
|
|
|
|
statusCode: {
|
|
|
|
204: reload_tbody,
|
|
|
|
403: function() {
|
|
|
|
alert( "Edit status failed!" );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
$( this ).dialog( "close" );
|
|
|
|
},
|
|
|
|
"<%= t(:cancel) %>": function() {
|
|
|
|
$( this ).dialog( "close" );
|
|
|
|
$( this ).remove();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
$(document).on("click", ".delete_asks_btn", function(){
|
|
|
|
if(window.confirm("<%=t(:sure?)%>")){
|
|
|
|
if(window.confirm("<%=t(:sure?)%>")){
|
|
|
|
batch_delete_asks();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
|
|
|
$(document).on("click", ".batch_modify_status_btn", function(){
|
|
|
|
batch_edit_status_asks();
|
|
|
|
})
|
|
|
|
</script>
|
|
|
|
<div>
|
|
|
|
<form>
|
|
|
|
<h4><%= t(:category) %></h4>
|
|
|
|
<select name="category" id="submit_when_change">
|
|
|
|
<% @cats_relations.each do |id, title| %>
|
|
|
|
<option value="<%=id%>" <%= @category_id == id ? 'selected' : '' %>><%= title %></option>
|
|
|
|
<% end %>
|
|
|
|
</select>
|
|
|
|
</form>
|
|
|
|
</div>
|
2014-10-02 06:00:35 +00:00
|
|
|
<table class="table main-list">
|
|
|
|
<thead>
|
|
|
|
<tr class="sort-header">
|
2022-10-11 15:16:34 +00:00
|
|
|
<th style="width: 1em;"></th>
|
2014-10-02 06:00:35 +00:00
|
|
|
<% @table_fields.each do |f| %>
|
2022-10-14 14:33:04 +00:00
|
|
|
<%= ask_thead(f, @ask_setting.field_name(f)) %>
|
2022-10-11 15:16:34 +00:00
|
|
|
<% end %>
|
|
|
|
<% @table_ext_fields.each do |f, v| %>
|
|
|
|
<%= ask_thead(f, v['field'][I18n.locale.to_s]) %>
|
2014-10-02 06:00:35 +00:00
|
|
|
<% end %>
|
|
|
|
</tr>
|
|
|
|
</thead>
|
|
|
|
<tbody>
|
2022-07-07 08:54:09 +00:00
|
|
|
<%
|
|
|
|
situation_class_relation = {
|
|
|
|
"is_waiting"=>"label-important",
|
|
|
|
"is_processed"=>"label-warning",
|
|
|
|
"is_referral"=>"",
|
|
|
|
"is_published"=>"label-success"
|
|
|
|
}
|
|
|
|
situation_trans = AskTicketStatus.all.map{|a| [a.key, a.title]}.to_h
|
2022-08-18 03:07:45 +00:00
|
|
|
last_serial_number = @ask_setting.last_serial_number
|
|
|
|
display_length = [last_serial_number.to_s.length + 1, 4].max
|
2022-10-14 14:33:04 +00:00
|
|
|
edit_button_display_index = @table_fields.count > 3 ? 2 : @table_fields.count
|
2022-07-07 08:54:09 +00:00
|
|
|
%>
|
2014-10-02 06:00:35 +00:00
|
|
|
<% @askquestions.each do |b| %>
|
|
|
|
<tr>
|
2022-10-14 14:33:04 +00:00
|
|
|
<% is_editable = can_edit_or_delete?(b)
|
|
|
|
ask_show_url = Page.where(:module=>'ask').first.url rescue nil
|
|
|
|
edit_button_can_show = true
|
|
|
|
%>
|
|
|
|
<% content_for :edit_button do %>
|
|
|
|
<div class="quick-edit">
|
|
|
|
<ul class="nav nav-pills">
|
|
|
|
<% if is_editable %>
|
|
|
|
<li><a href="/<%= I18n.locale %>/admin/asks/<%=b.id.to_s%>/edit"><%= t(:edit) %></a></li>
|
|
|
|
<li><a href="#" class="delete text-error" rel="/admin/asks/<%=b.id.to_s%>"><%= t(:delete_) %></a></li>
|
|
|
|
<% end %>
|
|
|
|
<li><a href="/<%= I18n.locale %>/admin/asks/<%=b.id.to_s%>/print" target="_blank"><%= t('ask.print') %></a></li>
|
|
|
|
</ul>
|
|
|
|
</div>
|
|
|
|
<% end %>
|
2022-10-11 15:16:34 +00:00
|
|
|
<td><% if is_editable %><input type="checkbox" class="batch_select" data-id="<%= b.id %>"><% end %></td>
|
2022-10-14 14:33:04 +00:00
|
|
|
<% @table_fields.each_with_index do |f,i| %>
|
2022-10-11 15:16:34 +00:00
|
|
|
<td>
|
2022-10-14 14:33:04 +00:00
|
|
|
<% case f %>
|
|
|
|
<% when 'serial_number' %>
|
|
|
|
<%= b.get_serial_number(last_serial_number, display_length) %>
|
|
|
|
<% when 'situation' %>
|
|
|
|
<span class='label <%=situation_class_relation[b.situation]%>'><%= situation_trans[b.situation] %></span>
|
|
|
|
<% when 'ask_category_id' %>
|
|
|
|
<%= b.category.title rescue 'category not set' %>
|
|
|
|
<% when 'sex' %>
|
|
|
|
<%= ['male','female'].include?(sex.to_s) ? t("mongoid.attributes.ask_question.#{sex}") : '' %>
|
|
|
|
<% when 'mail' %>
|
|
|
|
<%= b.mail %>
|
|
|
|
<% when 'title' %>
|
|
|
|
<% if b.situation == 'is_published' %>
|
|
|
|
<%= link_to b.title, (ask_show_url ? (ask_show_url+"?item=#{b.id}") : "javascript:alert('#{t('ask.no_index_page')}')") %>
|
|
|
|
<% else %>
|
|
|
|
<%= b.title %>
|
|
|
|
<% end %>
|
|
|
|
<% when 'name' %>
|
|
|
|
<%= b.name %>
|
|
|
|
<% when 'phone' %>
|
|
|
|
<%= b.phone %>
|
|
|
|
<% when 'appointment' %>
|
|
|
|
<%= b.appointment.strftime("%Y-%m-%d %H:%M") rescue nil %>
|
|
|
|
<% when 'created_at' %>
|
|
|
|
<%= b.created_at.strftime("%Y-%m-%d %H:%M") rescue nil %>
|
|
|
|
<% when 'ip' %>
|
|
|
|
<%= b.ip %>
|
|
|
|
<% end %>
|
|
|
|
<% if edit_button_display_index == i %>
|
|
|
|
<%= yield :edit_button %>
|
2022-10-11 15:16:34 +00:00
|
|
|
<% end %>
|
|
|
|
</td>
|
|
|
|
<% end %>
|
|
|
|
<% @table_ext_fields.each do |f, v| %>
|
|
|
|
<td>
|
|
|
|
<%= show_on_front(f,v,b.custom_values[f],true) %>
|
|
|
|
</td>
|
2020-04-30 05:18:02 +00:00
|
|
|
<% end %>
|
2014-10-02 06:00:35 +00:00
|
|
|
</tr>
|
|
|
|
<% end %>
|
|
|
|
</tbody>
|
|
|
|
</table>
|
|
|
|
|
|
|
|
<%=
|
|
|
|
content_tag :div, class: "bottomnav clearfix" do
|
|
|
|
content_tag :div, paginate(@askquestions), class: "pagination pagination-centered"
|
2022-10-11 15:16:34 +00:00
|
|
|
content_tag :div, link_to(I18n.t('ask.display_fields_setting'), backend_table_setting_admin_asks_path + (@category_id.present? ? "?category_id=#{@category_id}" : ''), :class=>'btn btn-primary' ) + link_to(t("ask.delete_selected"), "javascript:void(0)", :class=>"btn btn-danger delete_asks_btn hide", :style=>'margin-left: 0.5em;') + link_to(t("ask.batch_modify_status"), "javascript:void(0)", :class=>"btn btn-success batch_modify_status_btn hide", :style=>'margin-left: 0.5em;'), class: 'pull-right'
|
2014-10-02 06:00:35 +00:00
|
|
|
end
|
2022-10-11 15:16:34 +00:00
|
|
|
%>
|
|
|
|
<script>
|
|
|
|
$(document).ready(function(){
|
|
|
|
$("#submit_when_change").on("change",function(){
|
|
|
|
$(this)[0].form.submit();
|
|
|
|
})
|
|
|
|
})
|
|
|
|
</script>
|