add feature to connect with calendar

This commit is contained in:
chiu 2020-08-07 22:03:30 +08:00
parent 128bc5c158
commit 327dd7fdac
5 changed files with 66 additions and 4 deletions

View File

@ -2,6 +2,10 @@
class Admin::VenueAdminController < OrbitAdminController class Admin::VenueAdminController < OrbitAdminController
#alias_method :org_datetime_picker, :datetime_picker #alias_method :org_datetime_picker, :datetime_picker
#include OrbitFormHelper #include OrbitFormHelper
before_action :set_calendar_types,only: [:edit,:new]
def set_calendar_types
@calendar_types = CalendarType.all.collect{|v| [v.title,v.id.to_s]}
end
def initialize(*) def initialize(*)
super super
ActionView::Helpers::FormBuilder.send(:prepend,VenueAdminHelper) ActionView::Helpers::FormBuilder.send(:prepend,VenueAdminHelper)

View File

@ -1,14 +1,20 @@
module VenueAdminHelper module VenueAdminHelper
include ActionView::Helpers::FormOptionsHelper
include OrbitFormHelper include OrbitFormHelper
alias :org_datetime_picker :datetime_picker alias :org_datetime_picker :datetime_picker
def datetime_picker(*arg,**args) def datetime_picker(*arg,**args)
tp = org_datetime_picker(*arg,**args) tp = org_datetime_picker(*arg,**args)
venue = @template.instance_variable_get(:@venue) venue = @template.instance_variable_get(:@venue)
if !venue.nil? if !venue.nil?
base_name = @object.class.to_s.underscore
calendar_types = @template.instance_variable_get(:@calendar_types)
style_attr = '' style_attr = ''
calendar_show = !@object['calendar_dict'][arg[0]].nil?
hide_style = " style=\"display: none;\""
if !@object.send(arg[0].to_s+'_reminder') if !@object.send(arg[0].to_s+'_reminder')
style_attr = " style=\"display: none;\"" style_attr = hide_style
end end
style_attr2 = calendar_show ? '' : hide_style
onclick_func = "function reminder_switch(ele){ onclick_func = "function reminder_switch(ele){
if ($(ele).prop('checked')){ if ($(ele).prop('checked')){
$(ele).parents('.controls').find('.email_reminder').show() $(ele).parents('.controls').find('.email_reminder').show()
@ -16,10 +22,22 @@ module VenueAdminHelper
$(ele).parents('.controls').find('.email_reminder').hide() $(ele).parents('.controls').find('.email_reminder').hide()
} }
};reminder_switch(this)" };reminder_switch(this)"
onclick_func1 = "function reminder_switch_calendar(ele){
if ($(ele).prop('checked')){
$(ele).parents('.controls').find('.calendar_div').show()
}else{
$(ele).parents('.controls').find('.calendar_div').hide()
}
};reminder_switch_calendar(this)"
tp2 = content_tag(:div, :style => "float: left;flex-wrap: wrap;display: inline-flex;margin-left: 1em;align-items: center;") do tp2 = content_tag(:div, :style => "float: left;flex-wrap: wrap;display: inline-flex;margin-left: 1em;align-items: center;") do
self.check_box((arg[0].to_s+'_reminder').to_sym,:onclick => onclick_func) + "寄送Email提醒<div class=\"email_reminder\"#{style_attr}>:&nbsp;提前#{self.number_field((arg[0].to_s+'_reminder_day').to_sym, :class => 'input-mini')}天寄送</div>".html_safe self.check_box((arg[0].to_s+'_reminder').to_sym,:onclick => onclick_func) + "#{I18n.t('venue_management.send_email_reminder')}<div class=\"email_reminder\"#{style_attr}>:&nbsp;#{I18n.t('venue_management.before')}#{self.number_field((arg[0].to_s+'_reminder_day').to_sym, :class => 'input-mini')}#{I18n.t('venue_management.day_send_email')}</div>".html_safe
end end
tp = content_tag(:div, tp , :style=>"float: left;")+ tp2 calendar_type_key = "#{base_name}[calendar_data][type][#{arg[0]}]"
calendar_type = @object['calendar_data']['type'][arg[0]] rescue nil
tp3 = content_tag(:div, :style => "float: left;flex-wrap: wrap;display: inline-flex;margin-left: 1em;align-items: center;") do
check_box_tag("#{base_name}[calendar_data][key][]",arg[0],calendar_show,:onclick => onclick_func1) + "#{I18n.t('venue_management.add_to_calendar')}<div class=\"calendar_div\"#{style_attr2}>:&nbsp;#{select_tag(calendar_type_key,options_for_select(calendar_types,calendar_type))}</div>".html_safe
end
tp = content_tag(:div, tp , :style=>"float: left;")+ tp2 + tp3
end end
tp tp
end end

View File

@ -26,10 +26,43 @@ module VenueLinkFile
self.field v.name+'_reminder_day', type: Integer self.field v.name+'_reminder_day', type: Integer
end end
end end
self.field :calendar_data,type: Hash,default: {type:{},key:[]}
self.field :calendar_dict,type: Hash,default: {}
def calendar_id(field)
self.calendar_dict[field]
end
self.has_many :venue_management_emails, :autosave => true, :dependent => :destroy self.has_many :venue_management_emails, :autosave => true, :dependent => :destroy
self.accepts_nested_attributes_for :venue_management_emails, :allow_destroy => true self.accepts_nested_attributes_for :venue_management_emails, :allow_destroy => true
VenueManagementEmail.send(:belongs_to,tmp, :class_name => self.to_s, :foreign_key => "#{tmp}_id") VenueManagementEmail.send(:belongs_to,tmp, :class_name => self.to_s, :foreign_key => "#{tmp}_id")
self.before_save do self.before_save do
venue_main = self.class.to_s == 'VenueManagementMain' ? self : VenueManagementMain.find(self.venue_management_main_id)
calendar_keys = Array(self.calendar_data['key'])
(self.calendar_dict.keys - calendar_keys).each do |key_deleted|
event = Event.where(:id => self.calendar_dict[key_deleted]).first
event.model_class = nil
event.destroy
self.calendar_dict.delete(key_deleted)
end
if !calendar_keys.blank?
calendar_keys.each do |key|
key_id = self.calendar_id(key)
current_user_id = OrbitHelper.current_user.id rescue nil
in_use_locales = Site.first.in_use_locales
title_tp = {}
note_tp = {}
in_use_locales.each do |locale|
title_tp[locale] = venue_main['title'][locale] + ' ' + self.get_trans(key)
note_tp[locale] = self.case_no.blank? ? {} : I18n.t('vm_inviting.case_no') +': ' + self.case_no
end
update_dict = {key: key,model_class: self.class.to_s,model_id: self.id,update_user_id: current_user_id,calendar_type_id: calendar_data['type'][key],all_day: true,start: self.send(key),end: self.send(key),title_translations: title_tp,note_translations: note_tp}
if key_id.nil?
self.calendar_dict[key] = Event.create(update_dict.merge(create_user_id: current_user_id)).id
else
calendar = Event.find(key_id)
calendar.update_attributes(update_dict)
end
end
end
self.venue_management_emails.each do |venue_mail| self.venue_management_emails.each do |venue_mail|
email = venue_mail.email email = venue_mail.email
if !email.nil? if !email.nil?
@ -37,7 +70,6 @@ module VenueLinkFile
end end
end end
self.venue_management_emails = [] self.venue_management_emails = []
venue_main = self.class.to_s == 'VenueManagementMain' ? self : VenueManagementMain.find(self.venue_management_main_id)
manager_emails = venue_main.manager_emails manager_emails = venue_main.manager_emails
self.fields.values.each do|v| self.fields.values.each do|v|
if v.type==Date || v.type==DateTime if v.type==Date || v.type==DateTime

View File

@ -17,6 +17,10 @@ en:
verification_failed: Verification Failed #驗證碼錯誤 verification_failed: Verification Failed #驗證碼錯誤
venue_management: venue_management:
send_email_reminder: Send email reminder
before: Before
day_send_email: day send email
add_to_calendar: Add to calendar
manager: Manager manager: Manager
contractor: Contractor contractor: Contractor
land_number: Land number land_number: Land number

View File

@ -17,6 +17,10 @@ zh_tw:
verification_failed: 驗證碼錯誤 verification_failed: 驗證碼錯誤
venue_management: venue_management:
send_email_reminder: 寄送Email提醒
before: 提前
day_send_email: 天寄送
add_to_calendar: 加入行事曆
manager: 管理人 manager: 管理人
contractor: 廠商 contractor: 廠商
land_number: 地號 land_number: 地號