From 6ae35f3b94f36f4cfaf2f7110ba275e8190f69ef Mon Sep 17 00:00:00 2001 From: spen Date: Thu, 20 Mar 2014 15:02:05 +0800 Subject: [PATCH] Add Approval --- .../back_end/approvals_controller.rb | 48 ++++++++++++++ .../back_end/bulletins_controller.rb | 66 ++++++++++--------- app/models/bulletin.rb | 41 ++++++++++++ .../approvals/_modal_approve.html.erb | 12 +++- .../back_end/bulletins/index.html.erb | 6 +- lib/announcement.rb | 4 +- 6 files changed, 141 insertions(+), 36 deletions(-) diff --git a/app/controllers/panel/announcement/back_end/approvals_controller.rb b/app/controllers/panel/announcement/back_end/approvals_controller.rb index 81ce81e..a653f72 100644 --- a/app/controllers/panel/announcement/back_end/approvals_controller.rb +++ b/app/controllers/panel/announcement/back_end/approvals_controller.rb @@ -1,3 +1,4 @@ +# encoding: utf-8 class Panel::Announcement::BackEnd::ApprovalsController < OrbitBackendController before_filter :authenticate_user! before_filter :is_admin? @@ -15,6 +16,14 @@ class Panel::Announcement::BackEnd::ApprovalsController < OrbitBackendControlle @bulletin.proc_check(params[:bulletin][:is_checked],params[:bulletin][:not_checked_reason]) @bulletin.de_pending if @bulletin.save + + if @bulletin.email_sent == true && @bulletin.is_checked == true && !@bulletin.is_rejected + send_email_data(@bulletin) + + @bulletin.email_sent = false + @bulletin.save + end + notice = t('announcement.approve_bulletin_success') else notice = t('announcement.approve_bulletin_fail') @@ -61,5 +70,44 @@ class Panel::Announcement::BackEnd::ApprovalsController < OrbitBackendControlle object_auth.privilege_users = privilege_users object_auth end + + def send_email_data(bulletin) + + @site = Site.first + @user = User.find(bulletin.create_user_id) + @host = request.host_with_port + + @group_mail = MailCron.get_send_group_mail( bulletin.email_user_ids , bulletin.other_mailaddress ) + + if !@group_mail.join.blank? + + @mail_content = { + "host" => @host, + "lang" => I18n.locale, + "site_title" => @site.title, + "title" => bulletin.title, + "template" => 'announcement_mailer/cron_mail', + "url" => "http://#{@host}#{panel_announcement_front_end_bulletin_path(bulletin, :category_id => bulletin.category.id)}" + } + + @mail_cron = { + :mail_from_app => 'announcement', + # :mail_from => @user.email, + # :mail_reply_to => @user.email, + :mail_subject => "#{t("announcement.mail_subject",:site_title => @site.title)}:#{bulletin.title}", + :mail_to => @group_mail.join(','), + :mail_content => @mail_content , + :mail_sentdate => bulletin.email_sentdate, + :create_user_id => bulletin.create_user_id, + :update_user_id => bulletin.create_user_id + } + + @mail_cron = MailCron.new(@mail_cron) + + @mail_cron.save + + end + + end end diff --git a/app/controllers/panel/announcement/back_end/bulletins_controller.rb b/app/controllers/panel/announcement/back_end/bulletins_controller.rb index d607440..77b5de5 100644 --- a/app/controllers/panel/announcement/back_end/bulletins_controller.rb +++ b/app/controllers/panel/announcement/back_end/bulletins_controller.rb @@ -94,23 +94,23 @@ class Panel::Announcement::BackEnd::BulletinsController < OrbitBackendController @bulletin.create_user_id = current_user.id @bulletin.update_user_id = current_user.id - # if(is_manager? || is_admin?) - # @bulletin.is_checked = true - # @bulletin.is_rejected = false - # @bulletin.de_pending - # end + + if(is_manager? || is_admin?) + @bulletin.is_checked = true + @bulletin.is_rejected = false + @bulletin.de_pending + end respond_to do |format| if @bulletin.save - if @bulletin.email_sent == true && (is_manager? || is_admin?) + if @bulletin.email_sent == true && @bulletin.is_checked == true && !@bulletin.is_rejected send_email_data(@bulletin) @bulletin.email_sent = false @bulletin.save end - format.html { redirect_to(panel_announcement_back_end_bulletins_url, :notice => t('announcement.create_bulletin_success')) } format.xml { render :xml => @bulletin, :status => :created, :location => @bulletin } # format.js @@ -135,36 +135,42 @@ class Panel::Announcement::BackEnd::BulletinsController < OrbitBackendController # PUT /bulletins/1.xml def update - @bulletin = Bulletin.find(params[:id]) + @bulletin = Bulletin.find(params[:id]) - params[:bulletin][:tag_ids] = (params[:bulletin][:tag_ids] ? params[:bulletin][:tag_ids] : []) + params[:bulletin][:tag_ids] = (params[:bulletin][:tag_ids] ? params[:bulletin][:tag_ids] : []) - params[:bulletin][:email_user_ids] = params[:bulletin][:email_user_ids].uniq - params[:bulletin][:email_user_ids].delete('') - - delete_out_invalid_date_from_params - respond_to do |format| - if @bulletin.update_attributes(params[:bulletin]) + params[:bulletin][:email_user_ids] = params[:bulletin][:email_user_ids].uniq + params[:bulletin][:email_user_ids].delete('') + + delete_out_invalid_date_from_params + respond_to do |format| + if @bulletin.update_attributes(params[:bulletin]) - if @bulletin.email_sent == true && (is_manager? || is_admin?) - send_email_data(@bulletin) - - @bulletin.email_sent = false - @bulletin.save - end - - format.html { redirect_to(panel_announcement_back_end_bulletins_url, :notice => t('bulletin.update_bulletin_success')) } - format.js { render 'toggle_enable' } - format.xml { head :ok } - else - @tags = get_tags - format.html { render :action => "edit" } - format.xml { render :xml => @bulletin.errors, :status => :unprocessable_entity } + if(is_manager? || is_admin?) + @bulletin.is_checked = true + @bulletin.is_rejected = false + @bulletin.de_pending! end - end + if @bulletin.email_sent == true && @bulletin.is_checked == true && !@bulletin.is_rejected + send_email_data(@bulletin) + + @bulletin.email_sent = false + @bulletin.save + end + + format.html { redirect_to(panel_announcement_back_end_bulletins_url, :notice => t('bulletin.update_bulletin_success')) } + format.js { render 'toggle_enable' } + format.xml { head :ok } + else + @tags = get_tags + format.html { render :action => "edit" } + format.xml { render :xml => @bulletin.errors, :status => :unprocessable_entity } + end end + end + # DELETE /bulletins/1 # DELETE /bulletins/1.xml def destroy diff --git a/app/models/bulletin.rb b/app/models/bulletin.rb index 843d597..f0f44cf 100644 --- a/app/models/bulletin.rb +++ b/app/models/bulletin.rb @@ -25,14 +25,25 @@ class Bulletin field :create_user_id field :update_user_id, :class_name => "User" + field :is_top, :type => Boolean, :default => false + field :is_hot, :type => Boolean, :default => false + field :is_hidden, :type => Boolean, :default => false + field :is_checked, :type => Boolean, :default => false + field :is_pending, :type => Boolean, :default => true + field :is_rejected, :type => Boolean, :default => false field :view_count, :type => Integer, :default => 0 + field :not_checked_reason + field :public, :type => Boolean, :default => true field :email_sent, :type => Boolean, :default => false field :email_sentdate , :type => DateTime field :email_user_ids field :other_mailaddress + + scope :can_display, where(is_checked: true, is_rejected: false, is_pending: false) + scope :available_for_lang, ->(locale){ where("available_for_#{locale}".to_sym => true) } mount_uploader :image, ImageUploader @@ -114,6 +125,36 @@ class Bulletin end + def proc_check(check,not_pass_info = "") + self.is_checked = true + if check =="true" + self.is_rejected = false + elsif check == "false" + self.is_rejected = true + self.not_checked_reason = not_pass_info + end + end + + def de_pending + self.is_pending = false + end + + def de_pending! + de_pending + self.save! + end + + def is_checked? + !self.is_pending && self.is_checked && (self.is_rejected == false) + end + + def is_pending? + self.is_pending + end + + def is_rejected? + !self.is_pending && self.is_rejected && (self.is_rejected == true) + end def save_bulletin_links self.bulletin_links.each do |t| diff --git a/app/views/panel/announcement/back_end/approvals/_modal_approve.html.erb b/app/views/panel/announcement/back_end/approvals/_modal_approve.html.erb index 802156b..67a1f20 100644 --- a/app/views/panel/announcement/back_end/approvals/_modal_approve.html.erb +++ b/app/views/panel/announcement/back_end/approvals/_modal_approve.html.erb @@ -5,8 +5,18 @@ ×

<%= t(:preview) %>

-