archive/app/views/admin/archive_files/_index.html.erb

145 lines
4.7 KiB
Plaintext
Raw Normal View History

<script>
2014-07-28 07:09:27 +00:00
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.archive_delete_ids = [];
$(".delete_archives_btn").addClass('hide');
});
}
$(document).on("click", ".select_delete", function(){
var that = $(this);
var id = that.data("id");
if(window.archive_delete_ids == undefined){
window.archive_delete_ids = [];
}
if(that.prop("checked")){
window.archive_delete_ids.push(id);
}else{
window.archive_delete_ids.delete(id);
}
if(window.archive_delete_ids.length == 0){
$(".delete_archives_btn").addClass('hide');
}else{
$(".delete_archives_btn").removeClass('hide');
}
})
function delete_archives(){
if(!window.archive_delete_ids || window.archive_delete_ids.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.archive_delete_ids.forEach(function(val){
data.append('ids[]', val);
});
$.ajax({
url: "<%=admin_archive_files_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!" );
}
}
})
}
$(document).on("click", ".delete_archives_btn", function(){
if(window.confirm("<%=t(:sure?)%>")){
if(window.confirm("<%=t(:sure?)%>")){
delete_archives();
}
}
})
</script>
2014-05-14 11:52:06 +00:00
<table class="table main-list">
2014-08-07 10:46:24 +00:00
<thead>
<tr class="sort-header">
<th style="width: 1em;"></th>
2014-08-07 10:46:24 +00:00
<% @table_fields.each do |f| %>
2016-03-14 07:47:38 +00:00
<% if f == "archive.downloaded_times" %>
<%= thead(f,true,false) %>
<% else %>
<%= thead(f) %>
<% end %>
2014-08-07 10:46:24 +00:00
<% end %>
</tr>
</thead>
<tbody>
<% @archives.each do |archive| %>
<tr>
<% is_editable = can_edit_or_delete?(archive) %>
<td><% if is_editable %><input type="checkbox" class="select_delete" data-id="<%= archive.uid %>"><% end %></td>
2014-08-07 10:46:24 +00:00
<td><%= archive.status_for_table %></td>
2014-12-11 09:43:16 +00:00
<td>
<%= archive.category.title rescue "" %>
<% if (archive.category.disable rescue false) %>
<span class='label'><%= t(:disabled) %></span>
<% end %>
</td>
2014-08-07 10:46:24 +00:00
<td>
2019-09-16 12:35:57 +00:00
<a href="/admin/archive_files/show?title=<%= archive.title %>" target="_blank"><%= archive.title %></a>
2014-08-07 10:46:24 +00:00
<div class="quick-edit">
<ul class="nav nav-pills">
<% if is_editable %>
2014-08-07 10:46:24 +00:00
<li><a href="/<%= I18n.locale.to_s %>/admin/archive_files/<%= archive.id.to_s %>/edit"><%= t(:edit) %></a></li>
2018-01-25 09:24:39 +00:00
<li><a href="/admin/archive_files/<%= archive.id.to_s %>" class="delete text-error" data-method="delete" data-confirm="Are you sure?"><%= t(:delete_) %></a></li>
2014-08-07 10:46:24 +00:00
<% end %>
</ul>
</div>
</td>
<td><%= format_value archive.updated_at rescue nil %></td>
<td><%= User.find(archive.update_user_id).user_name rescue nil %></td>
2015-03-18 09:59:03 +00:00
<% download_total = 0
archive.archive_file_multiples.each do |afm|
download_total = download_total + afm.download_count
end
%>
<td><%= download_total %></td>
2014-08-07 10:46:24 +00:00
</tr>
<% end %>
</tbody>
2014-07-04 07:54:11 +00:00
</table>
<%=
content_tag :div, class: "bottomnav clearfix" do
2021-06-11 04:21:02 +00:00
content_tag(:div, paginate(@archives), class: "pagination pagination-centered") +
content_tag(:div, link_to(t("archive.delete_selected"), "javascript:void(0)", :class=>"btn btn-primary"), class: "pull-right hide delete_archives_btn") +
2022-05-22 12:22:45 +00:00
content_tag(:div, link_to(t(:new_),new_admin_archive_file_path, :class=>"btn btn-danger"), class: "pull-right")
2014-07-04 07:54:11 +00:00
end
%>