diff --git a/app/controllers/news_controller.rb b/app/controllers/news_controller.rb
index 2f84d33..73d2489 100644
--- a/app/controllers/news_controller.rb
+++ b/app/controllers/news_controller.rb
@@ -62,11 +62,12 @@ class NewsController < ApplicationController
end
anns = news.collect do |a|
- if a.image_description.nil?
+ if a.image_description.blank?
image_description = "裝飾性圖片"
else
image_description = a.image_description
end
+
statuses = a.statuses_with_classname.collect do |status|
{
"status" => status["name"],
@@ -121,7 +122,7 @@ class NewsController < ApplicationController
categories.unshift({"name" => t("news.all"), "category-link" => "/#{I18n.locale.to_s + page.url}/"})
anns = news.collect do |a|
- if a.image_description.nil?
+ if a.image_description.blank?
image_description = "裝飾性圖片"
else
image_description = a.image_description
@@ -200,7 +201,7 @@ class NewsController < ApplicationController
"news_bulletin_links" => links,
"categories" => categories,
"data" => {
- "categories-title" => t("news.categories"),
+ "categories-title" => t("news.category"),
"title" => HTMLEntities.new.encode(news.title),
"category" => news.category.title,
"category-link" => "/#{I18n.locale.to_s + page.url}/?category=#{news.category.to_param}",
@@ -212,7 +213,9 @@ class NewsController < ApplicationController
"updated_at" => news.postdate.strftime('%Y-%m-%d %H:%M'),
"body" => news.text == "" ? "Content unavailable for this language." : news.text,
"image" => news.image.url,
- "view_count" =>news.view_count
+ "view_count" =>news.view_count,
+ "unit-title" => t("news.unit"),
+ "view-count-title" => t("news.view_count")
},
"impressionist" => (news.is_preview ? nil : news),
"url_to_edit"=>url_to_edit
diff --git a/app/models/news_bulletin.rb b/app/models/news_bulletin.rb
index 052059e..2c55a2a 100644
--- a/app/models/news_bulletin.rb
+++ b/app/models/news_bulletin.rb
@@ -25,6 +25,7 @@ class NewsBulletin
field :rejection_reason
field :is_preview, :type => Boolean, :default => false
field :image_description, localize: true
+ field :expirable_created_at, type: DateTime
field :email_id
field :email_sent, :type => Boolean, :default => false
@@ -45,8 +46,14 @@ class NewsBulletin
before_destroy :destroy_email
+ before_create :set_expire
+ def set_expire
+ self.expirable_created_at = Time.now if self.is_preview
+ return true
+ end
+
scope :can_display, ->{where(:is_hidden=>false).any_of({:postdate.lt=>Time.now, :deadline.gt=>Time.now},{:postdate.lt=>Time.now, :deadline=>nil}).order_by([:is_top, :desc])}
- scope :can_display_postdate, ->{where(:is_hidden=>false).any_of({:postdate.lt=>Time.now},{:postdate.lt=>Time.now, :deadline=>nil}).order_by([:is_top, :desc])}
+ scope :can_display_postdate, ->{where(:is_hidden=>false,:postdate.lt=>Time.now).order_by([:is_top, :desc])}
scope :is_approved, ->{where(:approved => true)}
def update_user
diff --git a/app/views/admin/news/_form.html.erb b/app/views/admin/news/_form.html.erb
index 0330759..86cb2bd 100644
--- a/app/views/admin/news/_form.html.erb
+++ b/app/views/admin/news/_form.html.erb
@@ -84,14 +84,14 @@
- <%= f.datetime_picker :postdate, :no_label => true %>
+ <%= f.datetime_picker :postdate, :no_label => true, :new_record => @news_bulletin.new_record? %>
- <%= f.datetime_picker :deadline, :no_label => true %>
+ <%= f.datetime_picker :deadline, :no_label => true, :new_record => @news_bulletin.new_record? %>
@@ -334,6 +334,10 @@
var fileupload_size_limit = fileupload_size_limit_mb*1000*1000; // 1MB
$(function() {
+ var getDate = new Date();
+ var toDay = getDate.getFullYear()+"/"+ (getDate.getMonth()+1)+"/"+getDate.getDate()+" "+getDate.getHours()+":"+getDate.getMinutes();
+ $('input[name="news_bulletin[postdate]"]').val(toDay);
+
$("#main-wrap").after("");
$(document).on('click', '#add_link', function(){
@@ -401,10 +405,10 @@
});
var slug = data.split('/')[(data.split('/').length-1)];
- $('#preview-iframe').on('load', function(){
- $.get('/admin/news/destroy_preview/'+slug,function(data){
- });
- });
+ // $('#preview-iframe').on('load', function(){
+ // $.get('/admin/news/destroy_preview/'+slug,function(data){
+ // });
+ // });
});
$('.main-forms input[name="_method"]').val(method);
return false;
diff --git a/app/views/admin/news/_index.html.erb b/app/views/admin/news/_index.html.erb
index d79e57e..a06cb5b 100644
--- a/app/views/admin/news/_index.html.erb
+++ b/app/views/admin/news/_index.html.erb
@@ -154,12 +154,20 @@
}
<% end %>
-<% content_for :page_specific_javascript do %>
-
-<% end %>
\ No newline at end of file
+ });
+
+ $(".appoval_button").on("click",function(){
+ var url = $(this).data("approve-link"),
+ modal = $("#approvalModal");
+ modal.find("iframe").attr("src", url);
+ modal.find("#object_id").val($(this).data("id"));
+ modal.modal("show");
+ return false;
+ })
+
diff --git a/app/views/admin/news/index.html.erb b/app/views/admin/news/index.html.erb
index 7723682..bf04d60 100644
--- a/app/views/admin/news/index.html.erb
+++ b/app/views/admin/news/index.html.erb
@@ -7,13 +7,3 @@
<%= render :partial=> "approval_modal" %>
-
\ No newline at end of file
diff --git a/config/locales/en.yml b/config/locales/en.yml
index 89b3c52..8b3ac97 100644
--- a/config/locales/en.yml
+++ b/config/locales/en.yml
@@ -2,8 +2,10 @@ en:
news:
admins: Unit Setting
- unit: Unit
+ unit: Department
+ category: Category
department: Department
+ view_count: View Count
all: All
table:
title : Title
diff --git a/config/locales/zh_tw.yml b/config/locales/zh_tw.yml
index 76ec546..9f99e26 100644
--- a/config/locales/zh_tw.yml
+++ b/config/locales/zh_tw.yml
@@ -24,7 +24,9 @@ zh_tw:
ut_prompt: 請選擇單位
news:
unit: 單位
+ category: 分類
department: 系所
+ view_count: 查看次數
add_new: 新建
all_articles: 文章列表
all: 全部類別
diff --git a/config/routes.rb b/config/routes.rb
index 1e6ccf1..a573825 100644
--- a/config/routes.rb
+++ b/config/routes.rb
@@ -6,6 +6,7 @@ Rails.application.routes.draw do
namespace :admin do
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"
resources :news