epaper/app/views/admin/e_paper_subscribers/_index.html.erb

133 lines
5.8 KiB
Plaintext
Executable File
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<% if @thread %>
<div id="threadModal" class="modal hide fade in" tabindex="-1" role="dialog" aria-labelledby="threadModal" aria-hidden="false">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<h3 id="threadModal"><%=t("e_paper.#{@thread.key}")%></h3>
</div>
<div class="modal-body">
<div class="thread-status"><%= @thread.status[:status] %></div>
<div><span class="thread-current-count"><%= @thread.status[:current_count].to_i %></span>/<span class="thread-all-count"><%= @thread.status[:all_count].to_i %></span></div>
<span class="thread-finish_percent"><%= @thread.status[:finish_percent].to_i %></span> % finished
</div>
<div class="modal-footer">
<button class="btn" id="modal-close-btn" style="width: 4em;" data-dismiss="modal" aria-hidden="true"><%=t('close')%></button>
</div>
</div>
</div>
</div>
<% end %>
<table class="table main-list">
<thead>
<tr class="sort-header">
<% @table_fields.each do |f| %>
<%= thead(f) %>
<% end %>
</tr>
</thead>
<tbody>
<% @subscribers.each do |subscriber| %>
<tr>
<td>
<%= subscriber.email rescue "" %>
<div class="quick-edit">
<ul class="nav nav-pills">
<li><a class="delete text-error" href="<%= admin_e_paper_subscriber_path(subscriber.id) %>" data-method="delete" data-confirm="Are you sure?"><%= t(:delete_) %></a></li>
</ul>
</div>
</td>
<td>
<%= subscriber.subscribed ? "Subscribed" : "Unsubscribed" %>
</td>
<td>
<%= t(subscriber.language) %>
</td>
</tr>
<% end %>
</tbody>
</table>
<div class="bottomnav clearfix" style="left: 81px;">
<%= content_tag(:div, paginate(@subscribers), class: "pagination pagination-centered") %>
<div class="pull-right">
<%=
content_tag(:div, link_to(t("e_paper.export"), admin_e_paper_subscribers_export_excel_path + '.xlsx', :class=>"btn btn-success"), class: "pull-right")
%>
<div class="dropup upload-button pull-right">
<button class="btn btn-default" id="show-last-import-result" type="button">查看最近一次匯入</button>
<button class="btn btn-info dropdown-toggle" type="button" data-toggle="dropdown">
<i class="icon-upload-alt icon-white"></i><%= t('personal_journal.upload') %>
<span class="caret"></span>
</button>
<div class="dropdown-menu upload-box">
<form action="<%=admin_e_paper_subscribers_import_from_excel_path%>" method="post" enctype="multipart/form-data">
<%= hidden_field_tag :authenticity_token, form_authenticity_token %>
<input type="file" name="import_file" >
<button class="btn btn-primary" type="submit"><%= t(:submit) %></button>
<a class="" href="<%=admin_e_paper_subscribers_download_excel_format_path%>.xlsx">Download excel format</a>
</form>
</div>
</div>
</div>
</div>
<script>
$(document).ready(function(){
function update_thread(){
$.post("<%=admin_threads_get_status_path%>",{"id": "<%=params[:thread_id]%>"}).done(function(data){
var finish_percent = data["finish_percent"];
var current_count = data["current_count"];
var all_count = data["all_count"];
var is_finish = (data["status"] == "finish");
if(finish_percent){
$("#threadModal .modal-body .thread-status").text(data["status"]);
if(data["status"] != 'Processing'){
$("#threadModal .modal-body .thread-current-count").text(current_count);
$("#threadModal .modal-body .thread-all-count").text(all_count);
}
$("#threadModal .modal-body .thread-finish_percent").text(finish_percent)
}
if(!is_finish){
window.time_out_id = window.setTimeout(update_thread, 1000);
}else{
if(window.time_out_id)
window.clearTimeout(window.time_out_id);
window.setTimeout(function(){
$("#threadModal").modal("hide");
// 修改點is_finish後檢查failed_rows有內容才組成清單提醒取代原本單純alert(status)
var failed_rows = data["failed_rows"];
if(failed_rows && failed_rows.length > 0){
var msg = "匯入完成,但有 " + failed_rows.length + " 筆資料匯入失敗:\n\n";
failed_rows.slice(0, 20).forEach(function(r){
msg += "第" + r["row"] + "列 (" + r["email"] + ")" + r["reason"] + "\n";
});
if(failed_rows.length > 20){
msg += "\n...等共 " + failed_rows.length + " 筆僅顯示前20筆";
}
alert(msg);
}else{
alert(data["status"]);
}
}, 3000);
return;
}
});
}
if($("#threadModal").length != 0){
$("#threadModal").on('hidden.bs.modal',function(){
window.clearTimeout(window.time_out_id);
})
$("#threadModal").on('shown.bs.modal',function(){
window.time_out_id = window.setTimeout(update_thread, 1000);
})
}
$("#show-last-import-result").click(function(){
$.get("<%=admin_e_paper_subscribers_last_import_result_path%>", function(html){
if($("#lastImportResultModal").length == 0){
$("body").append('<div id="lastImportResultModal" class="modal hide fade" tabindex="-1"><div class="modal-dialog"><div class="modal-content"><div class="modal-header"><h3>上次匯入結果</h3></div><div id="lastImportResultBody"></div><div class="modal-footer"><button class="btn" data-dismiss="modal">關閉</button></div></div></div></div>');
}
$("#lastImportResultBody").html(html);
$("#lastImportResultModal").modal("show");
});
});
})
</script>