Compare commits

...

7 Commits

Author SHA1 Message Date
manson 0b88e53b62 Removed impressionist counter cache 2014-06-17 11:09:27 +08:00
spen b8464ae461 update default_widget field i18n 2014-05-12 11:17:37 +08:00
spen a357ce6669 fix widget reload_web_links 2014-05-08 14:12:32 +08:00
spen be8d8ff1e6 add backend form append note and fix show image 2014-05-02 16:12:25 +08:00
rulingcom f31481af18 fix search result page 2014-04-10 11:01:02 +08:00
Manson Wang 829fc54a1d Remove elasticsearch 2014-04-10 11:00:51 +08:00
spen 6ae35f3b94 Add Approval 2014-03-20 15:02:05 +08:00
13 changed files with 184 additions and 52 deletions

View File

@ -1,3 +1,4 @@
# encoding: utf-8
class Panel::Announcement::BackEnd::ApprovalsController < OrbitBackendController class Panel::Announcement::BackEnd::ApprovalsController < OrbitBackendController
before_filter :authenticate_user! before_filter :authenticate_user!
before_filter :is_admin? 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.proc_check(params[:bulletin][:is_checked],params[:bulletin][:not_checked_reason])
@bulletin.de_pending @bulletin.de_pending
if @bulletin.save 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') notice = t('announcement.approve_bulletin_success')
else else
notice = t('announcement.approve_bulletin_fail') notice = t('announcement.approve_bulletin_fail')
@ -62,4 +71,43 @@ class Panel::Announcement::BackEnd::ApprovalsController < OrbitBackendControlle
object_auth object_auth
end 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 end

View File

@ -94,23 +94,23 @@ class Panel::Announcement::BackEnd::BulletinsController < OrbitBackendController
@bulletin.create_user_id = current_user.id @bulletin.create_user_id = current_user.id
@bulletin.update_user_id = current_user.id @bulletin.update_user_id = current_user.id
# if(is_manager? || is_admin?)
# @bulletin.is_checked = true if(is_manager? || is_admin?)
# @bulletin.is_rejected = false @bulletin.is_checked = true
# @bulletin.de_pending @bulletin.is_rejected = false
# end @bulletin.de_pending
end
respond_to do |format| respond_to do |format|
if @bulletin.save 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) send_email_data(@bulletin)
@bulletin.email_sent = false @bulletin.email_sent = false
@bulletin.save @bulletin.save
end end
format.html { redirect_to(panel_announcement_back_end_bulletins_url, :notice => t('announcement.create_bulletin_success')) } 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.xml { render :xml => @bulletin, :status => :created, :location => @bulletin }
# format.js # format.js
@ -135,36 +135,44 @@ class Panel::Announcement::BackEnd::BulletinsController < OrbitBackendController
# PUT /bulletins/1.xml # PUT /bulletins/1.xml
def update 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] = params[:bulletin][:email_user_ids].uniq
params[:bulletin][:email_user_ids].delete('') params[:bulletin][:email_user_ids].delete('')
delete_out_invalid_date_from_params params[:bulletin][:update_user_id] = current_user.id
respond_to do |format|
if @bulletin.update_attributes(params[:bulletin])
if @bulletin.email_sent == true && (is_manager? || is_admin?) delete_out_invalid_date_from_params
send_email_data(@bulletin) respond_to do |format|
if @bulletin.update_attributes(params[:bulletin])
@bulletin.email_sent = false if(is_manager? || is_admin?)
@bulletin.save @bulletin.is_checked = true
end @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 }
else
@tags = get_tags
format.html { render :action => "edit" }
format.xml { render :xml => @bulletin.errors, :status => :unprocessable_entity }
end 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
end
# DELETE /bulletins/1 # DELETE /bulletins/1
# DELETE /bulletins/1.xml # DELETE /bulletins/1.xml
def destroy def destroy

View File

@ -12,8 +12,13 @@ class Panel::Announcement::FrontEnd::BulletinsController < OrbitWidgetController
if params[:search_query] == "" if params[:search_query] == ""
@bulletins = get_bulletins_for_index @bulletins = get_bulletins_for_index
else else
@search = Bulletin.tire.search "#{params[:search_query]}" key_string = params[:search_query]
search_result = @search.collect{|result| result.id} keywords = key_string.split(/\s+(?=(?:[^"]*"[^"]*")*[^"]*$)/)
regex = Regexp.union(keywords.map{|word| Regexp.new(".*"+word+".*", "i")})
query = ["title","subtitle","text"].map{|f| {f.to_sym => regex} }
res = Bulletin.any_of(query)
search_result = res.collect{|result| result.id}
@bulletins = Bulletin.all.available_for_lang(I18n.locale).can_display.any_in(_id:search_result).page( params[:page_main]).per(@page_num) @bulletins = Bulletin.all.available_for_lang(I18n.locale).can_display.any_in(_id:search_result).page( params[:page_main]).per(@page_num)
end end

View File

@ -146,7 +146,15 @@ class Panel::Announcement::Widget::BulletinsController < OrbitWidgetController
@selected_tag = Tag.find(params[:tag_id]).first @selected_tag = Tag.find(params[:tag_id]).first
@ModuleApp = ModuleApp.first(:conditions => {:key=>'web_resource'}) @ModuleApp = ModuleApp.first(:conditions => {:key=>'web_resource'})
@link_selected_tag = Tag.first(:conditions => {:name => @selected_tag.name, :module_tag_id => @ModuleApp.id}) @link_module_tag = ModuleTag.first(:conditions => {:name => @selected_tag.name, :module_app_id => @ModuleApp.id})
# @link_selected_tag = Tag.first(:conditions => {:name => @selected_tag.name, :tag_lease_id => @ModuleApp.id})
if !@link_module_tag.blank?
@link_selected_tag = Tag.first(:conditions => {:name => @selected_tag.name, :tag_lease_id => @link_module_tag.id})
else
@link_selected_tag = @link_module_tag
end
@web_links = WebLink.where(:tagged_ids => @link_selected_tag.id.to_s, :is_hidden => false).desc(:is_top,:created_at).available_for_lang(I18n.locale).page(params[:page]).per(@page_num) rescue nil @web_links = WebLink.where(:tagged_ids => @link_selected_tag.id.to_s, :is_hidden => false).desc(:is_top,:created_at).available_for_lang(I18n.locale).page(params[:page]).per(@page_num) rescue nil
end end

View File

@ -13,10 +13,10 @@ class Bulletin
include OrbitModel::TimeFrame include OrbitModel::TimeFrame
include OrbitTag::Taggable include OrbitTag::Taggable
include Tire::Model::Search # include Tire::Model::Search
include Tire::Model::Callbacks # include Tire::Model::Callbacks
is_impressionable :counter_cache => { :column_name => :view_count } is_impressionable
field :title, localize: true field :title, localize: true
field :subtitle, localize: true field :subtitle, localize: true
@ -25,8 +25,16 @@ class Bulletin
field :create_user_id field :create_user_id
field :update_user_id, :class_name => "User" 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 :view_count, :type => Integer, :default => 0
field :not_checked_reason
field :public, :type => Boolean, :default => true field :public, :type => Boolean, :default => true
field :email_sent, :type => Boolean, :default => false field :email_sent, :type => Boolean, :default => false
@ -34,6 +42,9 @@ class Bulletin
field :email_user_ids field :email_user_ids
field :other_mailaddress 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 mount_uploader :image, ImageUploader
has_many :bulletin_links, :autosave => true, :dependent => :destroy has_many :bulletin_links, :autosave => true, :dependent => :destroy
@ -44,9 +55,9 @@ class Bulletin
validates :title, :at_least_one => true validates :title, :at_least_one => true
def to_indexed_json # def to_indexed_json
self.to_json # self.to_json
end # end
# search_in :title, :subtitle, :text # search_in :title, :subtitle, :text
@ -114,6 +125,36 @@ class Bulletin
end 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 def save_bulletin_links
self.bulletin_links.each do |t| self.bulletin_links.each do |t|
@ -158,6 +199,10 @@ class Bulletin
User.find(self.email_user_ids) rescue [] User.find(self.email_user_ids) rescue []
end end
def view_count
Impression.where(:impressionable_id=>self.id).count
end
protected protected
# def clean_values # def clean_values

View File

@ -5,8 +5,18 @@
<a class="close" data-dismiss="modal">×</a> <a class="close" data-dismiss="modal">×</a>
<h3><%= t(:preview) %></h3> <h3><%= t(:preview) %></h3>
</div> </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> <iframe src=<%= panel_announcement_front_end_bulletin_path(bulletin, :category_id => bulletin.category.id ,:preview=>true) %>></iframe>
</div>
</div> </div>
<div class="modal-footer"> <div class="modal-footer">

View File

@ -33,7 +33,7 @@
<a href="#tag" data-toggle="tab"><%= t(:tags) %></a> <a href="#tag" data-toggle="tab"><%= t(:tags) %></a>
</li> </li>
<li> <li>
<a href="#imageupload" data-toggle="tab"><%= t(:image) %></a> <a href="#imageupload" data-toggle="tab"><%= t("announcement.image") %></a>
</li> </li>
<li> <li>
<a href="#mail-group" data-toggle="tab"><%= t('announcement.email_reminder')%></a> <a href="#mail-group" data-toggle="tab"><%= t('announcement.email_reminder')%></a>
@ -116,7 +116,7 @@
<!-- Images Upload --> <!-- Images Upload -->
<div class="control-group"> <div class="control-group">
<label class="control-label muted"><%= t(:image) %></label> <label class="control-label muted"><%= t("announcement.image") %></label>
<div class="controls"> <div class="controls">
<div class="fileupload fileupload-new clearfix <%= 'fileupload-edit' if @bulletin.image.file %>" data-provides="fileupload"> <div class="fileupload fileupload-new clearfix <%= 'fileupload-edit' if @bulletin.image.file %>" data-provides="fileupload">
<div class="fileupload-new thumbnail pull-left"> <div class="fileupload-new thumbnail pull-left">
@ -139,6 +139,7 @@
</label> </label>
</div> </div>
</div> </div>
<div class="image_note"><%= t("announcement.image_note")%></div>
</div> </div>
</div> </div>
@ -241,6 +242,10 @@
<% end %> <% end %>
<div class="control-group">
<div class="controls add-input"><%= t('announcement.append_note')%></div>
</div>
<!-- Link --> <!-- Link -->
<div class="control-group"> <div class="control-group">
<label class="control-label muted"><%= t(:link) %></label> <label class="control-label muted"><%= t(:link) %></label>

View File

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

View File

@ -32,3 +32,4 @@
</table> </table>
<%= paginate( @bulletins, :param_name => :page_main, :params => {:inner => 'false'} ) rescue nil%>

View File

@ -8,10 +8,6 @@
<span><%= link_to unit,panel_announcement_front_end_index_bulletins_by_unit_path(:name=>unit) unless unit.blank? %></span> <span><%= link_to unit,panel_announcement_front_end_index_bulletins_by_unit_path(:name=>unit) unless unit.blank? %></span>
</div> </div>
</div> </div>
<div class="news_image">
<%#= image_tag(@bulletin.image.url, :size => "320x240") if @bulletin.image.file %>
<%= link_to image_tag(@bulletin.image.url, :size => "320x240"), @bulletin.image.url, {:target => '_blank', :title => @bulletin.image_identifier} if @bulletin.image.file %>
</div>
<div class="news_paragraph"> <div class="news_paragraph">
<%= @bulletin.text.html_safe rescue '' %> <%= @bulletin.text.html_safe rescue '' %>
</div> </div>

View File

@ -4,6 +4,7 @@ en:
add_new: Add New add_new: Add New
all_articles: All Articles all_articles: All Articles
announcement: Announcement announcement: Announcement
append_note: Suggest to input underside Link and File's annotation to show correct info in frontend
approval_setting: Approval Setting approval_setting: Approval Setting
approve_bulletin_fail: Approval Fail approve_bulletin_fail: Approval Fail
approve_bulletin_success: Approve Successfully approve_bulletin_success: Approve Successfully
@ -13,7 +14,7 @@ en:
create_bulletin_category_success: Create Category Successfully create_bulletin_category_success: Create Category Successfully
date: Announcement Date date: Announcement Date
default_widget: default_widget:
bulletin_category_with_title: Bulletin Category with Title bulletin_category_with_title: Category
postdate: Post Date postdate: Post Date
subtitle: Subtitle subtitle: Subtitle
title: Title title: Title
@ -25,6 +26,8 @@ en:
frontend: frontend:
bulletins: Announcement front-end bulletins: Announcement front-end
search_result: Search result search_result: Search result
image: Cover image
image_note: The image will not show in content
link_name: Link Name link_name: Link Name
new_bulletin_category: New Bulletin Category new_bulletin_category: New Bulletin Category
picture: Cover Picture picture: Cover Picture

View File

@ -4,6 +4,7 @@ zh_tw:
add_new: 新建 add_new: 新建
all_articles: 文章列表 all_articles: 文章列表
announcement: 公告 announcement: 公告
append_note: 以下之附加連結與檔案,為使前台顯示名稱,建議您輸入註解。
approval_setting: 審核設定 approval_setting: 審核設定
approve_bulletin_fail: 審核失敗 approve_bulletin_fail: 審核失敗
approve_bulletin_success: 審核成功 approve_bulletin_success: 審核成功
@ -13,7 +14,7 @@ zh_tw:
create_bulletin_category_success: 建立類別成功 create_bulletin_category_success: 建立類別成功
date: 起迄日期 date: 起迄日期
default_widget: default_widget:
bulletin_category_with_title: 公告類別及標題 bulletin_category_with_title: 類別
postdate: 張貼日期 postdate: 張貼日期
subtitle: 副標題 subtitle: 副標題
title: 標題 title: 標題
@ -27,6 +28,8 @@ zh_tw:
frontend: frontend:
bulletins: 公告前台 bulletins: 公告前台
search_result: 搜尋結果頁 search_result: 搜尋結果頁
image: 封面圖片
image_note: 此處上傳的圖片不會在公告內文出現
link_name: 連結名稱 link_name: 連結名稱
new_bulletin_category: 新增公告類別 new_bulletin_category: 新增公告類別
picture: 刊頭圖片 picture: 刊頭圖片

View File

@ -28,13 +28,13 @@ module Announcement
data_count 1..10 data_count 1..10
authorizable authorizable
# approvable approvable
categorizable categorizable
taggable taggable
widgets do widgets do
default_widget 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"] enable ["typeA", "typeB_style3", "typeC"]
image :image image :image
field :postdate field :postdate