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 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 def setup_vars @module_app = ModuleApp.where(:key => "e_paper").first end def create_params params.require(:paper).permit! end end