added subscriber list and also test email sent done with email improvements.

This commit is contained in:
Harry Bomrah 2017-08-04 18:42:19 +08:00
parent 15ab527f37
commit 5ec89f067c
13 changed files with 428 additions and 24 deletions

View File

@ -0,0 +1,157 @@
.epaper-show {
.epaper-show-title {
border-bottom: 2px solid #ddd;
padding: 0 0 10px;
margin: 10px 0 20px;
color: #881f05;
}
.ep-info {
background: #fff;
border-radius: 3px;
padding: 10px;
margin: 0 0 15px;
}
.ep-info-title {
border-bottom: 1px solid #eee;
padding: 0 0 5px;
margin: 0 0 8px;
font-size: 18px;
}
.ep-info-date {
float: left;
width: 50%;
margin: 0 0 5px;
color: #888;
}
.ep-info-period {
float: right;
width: 50%;
margin: 0 0 5px;
text-align: right;
padding: 0 10px 0 0;
color: #888;
}
.ep-info-description {
clear: both;
padding: 10px 0 0;
overflow: hidden;
border-top: 1px solid #eee;
}
.ep-info-description span {
float: right;
width: calc(100% - 90px);
line-height: 1.5;
}
.ep-content-item {
float: left;
width: calc(50% - 20px);
border: 1px solid #ccc;
vertical-align: top;
min-height: 200px;
padding: 20px;
margin: 10px;
}
.ep-content-title {
color: #881f05;
font-size: 20px;
border-left: 4px solid #881f05;
display: block;
padding: 0 0 0 10px;
margin: 0 0 10px;
}
p.ep-content-text {
color: #666;
font-size: 15px;
}
a.ep-content-more {
background: #881f05;
color: #fff;
padding: 2px 10px;
border-radius: 5px;
font-size: 12px;
}
}
.ep-topic-show {
.ep-topic-title {
margin: 10px 0;
color: #881f05;
}
.ep-topic-date {
background: #fff;
padding: 10px;
border-radius: 3px;
margin: 0 0 10px;
}
.ep-topic-content {
font-size: 15px;
line-height: 2;
}
}
//widget
.epaper-form {
background: #fff;
padding: 20px;
width: 100%;
max-width: 300px;
margin: auto;
border-radius: 5px;
box-shadow: 0 0 30px rgba(0,0,0,0.05);
input.input-mail {
display: block;
width: 100%;
margin: 0 0 20px;
padding: 5px 10px;
border: 1px solid #ccc;
border-radius: 5px;
color: #333;
}
.btn-primary {
width: 50%;
float: left;
display: block;
}
.btn-white {
background: none;
width: 50%;
outline: none;
float: right;
color: #888;
}
.btn-white:active {
outline: none;
box-shadow: none;
}
.btn-white:hover {
text-decoration: underline;
}
.ep-form-title {
font-size: 20px;
margin: 0 0 15px;
}
h3.ep-form-title .en {
display: none;
}
form {
overflow: hidden;
}
}

View File

@ -62,6 +62,31 @@ class Admin::EPapersController < OrbitAdminController
redirect_to admin_e_papers_path(:page => params[:page]) redirect_to admin_e_papers_path(:page => params[:page])
end end
def subscribers
@table_fields = [:email, :actions]
@subscribers = Subscriber.all.desc(:created_at)
@filter_fields = {}
@subscribers = search_data(@subscribers, [:email]).page(params[:page]).per(10)
if request.xhr?
render :partial => "subscriber_index"
end
end
def delete_subscriber
subscriber = Subscriber.find(params[:id])
subscriber.destroy
redirect_to subscribers_admin_e_papers_path(:page => params[:page])
end
def send_test_email
paper = Paper.find(params[:id])
page = Page.where(:module_app => "e_paper").first.url rescue ""
email = Email.new(:mail_subject => paper.title, :mail_lang => :zh_tw, :template => "admin/e_papers/emailer", :template_data => {"paper" => paper, "page" => "http://" + request.host_with_port + page}, :mail_to => params[:email])
email.deliver
render :json => {"success" => true}.to_json
end
private private

View File

@ -7,7 +7,7 @@ class Paper
include Slug include Slug
field :title,as: :slug_title, localize: true field :title,as: :slug_title, localize: true
field :period, localize: true field :period, type: DateTime
field :description, localize: true field :description, localize: true
field :mailed, type: Boolean, default: false field :mailed, type: Boolean, default: false
field :ready_to_send, type: Boolean, default: false field :ready_to_send, type: Boolean, default: false

View File

@ -61,17 +61,13 @@
</div> </div>
</div> </div>
<div class="control-group input-period"> <div class="control-group input-period">
<%= f.label :period ,t('e_paper.period'), :class => "control-label muted" %> <%= f.label :period ,t('e_paper.period'), :class => "control-label muted" %>
<div class="controls"> <div class="controls">
<%= f.fields_for :period_translations do |f| %> <%= f.datetime_picker :period, :no_label => true, :new_record => @paper.new_record? %>
<%= f.text_field locale, :class=>'input-large', :value => (@paper.period_translations[locale] rescue nil) %> </div>
</div>
<% end %>
</div> </div>
<div class="control-group input-description"> <div class="control-group input-description">
<%= f.label :description ,t('e_paper.description'), :class => "control-label muted" %> <%= f.label :description ,t('e_paper.description'), :class => "control-label muted" %>
<%= f.fields_for :description_translations do |f| %> <%= f.fields_for :description_translations do |f| %>

View File

@ -32,6 +32,7 @@
<li><span class="label"><%= t('e_paper.published') %></span></li> <li><span class="label"><%= t('e_paper.published') %></span></li>
<% else %> <% else %>
<li><a href="<%= send_email_to_subscribers_admin_e_paper_path(paper.id) %>"><%= t('e_paper.send') %></a></li> <li><a href="<%= send_email_to_subscribers_admin_e_paper_path(paper.id) %>"><%= t('e_paper.send') %></a></li>
<li><a href="<%= send_test_email_admin_e_paper_path(paper.id) %>" class="test-email"><%= t('e_paper.test_mail') %></a></li>
<% end %> <% end %>
<% end %> <% end %>
</ul> </ul>
@ -46,11 +47,27 @@
</table> </table>
<div class="bottomnav clearfix" style="left: 81px;"> <div class="bottomnav clearfix" style="left: 81px;">
<% if user_has_rights %> <% if user_has_rights %>
<div class="action pull-right">
<div class="action pull-right"> <a class="btn btn-primary" href="<%= new_admin_e_paper_path %>">
<a class="btn btn-primary" href="<%= new_admin_e_paper_path %>"> <%= t("e_paper.new_paper") %>
<%= t("e_paper.new_paper") %> </a>
</a> </div>
</div>
<% end %> <% end %>
</div> </div>
<script type="text/javascript">
$(".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.")
})
}
return false;
})
</script>

View File

@ -0,0 +1,31 @@
<script>
if(document.querySelectorAll("#orbit-bar").length==0) location.reload();
</script>
<table class="table main-list">
<thead>
<tr class="sort-header">
<% @table_fields.each do |f| %>
<%= thead(f) %>
<% end %>
</tr>
</thead>
<tbody>
<% @subscribers.each do |sub| %>
<tr>
<td>
<%= sub.email %>
</td>
<td>
<a data-method="delete" data-confirm="Are you sure?" href="<%= delete_subscriber_admin_e_paper_path(sub.id, :page => params[:page]) %>" class="btn btn-danger"><%= t(:delete_) %></a>
</td>
</tr>
<% end %>
</tbody>
</table>
<%=
content_tag :div, class: "bottomnav clearfix" do
content_tag :div, paginate(@subscribers), class: "pagination pagination-centered"
end
%>

View File

@ -1,15 +1,175 @@
<% paper = @data["paper"] %> <% paper = @data["paper"] %>
<% page = @data["page"] %>
<!DOCTYPE html> <!DOCTYPE html>
<html> <html>
<head> <head>
<title><%= paper.title %></title> <title><%= paper.title %></title>
<style type="text/css">
.epaper-show .epaper-show-title {
border-bottom: 2px solid #ddd;
padding: 0 0 10px;
margin: 10px 0 20px;
color: #881f05;
}
.epaper-show .ep-info {
background: #fff;
border-radius: 3px;
padding: 10px;
margin: 0 0 15px;
}
.epaper-show .ep-info-title {
border-bottom: 1px solid #eee;
padding: 0 0 5px;
margin: 0 0 8px;
font-size: 18px;
}
.epaper-show .ep-info-date {
float: left;
width: 50%;
margin: 0 0 5px;
color: #888;
}
.epaper-show .ep-info-period {
float: right;
width: 50%;
margin: 0 0 5px;
text-align: right;
padding: 0 10px 0 0;
color: #888;
}
.epaper-show .ep-info-description {
clear: both;
padding: 10px 0 0;
overflow: hidden;
border-top: 1px solid #eee;
}
.epaper-show .ep-info-description span {
float: right;
width: calc(100% - 90px);
line-height: 1.5;
}
.epaper-show .ep-content-item {
float: left;
width: calc(50% - 20px);
border: 1px solid #ccc;
vertical-align: top;
min-height: 200px;
padding: 20px;
margin: 10px;
}
.epaper-show .ep-content-title {
color: #881f05;
font-size: 20px;
border-left: 4px solid #881f05;
display: block;
padding: 0 0 0 10px;
margin: 0 0 10px;
}
.epaper-show p.ep-content-text {
color: #666;
font-size: 15px;
}
.epaper-show a.ep-content-more {
background: #881f05;
color: #fff;
padding: 2px 10px;
border-radius: 5px;
font-size: 12px;
}
.ep-topic-show .ep-topic-title {
margin: 10px 0;
color: #881f05;
}
.ep-topic-show .ep-topic-date {
background: #fff;
padding: 10px;
border-radius: 3px;
margin: 0 0 10px;
}
.ep-topic-show .ep-topic-content {
font-size: 15px;
line-height: 2;
}
.epaper-form {
background: #fff;
padding: 20px;
width: 100%;
max-width: 300px;
margin: auto;
border-radius: 5px;
box-shadow: 0 0 30px rgba(0, 0, 0, 0.05);
}
.epaper-form input.input-mail {
display: block;
width: 100%;
margin: 0 0 20px;
padding: 5px 10px;
border: 1px solid #ccc;
border-radius: 5px;
color: #333;
}
.epaper-form .btn-primary {
width: 50%;
float: left;
display: block;
}
.epaper-form .btn-white {
background: none;
width: 50%;
outline: none;
float: right;
color: #888;
}
.epaper-form .btn-white:active {
outline: none;
box-shadow: none;
}
.epaper-form .btn-white:hover {
text-decoration: underline;
}
.epaper-form .ep-form-title {
font-size: 20px;
margin: 0 0 15px;
}
.epaper-form h3.ep-form-title .en {
display: none;
}
.epaper-form form {
overflow: hidden;
}
.school-heading{
padding: 20px;
text-align: center;
border-bottom: 1px solid #c8c8c8;
}
</style>
</head> </head>
<body> <body>
<h2><a href="#"><%= paper.title %></a></h2> <div class="school-heading">
<ol> <img src="http://hps.pending.rulingcom.com/uploads/site/site_logo/589d279202dcf06d74000018/title.png" alt="Health Promoting School">
<% paper.topics.each do |topic| %> </div>
<li><a href=""><%= topic.episode %></a></li> <div class="epaper-show">
<% end %> <h3 class="epaper-show-title"><%= t('e_paper.intro') %></h3>
</ol> <div class="ep-info">
<div class="ep-info-title"><%= t('e_paper.title') %><span><%= paper.title %></span></div>
<div class="ep-info-date"><%= t('e_paper.date') %><span><%= paper.created_at.strftime("%Y-%m-%d") %></span></div>
<div class="ep-info-period"><%= t('e_paper.period') %><span><%= paper.period.strftime("%Y-%m-%d") %></span></div>
<div class="ep-info-description"><%= t('e_paper.description') %><span><%= paper.description %></span></div>
</div>
<div class="ep-content">
<% paper.topics.desc(:created_at).each do |topic| %>
<div class="ep-content-item">
<a class="ep-content-title" href="<%= page + "/" + paper.to_param + "?method=showtopic" %>" target="_blank"><%= topic.episode %></a>
<% t = strip_tags(topic.content) %>
<p class="ep-content-text"><%= t[0..100] %></p>
<a class="ep-content-more" href="<%= page + "/" + paper.to_param + "?method=showtopic" %>" target="_blank">more</a>
</div>
<% end %>
</div>
</div>
</body> </body>
</html> </html>

View File

@ -0,0 +1,4 @@
<%= render_filter @filter_fields, "index_table" %>
<span id="index_table">
<%= render 'subscriber_index'%>
</span>

View File

@ -12,7 +12,8 @@ en:
history: "History Episode" history: "History Episode"
intro: "Intro" intro: "Intro"
date: "Date" date: "Date"
send: "Send e-Paper" send: "Mail e-Paper"
sending: "Sending in process" sending: "Sending in process"
published: "Published" published: "Published"
subscribers: Subscribers
test_mail: Send Test Email

View File

@ -15,4 +15,6 @@ zh_tw:
date: "日期" date: "日期"
send: "發送電子報" send: "發送電子報"
sending: "發送處理中" sending: "發送處理中"
published: "已發送" published: "已發送"
subscribers: 訂閱
test_mail: Send Test Email

View File

@ -7,6 +7,11 @@ Rails.application.routes.draw do
resources :e_papers do resources :e_papers do
member do member do
get :send_email_to_subscribers get :send_email_to_subscribers
delete "delete_subscriber"
get "send_test_email"
end
collection do
get "subscribers"
end end
end end
resources :topics resources :topics

View File

@ -24,6 +24,12 @@ module EPaper
:active_for_action=>{'admin/e_papers'=>"index"}, :active_for_action=>{'admin/e_papers'=>"index"},
:available_for => 'users' :available_for => 'users'
context_link 'e_paper.subscribers',
:link_path=>"subscribers_admin_e_papers_path" ,
:priority=>1,
:active_for_action=>{'admin/e_papers'=>"subscribers"},
:available_for => 'users'
# context_link 'new_', # context_link 'new_',
# :link_path=>"new_admin_e_paper_path" , # :link_path=>"new_admin_e_paper_path" ,
# :priority=>2, # :priority=>2,

View File

@ -4,7 +4,7 @@ namespace :epaper do
if !paper.nil? if !paper.nil?
subscribers = Subscriber.all subscribers = Subscriber.all
emails = [] emails = []
mail_limit = 2 mail_limit = 25
subscribers.each do |subscriber| subscribers.each do |subscriber|
emails << subscriber.email emails << subscriber.email
subscriber.last_paper_sent = paper.id.to_s subscriber.last_paper_sent = paper.id.to_s