diff --git a/app/controllers/admin/announcements_controller.rb b/app/controllers/admin/announcements_controller.rb index a18802d..e150c5d 100644 --- a/app/controllers/admin/announcements_controller.rb +++ b/app/controllers/admin/announcements_controller.rb @@ -5,7 +5,10 @@ class Admin::AnnouncementsController < OrbitAdminController before_action ->(module_app = @app_title) { set_variables module_app } before_action :set_bulletin, only: [:edit, :destroy, :comment] before_action :load_access_level, :load_settings - + before_action :set_module_pages, only: [:edit,:new] + def set_module_pages + @module_pages = Page.where(:module => 'announcement').collect{|p| [p.name,p.id] } + end def initialize super @app_title = "announcement" @@ -224,18 +227,7 @@ class Admin::AnnouncementsController < OrbitAdminController 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 + bps = update_calendar(bps,bulletin) end bulletin.create_user_id = current_user.id bulletin.update_user_id = current_user.id @@ -316,18 +308,7 @@ class Admin::AnnouncementsController < OrbitAdminController 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 + bps = update_calendar(bps,bulletin) end bulletin.update_attributes(bps) bulletin.update_user_id = current_user.id @@ -495,7 +476,31 @@ class Admin::AnnouncementsController < OrbitAdminController def settings_params params.require(:announcement_setting).permit! end - + def update_calendar(bps,bulletin) + 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(model_class: 'Bulletin', + module_key: 'announcement', + model_cat: bps[:category_id], + model_tags: bps[:tags], + model_page_id: bps[:page_id], + model_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_translations: bps[:title_translations], + note_translations: bps[:subtitle_translations]) + bps[:event_id] = event.id + end + bps + end def create_feed_cache(bulletin=nil,bulletin_feed=nil) if !bulletin.nil? BulletinFeed.where(:tag_ids.in => Array(bulletin.tag_ids).collect{|v| v.to_s}).each do |bulletin_feed| diff --git a/app/models/bulletin.rb b/app/models/bulletin.rb index 970c355..823b9fd 100644 --- a/app/models/bulletin.rb +++ b/app/models/bulletin.rb @@ -21,7 +21,7 @@ class Bulletin field :calendar_all_day,type: Boolean,default: false field :calendar_type_id field :event_id - + field :page_id field :title, type: String, localize: true field :subtitle, localize: true field :text, localize: true diff --git a/app/views/admin/announcements/_form.html.erb b/app/views/admin/announcements/_form.html.erb index 045b1d2..666095b 100644 --- a/app/views/admin/announcements/_form.html.erb +++ b/app/views/admin/announcements/_form.html.erb @@ -149,6 +149,12 @@ <%= f.check_box :calendar_all_day %> +
+ +
+ <%= f.select :page_id,[["----- Select a page -----",nil]]+@module_pages %> +
+
<%= f.hidden_field :event_id %>