announcements fix

This commit is contained in:
nccu 2015-03-06 09:26:36 +08:00
parent 55c1edebb7
commit 365019eabe
9 changed files with 36 additions and 21 deletions

View File

@ -182,7 +182,7 @@ class Admin::AnnouncementsController < OrbitAdminController
else
bulletin = Bulletin.new(bulletin_params)
end
bulletin.is_preview = true
bulletin.save
render :text=>page_for_bulletin(bulletin)

View File

@ -19,13 +19,13 @@ class AnnouncementsController < ApplicationController
elsif params[:tag]
!params[:sort].blank? ? sort = {params[:sort].to_sym=>params[:order]} : sort = {:is_top=>"desc",:postdate=>"desc"}
announcements = Bulletin.where(:title.ne => "" ,:is_preview.in=>[false,nil]).is_approved.order_by(sort).filter_by_categories(["all"]).filter_by_tags([params[:tag]])
announcements = Bulletin.where(:title.ne => "" ,:is_preview.in=>[false,nil]).can_display.is_approved.order_by(sort).filter_by_categories(["all"]).filter_by_tags([params[:tag]])
keyword = "搜尋有關 ' " + Tag.where(:id => params[:tag]).first.name + " '"
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
announcements = Bulletin.all.where(:title.ne => "").is_approved.order_by(sort).filter_by_categories([category.id.to_s]) if !category.nil?
announcements = Bulletin.all.where(:title.ne => "").can_display.is_approved.order_by(sort).filter_by_categories([category.id.to_s]) if !category.nil?
announcements_count = ",共有" + announcements.count.to_s + "筆資料"
keywords = params[:category].split("-")
@ -43,7 +43,7 @@ class AnnouncementsController < ApplicationController
if OrbitHelper.page_categories.first == "all"
announcements = Bulletin.where(:title.ne => "",:is_preview.in=>[false,nil]).can_display.is_approved.order_by(sort).filter_by_tags.page(params[:page_no]).per(OrbitHelper.page_data_count)
else
announcements = Bulletin.where(:title.ne => "",:is_preview.in=>[false,nil]).is_approved.filter_by_categories.filter_by_tags.order_by(sort).page(params[:page_no]).per(OrbitHelper.page_data_count)
announcements = Bulletin.where(:title.ne => "",:is_preview.in=>[false,nil]).can_display.is_approved.filter_by_categories.filter_by_tags.order_by(sort).page(params[:page_no]).per(OrbitHelper.page_data_count)
end
end
page = Page.where(:module => "announcement").first rescue nil
@ -161,7 +161,6 @@ class AnnouncementsController < ApplicationController
def show
params = OrbitHelper.params
# announcement = Bulletin.where(:title.ne => "").find_by(:uid=>params[:uid]) rescue nil
announcement = Bulletin.find_by(:uid=>params[:uid])
if !announcement.nil?
url_to_edit = OrbitHelper.user_can_edit?(announcement) ? "/admin/announcements/#{announcement.id.to_s}/edit" : ""
@ -227,7 +226,9 @@ class AnnouncementsController < ApplicationController
"image" => announcement.image.url,
"dept_link" => "/#{I18n.locale.to_s + page.url}/?unit=#{announcement.cache_dept}",
"cache_dept" => announcement.cache_dept,
"view_count" =>announcement.view_count
"view_count" =>announcement.view_count,
"view-count-title" => t("news.view_count"),
"dept-title" => t("announcement.dept_title")
},
"impressionist" => (announcement.is_preview ? nil : announcement),
"url_to_edit"=>url_to_edit

View File

@ -28,7 +28,7 @@ module Admin::AnnouncementsHelper
ann_page = pages.first.url if ann_page.nil?
end
request.protocol+(request.host_with_port+ann_page+'/'+bulletin.to_param).gsub('//','/') rescue "/"
request.protocol+(request.host_with_port+'/'+ann_page+'/'+'/'+bulletin.to_param).gsub('//','/') rescue "/"
end
def load_access_level

View File

@ -22,6 +22,7 @@ class Bulletin
field :rejected, :type => Boolean, :default => false
field :rejection_reason
field :is_preview, :type => Boolean, :default => false
field :expirable_created_at, type: DateTime
field :email_id
field :email_sent, :type => Boolean, :default => false
@ -42,6 +43,12 @@ class Bulletin
before_destroy :destroy_email
before_create :set_expire
def set_expire
self.expirable_created_at = Time.now if self.is_preview
return true
end
# before_save :fetch_dept
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])}

View File

@ -46,14 +46,14 @@
<div class="control-group">
<label class="control-label muted"><%= t(:start_date) %></label>
<div class="controls">
<%= f.datetime_picker :postdate, :no_label => true %>
<%= f.datetime_picker :postdate, :no_label => true, :new_record => @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 %>
<%= f.datetime_picker :deadline, :no_label => true, :new_record => @bulletin.new_record? %>
</div>
</div>
@ -227,6 +227,10 @@
<% content_for :page_specific_javascript do %>
<script>
$(function() {
var getDate = new Date();
var toDay = getDate.getFullYear()+"/"+ (getDate.getMonth()+1)+"/"+getDate.getDate()+" "+getDate.getHours()+":"+getDate.getMinutes();
$('input[name="bulletin[postdate]"]').val(toDay);
$("#main-wrap").after("");
$(document).on('click', '#add_link', function(){
@ -294,10 +298,10 @@
});
var slug = data.split('/')[(data.split('/').length-1)];
$('#preview-iframe').on('load', function(){
$.get('/admin/announcement/destroy_preview/'+slug,function(data){
});
});
// $('#preview-iframe').on('load', function(){
// $.get('/admin/announcement/destroy_preview/'+slug,function(data){
// });
// });
});
$('.main-forms input[name="_method"]').val(method);
return false;

View File

@ -59,28 +59,28 @@
<% end %>
<% end %>
<% elsif b.rejected %>
<% url = page_for_bulletin(b) %>
<%# 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(:rejected) %> : <%= b.rejection_reason rescue "" %></span><br />
<a href="<%=page_for_bulletin(b)%>" target="_blank"><%= b.title_translations["zh_tw"] %></a> <span class='label'><%= t(:rejected) %> : <%= b.rejection_reason rescue "" %></span><br />
<% end %>
<% if !b.title_translations["en"].blank? %>
<a href="<%= url %>" target="_blank"><%= b.title_translations["en"] %></a> <span class='label'><%= t(:rejected) %> : <%= b.rejection_reason rescue "" %></span>
<a href="<%=page_for_bulletin(b)%>" target="_blank"><%= b.title_translations["en"] %></a> <span class='label'><%= t(:rejected) %> : <%= b.rejection_reason rescue "" %></span>
<% end %>
<% elsif !b.approved? %>
<% url = page_for_news_bulletin(b) %>
<% if !b.title_translations["zh_tw"].blank? %>
<a href="<%= url %>" target="_blank"><%= b.title_translations["zh_tw"] %></a> <span class='label'><%= t(:pending) %></span><br />
<a href="<%=page_for_bulletin(b)%>" target="_blank"><%= b.title_translations["zh_tw"] %></a> <span class='label'><%= 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(:pending) %></span>
<a href="<%=page_for_bulletin(b)%>" target="_blank"><%= b.title_translations["en"] %></a> <span class='label'><%= t(:pending) %></span>
<% end %>
<% else %>
<% url = page_for_news_bulletin(b) %>
<% if !b.title_translations["zh_tw"].blank? %>
<a href="<%= url %>" target="_blank"><%= b.title_translations["zh_tw"] %></a><br />
<a href="<%=page_for_bulletin(b)%>" target="_blank"><%= b.title_translations["zh_tw"] %></a><br />
<% end %>
<% if !b.title_translations["en"].blank? %>
<a href="<%= url %>" target="_blank"><%= b.title_translations["en"] %></a>
<a href="<%=page_for_bulletin(b)%>" target="_blank"><%= b.title_translations["en"] %></a>
<% end %>
<% end %>
<div class="quick-edit">
@ -90,7 +90,7 @@
<li><a href="/admin/announcements/<%=b.id.to_s%>/edit"><%= t(:edit) %></a></li>
<li><a href="#" class="delete text-error" rel="/admin/announcements/<%=b.id.to_s%>"><%= t(:delete_) %></a></li>
<% if !b.approved && user_can_approve? && !b.expired? %>
<li><a href="#" class="appoval_button" data-approve-link="<%= "/#{I18n.locale.to_s}/announcements/#{b.to_param}" %>" data-id="<%= b.id.to_s %>"><%= t("announcements.approve") %></a></li>
<li><a href="#" class="appoval_button" data-approve-link="<%= "/#{I18n.locale.to_s}/announcement/#{b.to_param}" %>" data-id="<%= b.id.to_s %>"><%= t("announcement.approve") %></a></li>
<% end %>
<% end %>
</ul>

View File

@ -7,6 +7,7 @@ en:
status : Status
sub_title: Sub Title
category: Category
dept_title: Department
add_new: Add New
approve: Approve
tag_cloud: Tag Cloud

View File

@ -7,6 +7,7 @@ zh_tw:
status : 標籤
sub_title: 副標題
category: 類別
dept_title: 單位
add_new: 新建
approve: 審核
tag_cloud: 標籤雲

View File

@ -6,6 +6,7 @@ Rails.application.routes.draw do
namespace :admin do
post 'announcement/preview', to: 'announcements#preview'
get 'announcement/destroy_preview/:slug_title-:uid', to: 'announcements#destroy_preview'
get 'bulletins.json', to: 'bulletins#get_bulletins'
post 'announcement/approve_bulletin', to: 'announcements#approve_bulletin'
resources :announcements
end