2019-07-01 12:06:33 +00:00
|
|
|
require 'rake'
|
2019-05-28 15:54:32 +00:00
|
|
|
class Admin::EPaperCriteriasController < OrbitAdminController
|
|
|
|
|
|
|
|
def initialize
|
|
|
|
super
|
|
|
|
@app_title = "e_paper"
|
|
|
|
end
|
|
|
|
|
|
|
|
def index
|
|
|
|
@table_fields = [t('e_paper.criteria_title'),t('e_paper.date_span')]
|
|
|
|
|
|
|
|
@filter_fields = filter_fields([], @module_app.tags)
|
|
|
|
@filter_fields.delete(:status)
|
|
|
|
@filter_fields.delete(:categories)
|
|
|
|
@criterias = PaperCriteria.order_by(sort)
|
|
|
|
# .with_tags(filters("tags"))
|
|
|
|
|
|
|
|
@criterias = search_data(@criterias,[:title]).page(params[:page]).per(10)
|
2020-03-02 14:41:51 +00:00
|
|
|
#@url = "/" + I18n.locale.to_s + "/" +Page.where(:module => "e_paper").first.url + "?method=papers"
|
2019-05-28 15:54:32 +00:00
|
|
|
render :partial => "index" if request.xhr?
|
|
|
|
end
|
|
|
|
|
|
|
|
def new
|
|
|
|
@paper_criteria = PaperCriteria.new
|
|
|
|
end
|
|
|
|
|
|
|
|
def create
|
|
|
|
paper_criteria = PaperCriteria.create(paper_criteria_params)
|
|
|
|
redirect_to admin_e_paper_criterias_path
|
|
|
|
end
|
|
|
|
|
|
|
|
def edit
|
|
|
|
@paper_criteria = PaperCriteria.find(params[:id])
|
|
|
|
end
|
|
|
|
|
|
|
|
def update
|
|
|
|
paper_criteria = PaperCriteria.find(params[:id])
|
|
|
|
paper_criteria.update_attributes(paper_criteria_params)
|
|
|
|
redirect_to admin_e_paper_criterias_path
|
|
|
|
end
|
|
|
|
|
|
|
|
def destroy
|
|
|
|
paper_criteria = PaperCriteria.find(params[:id])
|
|
|
|
paper_criteria.destroy
|
|
|
|
redirect_to admin_e_paper_criterias_path
|
|
|
|
end
|
|
|
|
|
|
|
|
def send_test_email
|
|
|
|
paper_criteria = PaperCriteria.find(params[:id])
|
2019-07-01 12:06:33 +00:00
|
|
|
page = Page.where(:module => "e_paper").first.url rescue ""
|
2019-09-01 20:37:07 +00:00
|
|
|
email = Email.new(:mail_subject => paper_criteria.sending_title, :mail_lang => :zh_tw, :template => "admin/e_paper_criterias/emailer", :template_data => {"paper" => paper_criteria, "page" => "http://" + request.host_with_port + page, "siteurl" => "http://" + request.host_with_port }, :mail_to => params[:email])
|
2019-05-28 15:54:32 +00:00
|
|
|
email.deliver
|
2019-07-01 12:06:33 +00:00
|
|
|
render :json => {"success" => true}.to_json
|
|
|
|
end
|
|
|
|
|
|
|
|
def send_newsletter
|
|
|
|
Orbit::Application.load_tasks
|
|
|
|
rake = Rake::Task['epaper:send_email'].execute(OpenStruct.new({:paper_criteria_id => params[:id], :domain => request.host_with_port}))
|
|
|
|
# rake = Rake::Task['epaper:send_email'].invoke([params[:id], request.host_with_port])
|
|
|
|
render :json => {"success" => true}.to_json
|
2019-05-28 15:54:32 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def paper_criteria_params
|
|
|
|
params.require(:paper_criteria).permit!
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|