add comment feature for bulletin
This commit is contained in:
parent
c3ed827184
commit
6b29a2c2a1
|
@ -3,18 +3,31 @@ require 'rubyXL'
|
|||
class Admin::AnnouncementsController < OrbitAdminController
|
||||
include Admin::AnnouncementsHelper
|
||||
before_action ->(module_app = @app_title) { set_variables module_app }
|
||||
before_action :set_bulletin, only: [:edit, :destroy]
|
||||
before_action :set_bulletin, only: [:edit, :destroy, :comment]
|
||||
before_action :load_access_level, :load_settings
|
||||
|
||||
def initialize
|
||||
super
|
||||
@app_title = "announcement"
|
||||
end
|
||||
|
||||
def comment_hidden
|
||||
b = BulletinComment.find(params[:id]) rescue nil
|
||||
if !b.nil?
|
||||
b.is_hidden = !b.is_hidden
|
||||
b.save
|
||||
@table_feed_fields = ["announcement.time", "announcement.comment", "announcement.account","ip","is_hidden"]
|
||||
@comments = b.bulletin.bulletin_comments.reverse rescue []
|
||||
render partial: 'comment'
|
||||
end
|
||||
end
|
||||
def comment
|
||||
@table_feed_fields = ["announcement.time", "announcement.comment", "announcement.account","ip","is_hidden"]
|
||||
@comments = @bulletin.bulletin_comments.reverse rescue []
|
||||
end
|
||||
def index
|
||||
Bulletin.remove_expired_status
|
||||
@tags = @module_app.tags
|
||||
@table_fields = [:status, :category, :title, :start_date, :end_date, :last_modified]
|
||||
@table_fields = [:status, :category, :title, :start_date, :end_date, "announcement.comment", :last_modified]
|
||||
@current_user = current_user
|
||||
if AnnouncementSetting.first.is_display_edit_only && !current_user.is_admin? && !current_user.is_manager?(@module_app)
|
||||
current_user_is_sub_manager = !current_user.is_manager?(@module_app) && (current_user.is_sub_manager?(@module_app) || current_user.is_sub_manager_with_role?(@module_app)) rescue false
|
||||
|
|
|
@ -1,5 +1,17 @@
|
|||
class AnnouncementsController < ApplicationController
|
||||
include AnnouncementsHelper
|
||||
helper_method :complementaryColor,:lighten_color
|
||||
def comment
|
||||
@bulletin = Bulletin.where(:uid=>params[:uid]).first
|
||||
comment_val = params['comment']
|
||||
if !@bulletin.nil? && @bulletin.open_comment_for_user(OrbitHelper.current_user) && !comment_val.blank?
|
||||
account_id = OrbitHelper.current_user.member_profile.id.to_s rescue 'visitor'
|
||||
b = BulletinComment.new(ip: request.remote_ip,comment: comment_val,account_id: account_id)
|
||||
b.bulletin_id = @bulletin.id
|
||||
b.save
|
||||
render :json => {}
|
||||
end
|
||||
end
|
||||
def index
|
||||
Bulletin.remove_expired_status
|
||||
sorted,total_pages = get_sorted_annc
|
||||
|
@ -198,6 +210,7 @@ class AnnouncementsController < ApplicationController
|
|||
else
|
||||
announcement = Bulletin.can_display_and_sorted.where(:uid => uid).first
|
||||
end
|
||||
@bulletin = announcement
|
||||
announcement = Bulletin.where(:uid => uid).first if announcement.nil?
|
||||
url_to_edit = OrbitHelper.user_can_edit?(announcement) ? "/admin/announcements/#{announcement.id.to_s}/edit" : ""
|
||||
|
||||
|
@ -241,7 +254,7 @@ class AnnouncementsController < ApplicationController
|
|||
subtitle_ann = announcement.subtitle if announcement.display_subtitle?
|
||||
img_src = (announcement.image.thumb.url || "/assets/announcement-default.jpg") if announcement.display_img?
|
||||
img_description = announcement.image_description if (announcement.image_description.present?) && (announcement.display_img?)
|
||||
|
||||
show_comment_flag = announcement.open_comment_for_user(OrbitHelper.current_user)
|
||||
{
|
||||
"tags" => tags,
|
||||
"bulletin_files" => files,
|
||||
|
@ -258,6 +271,8 @@ class AnnouncementsController < ApplicationController
|
|||
"hide_class" => announcement.display_img? ? '' : ' hide',
|
||||
"alt_title" => desc
|
||||
},
|
||||
"comments" => announcement.comments,
|
||||
"show_comment_flag" => show_comment_flag,
|
||||
"impressionist" => (announcement.is_preview ? nil : announcement),
|
||||
"url_to_edit"=>url_to_edit
|
||||
}
|
||||
|
@ -327,6 +342,8 @@ class AnnouncementsController < ApplicationController
|
|||
"hide_class" => announcement["display_img"] ? '' : ' hide',
|
||||
"alt_title" => desc
|
||||
},
|
||||
"comments" => [],
|
||||
"show_comment_flag" => false,
|
||||
"impressionist" => nil,
|
||||
"url_to_edit" => url_to_edit
|
||||
}
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
# encoding: utf-8
|
||||
class BulletinsController < ApplicationController
|
||||
before_filter :set_I18n
|
||||
|
||||
def get_bulletins
|
||||
page = Page.where(:module => "announcement").first rescue nil
|
||||
|
||||
|
|
|
@ -1,4 +1,25 @@
|
|||
module AnnouncementsHelper
|
||||
def complementaryColor(my_hex)
|
||||
if my_hex[0] == '#'
|
||||
my_hex = my_hex[1..-1]
|
||||
end
|
||||
rgb = my_hex.split(//).each_slice(my_hex.length/3).map{|v| v.join}
|
||||
comp = rgb.map{|a| (255 - a.to_i(16)).to_s(16).rjust(2,'0')}
|
||||
'#'+comp.join
|
||||
end
|
||||
def lighten_color(my_hex,percent)
|
||||
if my_hex[0] == '#'
|
||||
my_hex = my_hex[1..-1]
|
||||
end
|
||||
rgb = my_hex.split(//).each_slice(my_hex.length/3).map{|v| v.join}
|
||||
comp = rgb.collect do |a|
|
||||
tmp = a.to_i(16)*(1+percent/100.0)
|
||||
tmp = 255 if tmp>255
|
||||
tmp = 0 if tmp < 0
|
||||
tmp.to_i.to_s(16).rjust(2,'0')
|
||||
end
|
||||
'#'+comp.join
|
||||
end
|
||||
def set_image_version_for_widget
|
||||
subpart = OrbitHelper.get_current_widget
|
||||
@image_version = 'thumb'
|
||||
|
|
|
@ -49,12 +49,15 @@ class Bulletin
|
|||
field :other_mailaddress
|
||||
field :image_description, localize: true
|
||||
field :top_end_date, :type => DateTime
|
||||
|
||||
field :open_comment, :type => Boolean, :default => false
|
||||
field :comment_end_time, :type => DateTime
|
||||
field :comment_role, :type => Array, :default => []
|
||||
|
||||
mount_uploader :image, ImageUploader
|
||||
|
||||
has_many :bulletin_links, :autosave => true, :dependent => :destroy
|
||||
has_many :bulletin_files, :autosave => true, :dependent => :destroy
|
||||
|
||||
has_many :bulletin_comments, :autosave => true, :dependent => :destroy
|
||||
accepts_nested_attributes_for :bulletin_files, :allow_destroy => true
|
||||
accepts_nested_attributes_for :bulletin_links, :allow_destroy => true
|
||||
|
||||
|
@ -166,4 +169,11 @@ class Bulletin
|
|||
def display_img?
|
||||
self.display_img rescue false
|
||||
end
|
||||
def comments
|
||||
self.bulletin_comments.select{|v| !v.is_hidden}
|
||||
end
|
||||
def open_comment_for_user(user)
|
||||
role_ids = user.member_profile.roles.collect{|v| v.id.to_s} rescue ['visitor']
|
||||
!self.comment_end_time.blank? && self.open_comment && self.comment_end_time > Time.now && (self.comment_role.any?{|v| role_ids.include?(v)} || self.comment_role.include?('visitor') || (self.comment_role.include?('all_member') && role_ids[0] != 'visitor'))
|
||||
end
|
||||
end
|
||||
|
|
|
@ -0,0 +1,21 @@
|
|||
# encoding: utf-8
|
||||
class BulletinComment
|
||||
include Mongoid::Document
|
||||
include Mongoid::Timestamps
|
||||
|
||||
field :ip
|
||||
field :comment
|
||||
field :account_id
|
||||
field :is_hidden,type: Boolean,default: false
|
||||
def time
|
||||
self.created_at.strftime('%Y/%m/%d %H:%M')
|
||||
end
|
||||
def account
|
||||
tmp = MemberProfile.where(:id => self.account_id).collect{|v| v.name}.join
|
||||
tmp.blank? ? I18n.t('announcement_visitor') : tmp
|
||||
end
|
||||
def roles
|
||||
MemberProfile.where(:id => self.account_id).collect{|v| v.roles}.flatten
|
||||
end
|
||||
belongs_to :bulletin
|
||||
end
|
|
@ -0,0 +1,25 @@
|
|||
<table class="table main-list">
|
||||
<thead>
|
||||
<tr class="sort-header">
|
||||
<% @table_feed_fields.each do |f| %>
|
||||
<%= thead(f) %>
|
||||
<% end %>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<% @comments.each do |comment| %>
|
||||
<tr>
|
||||
<td><%= comment.time %></td>
|
||||
<td><%= comment.comment.html_safe %></td>
|
||||
<td>
|
||||
<%= comment.account %>
|
||||
<% comment.roles.each do |role| %>
|
||||
<span class="label"><%= role.title rescue '' %></span>
|
||||
<% end %>
|
||||
</td>
|
||||
<td><%= comment.ip %></td>
|
||||
<td><%= button_tag (comment.is_hidden ? t('show') : t('is_hidden')), type: 'button',"data-href" => "/#{I18n.locale}/admin/annc-comment-hidden/#{comment.id}",:onclick => "update_status(this)" ,class: (comment.is_hidden ? 'btn btn-primary' : 'btn btn-info') %></td>
|
||||
</tr>
|
||||
<% end %>
|
||||
</tbody>
|
||||
</table>
|
|
@ -194,7 +194,33 @@
|
|||
<%= f.datetime_picker :top_end_date, :no_label => true, :new_record => @bulletin.new_record? %>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="control-group">
|
||||
<label class="control-label muted"><%= t('announcement.open_comment')%></label>
|
||||
<div class="controls">
|
||||
<%= f.check_box :open_comment %><%= t('announcement.open') %>
|
||||
</div>
|
||||
</div>
|
||||
<div class="control-group <%= @bulletin.open_comment ? "" : "hide" %>" data-for="open_comment">
|
||||
<label for="" class="control-label muted"><%= t('announcement.comment_end_time')%></label>
|
||||
<div class="controls">
|
||||
<%= f.datetime_picker :comment_end_time, :no_label => true, :new_record => @bulletin.new_record? %>
|
||||
</div>
|
||||
</div>
|
||||
<div class="control-group <%= @bulletin.open_comment ? "" : "hide" %>" data-for="open_comment">
|
||||
<label for="" class="control-label muted"><%= t('announcement.comment_role')%></label>
|
||||
<div class="controls">
|
||||
<%= check_box_tag 'bulletin[comment_role][]','visitor',@bulletin.comment_role.include?('visitor') %>
|
||||
<%= t('announcement.visitor') %>
|
||||
<br>
|
||||
<%= check_box_tag 'bulletin[comment_role][]','all_member',@bulletin.comment_role.include?('all_member'),class: 'role_all_member' %>
|
||||
<%= t('announcement.all_member') %>
|
||||
<br>
|
||||
<% Role.all.each do |role| %>
|
||||
<%= check_box_tag 'bulletin[comment_role][]',role.id.to_s,@bulletin.comment_role.include?(role.id.to_s),class: 'role' %>
|
||||
<%= role.title %>
|
||||
<% end %>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<% end %>
|
||||
|
||||
|
@ -459,6 +485,25 @@
|
|||
}
|
||||
|
||||
$(function() {
|
||||
$('#bulletin_open_comment').change(function(){
|
||||
$(this).prop('checked') ? $('div[data-for="open_comment"]').removeClass('hide') : $('div[data-for="open_comment"]').addClass('hide')
|
||||
})
|
||||
$('.role_all_member').change(function(){
|
||||
if ($(this).prop('checked')){
|
||||
$('.role').each(function() {
|
||||
$(this).prop("checked", true);
|
||||
})
|
||||
} else{
|
||||
$('.role').each(function() {
|
||||
$(this).prop("checked", false);
|
||||
})
|
||||
}
|
||||
})
|
||||
$('.role').change(function(){
|
||||
if (!$(this).prop('checked') && $('.role_all_member').prop('checked')){
|
||||
$('.role_all_member').prop('checked',false)
|
||||
}
|
||||
})
|
||||
if (location.pathname.substr(-3)=='new'){
|
||||
var getDate = new Date();
|
||||
var toDay = getDate.getFullYear()+"/"+ (Appendzero(getDate.getMonth()+1))+"/"+Appendzero(getDate.getDate())+" "+Appendzero(getDate.getHours())+":"+Appendzero(getDate.getMinutes());
|
||||
|
|
|
@ -57,6 +57,7 @@
|
|||
</td>
|
||||
<td><%= format_value b.postdate %></td>
|
||||
<td class="<%= b.expired? ? "expired" : "" %>"><%= format_value b.deadline %></td>
|
||||
<td><%= link_to b.bulletin_comments.count.to_s,"/#{I18n.locale}/admin/announcements/#{b.id}/comment" %></td>
|
||||
<td><%= b.update_user.user_name rescue ""%></td>
|
||||
</tr>
|
||||
<tr class="footable-row-detail">
|
||||
|
|
|
@ -0,0 +1,12 @@
|
|||
<% content_for :page_specific_css do %>
|
||||
<%= stylesheet_link_tag("admin/tags") %>
|
||||
<% end %>
|
||||
<script type="text/javascript">
|
||||
function update_status(ele) {
|
||||
$.get($(ele).data('href'),function(data){
|
||||
$('table').html(data)
|
||||
})
|
||||
return false
|
||||
}
|
||||
</script>
|
||||
<%= render 'comment' %>
|
|
@ -73,4 +73,91 @@
|
|||
<%= render_view %>
|
||||
<% if @show_back_and_next_flag==2 %>
|
||||
<%= content %>
|
||||
<% end %>
|
||||
<% site = Site.first
|
||||
hover_color = site.orbit_bar_background_hover_color rescue nil
|
||||
hover_color = '#0095CF' if hover_color.blank?
|
||||
bg_color = site.orbit_bar_background_color rescue nil
|
||||
bg_color = bg_color.blank? ? '#3a3b3c' : lighten_color(bg_color,-40)
|
||||
color1 = complementaryColor(bg_color)
|
||||
color2 = lighten_color(color1,30)
|
||||
%>
|
||||
<style type="text/css">
|
||||
div[contentEditable=true]:empty:before{
|
||||
content: attr(data-ph);
|
||||
color: <%= color1 %>;
|
||||
padding-left: 3%;
|
||||
font-weight: bold;
|
||||
font-family: serif;
|
||||
}
|
||||
.announcement-comment {
|
||||
background: <%= bg_color %>;
|
||||
color: <%= color2 %>;
|
||||
font-size: 1.3em;
|
||||
padding-left: 3%;
|
||||
border-radius: 0.7em;
|
||||
display: inline-block;
|
||||
width: 80%;
|
||||
padding: 1% 3%;
|
||||
outline: 0;
|
||||
}
|
||||
.annc-comment-div{
|
||||
display: flex;
|
||||
align-items: flex-start;
|
||||
}
|
||||
.btn-comment{
|
||||
margin-left: 3%;
|
||||
color: <%= color2 %>;
|
||||
font-size: 1.2em;
|
||||
background: <%= bg_color %>;
|
||||
margin-left: 3%;
|
||||
}
|
||||
.btn.btn-comment:focus{
|
||||
color: <%= color2 %>;
|
||||
}
|
||||
.btn-comment:hover{
|
||||
color: <%= color2 %>;
|
||||
background-color: <%= hover_color %>;
|
||||
}
|
||||
.comment-time{
|
||||
padding-left: 1em;
|
||||
color: <%= bg_color %>;
|
||||
}
|
||||
.annc-comments{
|
||||
margin: 1.5em 0;
|
||||
}
|
||||
</style>
|
||||
<script type="text/javascript">
|
||||
$(function(){
|
||||
$('.annc-comment-div .btn-comment').click(function(){
|
||||
$.ajax({
|
||||
url: "<%= "/xhr/announcements/#{params[:slug]}-#{params[:uid]}/comment" %>",
|
||||
data : {"comment" : $(this).parents('.annc-comment-div').find('.announcement-comment').html()},
|
||||
dataType : "json",
|
||||
type : "get",
|
||||
success : function(data){
|
||||
window.location.href = window.location.href
|
||||
}
|
||||
})
|
||||
})
|
||||
})
|
||||
</script>
|
||||
<% action_data['comments'].reverse.each do |comment| %>
|
||||
<div class="annc-comments">
|
||||
<div class="comment-time">
|
||||
<%= comment.time %>
|
||||
</div>
|
||||
<div class="announcement-comment">
|
||||
<%= comment.comment.html_safe %>
|
||||
</div>
|
||||
<br>
|
||||
</div>
|
||||
<% end %>
|
||||
<% if action_data['show_comment_flag'] %>
|
||||
<div class="annc-comment-div">
|
||||
<div data-ph="<%= t('announcement.comment') %>" contenteditable="true" class="announcement-comment"></div>
|
||||
<button class="btn btn-comment">
|
||||
<%= t('announcement.send_comment') %>
|
||||
</button>
|
||||
</div>
|
||||
<% end %>
|
|
@ -3,6 +3,16 @@ en:
|
|||
feed: Feed
|
||||
import: Import
|
||||
announcement:
|
||||
time: Time
|
||||
send_comment: Send Comment
|
||||
comment: Comment
|
||||
account: Account
|
||||
open_comment: Open for Comment
|
||||
open: Open
|
||||
comment_end_time: Comment End Time
|
||||
comment_role: Comment Role
|
||||
visitor: Visitor
|
||||
all_member: All Member
|
||||
add_to_calendar: Add to calendar
|
||||
blank_to_set: (blank to use announcement setting)
|
||||
stime: start time
|
||||
|
|
|
@ -3,6 +3,16 @@ zh_tw:
|
|||
feed: 供給
|
||||
import: 匯入
|
||||
announcement:
|
||||
time: 時間
|
||||
send_comment: 送出留言
|
||||
comment: 留言內容
|
||||
account: 帳號
|
||||
open_comment: 開放評論
|
||||
open: 開放
|
||||
comment_end_time: 停止開放時間
|
||||
comment_role: 留言身分
|
||||
visitor: 訪客
|
||||
all_member: 全部會員
|
||||
add_to_calendar: 加入行事曆
|
||||
blank_to_set: (留白則使用公告設定)
|
||||
stime: 開始時間
|
||||
|
|
|
@ -23,11 +23,13 @@ Rails.application.routes.draw do
|
|||
post 'announcement/import_from_wp', to: 'announcements#import_from_wp'
|
||||
post 'announcement/generate_iframe_url' => 'announcements#generate_iframe_url'
|
||||
resources :announcements
|
||||
get 'announcements/:id/comment'=> 'announcements#comment'
|
||||
get 'annc-comment-hidden/:id' => 'announcements#comment_hidden'
|
||||
end
|
||||
|
||||
resources :announcements do
|
||||
collection do
|
||||
get ':slug_title-:uid', to: 'announcements#show', as: :display
|
||||
get ':slug_title-:uid', to: 'announcements#show', as: :display
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -36,6 +38,7 @@ Rails.application.routes.draw do
|
|||
get "/xhr/announcements/feeds" => "announcement_feeds#feeds"
|
||||
get '/xhr/announcements/announcement.json', to: 'bulletins#get_bulletins'
|
||||
get '/xhr/panel/announcement/widget/sync_data' => 'announcements#show_widget'
|
||||
get '/xhr/announcements/:slug_title-:uid/comment', to: 'announcements#comment'
|
||||
end
|
||||
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue