2017-07-05 09:16:55 +00:00
|
|
|
class EPapersController < ApplicationController
|
|
|
|
|
|
|
|
def index
|
|
|
|
params = OrbitHelper.params
|
|
|
|
page = Page.where(:page_id => params[:page_id]).first rescue nil
|
|
|
|
papers = Paper.can_display.order_by(:order_position => "asc").filter_by_categories
|
|
|
|
f = papers.collect do |paper|
|
|
|
|
statuses = paper.statuses_with_classname.collect do |status|
|
|
|
|
{
|
|
|
|
"status" => status["name"],
|
|
|
|
"status-class" => "status-#{status['classname']}"
|
|
|
|
}
|
|
|
|
end
|
|
|
|
topics = paper.topics.collect do |topic|
|
|
|
|
{
|
|
|
|
|
|
|
|
"episode" => topic.episode,
|
|
|
|
"content" => topic.content,
|
2017-08-04 07:51:42 +00:00
|
|
|
"publish_date" => topic.created_at
|
2017-07-05 09:16:55 +00:00
|
|
|
}
|
|
|
|
end
|
|
|
|
|
|
|
|
{
|
|
|
|
"link_to_show" => OrbitHelper.url_to_show(paper.to_param),
|
|
|
|
"title" => paper.title,
|
|
|
|
"period" => paper.period,
|
|
|
|
"description" => paper.description,
|
|
|
|
"category" => paper.category.title,
|
|
|
|
"topic" => topics
|
|
|
|
}
|
|
|
|
end
|
|
|
|
{
|
|
|
|
"papers" => f,
|
|
|
|
"extras" => {
|
|
|
|
"widget-title"=>"EPaper",
|
|
|
|
"th_title" => t('e_paper.title'),
|
|
|
|
"th_category" => t('category'),
|
|
|
|
"th_period" => t('e_paper.period'),
|
|
|
|
"th_description" => t('e_paper.description'),
|
|
|
|
"th_history" => t('e_paper.history'),
|
|
|
|
"th_intro" => t('e_paper.intro'),
|
|
|
|
"th_episode" => t('e_paper.topic_name'),
|
|
|
|
"date" => t('e_paper.date')
|
|
|
|
},
|
|
|
|
"total_pages" => papers.total_pages
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
|
|
|
def show
|
|
|
|
params = OrbitHelper.params
|
|
|
|
paper = Paper.find_by(:uid => params[:uid])
|
|
|
|
|
|
|
|
topics = paper.topics.collect do |topic|
|
2017-08-04 07:39:47 +00:00
|
|
|
desc = ActionView::Base.full_sanitizer.sanitize(topic.content)
|
2017-07-05 09:16:55 +00:00
|
|
|
{
|
|
|
|
"link_to_show" => OrbitHelper.url_to_show(topic.to_param) + "?method=showtopic",
|
|
|
|
"episode" => topic.episode,
|
2017-08-04 07:30:30 +00:00
|
|
|
"content" => topic.content,
|
|
|
|
"description" => desc[0..100],
|
2017-08-04 07:51:42 +00:00
|
|
|
"publish_date" => topic.created_at
|
2017-07-05 09:16:55 +00:00
|
|
|
}
|
|
|
|
end
|
|
|
|
{
|
|
|
|
"data" => {
|
|
|
|
"title" => paper.title,
|
|
|
|
"period" => paper.period,
|
|
|
|
"description" => paper.description,
|
|
|
|
"category" => paper.category.title,
|
2017-08-04 07:51:42 +00:00
|
|
|
"publish_date" => paper.created_at,
|
2017-07-05 09:16:55 +00:00
|
|
|
"th_title" => t('e_paper.title'),
|
|
|
|
"th_category" => t('category'),
|
|
|
|
"th_period" => t('e_paper.period'),
|
|
|
|
"th_description" => t('e_paper.description'),
|
|
|
|
"th_history" => t('e_paper.history'),
|
|
|
|
"th_intro" => t('e_paper.intro'),
|
|
|
|
"th_episode" => t('e_paper.topic_name'),
|
|
|
|
"date" => t('e_paper.date'),
|
|
|
|
},
|
|
|
|
"topics" => topics
|
|
|
|
}
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
def subscriber_widget
|
|
|
|
{}
|
|
|
|
end
|
|
|
|
|
|
|
|
def subscribeuser
|
|
|
|
if Subscriber.where(:email => params[:email]).count == 0
|
|
|
|
subscriber = Subscriber.new
|
|
|
|
subscriber.email = params[:email]
|
|
|
|
subscriber.save
|
|
|
|
data = {"success" => true, "msg" => "Successfully Subscribed!!!"}
|
|
|
|
else
|
|
|
|
data = {"success" => false, "msg" => "Already Subscribed!!!"}
|
|
|
|
end
|
|
|
|
render :json => data.to_json
|
|
|
|
end
|
|
|
|
|
|
|
|
def unsubscribeuser
|
|
|
|
subscriber = Subscriber.where(:email => params[:email]).first rescue nil
|
|
|
|
if !subscriber.nil?
|
|
|
|
subscriber.destroy
|
|
|
|
data = {"success" => true, "msg" => "Successfully Unsubscribed!!!"}
|
|
|
|
# else
|
|
|
|
# data = {"success" => false, "msg" => "Already Subscribed!!!"}
|
|
|
|
end
|
|
|
|
render :json => data.to_json
|
|
|
|
end
|
|
|
|
|
|
|
|
def showtopic
|
|
|
|
params = OrbitHelper.params
|
|
|
|
topic = Topic.where(:uid => params[:uid]).first
|
|
|
|
|
|
|
|
{
|
|
|
|
"episode" => topic.episode,
|
|
|
|
"content" => topic.content,
|
|
|
|
"publish_date" => topic.created_at
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def sub_params
|
|
|
|
params.require(:subscriber).permit!
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
end
|