fix some error

This commit is contained in:
chiu 2020-08-08 20:33:26 +08:00
parent 3ac2655d72
commit e7bcef96a7
5 changed files with 55 additions and 46 deletions

View File

@ -84,12 +84,12 @@ var Calendar = function(dom){
var checked = ($("#all_day_check").is(":checked") ? true : false);
var checked_function = function(c){
if(c){
for(i in pickers){
for(i=0;i<pickers.length;i++){
var input = pickers[i].find("input");
input.val(input.val().split(" ")[0]);
}
}else{
for(i in pickers){
for(i=0;i<pickers.length;i++){
var d = new Date();
var input = pickers[i].find("input");
if(input.val())
@ -145,9 +145,9 @@ var Calendar = function(dom){
c.calendar.fullCalendar("refetchEvents");
});
c.event_create_space.find("#event_period").change(function(){
repeat_function();
//repeat_function();
})
for(i in pickers){
for(i=0;i<pickers.length;i++){
pickers[i].on("changeDate",function(e){
if(checked){
var input = $(this).find("input");
@ -155,7 +155,7 @@ var Calendar = function(dom){
}
})
}
repeat_function();
//repeat_function();
if(allDay)
checked_function(checked);
}
@ -353,7 +353,7 @@ var EventDialog = function(calendar,event){
var start_time = "",
end_time = "",
time_string = null;
Event_e = _event
if(_event.allDay) {
start_time = $.fullCalendar.formatDate(_event._start,"MMM dd, yyyy");
if(_event._end)
@ -411,7 +411,6 @@ var EventDialog = function(calendar,event){
var x = pos.x,
y = pos.y,
winheight = $(window).height();
console.log(event_quick_view.width())
if((x + event_quick_view.width()) > $(window).width()){
x = x - event_quick_view.width();
}

View File

@ -919,7 +919,6 @@ function EventManager(options, _sources) {
_fetchEventSource(source, function(events) {
if (fetchID == currentFetchID) {
if (events) {
if (options.eventDataTransform) {
events = $.map(events, options.eventDataTransform);
}
@ -1191,8 +1190,8 @@ function EventManager(options, _sources) {
}
event._start = cloneDate(event.start = parseDate(event.start, ignoreTimezone));
event.end = parseDate(event.end, ignoreTimezone);
if (event.end && event.end <= event.start) {
event.end = null;
if (event.end && event.end < event.start) {
event.end = event.start;
}
event._end = event.end ? cloneDate(event.end) : null;
if (event.allDay === undefined) {

View File

@ -136,7 +136,7 @@ class Admin::CalendarsController < OrbitAdminController
if !bulletin.nil?
bulletin.update_attributes(calendar_start_date: p[:start],calendar_end_date: p[:end],calendar_all_day: p[:all_day],calendar_type_id: p[:calendar_type_id])
end
if @event.update_attributes(p)
if @event.update_attributes!(p)
e = @event.to_json
e = JSON.parse(e)
e["can_edit"] = true

View File

@ -38,9 +38,9 @@ class CalendarsController < ApplicationController
if params[:start].present? && params[:end].present?
sdt = Time.at(params[:start].to_i)
edt = Time.at(params[:end].to_i)
events = Event.monthly_event(sdt,edt)
events = Event.monthly_event(sdt,edt)+Event.recurring_event(sdt,edt)
end
end
end
respond_to do |format|
format.html # index.html.erb
format.json { render json: events.to_json }

View File

@ -46,8 +46,8 @@ class Event
end
end
########################################
validates_presence_of :title, :message => "Please fill the title of the Event", :unless => lambda { self.title_translations.blank? }
validates_presence_of :title_translations, :message => "Please fill the title of the Event", :unless => lambda { self.title.blank? }
validates_presence_of :title, :message => "Please fill the title of the Event", :if => lambda { self['title_translations'].blank? }
validates_presence_of :title_translations, :message => "Please fill the title of the Event", :if => lambda { self['title'].blank? }
def title
tp = self['title_translations'][I18n.locale]
tp.blank? ? self['title'] : tp
@ -112,57 +112,68 @@ class Event
def self.monthly_event(start_date,end_date)
self.any_of(:start.gte => start_date, :end.gte => start_date).and(:start.lte => end_date).asc(:start)
end
def self.recurring_event(start_date,end_date)
def self.get_diff_month(date1,date2)
(date2.year-date1.year)*12+(date2.month-date1.month)
end
def self.recurring_event(start_date,end_date)
@recurring_events = self.where(:recurring => true)
@recurring = []
@recurring_events.each do |re|
case re.period
edit_url = Rails.application.routes.url_helpers.edit_admin_calendar_path(:locale=>I18n.locale, :id=>re.id)
delete_url = Rails.application.routes.url_helpers.admin_calendar_path(:locale=>I18n.locale, :id=>re.id)
data = {:id => re.id.to_s, :title=>re.title, :note=>re.note, :allDay => re.all_day, :recurring => re.recurring, :calendar => re.calendar_type.id.to_s, :color => re.calendar_type.color, :edit_url => edit_url, :delete_url => delete_url}
case re.period
when 'Daily'
if (start_date..end_date).cover?(re.start)
@i = TimeDifference.between(re.start,end_date).in_days.to_i
(1..@i).each do |i|
days = (end_date.to_date-re.start.to_date)
freq = re.frequency.to_i
(1..days).each do |i|
if i%freq==0
@start_date = re.start + i
@recurring << {:id => re.id.to_s, :title=>re.title, :note=>re.note, :start=>@start_date, :end => @start_date, :allDay => re.all_day, :recurring => re.recurring, :calendar => re.calendar_type.id.to_s, :color => re.calendar_type.color, :edit_url => Rails.application.routes.url_helpers.edit_admin_calendar_path(:locale=>I18n.locale, :id=>re.id), :delete_url => Rails.application.routes.url_helpers.admin_calendar_path(:locale=>I18n.locale, :id=>re.id)}
@end_date = re.end + i
@recurring << data.merge({:start => @start_date, :end => @end_date})
end
elsif re.start < start_date
@i = TimeDifference.between(start_date,end_date).in_days.to_i
(0..@i-1).each do |i|
@start_date = start_date.to_date + i
@recurring << {:id => re.id.to_s, :title=>re.title, :note=>re.note, :start=>@start_date, :end => @start_date, :allDay => re.all_day, :recurring => re.recurring, :calendar => re.calendar_type.id.to_s, :color => re.calendar_type.color, :edit_url => Rails.application.routes.url_helpers.edit_admin_calendar_path(:locale=>I18n.locale, :id=>re.id), :delete_url => Rails.application.routes.url_helpers.admin_calendar_path(:locale=>I18n.locale, :id=>re.id)}
end
end
when "Weekly"
@start_date = re.start
@end_date = re.end
@i = TimeDifference.between(re.start,end_date).in_weeks.to_i
(1..@i).each do |i|
(1..@i).each do |i|
@start_date += (7*re.frequency.to_i)
@end_date += (7*re.frequency.to_i)
@recurring << {:id => re.id.to_s, :title=>re.title, :note=>re.note, :start=>@start_date, :end => @end_date, :allDay => re.all_day, :recurring => re.recurring, :calendar => re.calendar_type.id.to_s, :color => re.calendar_type.color, :edit_url => Rails.application.routes.url_helpers.edit_admin_calendar_path(:locale=>I18n.locale, :id=>re.id), :delete_url => Rails.application.routes.url_helpers.admin_calendar_path(:locale=>I18n.locale, :id=>re.id)}
@recurring << data.merge({:start => @start_date, :end => @end_date})
end
when "Monthly"
if !(start_date..end_date).cover?(re.start) && start_date.to_datetime>re.start
sd = re.start
ed = re.end
end_datetime = end_date.to_datetime
start_datetime = start_date.to_datetime
months = self.get_diff_month(sd,start_datetime)..self.get_diff_month(sd,end_datetime)
months.each do |diff_month|
if (diff_month%re.frequency.to_i)==0
sd_tp = sd + diff_month.month
ed_tp = ed + diff_month.month
@recurring << data.merge({:start => sd_tp, :end => ed_tp})
end
end
end
when "Yearly"
if !(start_date..end_date).cover?(re.start)
sd = re.start
ed = re.end
@i = TimeDifference.between(re.start,end_date).in_months.to_i
@start_date = sd
sd = sd >> @i*re.frequency.to_i
ed = ed >> @i*re.frequency.to_i
@recurring << {:id => re.id.to_s, :title=>re.title, :note=>re.note, :start=>sd, :end => ed, :allDay => re.all_day, :recurring => re.recurring, :calendar => re.calendar_type.id.to_s, :color => re.calendar_type.color, :edit_url => Rails.application.routes.url_helpers.edit_admin_calendar_path(:locale=>I18n.locale, :id=>re.id), :delete_url => Rails.application.routes.url_helpers.admin_calendar_path(:locale=>I18n.locale, :id=>re.id)}
start_datetime = start_date.to_datetime
end_datetime = end_date.to_datetime
if start_datetime>sd
((start_datetime.year-sd.year)..(end_datetime.year-sd.year)).each do |year_diff|
if (year_diff%re.frequency.to_i)==0
sd_tp = sd + year_diff.year
ed_tp = ed + year_diff.year
@recurring << data.merge({:start => sd_tp, :end => ed_tp})
end
end
end
when "Yearly"
if !(start_date..end_date).cover?(re.start)
sd = re.start
ed = re.end
@i = TimeDifference.between(re.start,end_date).in_years.to_i
@start_date = sd
sd = sd >> 12 * @i*re.frequency.to_i
ed = ed >> 12 * @i*re.frequency.to_i
@recurring << {:id => re.id.to_s, :title=>re.title, :note=>re.note, :start=>sd, :end => ed, :allDay => re.all_day, :recurring => re.recurring, :calendar => re.calendar_type.id.to_s, :color => re.calendar_type.color, :edit_url => Rails.application.routes.url_helpers.edit_admin_calendar_path(:locale=>I18n.locale, :id=>re.id), :delete_url => Rails.application.routes.url_helpers.admin_calendar_path(:locale=>I18n.locale, :id=>re.id)}
end
end
end
end
@recurring