diff --git a/app/controllers/panel/announcement/back_end/approvals_controller.rb b/app/controllers/panel/announcement/back_end/approvals_controller.rb index 81ce81e..8264c25 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? @@ -6,6 +7,7 @@ class Panel::Announcement::BackEnd::ApprovalsController < OrbitBackendControlle def preview_and_approve + email_group_data @bulletin = Bulletin.find params[:bulletin_id] end @@ -15,6 +17,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 +71,68 @@ 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 + + email_group_data + + @group_mail = Array.new + + bulletin.email_group.each do |egroup| + + if @email_group_data.include?(egroup) and (egroup == 'e_0' or egroup == 'e_1' or egroup == 'e_2' or egroup == 'e_3') + + @group_mail << @email_group_data[egroup]["email"] + + elsif @email_group_data.include?(egroup) and egroup == 'e_4' + + @group_mail << bulletin.other_mailaddress + + end + + end + + if !@group_mail.join.blank? + + @mail_content = { + "host" => @host, + "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, + :mail_sentdate => DateTime.now, + :create_user_id => bulletin.create_user_id, + :update_user_id => bulletin.create_user_id + } + + @mail_cron = MailCron.new(@mail_cron) + + @mail_cron.save + + MailCron.send_mail_now(@mail_cron.id) + + end + + end + + def email_group_data + + @email_group_data = Bulletin.email_group_data + + 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 de369ee..76ac4d5 100644 --- a/app/controllers/panel/announcement/back_end/bulletins_controller.rb +++ b/app/controllers/panel/announcement/back_end/bulletins_controller.rb @@ -1,3 +1,5 @@ +# encoding: utf-8 + class Panel::Announcement::BackEnd::BulletinsController < OrbitBackendController # include OrbitControllerLib::DivisionForDisable @@ -19,6 +21,8 @@ class Panel::Announcement::BackEnd::BulletinsController < OrbitBackendController def index + email_group_data + @tags = get_tags @categories = get_categories_for_index @statuses = get_statuses @@ -47,6 +51,9 @@ class Panel::Announcement::BackEnd::BulletinsController < OrbitBackendController # GET /bulletins/new # GET /bulletins/new.xml def new + + email_group_data + if(session[:in_validate_object].blank?) @bulletin = Bulletin.new(:postdate => DateTime.now) else @@ -64,6 +71,9 @@ class Panel::Announcement::BackEnd::BulletinsController < OrbitBackendController # GET /bulletins/1/edit def edit + + email_group_data + @bulletin = Bulletin.find(params[:id]) @tags = get_tags is_authorized_sub_manager = @bulletin.category.auth_sub_manager.authorized_user_ids rescue nil @@ -82,21 +92,31 @@ class Panel::Announcement::BackEnd::BulletinsController < OrbitBackendController # POST /bulletins # POST /bulletins.xml def create + + email_group_data + @tags = get_tags @bulletin = Bulletin.new(params[:bulletin]) @bulletin.deadline = nil if (@bulletin.deadline < @bulletin.postdate rescue nil) @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 && @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 @@ -121,12 +141,18 @@ class Panel::Announcement::BackEnd::BulletinsController < OrbitBackendController # PUT /bulletins/1.xml def update - @bulletin = Bulletin.find(params[:id]) - delete_out_invalid_date_from_params - respond_to do |format| - if @bulletin.update_attributes(params[:bulletin]) + email_group_data + + @bulletin = Bulletin.find(params[:id]) + delete_out_invalid_date_from_params + respond_to do |format| + if @bulletin.update_attributes(params[:bulletin]) + if(is_manager? || is_admin?) + @bulletin.is_checked = true + @bulletin.is_rejected = false + @bulletin.de_pending! 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 } @@ -135,10 +161,27 @@ class Panel::Announcement::BackEnd::BulletinsController < OrbitBackendController format.html { render :action => "edit" } format.xml { render :xml => @bulletin.errors, :status => :unprocessable_entity } 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 @@ -164,6 +207,70 @@ class Panel::Announcement::BackEnd::BulletinsController < OrbitBackendController protected + def send_email_data(bulletin) + + @site = Site.first + @user = User.find(bulletin.create_user_id) + @host = request.host_with_port + + email_group_data + + @group_mail = Array.new + + bulletin.email_group.each do |egroup| + + if @email_group_data.include?(egroup) and (egroup == 'e_0' or egroup == 'e_1' or egroup == 'e_2' or egroup == 'e_3') + + @group_mail << @email_group_data[egroup]["email"] + + elsif @email_group_data.include?(egroup) and egroup == 'e_4' + + @group_mail << bulletin.other_mailaddress + + end + + end + + if !@group_mail.join.blank? + + @mail_content = { + "host" => @host, + "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")}:", + :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, + :mail_sentdate => DateTime.now, + :create_user_id => bulletin.create_user_id, + :update_user_id => bulletin.create_user_id + } + + @mail_cron = MailCron.new(@mail_cron) + + @mail_cron.save + + MailCron.send_mail_now(@mail_cron.id) + + end + + end + + def email_group_data + + @email_group_data = Bulletin.email_group_data + + end + def delete_out_invalid_date_from_params if((params[:bulletin]["deadline(1i)"] && params[:bulletin]["deadline(1i)"].blank?) or (params[:bulletin]["deadline(2i)"] && params[:bulletin]["deadline(2i)"].blank?) or (params[:bulletin]["deadline(3i)"] && params[:bulletin]["deadline(3i)"].blank?)) params[:bulletin].delete("deadline(1i)") diff --git a/app/models/bulletin.rb b/app/models/bulletin.rb index 77fa12b..7731946 100644 --- a/app/models/bulletin.rb +++ b/app/models/bulletin.rb @@ -25,10 +25,23 @@ 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_group, :type => Array + field :other_mailaddress + mount_uploader :image, ImageUploader has_many :bulletin_links, :autosave => true, :dependent => :destroy @@ -109,6 +122,37 @@ 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| @@ -149,9 +193,47 @@ class Bulletin preview_object end + def get_email_group_data(email_group_data) + + group_mail = Array.new + + self.email_group.each do |egroup| + + if email_group_data.include?(egroup) and (egroup == 'e_0' or egroup == 'e_1' or egroup == 'e_2' or egroup == 'e_3') + + group_mail << "#{email_group_data[egroup]["email"]}(#{email_group_data[egroup]["name"]})" + + elsif email_group_data.include?(egroup) and egroup == 'e_4' + + self.other_mailaddress.split(",").each do |otmail| + + group_mail << "#{otmail}(#{email_group_data[egroup]["name"]})" + + end + + end + + end + + group_mail.join("
").html_safe + + end + protected + def self.email_group_data + + @email_group_data = { + 'e_0'=> {"name"=>I18n.t('announcement.email_group_data_0'), "email"=>"alluser@tea.ntue.edu.tw"}, + 'e_1'=> {"name"=>I18n.t('announcement.email_group_data_1'), "email"=>"allstu@tea.ntue.edu.tw"}, + 'e_2'=> {"name"=>I18n.t('announcement.email_group_data_2'), "email"=>"allgrad@tea.ntue.edu.tw"}, + 'e_3'=> {"name"=>I18n.t('announcement.email_group_data_3'), "email"=>"allad@tea.ntue.edu.tw"}, + 'e_4'=> {"name"=>I18n.t('announcement.email_group_data_4')} + } + + end + # def clean_values # self.bulletin_links.each do |link| # link.delete if link.url.blank? && link.title.blank? diff --git a/app/views/announcement_mailer/cron_mail.html.erb b/app/views/announcement_mailer/cron_mail.html.erb new file mode 100644 index 0000000..fbf7e0b --- /dev/null +++ b/app/views/announcement_mailer/cron_mail.html.erb @@ -0,0 +1,29 @@ +<% # encoding: utf-8 %> + + + + + + +
+
+ + <%= t('announcement.mail_hi') %>

+ <%= t('announcement.mail_url_view') %>

+ " target="_blank"> <%= @data.mail_content["title"] %>

+ + --
+ <%= t('announcement.mail_source') %> :" target="_blank"> <%= @data.mail_content["site_title"] %>
+ <%= t('announcement.mail_time') %> <%= DateTime.now %> +
+ + + + + + + + + + + \ No newline at end of file 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..3a60638 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) %>

- +
+ + <%= t("ad.widget_info_for_ad_image_size", :best_size=> "290px(w) x 230px(h)") %> +
+ <%= t("announcement.image_upload_size_note", :image_upload_size =>'900kb') %> +
+ + + + + + + +
+ + +
+ +
+ + + +
+ + <% @email_group_data.collect do |k,v| %> + + + + <% end if !@email_group_data.blank? %> + +
+
+
+
+ +
+
+ <%= "#{t("announcement.other_mailaddress")}(#{t("announcement.other_mailaddress_note")})"%> + <%= f.text_area :other_mailaddress, :class=>"span12", :cols=>"25", :rows=>"10" %>
@@ -302,6 +349,11 @@ $(this).parents('.start-line').hide(); } }); + + $('#remind-check').prop('checked') ? '':$('.content-box').addClass('hide') + $('#remind-check').on('change', function() { + $(this).prop('checked') ? $('.content-box').removeClass('hide'):$('.content-box').addClass('hide') + }) }); <% end %> diff --git a/app/views/panel/announcement/back_end/bulletins/index.html.erb b/app/views/panel/announcement/back_end/bulletins/index.html.erb index e2ffb3e..9680de1 100644 --- a/app/views/panel/announcement/back_end/bulletins/index.html.erb +++ b/app/views/panel/announcement/back_end/bulletins/index.html.erb @@ -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', diff --git a/app/views/panel/announcement/front_end/bulletins/show.html.erb b/app/views/panel/announcement/front_end/bulletins/show.html.erb index 0f60d98..1550e71 100644 --- a/app/views/panel/announcement/front_end/bulletins/show.html.erb +++ b/app/views/panel/announcement/front_end/bulletins/show.html.erb @@ -4,8 +4,11 @@
<%= dislpay_view_count(@bulletin) %> <%= display_date_time(@bulletin.postdate) %> - <% unit = @bulletin.cache_dept[I18n.locale.to_s] rescue nil %> - <%= link_to unit,panel_announcement_front_end_index_bulletins_by_unit_path(:name=>unit) unless unit.blank? %> + <% + unit_field = User.get_member_list_attribute_field("staff","Unit") + unit = User.get_member_list_attribute_value(@bulletin.create_user_id,unit_field.id).get_value_by_locale(I18n.locale) rescue nil + %> + <%= t('announcement.default_widget.bulletin_create_dept') + ": " + unit unless unit.blank? %>
diff --git a/config/locales/en.yml b/config/locales/en.yml index 990fcd7..350f09f 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -17,6 +17,7 @@ en: postdate: Post Date subtitle: Subtitle title: Title + bulletin_create_dept: Unit editing_announcement: Edit Announcement editing_announcement_category: Edit Category file: Attachment @@ -36,3 +37,21 @@ en: bulletins_and_web_links: Differential Nav. index: Index search: Search + email_reminder: Email Reminder + activate_email_eminder: Activate Email Reminder + email_sentdate: Email Time + email_group: Email Group + email_group_data_0: All Faculty + email_group_data_1: Undergraduates + email_group_data_2: Postgraduates + email_group_data_3: Continuing Ed. Postgraduates + email_group_data_4: Other + # mail_subject: this is an announcement reminder from【%{site_title}】 + mail_subject: 【北教大公告提醒】 + other_mailaddress: Other Email + other_mailaddress_note: Divide different email accounts with "," + mail_hi: Hi + mail_url_view: This email is the reminder of an announcement, please click the link for the details + mail_source: Source + mail_time: Time + image_upload_size_note: The following recommendations %{image_upload_size} upload size \ No newline at end of file diff --git a/config/locales/zh_tw.yml b/config/locales/zh_tw.yml index cb5128a..738a1da 100644 --- a/config/locales/zh_tw.yml +++ b/config/locales/zh_tw.yml @@ -17,6 +17,7 @@ zh_tw: postdate: 張貼日期 subtitle: 副標題 title: 標題 + bulletin_create_dept: 單位 editing_announcement: 編輯類別 editing_announcement_category: 編輯類別 error: @@ -38,4 +39,22 @@ zh_tw: bulletins_and_web_links: 分眾頁籤 index: 索引 search: 搜尋 - more: 更多+ \ No newline at end of file + more: 更多+ + email_reminder: 寄送提醒 + activate_email_eminder: 開啟寄送提醒 + email_sentdate: 寄送時間 + email_group: 寄送群組 + other_mailaddress: 其他Mail + other_mailaddress_note: 輸入多組mail時,請用","逗號隔開 + email_group_data_0: 全校教職員 + email_group_data_1: 大學部學生 + email_group_data_2: 日間部研究生 + email_group_data_3: 進修部研究生 + email_group_data_4: 其他 + # mail_subject: 來自【%{site_title}】的公告事件提醒 + mail_subject: 【北教大公告提醒】 + mail_hi: 您好 + mail_url_view: 此封信件為公告事件提醒,請點選以下連結詳細觀看 + mail_source: 來源 + mail_time: 時間 + image_upload_size_note: 建議檔案小於%{image_upload_size} \ No newline at end of file