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

122 lines
4.6 KiB
Plaintext
Executable File

<table class="table main-list">
<thead>
<tr class="sort-header">
<% @table_fields.each do |f| %>
<%= thead(f) %>
<% end %>
</tr>
</thead>
<tbody>
<% @criterias.each do |criteria| %>
<tr>
<td>
<%= criteria.title %>
<div class="quick-edit">
<ul class="nav nav-pills">
<li><a href="<%= edit_admin_e_paper_criteria_path(criteria.id) %>"><%= t(:edit) %></a></li>
<li><a class="test-email" href="<%= send_test_email_admin_e_paper_criteria_path(criteria.id) %>"><%= t('e_paper.test_mail') %></a></li>
<li><a class="send-newsletter" href="<%= send_newsletter_admin_e_paper_criteria_path(criteria.id) %>"><%= t('e_paper.send_newsletter') %></a></li>
<li><a class="get_failed_emails" href="<%= get_failed_emails_admin_e_paper_criteria_path(criteria.id) %>"><%= t('e_paper.get_failed_emails') %></a></li>
<li><a class="get_failed_emails" href="<%= get_invalid_emails_admin_e_paper_criteria_path(criteria.id) %>"><%= t('e_paper.get_invalid_emails') %></a></li>
<li><a class="delete text-error" href="<%= admin_e_paper_criteria_path(criteria.id) %>" data-method="delete" data-confirm="Are you sure?"><%= t(:delete_) %></a></li>
</ul>
</div>
</td>
<td><%= criteria.start_date.strftime("%Y/%m/%d") rescue "N/A" %> ~ <%= criteria.end_date.strftime("%Y/%m/%d") rescue "N/A" %></td>
</tr>
<% end %>
</tbody>
</table>
<div id="show_epaper_message"></div>
<div class="bottomnav clearfix" style="left: 81px;">
<%= content_tag :div, paginate(@criterias), class: "pagination pagination-centered" %>
<div class="action pull-right">
<a class="btn btn-primary" href="<%= new_admin_e_paper_criteria_path %>">
<%= t("e_paper.new_criteria") %>
</a>
</div>
</div>
<style type="text/css">
#show_epaper_message span {
background: #9C27B0;
color: white;
}
</style>
<script type="text/javascript">
function convert_email_to_html(data){
return ('count:&nbsp;'+data.length+'<br><pre><span>'+data.join('</span></pre><br><pre><span>')+'</span></pre>')
}
$(".test-email").on("click",function(){
var el = $(this),
email = prompt("Please enter an email address to send test email.", "<%= current_user.member_profile.email rescue "" %>");
if(email != null){
$.ajax({
url : el.attr("href"),
data : {"email" : email},
dataType : "json",
type : "get"
}).done(function(){
alert("Email sent.");
}).fail(function(jqXHR, textStatus, errorThrown){
alert("Something went wrong!\nPlease contact customer service!");
console.log(errorThrown);
})
}
return false;
})
$(".send-newsletter").on("click",function(){
var el = $(this);
if(confirm("Are you sure?")){
$.ajax({
url : el.attr("href"),
dataType : "json",
type : "get",
success: function(data){
if (data.success){
alert(data.msg)
}else{
var window_width = window.innerWidth
var window_height = window.innerHeight
var show_html = (typeof(data.invalid_emails)=='string' ? data.invalid_emails : convert_email_to_html(data.invalid_emails))
$("div#show_epaper_message").html(show_html)
$("div#show_epaper_message").dialog({
autoOpen: true,
show: "blind",
model: true,
hide: "explode",
width: window_width*0.7,
height: window_height*0.6
})
}
},
error: function(error){
alert("Something went wrong!\nPlease contact customer service!");
console.log(error);
}
})
}
return false;
})
$('.get_failed_emails').on('click',function(){
$.ajax({
url : $(this).attr("href"),
dataType : "json",
type : "get",
success: function(data){
var window_width = window.innerWidth
var window_height = window.innerHeight
var show_html = (typeof(data.data)=='string' ? data.data : convert_email_to_html(data.data))
$("div#show_epaper_message").html(show_html)
$("div#show_epaper_message").dialog({
autoOpen: true,
show: "blind",
model: true,
hide: "explode",
width: window_width*0.7,
height: window_height*0.6
})
}
})
return false;
})
</script>