add connect calendar feature
This commit is contained in:
parent
212530361b
commit
6258e8886d
|
@ -179,6 +179,14 @@ class Admin::AnnouncementsController < OrbitAdminController
|
||||||
@bulletin = Bulletin.new
|
@bulletin = Bulletin.new
|
||||||
@bulletin.email_sentdate = Time.now
|
@bulletin.email_sentdate = Time.now
|
||||||
@reach_limit = @bulletin.check_status_limit(current_user,true)
|
@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
|
end
|
||||||
|
|
||||||
def create
|
def create
|
||||||
|
@ -200,6 +208,20 @@ class Admin::AnnouncementsController < OrbitAdminController
|
||||||
end
|
end
|
||||||
|
|
||||||
bulletin = Bulletin.new(bps)
|
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.create_user_id = current_user.id
|
||||||
bulletin.update_user_id = current_user.id
|
bulletin.update_user_id = current_user.id
|
||||||
if AnnouncementSetting.is_pro?
|
if AnnouncementSetting.is_pro?
|
||||||
|
@ -239,6 +261,14 @@ class Admin::AnnouncementsController < OrbitAdminController
|
||||||
@reach_limit = @bulletin.check_status_limit(current_user,true)
|
@reach_limit = @bulletin.check_status_limit(current_user,true)
|
||||||
@tags = @module_app.tags
|
@tags = @module_app.tags
|
||||||
@categories = @module_app.categories.enabled
|
@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 = []
|
@statuses = []
|
||||||
@bulletin.email_sentdate = Time.now if @bulletin.email_sent == false
|
@bulletin.email_sentdate = Time.now if @bulletin.email_sent == false
|
||||||
else
|
else
|
||||||
|
@ -268,6 +298,20 @@ class Admin::AnnouncementsController < OrbitAdminController
|
||||||
bps[:is_hot] = bulletin.is_hot
|
bps[:is_hot] = bulletin.is_hot
|
||||||
bps[:is_hidden] = bulletin.is_hidden
|
bps[:is_hidden] = bulletin.is_hidden
|
||||||
end
|
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_attributes(bps)
|
||||||
bulletin.update_user_id = current_user.id
|
bulletin.update_user_id = current_user.id
|
||||||
if bulletin.rejected
|
if bulletin.rejected
|
||||||
|
|
|
@ -15,6 +15,13 @@ class Bulletin
|
||||||
before_destroy do
|
before_destroy do
|
||||||
AnnsCache.all.destroy
|
AnnsCache.all.destroy
|
||||||
end
|
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 :title, type: String, localize: true
|
||||||
field :subtitle, localize: true
|
field :subtitle, localize: true
|
||||||
field :text, localize: true
|
field :text, localize: true
|
||||||
|
@ -58,6 +65,17 @@ class Bulletin
|
||||||
|
|
||||||
before_create :set_expire
|
before_create :set_expire
|
||||||
before_save :check_limit
|
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
|
def check_limit
|
||||||
check_status_limit(update_user)
|
check_status_limit(update_user)
|
||||||
end
|
end
|
||||||
|
|
|
@ -22,7 +22,15 @@
|
||||||
<%= javascript_include_tag "lib/module-area" %>
|
<%= javascript_include_tag "lib/module-area" %>
|
||||||
<%= javascript_include_tag "form" %>
|
<%= javascript_include_tag "form" %>
|
||||||
<% end %>
|
<% 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 -->
|
<!-- Input Area -->
|
||||||
<div class="input-area">
|
<div class="input-area">
|
||||||
|
|
||||||
|
@ -30,6 +38,9 @@
|
||||||
<div class="nav-name"><strong><%= t(:module) %></strong></div>
|
<div class="nav-name"><strong><%= t(:module) %></strong></div>
|
||||||
<ul class="nav nav-pills module-nav">
|
<ul class="nav nav-pills module-nav">
|
||||||
<li class="active"><a href="#basic" data-toggle="tab"><%= t(:basic) %></a></li>
|
<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))) ) %>
|
<% 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>
|
<li><a href="#status" data-toggle="tab"><%= t(:status) %></a></li>
|
||||||
<% end %>
|
<% end %>
|
||||||
|
@ -98,6 +109,50 @@
|
||||||
</div>
|
</div>
|
||||||
</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 -->
|
<!-- 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))) ) %>
|
<% 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">
|
<div class="tab-pane fade" id="status">
|
||||||
|
|
|
@ -3,6 +3,8 @@ en:
|
||||||
feed: Feed
|
feed: Feed
|
||||||
import: Import
|
import: Import
|
||||||
announcement:
|
announcement:
|
||||||
|
add_to_calendar: Add to calendar
|
||||||
|
blank_to_set: (blank to use announcement setting)
|
||||||
stime: start time
|
stime: start time
|
||||||
etime: end time
|
etime: end time
|
||||||
select_prompt: --select category--
|
select_prompt: --select category--
|
||||||
|
|
|
@ -3,6 +3,8 @@ zh_tw:
|
||||||
feed: 供給
|
feed: 供給
|
||||||
import: 匯入
|
import: 匯入
|
||||||
announcement:
|
announcement:
|
||||||
|
add_to_calendar: 加入行事曆
|
||||||
|
blank_to_set: (留白則使用公告設定)
|
||||||
stime: 開始時間
|
stime: 開始時間
|
||||||
etime: 結束時間
|
etime: 結束時間
|
||||||
select_prompt: --選取類別--
|
select_prompt: --選取類別--
|
||||||
|
|
Loading…
Reference in New Issue