add connect calendar feature

This commit is contained in:
chiu 2020-05-28 19:16:00 +08:00
parent 212530361b
commit 6258e8886d
5 changed files with 122 additions and 1 deletions

View File

@ -179,6 +179,14 @@ class Admin::AnnouncementsController < OrbitAdminController
@bulletin = Bulletin.new
@bulletin.email_sentdate = Time.now
@reach_limit = @bulletin.check_status_limit(current_user,true)
if defined? Calendar
categories = user_authenticated_categories rescue ['all']
if categories.first == "all"
@calendar_categories = CalendarType.all
else
@calendar_categories = CalendarType.where(:category_id.in => categories) rescue []
end
end
end
def create
@ -200,6 +208,20 @@ class Admin::AnnouncementsController < OrbitAdminController
end
bulletin = Bulletin.new(bps)
if !defined?(Calendar).nil?
if bps[:add_to_calendar] == '0' && !bps[:event_id].blank?
Event.find(bps[:event_id]).destroy rescue nil
bps[:event_id] = nil
elsif bps[:add_to_calendar] == '1'
event = Event.find(bps[:event_id]) rescue Event.new(create_user_id: current_user.id)
e_start = bps[:calendar_start_date].blank? ? bps[:postdate] : bps[:calendar_start_date]
e_start = Time.now.to_datetime if e_start.blank?
e_end = bps[:calendar_end_date].blank? ? bps[:deadline] : bps[:calendar_end_date]
e_end = Time.now.to_datetime + 1.year if e_end.blank?
event.update_attributes(bulletin_id: bulletin.id,start: e_start,end: e_end,update_user_id: current_user.id,all_day: bps[:calendar_all_day],calendar_type_id: bps[:calendar_type_id],title: bps[:title_translations][I18n.locale],note: bps[:subtitle_translations][I18n.locale])
bps[:event_id] = event.id
end
end
bulletin.create_user_id = current_user.id
bulletin.update_user_id = current_user.id
if AnnouncementSetting.is_pro?
@ -239,6 +261,14 @@ class Admin::AnnouncementsController < OrbitAdminController
@reach_limit = @bulletin.check_status_limit(current_user,true)
@tags = @module_app.tags
@categories = @module_app.categories.enabled
if defined? Calendar
categories = user_authenticated_categories rescue ['all']
if categories.first == "all"
@calendar_categories = CalendarType.all
else
@calendar_categories = CalendarType.where(:category_id.in => categories) rescue []
end
end
@statuses = []
@bulletin.email_sentdate = Time.now if @bulletin.email_sent == false
else
@ -268,6 +298,20 @@ class Admin::AnnouncementsController < OrbitAdminController
bps[:is_hot] = bulletin.is_hot
bps[:is_hidden] = bulletin.is_hidden
end
if !defined?(Calendar).nil?
if bps[:add_to_calendar] == '0' && !bps[:event_id].blank?
Event.find(bps[:event_id]).destroy rescue nil
bps[:event_id] = nil
elsif bps[:add_to_calendar] == '1'
event = Event.find(bps[:event_id]) rescue Event.new(create_user_id: current_user.id)
e_start = bps[:calendar_start_date].blank? ? bps[:postdate] : bps[:calendar_start_date]
e_start = Time.now.to_datetime if e_start.blank?
e_end = bps[:calendar_end_date].blank? ? bps[:deadline] : bps[:calendar_end_date]
e_end = Time.now.to_datetime + 1.year if e_end.blank?
event.update_attributes(bulletin_id: bulletin.id,start: e_start,end: e_end,update_user_id: current_user.id,all_day: bps[:calendar_all_day],calendar_type_id: bps[:calendar_type_id],title: bps[:title_translations][I18n.locale],note: bps[:subtitle_translations][I18n.locale])
bps[:event_id] = event.id
end
end
bulletin.update_attributes(bps)
bulletin.update_user_id = current_user.id
if bulletin.rejected

View File

@ -15,6 +15,13 @@ class Bulletin
before_destroy do
AnnsCache.all.destroy
end
field :add_to_calendar,type: Boolean,default: false
field :calendar_start_date, :type => DateTime
field :calendar_end_date, :type => DateTime
field :calendar_all_day,type: Boolean,default: false
field :calendar_type_id
field :event_id
field :title, type: String, localize: true
field :subtitle, localize: true
field :text, localize: true
@ -58,6 +65,17 @@ class Bulletin
before_create :set_expire
before_save :check_limit
def calendar_type
CalendarType.where(:category_id.in => self.calendar_type_id)
end
def event
if !self.event_id.nil?
Event.where(:id => self.event_id).first
else
nil
end
end
def check_limit
check_status_limit(update_user)
end

View File

@ -22,7 +22,15 @@
<%= javascript_include_tag "lib/module-area" %>
<%= javascript_include_tag "form" %>
<% end %>
<script type="text/javascript">
function trigger_on_add_calendar(ele){
if ($(ele).prop('checked')){
$('.trigger_on_add_calendar').show()
}else{
$('.trigger_on_add_calendar').hide()
}
}
</script>
<!-- Input Area -->
<div class="input-area">
@ -30,6 +38,9 @@
<div class="nav-name"><strong><%= t(:module) %></strong></div>
<ul class="nav nav-pills module-nav">
<li class="active"><a href="#basic" data-toggle="tab"><%= t(:basic) %></a></li>
<% if defined? Calendar %>
<li><a href="#calendar" data-toggle="tab"><%= t('calendar.calendar') %></a></li>
<% end %>
<% if((!AnnouncementSetting.first.only_manager_can_edit_status) || (AnnouncementSetting.first.only_manager_can_edit_status && (@current_user.is_admin? || @current_user.is_manager?(@module_app))) ) %>
<li><a href="#status" data-toggle="tab"><%= t(:status) %></a></li>
<% end %>
@ -98,6 +109,50 @@
</div>
</div>
<!-- Calendar Module -->
<% if defined? Calendar %>
<div class="tab-pane fade" id="calendar">
<div class="control-group">
<label class="control-label muted"><%= t('announcement.add_to_calendar') %></label>
<div class="controls">
<%= f.check_box :add_to_calendar,onchange: 'trigger_on_add_calendar(this)' %>
</div>
</div>
<div class="trigger_on_add_calendar" <%= "style=display:none;" if !@bulletin.add_to_calendar %>>
<div class="control-group">
<label class="control-label muted"><%= t('calendar.calendar') %></label>
<div class="controls">
<%= f.select :calendar_type_id, @calendar_categories.collect{|t| [ t.title, t.id ]} %>
</div>
</div>
<div class="control-group" style="display: flex;flex-wrap: wrap;">
<div style="display: flex;flex-direction: column;">
<label class="control-label muted"><%= t(:start_date) %></label>
<label class="control-label muted"><%= t('announcement.blank_to_set') %></label>
</div>
<div class="controls" style="margin-left: 1.5em;">
<%= f.datetime_picker :calendar_start_date, :new_record => @bulletin.new_record?, :no_label => true, :data=>{"picker-type" => "range", "range" => "start"} %>
</div>
</div>
<div class="control-group" style="display: flex;flex-wrap: wrap;">
<div style="display: flex;flex-direction: column;">
<label class="control-label muted"><%= t(:end_date) %></label>
<label class="control-label muted"><%= t('announcement.blank_to_set') %></label>
</div>
<div class="controls" style="margin-left: 1.5em;">
<%= f.datetime_picker :calendar_end_date, :new_record => @bulletin.new_record?, :no_label => true, :data=>{"picker-type" => "range", "range" => "end"} %>
</div>
</div>
<div class="control-group">
<label class="control-label muted"><%= t('calendar.all_day') %></label>
<div class="controls">
<%= f.check_box :calendar_all_day %>
</div>
</div>
</div>
<%= f.hidden_field :event_id %>
</div>
<% end %>
<!-- Status Module -->
<% if((!AnnouncementSetting.first.only_manager_can_edit_status) || (AnnouncementSetting.first.only_manager_can_edit_status && (@current_user.is_admin? || @current_user.is_manager?(@module_app))) ) %>
<div class="tab-pane fade" id="status">

View File

@ -3,6 +3,8 @@ en:
feed: Feed
import: Import
announcement:
add_to_calendar: Add to calendar
blank_to_set: (blank to use announcement setting)
stime: start time
etime: end time
select_prompt: --select category--

View File

@ -3,6 +3,8 @@ zh_tw:
feed: 供給
import: 匯入
announcement:
add_to_calendar: 加入行事曆
blank_to_set: (留白則使用公告設定)
stime: 開始時間
etime: 結束時間
select_prompt: --選取類別--