e_paper/app/controllers/admin/e_papers_controller.rb

77 lines
2.0 KiB
Ruby
Raw Normal View History

2017-07-05 09:16:55 +00:00
class Admin::EPapersController < OrbitAdminController
before_filter :setup_vars
def index
@table_fields = [:category,t('e_paper.title'),t('e_paper.publish_date')]
@categories = @module_app.categories.enabled
@filter_fields = filter_fields(@categories, [])
@filter_fields.delete(:status)
@filter_fields.delete(:tags)
@papers = Paper.order_by(sort)
.with_categories(filters("category"))
@papers = search_data(@papers,[:title]).page(params[:page]).per(10)
render :partial => "index" if request.xhr?
end
def new
user_has_rights = (current_user.is_admin? ? true : (current_user.is_manager?(@module_app) ? true : current_user.is_manager_with_role?(@module_app) ? true : false)) rescue false
@paper = Paper.new
render_401 if !user_has_rights
end
def create
@paper = Paper.new(create_params)
@paper.save
redirect_to params['referer_url']
end
def edit
user_has_rights = (current_user.is_admin? ? true : (current_user.is_manager?(@module_app) ? true : current_user.is_manager_with_role?(@module_app) ? true : false)) rescue false
@paper = Paper.find(params[:id])
if !can_edit_or_delete?(@paper)
render_401
end
end
def update
paper = Paper.find(params[:id])
paper.update_attributes(create_params)
paper.save
redirect_to params['referer_url']
end
def destroy
paper = Paper.find(params[:id])
paper.destroy
redirect_to admin_e_papers_path(:page => params[:page])
end
def show
@paper = Paper.find(params[:id])
@table_fields = [t('e_paper.title'),t('e_paper.topic_name'),t('e_paper.publish_date')]
@topics = @paper.topics.all
end
def send_email_to_subscribers
paper = Paper.find(params[:id])
paper.ready_to_send = true
paper.save
redirect_to admin_e_papers_path(:page => params[:page])
end
private
def setup_vars
@module_app = ModuleApp.where(:key => "e_paper").first
end
def create_params
params.require(:paper).permit!
end
end