Compare commits

..

1 Commits
master ... temp

Author SHA1 Message Date
JiangRu 0e32154d53 1.fix add news prompt
2.add is_hidden didn't show on son
2015-04-15 20:10:46 +08:00
19 changed files with 61 additions and 1167 deletions

View File

@ -28,8 +28,8 @@ class Admin::NewsAdminsController < OrbitAdminController
end
def update
@unit = Unit.where(:uid => params[:id].split("-").last).first rescue nil
@unit.update_attributes(unit_params) #if !@unit.nil?
@unit = Unit.find(params[:id])
@unit.update_attributes(unit_params)
redirect_to admin_news_admins_path
end
@ -40,6 +40,10 @@ class Admin::NewsAdminsController < OrbitAdminController
redirect_to admin_news_admins_path
end
def unit_params
params.require(:unit).permit!
end
def get_departments
unit = Unit.find(Sanitize.clean(params[:unit]))
departments = unit.departments.collect do |d|
@ -51,10 +55,4 @@ class Admin::NewsAdminsController < OrbitAdminController
render :json => {"departments" => departments}.to_json
end
private
def unit_params
params.require(:unit).permit!
end
end

View File

@ -1,6 +1,5 @@
# encoding: utf-8
class Admin::NewsController < OrbitAdminController
require 'rubyXL'
include Admin::NewsHelper
before_action ->(module_app = @app_title) { set_variables module_app }
before_action :set_news_bulletin, only: [:edit, :destroy]
@ -63,17 +62,9 @@ class Admin::NewsController < OrbitAdminController
news_bulletin.update_user_id = current_user.id
if user_can_approve?
news_bulletin.approved = true
news_bulletin.save
else
news_bulletin.save
# Thread.new do
# begin
# send_notification_mail_to_managers(news_bulletin,"approval")
# rescue e
# end
# end
end
# build_email(news_bulletin)
news_bulletin.save
build_email(news_bulletin)
redirect_to params['referer_url']
end
@ -83,15 +74,11 @@ class Admin::NewsController < OrbitAdminController
if params["approved"] == "true"
news_bulletin.approved = true
news_bulletin.rejected = false
news_bulletin.reapproval = false
news_bulletin.save
else
news_bulletin.rejected = true
news_bulletin.reapproval = false
news_bulletin.rejection_reason = params["reason"]
news_bulletin.save
# send_rejection_email(news_bulletin)
end
news_bulletin.save
redirect_to "/admin/news"
end
@ -112,13 +99,7 @@ class Admin::NewsController < OrbitAdminController
def update
uid = params[:id].split('-').last
news_bulletin = NewsBulletin.where(:uid=>uid).first rescue nil
NewsBulletin.where(:copy_id=>news_bulletin.id.to_s).destroy
news_bulletin.is_edit = true
news_bulletin.save
set_approved = news_bulletin.is_preview
news_bulletin = news_bulletin.get_org_model
news_bulletin.approved = true if set_approved
news_bulletin = NewsBulletin.find_by(:uid=>uid)
news_bulletin_params[:tags] = news_bulletin_params[:tags].blank? ? [] : news_bulletin_params[:tags]
news_bulletin_params[:email_member_ids] = news_bulletin_params[:email_member_ids].blank? ? [] : news_bulletin_params[:email_member_ids]
@ -129,18 +110,8 @@ class Admin::NewsController < OrbitAdminController
end
news_bulletin.update_attributes(news_bulletin_params)
if news_bulletin.rejected
news_bulletin.reapproval = true
news_bulletin.save
# Thread.new do
# begin
# send_notification_mail_to_managers(news_bulletin, "reapproval")
# rescue e
# end
# end
end
news_bulletin.save
# build_email(news_bulletin)
build_email(news_bulletin)
redirect_to params['referer_url']
end
@ -156,140 +127,6 @@ class Admin::NewsController < OrbitAdminController
redirect_to "/admin/news"
end
def render_404
render :file => "#{Rails.root}/app/views/errors/404.html", :layout => false, :status => 404, :formats => [:html]
end
def import_export
@thread = Multithread.where(:id=>params[:thread_id]).first if params[:thread_id].present?
end
def download_file_from_thread
@thread = Multithread.where(:id=>params[:id]).first if params[:id].present?
if @thread && @thread.status[:file]
send_file(@thread.status[:file],:filename=>@thread.status[:filename])
else
render_404
end
end
def excel_format
respond_to do |format|
format.xlsx {
response.headers['Content-Disposition'] = 'attachment; filename="news_import_format.xlsx"'
}
end
end
def export_excel
@thread = Multithread.where(:key=>'export_news').first
update_flag = true
if @thread.nil?
@thread = Multithread.create(:key=>'export_news',:status=>{:status=>'Processing'})
else
update_flag = false if @thread.status[:status] == 'Processing' && @thread.respond_to?(:updated_at) && (@thread.updated_at > DateTime.now - 1.minute rescue false)
if update_flag
@thread.update(:status=>{:status=>'Processing'})
end
end
if update_flag
@host = Site.first.root_url
if @host == "http"
@host = request.protocol + request.host_with_port
end
Thread.new do
begin
@news = NewsBulletin.where(:is_preview.ne=>true).desc(:id)
last_updated = [NewsBulletin.max(:updated_at).to_i, Unit.max(:updated_at).to_i, Department.max(:updated_at).to_i].max
filename = "public/news_export_#{last_updated}.xlsx"
if File.exist?(filename)
@thread.update(:status=>{:status=>'finish','finish_percent'=>100,'info'=>I18n.t('announcement.read_from_cache')})
else
excel_contents = render_to_string( handlers: [:axlsx], formats: [:xlsx] ,partial: 'export_excel.xlsx' )
File.open(filename, 'w') do |f|
f.write excel_contents
end
end
@thread.status[:file] = filename
@thread.status[:filename] = "news_export_#{DateTime.now.in_time_zone(Time.zone.utc_offset / 3600).strftime('%Y_%m_%d_%H%M')}.xlsx"
@thread.save
rescue => e
@thread.status[:status] = 'error'
# @thread.status[:info] = [e.to_s, e.backtrace]
puts [e.to_s, e.backtrace]
@thread.save
end
end
end
redirect_to admin_news_import_export_path(:thread_id=>@thread.id.to_s)
end
def importnews
workbook = RubyXL::Parser.parse(params["import_file"].tempfile)
raw_categories = @module_app.categories.asc(:created_at).to_a.map.with_index{|v, k| [k.to_s,v]}.to_h
raw_tags = @module_app.tags.asc(:created_at).to_a.map.with_index{|v, k| [k.to_s,v]}.to_h
categories = raw_categories.clone
tags = raw_tags.clone
sheet = workbook[0]
if sheet.count <= 503
sheet.each_with_index do |row, i|
if i == 2
begin
cats_text = row.cells[0].value.to_s.sub(/(^|,)\s*Example\s*:.*$/,'')
cats_keys = cats_text.split('->').map{|s| s.split(',')[-1].strip}[0...-1]
cats_values = cats_text.split('->')[1..-1].to_a.map{|s| s.strip.sub(/,\s*\d+$/,'')}
categories_relations = cats_keys.zip(cats_values).to_h
rescue => e
categories_relations = {}
end
begin
tags_text = row.cells[1].value.to_s.sub(/(^|,)\s*Example\s*:.*$/,'')
tags_keys = tags_text.split('->').map{|s| s.split(',')[-1].strip}[0...-1]
tags_values = tags_text.split('->')[1..-1].to_a.map{|s| s.strip.sub(/,\s*\d+$/,'')}
tags_relations = tags_keys.zip(tags_values).to_h
rescue => e
tags_relations = {}
end
if categories_relations.present?
categories = categories_relations.map do |k, v|
tmp = raw_categories[k]
if tmp && tmp.title.strip == v
[k, tmp]
else
tmp = raw_categories.detect{|kk, vv| vv.title.strip == v}
if tmp.nil?
tmp = @module_app.categories.create(:title_translations=> localize_data(v))
end
[k, tmp]
end
end.to_h
end
if tags_relations.present?
tags = tags_relations.map do |k, v|
tmp = raw_tags[k]
if tmp && tmp.name.strip == v
[k, tmp]
else
tmp = raw_tags.detect{|kk, vv| vv.name.strip == v}
if tmp.nil?
tmp = @module_app.tags.create(:name_translations=> localize_data(v))
end
[k, tmp]
end
end.to_h
end
end
next if i < 3
v = row.cells.first.value rescue nil
next if v.blank? #類別為空
import_this_news(row, categories, tags)
end
redirect_to admin_news_index_path
else
redirect_to admin_news_index_path(:error => "1")
end
end
def preview
if params['preview_type'].eql?('edit')
news_bulletin_data = news_bulletin_params
@ -348,7 +185,6 @@ class Admin::NewsController < OrbitAdminController
news_bulletin_data.delete('news_bulletin_files_attributes')
news_bulletin_data.delete('news_bulletin_links_attributes')
news_bulletin.update_attributes(news_bulletin_data)
news_bulletin.copy_id = params['news_bulletin_id']
else
news_bulletin = NewsBulletin.new(news_bulletin_params)
end
@ -357,18 +193,7 @@ class Admin::NewsController < OrbitAdminController
news_bulletin.save
render :text=>page_for_news_bulletin(news_bulletin)
end
def get_preview_action
news_bulletin = NewsBulletin.find_by(:uid=>params['uid'])
is_not_edit = (!news_bulletin.is_edit)
org_bulletin = news_bulletin.get_org_model
NewsBulletin.where(:copy_id=>org_bulletin.id.to_s).destroy
if is_not_edit
news_bulletin.destroy
render :json=> {:success=>true,:action=>"close"}
else
render :json=> {:success=>true,:action=>"redirect",:path=>edit_admin_news_path(:id=>org_bulletin.id)}
end
end
def destroy_preview
news_bulletin = NewsBulletin.find_by(:uid=>params['uid'])
if news_bulletin.is_preview

View File

@ -15,10 +15,12 @@ class Admin::NewsbulletinsController < ApplicationController
keyword = Regexp.new(".*"+params[:keyword]+".*")
bulletins = NewsBulletin.any_of({:title=>keyword},{:subtitle=>keyword},{:text=>keyword})
else
bulletins = NewsBulletin.all.can_display
bulletins = NewsBulletin.all
end
bulletins = bulletins.where(:is_hot => params[:is_hot]) if !params[:is_hot].blank?
bulletins = bulletins.where(:is_hidden => false)
bulletins = bulletins.where(:category_id.in => params[:categories]) if !params[:categories].blank?
bulletins = bulletins.where(:tagged_ids.in => params[:tags]) if !params[:tags].blank?
bulletins = bulletins.where(:is_preview.in=>[false,nil])

View File

@ -6,13 +6,13 @@ class NewsController < ApplicationController
if params[:keywords]
!params[:sort].blank? ? sort = {params[:sort].to_sym=>params[:order]} : sort = {:is_top=>"desc",:postdate=>"desc"}
news = NewsBulletin.where(:title.ne => "",:is_preview.in=>[false,nil]).any_of(:title => /#{params[:keywords].to_s}/i).can_display_postdate.is_approved.order_by(sort).filter_by_categories(["all"]).per(15) if !params[:keywords].nil?
news = NewsBulletin.where(:title.ne => "").any_of(:title => /#{params[:keywords].to_s}/i).can_display_postdate.is_approved.order_by(sort).filter_by_categories(["all"]).per(15) if !params[:keywords].nil?
news_count = ",共搜尋到" + news.count.to_s + "筆資料"
keyword = "搜尋標題有關 ' " + params[:keywords] + " '"
elsif params[:department]
!params[:sort].blank? ? sort = {params[:sort].to_sym=>params[:order]} : sort = {:is_top=>"desc",:postdate=>"desc"}
dept = Department.find_by(:uid => params["department"].split("-").last) rescue nil
news = NewsBulletin.where(:title.ne => "" ,:department => dept,:is_preview.in=>[false,nil]).can_display_postdate.is_approved.order_by(sort).filter_by_categories(["all"]) if !dept.nil?
news = NewsBulletin.where(:title.ne => "" ,:department => dept).can_display_postdate.is_approved.order_by(sort).filter_by_categories(["all"]) if !dept.nil?
news_count = ",共搜尋到" + news.count.to_s + "筆資料"
keywords = params[:department].split("-")
@ -26,7 +26,7 @@ class NewsController < ApplicationController
elsif params[:unit]
unit = Unit.find_by(:uid => params["unit"].split("-").last) rescue nil
!params[:sort].blank? ? sort = {params[:sort].to_sym=>params[:order]} : sort = {:is_top=>"desc",:postdate=>"desc"}
news = NewsBulletin.where(:title.ne => "" ,:unit => unit,:is_preview.in=>[false,nil]).can_display_postdate.is_approved.order_by(sort).filter_by_categories(["all"]) if !unit.nil?
news = NewsBulletin.where(:title.ne => "" ,:unit => unit).can_display_postdate.is_approved.order_by(sort).filter_by_categories(["all"]) if !unit.nil?
news_count = ",共搜尋到" + news.count.to_s + "筆資料"
keywords = params[:unit].split("-")
@ -39,7 +39,7 @@ class NewsController < ApplicationController
elsif params["category"]
!params[:sort].blank? ? sort = {params[:sort].to_sym=>params[:order]} : sort = {:is_top=>"desc",:postdate=>"desc"}
category = Category.find_by(:uid => params["category"].split("-").last) rescue nil
news = NewsBulletin.all.where(:title.ne => "",:is_preview.in=>[false,nil]).can_display_postdate.is_approved.order_by(sort).filter_by_categories([category.id.to_s]) if !category.nil?
news = NewsBulletin.all.where(:title.ne => "").can_display_postdate.is_approved.order_by(sort).filter_by_categories([category.id.to_s]) if !category.nil?
news_count = ",共搜尋到" + news.count.to_s + "筆資料"
keywords = params[:category].split("-")
@ -106,26 +106,12 @@ class NewsController < ApplicationController
end
def widget
more_stories = {"en" => "More Stories+", "zh_tw" => "更多新聞+"}
params = OrbitHelper.params
!params[:sort].blank? ? sort = {params[:sort].to_sym=>params[:order]} : sort = {:is_top=>"desc",:postdate=>"desc"}
news = NewsBulletin.where(:title.ne => "",:is_preview.in=>[false,nil],:is_hot => true).can_display.is_approved.order_by(sort).filter_by_widget_categories if news.nil?
page = Page.where(:module => "news").first rescue nil
ma = ModuleApp.find_by_key("news") rescue nil
current_categories = OrbitHelper.widget_categories
categories_for_url = ma.categories.enabled.collect do |cat|
if current_categories.include?(cat.id.to_s)
{
"name" => cat.title,
"category-link" => "/#{I18n.locale.to_s + page.url}/?category=#{cat.to_param}"
}
end
end
categories_for_url.delete(nil)
categories_for_url = {"name" => "ALL", "category-link" => "/#{I18n.locale.to_s + page.url}/"} if categories_for_url.count != 1
categories = ma.categories.enabled.collect do |cat|
{
"name" => cat.title,
@ -155,6 +141,8 @@ class NewsController < ApplicationController
subtitle = a.subtitle.truncate(200)
end
{
"title" => HTMLEntities.new.encode(a.title),
"subtitle" => subtitle,
@ -169,9 +157,7 @@ class NewsController < ApplicationController
{
"news" => anns,
"categories" => categories,
"categories_for_url" => categories_for_url,
"extras" => {
"more_stories" => more_stories[I18n.locale.to_s],
"more_url"=>OrbitHelper.widget_more_url,
"title-head" => t('news.table.title'),
"date-head" => t('news.table.date'),
@ -182,67 +168,6 @@ class NewsController < ApplicationController
}
end
def widget2
more_stories = {"en" => "More Stories+", "zh_tw" => "更多新聞+"}
categories = OrbitHelper.widget_categories
ma = ModuleApp.find_by_key("news")
page = Page.where(:module => "news").first rescue nil
if categories.first == "all" || categories.count == 0
categories = ma.categories.enabled.limit(3)
else
if categories.count > 3
categories = Category.find(categories.sample(3))
else
categories = Category.find(categories)
end
end
categories_data = []
categories_for_dropdown = ma.categories.enabled.collect do |cat|
link = page.nil? ? "#" : "/#{I18n.locale.to_s + page.url}/?category=#{cat.to_param}"
{
"name" => cat.title,
"category-link" => link
}
end
link = page.nil? ? "#" : "/#{I18n.locale.to_s + page.url}/"
categories_for_dropdown.unshift({"name" => t("news.all"), "category-link" => link})
hot_news = NewsBulletin.where(:title.ne => "",:is_preview.in=>[false,nil], :is_hot => true).can_display.is_approved.desc(:postdate).limit(1)
hot_news = hot_news.first
categories.each_with_index do |category,index|
if hot_news.nil?
nbs = NewsBulletin.where(:title.ne => "",:is_preview.in=>[false,nil], :category_id => category.id).can_display.is_approved.desc(:postdate).limit(OrbitHelper.widget_data_count)
else
nbs = NewsBulletin.where(:id.ne => hot_news.id, :title.ne => "",:is_preview.in=>[false,nil], :category_id => category.id).can_display.is_approved.desc(:postdate).limit(OrbitHelper.widget_data_count)
end
temp = nbs.collect do |nb|
{
"title" => nb.title,
"link_to_show" => OrbitHelper.widget_item_url(nb.to_param)
}
end
link = page.nil? ? "#" : "/#{I18n.locale.to_s + page.url}/?category=#{category.to_param}"
categories_data << {
"name" => category.title,
"category-link" => link,
"news" => temp
}
end
image_description = hot_news.nil? || hot_news.image_description.blank? ? "裝飾性圖片" : hot_news.image_description
{
"categorized_news" => categories_data,
"categories" => categories_for_dropdown,
"extras" => {
"more_stories" => more_stories[I18n.locale.to_s],
"hot_news_title" => (hot_news.nil? ? "" : hot_news.title),
"hot_news_subtitle" => (hot_news.nil? ? "" : hot_news.subtitle),
"hot_news_image" => (hot_news.nil? ? "" : hot_news.image.mobile.url),
"hot_news_image_description" => image_description,
"hot_news_link_to_show" => (hot_news.nil? ? "" : OrbitHelper.widget_item_url(hot_news.to_param))
}
}
end
def show
params = OrbitHelper.params
news = NewsBulletin.find_by(:uid=>params[:uid])
@ -270,10 +195,6 @@ class NewsController < ApplicationController
links = news.news_bulletin_links.collect{|link| { "link_url" => link.url, "link_title" => (link.title.blank? ? link.url : link.title) } } rescue []
update_user = news.update_user.member_profile.name rescue ""
department = news.department rescue ""
request = OrbitHelper.request
meta_desc = news.subtitle.nil? || news.subtitle == "" ? news.text[0..200] : news.subtitle
OrbitHelper.render_meta_tags([{"property" => "og:title", "content" => news.title},{"property" => "og:site_name", "content" => Site.first.title},{"property" => "og:url", "content" => request.original_url},{"property" => "og:description", "content" => meta_desc},{"property" => "og:image", "content" => "#{request.base_url}#{news.image.url}"},{"property" => "og:type", "content" => "Article"}])
{
"tags" => tags,
"news_bulletin_files" => files,

View File

@ -1,5 +1,4 @@
module Admin::NewsHelper
InUseLocales = (Site.first.in_use_locales rescue [:en,:zh_tw])
def page_for_news_bulletin(news_bulletin)
ann_page = nil
pages = Page.where(:module=>'news')
@ -26,282 +25,6 @@ module Admin::NewsHelper
request.protocol+(request.host_with_port+ann_page.url+'/'+news_bulletin.to_param).gsub('//','/') rescue "/"
end
def get_response(uri)
http = Net::HTTP.new(uri.host, uri.port)
if uri.scheme == 'https'
http.use_ssl = true
http.verify_mode = OpenSSL::SSL::VERIFY_NONE
end
timeout = 5
http.open_timeout = timeout #set read_timeout to avoid web die caused by no response
http.ssl_timeout = timeout
http.read_timeout = 1
req = Net::HTTP::Get.new(uri.request_uri)
res = http.request(req)
if res.code == "301" || res.code == "302"
location = res['Location']
cookie = res['Set-Cookie']
headers = {
'Cookie' => cookie,
}
if location[0] == "/"
uri = URI.parse("#{uri.scheme}://#{uri.host}#{location}")
else
uri = URI.parse(location)
end
res = Net::HTTP.get_response(uri,nil,headers)
end
return res
end
def restore_remote_file(uri,save_path)
response = get_response(uri)
uri_params = CGI.parse(response['Content-Disposition']) rescue {}
if save_path[-1] == "/"
filename = ""
if uri_params["filename*"].present?
filename = uri_params["filename*"][0].split("'").last rescue ""
end
if uri_params["filename"].present? && filename.blank?
filename = uri_params["filename"][0].to_s.gsub(/[\'\"]/,'') rescue ""
end
if filename.blank?
filename = response.uri.to_s.split('/').last.split('?').first
end
save_path = save_path + filename
end
if File.exist?(save_path)
File.open(save_path,"w+b"){|f| f.write(response.body)}
else
FileUtils.mkdir_p(File.dirname(save_path))
File.open(save_path,"w+b"){|f| f.write(response.body)}
end
return save_path
end
def localize_data(data)
return InUseLocales.map{|locale| [locale, data] }.to_h
end
def import_this_news(row,categories,tags)
value = {}
anns = NewsBulletin.new
row.cells.each_with_index do |cell,index|
val = cell.nil? ? nil : cell.value rescue nil
case index
when 0
anns.category = categories[val.to_s.strip]
when 1
val = val.to_s
new_tags = []
if (val.include?(",") rescue false)
ts = val.split(",")
ts.each do |t|
new_tags << tags[t.strip]
end
else
new_tags << tags[val.strip]
end
anns.tags=new_tags
when 2
anns.postdate = val
when 3
anns.deadline = val
when 4
anns.is_top = (val.to_i == 1 ? true : false)
when 5
anns.is_hot = (val.to_i == 1 ? true : false)
when 6
anns.is_hidden = (val.to_i == 1 ? true : false)
when 7
anns.remote_image_url = val
when 8
value["en"] = val if val.present?
anns.image_description_translations = value.clone
when 9
value["zh_tw"] = val if val.present?
anns.image_description_translations = value.clone
value = {}
when 10
value["en"] = val if val.present?
anns.title_translations = value.clone
when 11
value["zh_tw"] = val if val.present?
anns.title_translations = value.clone
value = {}
when 12
value["en"] = val if val.present?
anns.subtitle_translations = value.clone
when 13
value["zh_tw"] = val if val.present?
anns.subtitle_translations = value.clone
value = {}
when 14, 15
if index == 14
tmp_locale = 'en'
else
tmp_locale = 'zh_tw'
end
if val.present?
doc = Nokogiri::HTML.fragment(val)
doc.css('[src]').each do |el|
src = el.attributes['src'].value.to_s rescue ""
if src.present?
a = Asset.new
uri = URI.parse(URI.encode(src))
uri_params = CGI::parse(uri.query) rescue {}
if uri.query.present?
filename = uri_params["title"][0] + (File.extname(uri_params["filename"][0])) rescue ""
else
filename = src.split("/").last
end
save_path = "public/" + a.data.store_path + filename
begin
save_path = restore_remote_file(uri,save_path)
rescue
next
end
filename = File.basename(save_path)
a["data"] = URI.decode(filename)
a.title_translations = localize_data(filename)
if (a.save! rescue false)
el.attributes['src'].value = URI.decode(a.data.url)
end
end
end
doc.css('[href]').each do |el|
href = el.attributes['href'].value.to_s rescue ""
if href.present?
a = Asset.new
uri = URI.parse(URI.encode(href))
uri_params = CGI::parse(uri.query) rescue {}
if uri.query.present?
filename = uri_params["title"][0] + (File.extname(uri_params["filename"][0])) rescue ""
else
filename = href.split("/").last
end
save_path = "public/" + a.data.store_path + filename
begin
save_path = restore_remote_file(uri,save_path)
rescue => e
puts [e.to_s, e.backtrace[0..10].to_s]
next
end
filename = File.basename(save_path)
a["data"] = URI.decode(filename)
a.title_translations = localize_data(filename)
if (a.save! rescue false)
el.attributes['href'].value = URI.decode(a.data.url)
end
end
end
value[tmp_locale] = doc.to_s
end
anns.text_translations = value.clone
if index == 15
value = {}
end
when 16
links = val.split(";") rescue []
desc_en = row.cells[17].value.split(";") rescue []
desc_zh_tw = row.cells[18].value.split(";") rescue []
links.each_with_index do |link,i|
bl = NewsBulletinLink.new
bl.url = link.strip
bl.title_translations = {"en" => desc_en[i], "zh_tw" => desc_zh_tw[i]}
bl.news_bulletin_id = anns.id
bl.save
end
when 19
files = val.split(";") rescue []
desc_en = row.cells[20].value.split(";") rescue []
desc_zh_tw = row.cells[21].value.split(";") rescue []
alt_en = row.cells[22].value.split(";") rescue []
alt_zh_tw = row.cells[23].value.split(";") rescue []
files.each_with_index do |file, i|
bf = NewsBulletinFile.new
bf.remote_file_url = file.strip rescue nil
bf.title_translations = {"en" => (alt_en[i] rescue ""), "zh_tw" => (alt_zh_tw[i] rescue "")}
bf.description_translations = {"en" => (desc_en[i] rescue ""), "zh_tw" => (desc_zh_tw[i] rescue "")}
bf.news_bulletin_id = anns.id
bf.save
end
when 24
if val.present?
tmp = val.split("-", 2).map{|v| v.strip}
unit_text = tmp[0]
dept_text = tmp[1]
if unit_text
unit = Unit.where(:name=>/\s*#{unit_text}\s*/).first
if unit.nil?
unit = Unit.create(:name_translations=>localize_data(unit_text))
end
else
unit = nil
end
if unit && dept_text
dept = unit.departments.where(:name=>/\s*#{dept_text}\s*/).first
if dept.nil?
dept = unit.departments.create(:name_translations=>localize_data(dept_text))
end
else
dept = nil
end
anns.unit = unit
anns.department = dept
end
when 25
anns.view_count = (val.to_i rescue 0)
end
end
current_user_id = current_user.id
anns.create_user_id = current_user_id
anns.update_user_id = current_user_id
anns.approved = true
anns.save
end
def send_rejection_email(news)
user = User.find(news.create_user_id) rescue nil
if !user.nil?
email = user.member_profile.email
if !email.nil? && email != ""
url = page_for_news_bulletin(news)
mail = Email.new(:mail_to => email, :mail_subject => "News rejected : #{news.title}.", :template => "email/rejection_email.html.erb", :template_data => {"url" => url, "rejector" => current_user.name, "name" => user.name, "reason" => news.rejection_reason})
mail.deliver
end
end
end
def send_notification_mail_to_managers(news, type)
authorizations = Authorization.where(:module_app_id => @module_app.id)
users = authorizations.collect do |auth|
auth.user
end
users.each do |user|
email = user.member_profile.email
if !email.nil? && email != ""
send_email(user.name, email, news, type)
sleep(2)
end
end
users = Workgroup.where(:key => "admin").first.users rescue []
users.each do |user|
email = user.member_profile.email
if !email.nil? && email != ""
send_email(user.name, email, news, type)
sleep(2)
end
end
end
def send_email(name, useremail, news, type)
url = page_for_news_bulletin(news)
template = (type == "approval" ? "email/new_news_email.html.erb" : "email/reapproval_news_email.html.erb")
email = Email.new(:mail_to => useremail, :mail_subject => "校園新聞請審核通知", :template => template, :template_data => {"url" => url, "submitter" => current_user.name, "name" => name})
email.deliver
end
def load_access_level
if current_user.is_admin?
@access_level = "admin"

View File

@ -9,9 +9,6 @@ class NewsBulletin
include OrbitCategory::Categorizable
include Slug
field :is_edit, type: Boolean, default: false #use to check whether the preview record changed
field :copy_id
field :title, as: :slug_title, type: String, localize: true
field :subtitle, localize: true
field :text, localize: true
@ -25,7 +22,6 @@ class NewsBulletin
field :rss2_sn
field :approved, :type => Boolean, :default => false
field :rejected, :type => Boolean, :default => false
field :reapproval, :type => Boolean, :default => false
field :rejection_reason
field :is_preview, :type => Boolean, :default => false
field :image_description, localize: true
@ -60,18 +56,6 @@ class NewsBulletin
scope :can_display_postdate, ->{where(:is_hidden=>false,:postdate.lt=>Time.now).order_by([:is_top, :desc])}
scope :is_approved, ->{where(:approved => true)}
def get_org_model
if self.is_preview
org_model = nil
if self.copy_id
org_model = self.class.find(self.copy_id) rescue nil
end
org_model.nil? ? self : org_model
else
self
end
end
def update_user
User.find(update_user_id) rescue nil
end

View File

@ -7,8 +7,18 @@ class Unit
field :name, as: :slug_title, :localize => true
field :sort_number, type: Integer
has_many :departments, :dependent => :destroy
has_many :departments, :autosave => true, :dependent => :destroy
accepts_nested_attributes_for :departments, :allow_destroy => true
after_save :save_departments
def save_departments
self.departments.each do |t|
if t.should_destroy
t.destroy
end
end
end
end

View File

@ -1,233 +0,0 @@
# encoding: utf-8
require 'nokogiri'
wb = xlsx_package.workbook
wb.add_worksheet(name: "News") do |sheet|
heading = sheet.styles.add_style(:b => true, :locked => true)
example = sheet.styles.add_style(:i => true)
row = []
row1 = []
row2 = []
row << t("category")
row1 << "select"
t = ""
categories = @module_app.categories.asc(:created_at)
categories.each_with_index do |cat,i|
t = t + "#{i}" + " -> " + cat.title + ", "
end
if categories.count > 0
t = t + " Example : 0"
else
t = "Leave this field blank"
end
row2 << t
row << t("tags")
row1 << "select"
t = ""
tags = @module_app.tags.asc(:created_at)
tags.each_with_index do |tag,i|
t = t + "#{i}" + " -> " + tag.name + ", "
end
if tags.count > 0
t = t + " Example : 0,1,2"
else
t = "Leave this field blank"
end
row2 << t
row << t("start_date")
row1 << "datetime"
row2 << "Format: YYYY/MM/DD hh:mm, Example: 2015/12/10 00:00"
row << t("end_date")
row1 << "datetime"
row2 << "Format: YYYY/MM/DD hh:mm, Example: 2015/12/12 00:00"
row << t("top")
row1 << "boolean"
row2 << "0 for false, 1 for true"
row << t("hot")
row1 << "boolean"
row2 << "0 for false, 1 for true"
row << t("hide")
row1 << "boolean"
row2 << "0 for false, 1 for true "
row << t("image")
row1 << "url"
row2 << "http://www.example.com/images/example.png"
row << t("image") + " " + t("description") + " - " + t("en")
row1 << "textfield"
row2 << ""
row << t("image") + " " + t("description") + " - " + t("zh_tw")
row1 << "textfield"
row2 << ""
row << t("title") + " - " + t("en")
row1 << "textfield"
row2 << ""
row << t("title") + " - " + t("zh_tw")
row1 << "textfield"
row2 << ""
row << t("subtitle") + " - " + t("en")
row1 << "textarea"
row2 << ""
row << t("subtitle") + " - " + t("zh_tw")
row1 << "textarea"
row2 << ""
row << t("content") + " - " + t("en")
row1 << "editor"
row2 << ""
row << t("content") + " - " + t("zh_tw")
row1 << "editor"
row2 << ""
row << t("link")
row1 << "textfield"
row2 << "Seperate with ';'. Example: http://rulingcom.com; http://google.com"
row << t("link") + " " + t("url_alt") + " - " + t("en")
row1 << "textfield"
row2 << "Seperate with ';' with respective to the links in the link columns. Example : Rulingcom official site; Google search engine"
row << t("link") + " " + t("url_alt") + " - " + t("zh_tw")
row1 << "textfield"
row2 << "Seperate with ';' with respective to the links in the link columns. Example : Rulingcom official site; Google search engine"
row << t("file_")
row1 << "textfield"
row2 << "Seperate with ';'. Example: http://www.example.com/images/example.png; http://www.example.com/images/example2.png"
row << t("file_") + " " + t("description") + " - " + t("en")
row1 << "textfield"
row2 << "Seperate with ';' with respective to the links in the link columns. Example : Great view; Nice potrait"
row << t("file_") + " " + t("description") + " - " + t("zh_tw")
row1 << "textfield"
row2 << "Seperate with ';' with respective to the links in the link columns. Example : Great view; Nice potrait"
row << t("file_") + " " + t("alternative") + " - " + t("en")
row1 << "textfield"
row2 << "Seperate with ';' with respective to the links in the link columns. Example : example1; example2"
row << t("file_") + " " + t("alternative") + " - " + t("zh_tw")
row1 << "textfield"
row2 << "Seperate with ';' with respective to the links in the link columns. Example : example1; example2"
row << t("news.unit")
row1 << "textfield"
row2 << "Unit - Department"
row << t("view_count")
row1 << "integer"
row2 << ""
sheet.add_row row, :style => heading
sheet.add_row row1
sheet.add_row row2, :style => example
if @thread
all_count = @news.count
puts_every_count = [all_count * 3 / 100, 1].max
current_count = 0
finish_percent = 0
@thread.update(:status=>{:status=>'Processing','all_count'=>all_count,'current_count'=>current_count,'finish_percent'=>finish_percent})
end
@news.each do |anns|
row = []
row << categories.to_a.index(anns.category)
t = []
anns.tags.each do |tag|
t << tags.to_a.index(tag)
end
row << t.join(",")
row << (anns.postdate.strftime("%Y/%m/%d %H:%M") rescue "")
row << (anns.deadline.strftime("%Y/%m/%d %H:%M") rescue "")
row << (anns.is_top? ? 1 : 0)
row << (anns.is_hot? ? 1 : 0)
row << (anns.is_hidden? ? 1 : 0)
image_url = anns.image.url rescue ""
row << (image_url.blank? ? "" : (@host + image_url))
row << anns.image_description_translations["en"]
row << anns.image_description_translations["zh_tw"]
row << anns.title_translations["en"]
row << anns.title_translations["zh_tw"]
row << anns.subtitle_translations["en"]
row << anns.subtitle_translations["zh_tw"]
["en", "zh_tw"].each do |l|
text = anns.text_translations[l]
doc = Nokogiri::HTML.fragment(text)
doc.css('[src]').each do |el|
src = el.attributes['src'].value.to_s rescue ""
if src.match(/^\/([^\/]|$)/)
src = @host + src
el.attributes['src'].value = src
end
end
doc.css('[href]').each do |el|
href = el.attributes['href'].value.to_s rescue ""
if href.match(/^\/([^\/]|$)/)
href = @host + href
el.attributes['href'].value = href
end
end
row << doc.to_s
end
links = anns.news_bulletin_links.asc(:created_at)
t = links.collect{|l|l.url}
row << t.join(";")
t = links.collect{|l|l.title_translations["en"]}
row << t.join(";")
t = links.collect{|l|l.title_translations["zh_tw"]}
row << t.join(";")
files = anns.news_bulletin_files.asc(:created_at)
t = files.collect{|f|(@host + f.file.url rescue nil)}
t.delete(nil)
row << t.join(";")
t = files.collect{|l|l.description_translations["en"]}
row << t.join(";")
t = files.collect{|l|l.description_translations["zh_tw"]}
row << t.join(";")
t = files.collect{|l|l.title_translations["en"]}
row << t.join(";")
t = files.collect{|l|l.title_translations["zh_tw"]}
row << t.join(";")
tmp_unit = ""
Unit.where({:id => anns.unit_id}).each do |u|
tmp_unit += u.name
end
Department.where({:id => anns.department_id}).each do |d|
tmp_unit += "-#{d.name}"
end
row << tmp_unit
row << anns.view_count.to_s
sheet.add_row row
if @thread
current_count += 1
if current_count % puts_every_count == 0
finish_percent = (current_count * 100.0 / all_count).round(1)
@thread.update(:status=>{:status=>'Processing','all_count'=>all_count,'current_count'=>current_count,'finish_percent'=>finish_percent})
end
end
end
if @thread
finish_percent = 100
@thread.update(:status=>{:status=>'finish','all_count'=>all_count,'current_count'=>current_count,'finish_percent'=>finish_percent})
end
end

View File

@ -84,14 +84,14 @@
<div class="control-group">
<label class="control-label muted"><%= t(:start_date) %></label>
<div class="controls">
<%= f.datetime_picker :postdate, :no_label => true, :new_record => @news_bulletin.new_record?, :data=>{"picker-type" => "range", "range" => "start"} %>
<%= f.datetime_picker :postdate, :no_label => true, :new_record => @news_bulletin.new_record? %>
</div>
</div>
<div class="control-group">
<label class="control-label muted"><%= t(:end_date) %></label>
<div class="controls">
<%= f.datetime_picker :deadline, :no_label => true, :new_record => @news_bulletin.new_record?, :data=>{"picker-type" => "range", "range" => "end"} %>
<%= f.datetime_picker :deadline, :no_label => true, :new_record => @news_bulletin.new_record? %>
</div>
</div>
@ -151,18 +151,21 @@
<div class="fileupload-alert alert alert-danger text-center" role="alert"></div>
<div class="image_note" style="color:red; font-size:14px;">
<br />
<%= t("ad.widget_info_for_ad_image_size", :best_size=> "( 400px x 200px )") %>
此區塊圖片尺寸使用比例為2:1(圖片寬:高)寬度最低400px亦即最小尺寸為400px*200px。
<br />
※<%= t("news.image_size_limit")%>
<br />
※上傳圖片格式僅支援.gif、.jpg、.png
<br />
※<%= t("news.image_note")%>
<br />
<a href="http://itservice.nccu.edu.tw/nccuweb/%E5%A6%82%E4%BD%95%E8%A3%81%E5%89%AA%E6%96%B0%E8%81%9E%E5%B0%81%E9%9D%A2%E5%9C%96%E7%89%87.pdf" target="_blank" style="color:red;">※如何裁剪新聞封面圖片</a>
※欲知「如何裁剪新聞封面圖片」,請點選
<a href="http://itservice.nccu.edu.tw/nccuweb/%E5%A6%82%E4%BD%95%E8%A3%81%E5%89%AA%E6%96%B0%E8%81%9E%E5%B0%81%E9%9D%A2%E5%9C%96%E7%89%87.pdf" target="_blank" style="color:red;"><此處></a>。
</div>
</div>
<div class="controls pull-left">
<input type="checkbox" id="use_default_image" />
<label class="checkbox inline muted"> <%= t('news_bulletin.use_default_image')%></label>
<input type="checkbox" id="user_default_image" />
<label class="checkbox inline muted"> <%= t('news_bulletin.user_default_image')%></label>
</div>
</div>
<% @site_in_use_locales.each do |locale| %>
@ -224,11 +227,12 @@
<div class="image_note" style="color:red; font-size:14px;">
<span style="font-weight: bolder;">※建議使用IE10、IE11、Chrome(最佳)、Firefox等瀏覽器。</span>
<br />
※內文裡單一圖片大小為1MB以下
※內文裡單一圖片大小為1MB以下
<br />
※內文裡單一圖片尺寸的最大寬度600px(滿版),如圖片要縮小,請依比例調整。
<br />
<a href="http://itservice.nccu.edu.tw/nccuweb/%E5%A6%82%E4%BD%95%E8%A3%81%E5%89%AA%E6%96%B0%E8%81%9E%E5%9C%96%E7%89%87.pdf" target="_blank" style="color:red;">※如何剪裁新聞圖片。</a>
※欲知「如何裁剪新聞圖片」,請點選
<a href="http://itservice.nccu.edu.tw/nccuweb/%E5%A6%82%E4%BD%95%E8%A3%81%E5%89%AA%E6%96%B0%E8%81%9E%E5%9C%96%E7%89%87.pdf" target="_blank" style="color:red;"><此處></a>。
</div>
<div class="textarea">
<%= f.fields_for :text_translations do |f| %>
@ -400,26 +404,11 @@
processData: false,
contentType: false
}).done(function(data){
if(window.location.protocol === "https:"){
data = data.replace("http:","https:");
}
window.preview_news_uid = data.split("-").slice(-1)[0].split("?")[0];
$('.modal-body iframe').attr('src',data);
$('#show_preview .modal').modal();
$('#show_preview .modal').height(function() {
return $(window).height() * 0.7;
});
$('#show_preview .modal').on('hidden.bs.modal', function () {
$.ajax({
type: "post",
url: '<%= admin_news_get_preview_action_path %>',
data: {uid: window.preview_news_uid}
}).done(function(data){
if(data["action"] == "redirect"){
window.location.href = data["path"];
}
})
});
var slug = data.split('/')[(data.split('/').length-1)];
// $('#preview-iframe').on('load', function(){
@ -482,7 +471,7 @@
var validate_image = function(){
var validate = true,
file_size = 0;
if($("#use_default_image").prop("checked")){
if($("#user_default_image").prop("checked")){
return validate;
}else{
fileupload_alert = $("#news_bulletin_image").parent().parent().parent().find('.fileupload-alert');
@ -496,7 +485,7 @@
}
}
if(!validate){
alert("<%=t('news.cover_image_not_yet_upload')%>");
alert("您還沒有上傳封面圖片");
fileupload_alert.text("<%= t("news.file_size")%>: "+file_size.toFixed(1)+"MB , <%= t("news.file_size_limit") %>: "+fileupload_size_limit_mb+"MB");
fileupload_alert.show();
$("#basic").removeClass("active");

View File

@ -34,14 +34,6 @@
<%= b.title_translations["en"] %> <span class='label'><%= t(:expired) %></span>
<% end %>
<% end %>
<% elsif b.rejected && b.reapproval %>
<% url = page_for_bulletin(b) %>
<% if !b.title_translations["zh_tw"].blank? %>
<a href="<%= url %>" target="_blank"><%= b.title_translations["zh_tw"] %></a> <span class='label'><%= t("news.reapproval") %> : <%= t(:pending) %></span><br />
<% end %>
<% if !b.title_translations["en"].blank? %>
<a href="<%= url %>" target="_blank"><%= b.title_translations["en"] %></a> <span class='label'><%= t("news.reapproval") %> : <%= t(:pending) %></span>
<% end %>
<% elsif b.rejected %>
<% url = page_for_bulletin(b) %>
<% if !b.title_translations["zh_tw"].blank? %>
@ -75,7 +67,7 @@
<li><a href="/admin/news/<%=b.id.to_s%>/edit"><%= t(:edit) %></a></li>
<li><a href="#" class="delete text-error" rel="/admin/news/<%=b.id.to_s%>"><%= t(:delete_) %></a></li>
<% elsif is_user_sub_manager? %>
<% if b.rejected && !b.approved %>
<% if !b.rejected && !b.approved %>
<li><a href="/admin/news/<%=b.id.to_s%>/edit"><%= t(:edit) %></a></li>
<% end %>
<li><a href="#" class="delete text-error" rel="/admin/news/<%=b.id.to_s%>"><%= t(:delete_) %></a></li>
@ -87,7 +79,7 @@
<% end %>
<% if (!b.rejected && !b.approved && user_can_approve? && !b.expired?) || (b.rejected && !b.approved && user_can_approve? && !b.expired? && b.reapproval) %>
<% if !b.rejected && !b.approved && user_can_approve? && !b.expired? %>
<li><a href="#" class="appoval_button" data-approve-link="<%= "/#{I18n.locale.to_s}/news/#{b.to_param}" %>" data-id="<%= b.id.to_s %>"><%= t("news.approve") %></a></li>
<% end %>
<% end %>
@ -103,7 +95,7 @@
<% Unit.where({:id => b.unit_id}).each do |u| %>
<%= u.name %>
<% end %>
<% Department.where({:id => b.department_id}).each do |d| %>
<% Department.where({:id => b.department}).each do |d| %>
-<%= d.name %>
<% end %>
</td>

View File

@ -1,132 +0,0 @@
# encoding: utf-8
wb = xlsx_package.workbook
wb.add_worksheet(name: "News") do |sheet|
heading = sheet.styles.add_style(:b => true, :locked => true)
example = sheet.styles.add_style(:i => true)
row = []
row1 = []
row2 = []
row << t("category")
row1 << "select"
t = ""
@module_app.categories.asc(:created_at).each_with_index do |cat,i|
t = t + "#{i}" + " -> " + cat.title + ", "
end
if @module_app.categories.count > 0
t = t + " Example : 0"
else
t = "Leave this field blank"
end
row2 << t
row << t("tags")
row1 << "select"
t = ""
@module_app.tags.asc(:created_at).each_with_index do |tag,i|
t = t + "#{i}" + " -> " + tag.name + ", "
end
if @module_app.tags.count > 0
t = t + " Example : 0,1,2"
else
t = "Leave this field blank"
end
row2 << t
row << t("start_date")
row1 << "datetime"
row2 << "Format: YYYY/MM/DD hh:mm, Example: 2015/12/10 00:00"
row << t("end_date")
row1 << "datetime"
row2 << "Format: YYYY/MM/DD hh:mm, Example: 2015/12/12 00:00"
row << t("top")
row1 << "boolean"
row2 << "0 for false, 1 for true"
row << t("hot")
row1 << "boolean"
row2 << "0 for false, 1 for true"
row << t("hide")
row1 << "boolean"
row2 << "0 for false, 1 for true "
row << t("image")
row1 << "url"
row2 << "http://www.example.com/images/example.png"
row << t("image") + " " + t("description") + " - " + t("en")
row1 << "textfield"
row2 << ""
row << t("image") + " " + t("description") + " - " + t("zh_tw")
row1 << "textfield"
row2 << ""
row << t("title") + " - " + t("en")
row1 << "textfield"
row2 << ""
row << t("title") + " - " + t("zh_tw")
row1 << "textfield"
row2 << ""
row << t("subtitle") + " - " + t("en")
row1 << "textarea"
row2 << ""
row << t("subtitle") + " - " + t("zh_tw")
row1 << "textarea"
row2 << ""
row << t("content") + " - " + t("en")
row1 << "editor"
row2 << ""
row << t("content") + " - " + t("zh_tw")
row1 << "editor"
row2 << ""
row << t("link")
row1 << "textfield"
row2 << "Seperate with ';'. Example: http://rulingcom.com; http://google.com"
row << t("link") + " " + t("url_alt") + " - " + t("en")
row1 << "textfield"
row2 << "Seperate with ';' with respective to the links in the link columns. Example : Rulingcom official site; Google search engine"
row << t("link") + " " + t("url_alt") + " - " + t("zh_tw")
row1 << "textfield"
row2 << "Seperate with ';' with respective to the links in the link columns. Example : Rulingcom official site; Google search engine"
row << t("file_")
row1 << "textfield"
row2 << "Seperate with ';'. Example: http://www.example.com/images/example.png; http://www.example.com/images/example2.png"
row << t("file_") + " " + t("description") + " - " + t("en")
row1 << "textfield"
row2 << "Seperate with ';' with respective to the links in the link columns. Example : Great view; Nice potrait"
row << t("file_") + " " + t("description") + " - " + t("zh_tw")
row1 << "textfield"
row2 << "Seperate with ';' with respective to the links in the link columns. Example : Great view; Nice potrait"
row << t("file_") + " " + t("alternative") + " - " + t("en")
row1 << "textfield"
row2 << "Seperate with ';' with respective to the links in the link columns. Example : example1; example2"
row << t("file_") + " " + t("alternative") + " - " + t("zh_tw")
row1 << "textfield"
row2 << "Seperate with ';' with respective to the links in the link columns. Example : example1; example2"
row << t("news.unit")
row1 << "textfield"
row2 << "Unit - Department"
row << t("view_count")
row1 << "integer"
row2 << ""
sheet.add_row row, :style => heading
sheet.add_row row1
sheet.add_row row2, :style => example
end

View File

@ -1,127 +0,0 @@
<% content_for :page_specific_javascript do %>
<script type="text/javascript" src="/assets/validator.js"></script>
<% end %>
<% if @thread %>
<div id="threadModal" class="modal hide fade in" tabindex="-1" role="dialog" aria-labelledby="threadModal" aria-hidden="false">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<h3 id="threadModal"><%=t("e_paper.#{@thread.key}")%></h3>
</div>
<div class="modal-body">
<div class="thread-status"><%= @thread.status[:status] %></div>
<div class="thread-count-zone <%= 'hide' unless @thread.status[:current_count]%>">
<span class="thread-current-count"><%= @thread.status[:current_count].to_i %></span>/<span class="thread-all-count"><%= @thread.status[:all_count].to_i %></span>
</div>
<span class="thread-finish_percent"><%= @thread.status[:finish_percent].to_i %></span> % finished
<br>
<span class="thread-info"><%= @thread.status[:info].to_s.html_safe %></span>
<br>
<span class="thread-file">
<% if @thread.status[:filename] %>
<a href="<%=admin_news_download_file_from_thread_path(:id=>@thread.id.to_s) %>" title="<%= @thread.status[:filename] %>"><%= @thread.status[:filename] %></a>
<% end %>
</span>
</div>
<div class="modal-footer">
<button class="btn" id="modal-close-btn" style="width: 4em;" data-dismiss="modal" aria-hidden="true"><%=t('close')%></button>
</div>
</div>
</div>
</div>
<% end %>
<form action="<%= admin_news_importnews_path %>" method="post" class="form-horizontal main-forms" id="import-news-xls" enctype="multipart/form-data">
<h3 style="padding-left: 30px;"><%= t("news.export_to_excel") %></h3>
<div class="control-group">
<div class="controls">
<a href="<%= admin_news_export_excel_path %>"><%= t("news.export_all_news") %></a>
</div>
</div>
<h3 style="padding-left: 30px;"><%= t("news.import_from_excel") %></h3>
<%= hidden_field_tag :authenticity_token, form_authenticity_token %>
<div class="input-area">
<div class="control-group">
<div class="controls">
<a href="<%= admin_news_excel_format_path(:format => "xlsx") %>"><%= t("news.download_example_sheet_here") %></a>
</div>
</div>
<div class="control-group">
<label for="import-news" class="control-label muted"><%= t("upload") %></label>
<div class="controls">
<input type="file" id="import-news" name="import_file" data-fv-validation="required;mustbexls;" data-fv-messages="Cannot be empty; Must be an excel file.;" />
</div>
</div>
</div>
<div class="form-actions">
<input type="submit" value="<%= t("restful_actions.import") %>" class="btn btn-primary">
</div>
</form>
<script type="text/javascript">
var form = new FormValidator($("#import-news-xls"));
form.validate_functions.mustbexls = function(val){
var t = val.split("."),
ext = t[t.length - 1];
return (ext == "xls" || ext == "xlsx")
}
var form = new FormValidator($("#import-news-wp-xml"));
form.validate_functions.mustbexml = function(val){
var t = val.split("."),
ext = t[t.length - 1];
return (ext == "xml")
}
$(document).ready(function(){
function update_thread(){
$.post("<%=admin_threads_get_status_path%>",{"id": "<%=params[:thread_id]%>"}).done(function(data){
var finish_percent = data["finish_percent"];
var current_count = data["current_count"];
var all_count = data["all_count"];
var is_finish = ((data["status"] == "finish" && data["filename"]) || data["status"] == "error");
var info = data["info"]
if(finish_percent){
$("#threadModal .modal-body .thread-status").text(data["status"]);
if(data["current_count"]){
$("#threadModal .modal-body .thread-count-zone").removeClass('hide');
$("#threadModal .modal-body .thread-current-count").text(current_count);
$("#threadModal .modal-body .thread-all-count").text(all_count);
}else{
$("#threadModal .modal-body .thread-count-zone").addClass('hide');
}
$("#threadModal .modal-body .thread-finish_percent").text(finish_percent);
if(info){
$("#threadModal .modal-body .thread-info").text(info);
}
}
if(!is_finish){
window.time_out_id = window.setTimeout(update_thread, 1000);
}else{
var id = "<%=@thread.id if @thread%>";
var filename = data["filename"];
if(filename){
$("#threadModal .modal-body .thread-file").html(`<a href="<%=admin_news_download_file_from_thread_path%>?id=${id}" title="${filename}">${filename}</a>`);
}
if(window.time_out_id)
window.clearTimeout(window.time_out_id);
// window.setTimeout(function(){
// $("#threadModal").modal("hide");
// alert(data["status"]);
// }, 3000);
return;
}
});
}
if($("#threadModal").length != 0){
$("#threadModal").on('hidden.bs.modal',function(){
window.clearTimeout(window.time_out_id);
window.history.replaceState(null,$('title').text(),window.location.pathname);
})
$("#threadModal").on('shown.bs.modal',function(){
window.time_out_id = window.setTimeout(update_thread, 1000);
})
$("#threadModal").modal("show");
$(".show_progress").click(function(){
$("#threadModal").modal("show");
})
}
})
</script>

View File

@ -1,3 +0,0 @@
<h3>Hello <%= @data["name"] %>,</h3>
<p><%= @data["submitter"] %> submitted a new news.
<a href="<%= @data['url'] %>" > Please click here to view the news.</a>

View File

@ -1,3 +0,0 @@
<h3>Hello <%= @data["name"] %>,</h3>
<p><%= @data["submitter"] %> updated the news.
<a href="<%= @data['url'] %>" > Please click here to view the news.</a>

View File

@ -1,3 +0,0 @@
<h3>Hello <%= @data["name"] %>,</h3>
<p>Your news has been rejected<%= @data["reason"].nil? || @data["reason"] == "" ? "." : ", because #{@data["reason"]}" %></p>
<a href="<%= @data['url'] %>" > Please click here to view the news.</a>

View File

@ -1,34 +1,6 @@
en:
module_name:
news: News
news_bulletin:
use_default_image: Use Default Image
all_category: All Category
campus_news: Campus News
category: Category
create_news_bulletin_category_success: News Category create successfully
create_news_bulletin_success: News create successfully
department: Department
editing_news: Edit News
editing_news_category: Edit Category
error:
no_avilb_cate_for_posting: News must have a category to send, please contact the administrator
hot: Headlines
news_bulletins: News
new_news_category: Create News Category
search: Search News
update_news_bulletin_category_success: News Category update successfully
update_news_bulletin_success: News update successfully
ut_prompt: Please choose department
news:
cover_image_not_yet_upload: The cover image has not been uploaded yet.
import_export: Import / Export
import: Import
export_news: Export News
export_to_excel: Export to Excel
export_all_news: Export all News
import_from_excel: Import from Excel
download_example_sheet_here: Download example sheet here
admins: Unit Setting
unit: Department
category: Category
@ -43,7 +15,6 @@ en:
category: Category
add_new: Add New
approve: Approve
reapproval: Re-approval
all_articles: All Articles
news: News
approval_setting: Approval Setting

View File

@ -1,8 +1,10 @@
zh_tw:
module_name:
news: 新聞
news_bulletin:
use_default_image: 或使用預設圖片
user_default_image: 或使用預設圖片
all_category: 全部類別
campus_news: 校園新聞
category: 分類
@ -21,14 +23,6 @@ zh_tw:
update_news_bulletin_success: 新聞已成功更新
ut_prompt: 請選擇單位
news:
cover_image_not_yet_upload: 您還沒有上傳封面圖片
import_export: 匯入 / 匯出
import: 匯入
export_news: 匯出新聞
export_to_excel: 匯出至Excel檔
export_all_news: 匯出所有新聞
import_from_excel: 從Excel檔匯入
download_example_sheet_here: 在此下載範例
unit: 單位
category: 分類
department: 系所
@ -38,7 +32,6 @@ zh_tw:
all: 全部類別
news: 新聞
approve: 審核
reapproval: 重新審核
admins: 單位設定
append_note: 以下之附加連結與檔案,為使前台顯示名稱,建議您輸入註解。
approval_setting: 審核設定
@ -70,7 +63,7 @@ zh_tw:
search_result: 搜尋結果頁
index_by_unit: index_by_unit
image: 封面圖片
image_note: 此處上傳的圖片不會在公告內文出現
image_note: 此處上傳的圖片不會在內文出現
image_size_limit: 圖片大小為1MB以下
link_name: 連結名稱
new_news_bulletin_category: 新增新聞類別

View File

@ -4,17 +4,11 @@ Rails.application.routes.draw do
scope "(:locale)", locale: Regexp.new(locales.join("|")) do
namespace :admin do
post 'news/get_preview_action', to: 'news#get_preview_action'
post 'news/preview', to: 'news#preview'
get 'news/destroy_preview/:slug_title-:uid', to: 'news#destroy_preview'
get 'newsbulletins.json', to: 'newsbulletins#get_bulletins'
post 'news/approve_news_bulletin', to: 'news#approve_news_bulletin'
get 'news_admins/get_departments' => "news_admins#get_departments"
get 'news/import_export', to: 'news#import_export'
get 'news/download_file_from_thread', to: 'news#download_file_from_thread'
post 'news/importnews', to: 'news#importnews'
get 'news/excel_format', to: 'news#excel_format'
get 'news/export_excel', to: 'news#export_excel'
resources :news
resources :news_admins
end

View File

@ -4,11 +4,9 @@ module News
OrbitApp.registration "News", :type => "ModuleApp" do
module_label "news.news"
base_url File.expand_path File.dirname(__FILE__)
widget_methods ["widget","widget2"]
widget_methods ["widget"]
widget_settings [{"data_count"=>12}]
models_to_cache [:news_bulletin]
# taggable "NewsBulletin"
models_to_cache [:news_bulletin]
categorizable
authorizable
frontend_enabled
@ -30,6 +28,11 @@ module News
:priority=>2,
:active_for_action=>{'admin/news'=>'news'},
:available_for => 'sub_managers'
context_link 'news.admins',
:link_path=>"admin_news_admins_path" ,
:priority=>4,
:active_for_action=>{'admin/news'=>'admins'},
:available_for => 'managers'
context_link 'categories',
:link_path=>"admin_module_app_categories_path" ,
:link_arg=>"{:module_app_id=>ModuleApp.find_by(:key=>'news').id}",
@ -44,16 +47,6 @@ module News
:active_for_action=>{'admin/news'=>'tags'},
:active_for_tag => 'News',
:available_for => 'managers'
context_link 'news.import_export',
:link_path=>"admin_news_import_export_path" ,
:priority=>5,
:active_for_action=>{'admin/news'=>'import_export'},
:available_for => 'managers'
context_link 'news.admins',
:link_path=>"admin_news_admins_path" ,
:priority=>6,
:active_for_action=>{'admin/news'=>'admins'},
:available_for => 'managers'
end
end