This commit is contained in:
nccu 2015-03-06 09:31:21 +08:00
parent 93f103094e
commit c9bf5c7ca5
8 changed files with 47 additions and 30 deletions

View File

@ -62,11 +62,12 @@ class NewsController < ApplicationController
end end
anns = news.collect do |a| anns = news.collect do |a|
if a.image_description.nil? if a.image_description.blank?
image_description = "裝飾性圖片" image_description = "裝飾性圖片"
else else
image_description = a.image_description image_description = a.image_description
end end
statuses = a.statuses_with_classname.collect do |status| statuses = a.statuses_with_classname.collect do |status|
{ {
"status" => status["name"], "status" => status["name"],
@ -121,7 +122,7 @@ class NewsController < ApplicationController
categories.unshift({"name" => t("news.all"), "category-link" => "/#{I18n.locale.to_s + page.url}/"}) categories.unshift({"name" => t("news.all"), "category-link" => "/#{I18n.locale.to_s + page.url}/"})
anns = news.collect do |a| anns = news.collect do |a|
if a.image_description.nil? if a.image_description.blank?
image_description = "裝飾性圖片" image_description = "裝飾性圖片"
else else
image_description = a.image_description image_description = a.image_description
@ -200,7 +201,7 @@ class NewsController < ApplicationController
"news_bulletin_links" => links, "news_bulletin_links" => links,
"categories" => categories, "categories" => categories,
"data" => { "data" => {
"categories-title" => t("news.categories"), "categories-title" => t("news.category"),
"title" => HTMLEntities.new.encode(news.title), "title" => HTMLEntities.new.encode(news.title),
"category" => news.category.title, "category" => news.category.title,
"category-link" => "/#{I18n.locale.to_s + page.url}/?category=#{news.category.to_param}", "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'), "updated_at" => news.postdate.strftime('%Y-%m-%d %H:%M'),
"body" => news.text == "" ? "Content unavailable for this language." : news.text, "body" => news.text == "" ? "Content unavailable for this language." : news.text,
"image" => news.image.url, "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), "impressionist" => (news.is_preview ? nil : news),
"url_to_edit"=>url_to_edit "url_to_edit"=>url_to_edit

View File

@ -25,6 +25,7 @@ class NewsBulletin
field :rejection_reason field :rejection_reason
field :is_preview, :type => Boolean, :default => false field :is_preview, :type => Boolean, :default => false
field :image_description, localize: true field :image_description, localize: true
field :expirable_created_at, type: DateTime
field :email_id field :email_id
field :email_sent, :type => Boolean, :default => false field :email_sent, :type => Boolean, :default => false
@ -45,8 +46,14 @@ class NewsBulletin
before_destroy :destroy_email 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, ->{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)} scope :is_approved, ->{where(:approved => true)}
def update_user def update_user

View File

@ -84,14 +84,14 @@
<div class="control-group"> <div class="control-group">
<label class="control-label muted"><%= t(:start_date) %></label> <label class="control-label muted"><%= t(:start_date) %></label>
<div class="controls"> <div class="controls">
<%= f.datetime_picker :postdate, :no_label => true %> <%= f.datetime_picker :postdate, :no_label => true, :new_record => @news_bulletin.new_record? %>
</div> </div>
</div> </div>
<div class="control-group"> <div class="control-group">
<label class="control-label muted"><%= t(:end_date) %></label> <label class="control-label muted"><%= t(:end_date) %></label>
<div class="controls"> <div class="controls">
<%= f.datetime_picker :deadline, :no_label => true %> <%= f.datetime_picker :deadline, :no_label => true, :new_record => @news_bulletin.new_record? %>
</div> </div>
</div> </div>
@ -334,6 +334,10 @@
var fileupload_size_limit = fileupload_size_limit_mb*1000*1000; // 1MB var fileupload_size_limit = fileupload_size_limit_mb*1000*1000; // 1MB
$(function() { $(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(""); $("#main-wrap").after("");
$(document).on('click', '#add_link', function(){ $(document).on('click', '#add_link', function(){
@ -401,10 +405,10 @@
}); });
var slug = data.split('/')[(data.split('/').length-1)]; var slug = data.split('/')[(data.split('/').length-1)];
$('#preview-iframe').on('load', function(){ // $('#preview-iframe').on('load', function(){
$.get('/admin/news/destroy_preview/'+slug,function(data){ // $.get('/admin/news/destroy_preview/'+slug,function(data){
}); // });
}); // });
}); });
$('.main-forms input[name="_method"]').val(method); $('.main-forms input[name="_method"]').val(method);
return false; return false;

View File

@ -154,12 +154,20 @@
} }
</style> </style>
<% end %> <% end %>
<% content_for :page_specific_javascript do %>
<script type="text/javascript"> <script type="text/javascript">
$(document).ready(function() { $(document).ready(function() {
$('.img-peview').popover({ $('.img-peview').popover({
html: true html: true
});
}); });
</script> });
<% end %>
$(".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;
})
</script>

View File

@ -7,13 +7,3 @@
<%= render :partial=> "approval_modal" %> <%= render :partial=> "approval_modal" %>
<script type="text/javascript">
$(".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;
})
</script>

View File

@ -2,8 +2,10 @@ en:
news: news:
admins: Unit Setting admins: Unit Setting
unit: Unit unit: Department
category: Category
department: Department department: Department
view_count: View Count
all: All all: All
table: table:
title : Title title : Title

View File

@ -24,7 +24,9 @@ zh_tw:
ut_prompt: 請選擇單位 ut_prompt: 請選擇單位
news: news:
unit: 單位 unit: 單位
category: 分類
department: 系所 department: 系所
view_count: 查看次數
add_new: 新建 add_new: 新建
all_articles: 文章列表 all_articles: 文章列表
all: 全部類別 all: 全部類別

View File

@ -6,6 +6,7 @@ Rails.application.routes.draw do
namespace :admin do namespace :admin do
post 'news/preview', to: 'news#preview' post 'news/preview', to: 'news#preview'
get 'news/destroy_preview/:slug_title-:uid', to: 'news#destroy_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' post 'news/approve_news_bulletin', to: 'news#approve_news_bulletin'
get 'news_admins/get_departments' => "news_admins#get_departments" get 'news_admins/get_departments' => "news_admins#get_departments"
resources :news resources :news