diff --git a/app/assets/stylesheets/e_paper/emailer.scss b/app/assets/stylesheets/e_paper/emailer.scss new file mode 100644 index 0000000..89ce09e --- /dev/null +++ b/app/assets/stylesheets/e_paper/emailer.scss @@ -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; + } +} \ No newline at end of file diff --git a/app/controllers/admin/e_papers_controller.rb b/app/controllers/admin/e_papers_controller.rb index 8239a26..472527b 100644 --- a/app/controllers/admin/e_papers_controller.rb +++ b/app/controllers/admin/e_papers_controller.rb @@ -62,6 +62,31 @@ class Admin::EPapersController < OrbitAdminController redirect_to admin_e_papers_path(:page => params[:page]) 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 diff --git a/app/models/paper.rb b/app/models/paper.rb index b51b4e4..8c90db9 100644 --- a/app/models/paper.rb +++ b/app/models/paper.rb @@ -7,7 +7,7 @@ class Paper include Slug field :title,as: :slug_title, localize: true - field :period, localize: true + field :period, type: DateTime field :description, localize: true field :mailed, type: Boolean, default: false field :ready_to_send, type: Boolean, default: false diff --git a/app/views/admin/e_papers/_form.html.erb b/app/views/admin/e_papers/_form.html.erb index d953a7c..e3758e8 100644 --- a/app/views/admin/e_papers/_form.html.erb +++ b/app/views/admin/e_papers/_form.html.erb @@ -61,17 +61,13 @@ -
<%= f.label :period ,t('e_paper.period'), :class => "control-label muted" %> -
- <%= f.fields_for :period_translations do |f| %> - <%= f.text_field locale, :class=>'input-large', :value => (@paper.period_translations[locale] rescue nil) %> -
- <% end %> +
+ <%= f.datetime_picker :period, :no_label => true, :new_record => @paper.new_record? %> +
-
<%= f.label :description ,t('e_paper.description'), :class => "control-label muted" %> <%= f.fields_for :description_translations do |f| %> diff --git a/app/views/admin/e_papers/_index.html.erb b/app/views/admin/e_papers/_index.html.erb index 06fec85..0c8632d 100644 --- a/app/views/admin/e_papers/_index.html.erb +++ b/app/views/admin/e_papers/_index.html.erb @@ -32,6 +32,7 @@
  • <%= t('e_paper.published') %>
  • <% else %>
  • <%= t('e_paper.send') %>
  • +
  • <%= t('e_paper.test_mail') %>
  • <% end %> <% end %> @@ -46,11 +47,27 @@
    <% if user_has_rights %> - - + <% end %>
    + \ No newline at end of file diff --git a/app/views/admin/e_papers/_subscriber_index.html.erb b/app/views/admin/e_papers/_subscriber_index.html.erb new file mode 100644 index 0000000..e11b52d --- /dev/null +++ b/app/views/admin/e_papers/_subscriber_index.html.erb @@ -0,0 +1,31 @@ + + + + + + <% @table_fields.each do |f| %> + <%= thead(f) %> + <% end %> + + + + <% @subscribers.each do |sub| %> + + + + + <% end %> + +
    + <%= sub.email %> + + <%= t(:delete_) %> +
    + +<%= + content_tag :div, class: "bottomnav clearfix" do + content_tag :div, paginate(@subscribers), class: "pagination pagination-centered" + end +%> \ No newline at end of file diff --git a/app/views/admin/e_papers/emailer.html.erb b/app/views/admin/e_papers/emailer.html.erb index 1f50a37..d6e7cd5 100644 --- a/app/views/admin/e_papers/emailer.html.erb +++ b/app/views/admin/e_papers/emailer.html.erb @@ -1,15 +1,175 @@ <% paper = @data["paper"] %> +<% page = @data["page"] %> <%= paper.title %> + -

    <%= paper.title %>

    -
      - <% paper.topics.each do |topic| %> -
    1. <%= topic.episode %>
    2. - <% end %> -
    +
    + Health Promoting School +
    +
    +

    <%= t('e_paper.intro') %>

    +
    +
    <%= t('e_paper.title') %>:<%= paper.title %>
    +
    <%= t('e_paper.date') %>:<%= paper.created_at.strftime("%Y-%m-%d") %>
    +
    <%= t('e_paper.period') %>:<%= paper.period.strftime("%Y-%m-%d") %>
    +
    <%= t('e_paper.description') %><%= paper.description %>
    +
    + +
    + <% paper.topics.desc(:created_at).each do |topic| %> +
    + " target="_blank"><%= topic.episode %> + <% t = strip_tags(topic.content) %> +

    <%= t[0..100] %>

    + " target="_blank">more +
    + <% end %> +
    +
    + \ No newline at end of file diff --git a/app/views/admin/e_papers/subscribers.html.erb b/app/views/admin/e_papers/subscribers.html.erb new file mode 100644 index 0000000..27ba5d7 --- /dev/null +++ b/app/views/admin/e_papers/subscribers.html.erb @@ -0,0 +1,4 @@ +<%= render_filter @filter_fields, "index_table" %> + + <%= render 'subscriber_index'%> + \ No newline at end of file diff --git a/config/locales/en.yml b/config/locales/en.yml index 83137b5..fa6a390 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -12,7 +12,8 @@ en: history: "History Episode" intro: "Intro" date: "Date" - send: "Send e-Paper" + send: "Mail e-Paper" sending: "Sending in process" published: "Published" - + subscribers: Subscribers + test_mail: Send Test Email \ No newline at end of file diff --git a/config/locales/zh_tw.yml b/config/locales/zh_tw.yml index cb16eca..b40ab09 100644 --- a/config/locales/zh_tw.yml +++ b/config/locales/zh_tw.yml @@ -15,4 +15,6 @@ zh_tw: date: "日期" send: "發送電子報" sending: "發送處理中" - published: "已發送" \ No newline at end of file + published: "已發送" + subscribers: 訂閱 + test_mail: Send Test Email \ No newline at end of file diff --git a/config/routes.rb b/config/routes.rb index e60aaf1..71a9156 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -7,6 +7,11 @@ Rails.application.routes.draw do resources :e_papers do member do get :send_email_to_subscribers + delete "delete_subscriber" + get "send_test_email" + end + collection do + get "subscribers" end end resources :topics diff --git a/lib/e_paper/engine.rb b/lib/e_paper/engine.rb index 7d7e413..a93671a 100644 --- a/lib/e_paper/engine.rb +++ b/lib/e_paper/engine.rb @@ -24,6 +24,12 @@ module EPaper :active_for_action=>{'admin/e_papers'=>"index"}, :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_', # :link_path=>"new_admin_e_paper_path" , # :priority=>2, diff --git a/lib/tasks/e_paper_tasks.rake b/lib/tasks/e_paper_tasks.rake index c5b63fa..dd65259 100644 --- a/lib/tasks/e_paper_tasks.rake +++ b/lib/tasks/e_paper_tasks.rake @@ -4,7 +4,7 @@ namespace :epaper do if !paper.nil? subscribers = Subscriber.all emails = [] - mail_limit = 2 + mail_limit = 25 subscribers.each do |subscriber| emails << subscriber.email subscriber.last_paper_sent = paper.id.to_s