announcement-test/app/views/admin/announcements/_index.html.erb

193 lines
6.8 KiB
Plaintext
Raw Normal View History

<script>
2014-07-28 07:08:41 +00:00
if(document.querySelectorAll("#orbit-bar").length==0) location.reload();
2022-05-22 12:12:32 +00:00
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);
}
2022-05-22 12:19:38 +00:00
window.anncs_delete_ids = [];
$(".delete_anncs_btn").addClass('hide');
2022-05-22 12:12:32 +00:00
});
}
$(document).on("click", ".select_delete", function(){
var that = $(this);
var id = that.data("id");
2022-05-22 12:19:38 +00:00
if(window.anncs_delete_ids == undefined){
window.anncs_delete_ids = [];
2022-05-22 12:12:32 +00:00
}
if(that.prop("checked")){
2022-05-22 12:19:38 +00:00
window.anncs_delete_ids.push(id);
2022-05-22 12:12:32 +00:00
}else{
2022-05-22 12:19:38 +00:00
window.anncs_delete_ids.delete(id);
2022-05-22 12:12:32 +00:00
}
2022-05-22 12:19:38 +00:00
if(window.anncs_delete_ids.length == 0){
$(".delete_anncs_btn").addClass('hide');
2022-05-22 12:12:32 +00:00
}else{
2022-05-22 12:19:38 +00:00
$(".delete_anncs_btn").removeClass('hide');
2022-05-22 12:12:32 +00:00
}
})
2022-05-22 12:19:38 +00:00
function delete_anncs(){
if(!window.anncs_delete_ids || window.anncs_delete_ids.length == 0){
2022-05-22 12:12:32 +00:00
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);
}
2022-05-22 12:19:38 +00:00
window.anncs_delete_ids.forEach(function(val){
2022-05-22 12:12:32 +00:00
data.append('ids[]', val);
});
$.ajax({
url: "<%=admin_announcements_delete_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!" );
}
}
})
}
2022-05-22 12:19:38 +00:00
$(document).on("click", ".delete_anncs_btn", function(){
2022-05-22 12:12:32 +00:00
if(window.confirm("<%=t(:sure?)%>")){
if(window.confirm("<%=t(:sure?)%>")){
2022-05-22 12:19:38 +00:00
delete_anncs();
2022-05-22 12:12:32 +00:00
}
}
})
</script>
2014-05-02 10:21:51 +00:00
<table class="table main-list">
<thead>
<tr class="sort-header">
2022-05-22 12:12:32 +00:00
<th style="width: 1em;"></th>
2014-05-02 10:21:51 +00:00
<% @table_fields.each do |f| %>
<%= thead(f) %>
<% end %>
</tr>
</thead>
<tbody>
<% @bulletins.each do |b| %>
<tr>
2022-05-22 12:12:32 +00:00
<% is_editable = can_edit_or_delete?(b) %>
<td><% if is_editable %><input type="checkbox" class="select_delete" data-id="<%= b.uid %>"><% end %></td>
<td>
<%= b.status_for_table %>
</td>
2022-04-21 14:01:50 +00:00
<% if @enable_annc_dept %>
2022-04-19 04:31:17 +00:00
<td>
<%= b.annc_dept ? @annc_depts[b.annc_dept] : '' rescue "" %>
</td>
2022-04-21 14:01:50 +00:00
<% end %>
2014-12-11 09:41:42 +00:00
<td>
<%= b.category.title rescue "" %>
<% if (b.category.disable rescue false) %>
<span class='label'><%= t(:disabled) %></span>
<% end %>
</td>
2014-05-02 10:21:51 +00:00
<td>
<% if b.expired? || (b.category.disable rescue false)%>
2020-04-23 08:52:53 +00:00
<%= b.title.to_s.html_safe %>
<% else %>
2020-04-23 08:52:53 +00:00
<a href="<%= page_for_bulletin(b) %>" target="_blank"><%= b.title.to_s.html_safe %></a>
<% end %>
<% if b.expired? %>
<span class='label'><%= t(:expired) %></span>
<% end %>
<% if b.reapproval %>
<span class='label'><%= t("announcement.reapproval") + " " + t(:pending) %></span>
<% end %>
<% if b.rejected %>
<span class='label'><%= t(:rejected) %> : <%= b.rejection_reason rescue "" %></span>
<% end %>
<% if !b.approved? && !b.rejected %>
2014-12-11 09:41:42 +00:00
<span class='label'><%= t(:pending) %></span>
<% end %>
2014-05-02 10:21:51 +00:00
<div class="quick-edit">
<ul class="nav nav-pills">
2014-07-19 19:30:33 +00:00
<li><a href="#" class="detail-row" onclick="$('#<%= "#{b.id.to_s}-detail" %>').slideToggle(300); return false;"><%= t(:detail) %></a></li>
2022-05-22 12:12:32 +00:00
<% if is_editable %>
2014-07-31 09:12:13 +00:00
<li><a href="/admin/announcements/<%=b.id.to_s%>/edit"><%= t(:edit) %></a></li>
<li><a href="#" class="delete text-error" rel="/admin/announcements/<%=b.id.to_s%>"><%= t(:delete_) %></a></li>
<% end %>
<% if ((!b.approved && !b.rejected && !b.reapproval) || (b.rejected && b.reapproval)) && user_can_approve?(b) %>
<li><a href="<%= page_for_bulletin(b) %>" class="approval_button" data-id="<%= b.id.to_s %>" ><%= t("announcement.approval_waiting") %></a></li>
2014-07-31 09:12:13 +00:00
<% end %>
2014-05-02 10:21:51 +00:00
</ul>
</div>
</td>
<td><%= format_value b.postdate %></td>
<td class="<%= b.expired? ? "expired" : "" %>"><%= format_value b.deadline %></td>
2020-07-30 14:12:21 +00:00
<td><%= link_to b.bulletin_comments.count.to_s,"/#{I18n.locale}/admin/announcements/#{b.id}/comment" %></td>
2021-12-28 05:55:50 +00:00
<td><%= b.update_user.user_name rescue ""%><br><%= format_value b.updated_at %></td>
2014-05-02 10:21:51 +00:00
</tr>
<tr class="footable-row-detail">
<td class="footable-cell-detail" colspan="6">
<div id="<%= "#{b.id.to_s}-detail" %>" class="footable-row-detail-inner" style="display: none;">
2017-01-17 05:43:58 +00:00
<div>
<strong><%= t(:view_count) %></strong> :
<span class="label label-info"><%= b.view_count %></span>
</div>
<div>
<strong><%= t(:tags) %></strong> :
<% b.tags.each do |tag| %>
<span class="label label-warning"><%= tag.name %></span>
<% end %>
</div>
<div>
<strong><%= t("announcement.email_to") %></strong> :
<% b.email_members.each do |member| %>
<span class="label"><%= member.name %></span>
<% end %>
<% unless b.other_mailaddress.nil? %>
<% b.other_mailaddress.split(',').each do |mailaddress| %>
<span class="label"><%= mailaddress %></span>
<% end %>
<% end %>
</div>
</div>
</td>
</tr>
2014-05-02 10:21:51 +00:00
<% end %>
</tbody>
</table>
<%=
content_tag :div, class: "bottomnav clearfix" do
2021-06-11 03:59:31 +00:00
content_tag(:div, paginate(@bulletins), class: "pagination pagination-centered") +
2022-05-23 04:40:41 +00:00
content_tag(:div, link_to(t("announcement.delete_selected"), "javascript:void(0)", :class=>"btn btn-danger"), class: "pull-right hide delete_anncs_btn") +
content_tag(:div, link_to(t(:new_),new_admin_announcement_path, :class=>"btn btn-primary"), class: "pull-right")
2014-05-02 10:21:51 +00:00
end
2014-07-21 06:11:58 +00:00
%>