class Admin::EmailersController < OrbitAdminController include Admin::EmailersHelper before_action :load_access_level def index @table_fields = [:category, "emailer.mail_subject", "emailer.delivery_date", "emailer.created_by", "emailer.status"] @emails = EmailEntry.all.order(sort) @emails = search_data(@emails,[:mail_subject]).page(params[:page]).per(10) if request.xhr? render :partial => "index" end end def new @email = EmailEntry.new end def approve email = EmailEntry.find(params[:id]) email.recipients.each do |recipient| e = Email.new(:module_app_key => "emailer", :mail_to => recipient, :mail_subject => email.mail_subject, :mail_content => email.mail_content, :create_user_id => email.create_user_id) if !email.email_sentdate.nil? && email.email_sentdate > Time.now e.mail_sentdate = email.email_sentdate end if !email.email_entry_files.blank? email.email_entry_files.each do |file| e_file = EmailFile.new e_file.title = file.title e_file.file = file.file e_file.emails_id = e.id e_file.save end end e.save end email.approved = true email.save redirect_to :back end def create email = EmailEntry.new(email_params) email.create_user_id = current_user.id email.save redirect_to admin_emailers_path end def edit @email = EmailEntry.find(params[:id]) end def update email = EmailEntry.find(params[:id]) email.update_attributes(email_params) email.save redirect_to admin_emailers_path end def destroy email = EmailEntry.find(params[:id]) email.destroy redirect_to :back end private def email_params params.require(:email_entry).permit! end end