Add Approval

This commit is contained in:
spen 2014-03-20 15:02:05 +08:00
parent 5bab384195
commit 6ae35f3b94
6 changed files with 141 additions and 36 deletions

View File

@ -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

View File

@ -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

View File

@ -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|

View File

@ -5,8 +5,18 @@
<a class="close" data-dismiss="modal">×</a>
<h3><%= t(:preview) %></h3>
</div>
<div class="modal-body">
<div class="modal-body clearfix">
<div class="modal-left">
<%= label_tag t('announcement.email_to') %>
<% if @bulletin.email_sent == true and ( !@bulletin.email_user_ids.blank? || !@bulletin.other_mailaddress.blank? ) %>
<%= MailCron.get_send_group_mail(@bulletin.email_user_ids , @bulletin.other_mailaddress).join("<br />").html_safe %>
<% end %>
</div>
<div class="modal-right">
<iframe src=<%= panel_announcement_front_end_bulletin_path(bulletin, :category_id => bulletin.category.id ,:preview=>true) %>></iframe>
</div>
</div>
<div class="modal-footer">

View File

@ -6,9 +6,9 @@
quick_edit_link type: 'delete',
link: 'panel_announcement_back_end_bulletin_path'
# can have: title, warning, cancel and submit values
# quick_edit_link type: 'approval',
# link: 'panel_announcement_back_end_bulletin_approval_preview_path'
# quick_edit_link type: 'reject_reason'
quick_edit_link type: 'approval',
link: 'panel_announcement_back_end_bulletin_approval_preview_path'
quick_edit_link type: 'reject_reason'
field type: 'status',
db_field: @statuses,
translation: 'status',

View File

@ -28,13 +28,13 @@ module Announcement
data_count 1..10
authorizable
# approvable
approvable
categorizable
taggable
widgets do
default_widget do
query 'Bulletin'
query 'Bulletin.can_display.available_for_lang(I18n.locale).any_of( {deadline: nil,:postdate.lte => Time.now} , {:deadline.gte => Time.now,:postdate.lte => Time.now} )'
enable ["typeA", "typeB_style3", "typeC"]
image :image
field :postdate