fix some error
This commit is contained in:
parent
3ac2655d72
commit
e7bcef96a7
|
@ -84,12 +84,12 @@ var Calendar = function(dom){
|
||||||
var checked = ($("#all_day_check").is(":checked") ? true : false);
|
var checked = ($("#all_day_check").is(":checked") ? true : false);
|
||||||
var checked_function = function(c){
|
var checked_function = function(c){
|
||||||
if(c){
|
if(c){
|
||||||
for(i in pickers){
|
for(i=0;i<pickers.length;i++){
|
||||||
var input = pickers[i].find("input");
|
var input = pickers[i].find("input");
|
||||||
input.val(input.val().split(" ")[0]);
|
input.val(input.val().split(" ")[0]);
|
||||||
}
|
}
|
||||||
}else{
|
}else{
|
||||||
for(i in pickers){
|
for(i=0;i<pickers.length;i++){
|
||||||
var d = new Date();
|
var d = new Date();
|
||||||
var input = pickers[i].find("input");
|
var input = pickers[i].find("input");
|
||||||
if(input.val())
|
if(input.val())
|
||||||
|
@ -145,9 +145,9 @@ var Calendar = function(dom){
|
||||||
c.calendar.fullCalendar("refetchEvents");
|
c.calendar.fullCalendar("refetchEvents");
|
||||||
});
|
});
|
||||||
c.event_create_space.find("#event_period").change(function(){
|
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){
|
pickers[i].on("changeDate",function(e){
|
||||||
if(checked){
|
if(checked){
|
||||||
var input = $(this).find("input");
|
var input = $(this).find("input");
|
||||||
|
@ -155,7 +155,7 @@ var Calendar = function(dom){
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
repeat_function();
|
//repeat_function();
|
||||||
if(allDay)
|
if(allDay)
|
||||||
checked_function(checked);
|
checked_function(checked);
|
||||||
}
|
}
|
||||||
|
@ -353,7 +353,7 @@ var EventDialog = function(calendar,event){
|
||||||
var start_time = "",
|
var start_time = "",
|
||||||
end_time = "",
|
end_time = "",
|
||||||
time_string = null;
|
time_string = null;
|
||||||
|
Event_e = _event
|
||||||
if(_event.allDay) {
|
if(_event.allDay) {
|
||||||
start_time = $.fullCalendar.formatDate(_event._start,"MMM dd, yyyy");
|
start_time = $.fullCalendar.formatDate(_event._start,"MMM dd, yyyy");
|
||||||
if(_event._end)
|
if(_event._end)
|
||||||
|
@ -411,7 +411,6 @@ var EventDialog = function(calendar,event){
|
||||||
var x = pos.x,
|
var x = pos.x,
|
||||||
y = pos.y,
|
y = pos.y,
|
||||||
winheight = $(window).height();
|
winheight = $(window).height();
|
||||||
console.log(event_quick_view.width())
|
|
||||||
if((x + event_quick_view.width()) > $(window).width()){
|
if((x + event_quick_view.width()) > $(window).width()){
|
||||||
x = x - event_quick_view.width();
|
x = x - event_quick_view.width();
|
||||||
}
|
}
|
||||||
|
|
|
@ -919,7 +919,6 @@ function EventManager(options, _sources) {
|
||||||
_fetchEventSource(source, function(events) {
|
_fetchEventSource(source, function(events) {
|
||||||
if (fetchID == currentFetchID) {
|
if (fetchID == currentFetchID) {
|
||||||
if (events) {
|
if (events) {
|
||||||
|
|
||||||
if (options.eventDataTransform) {
|
if (options.eventDataTransform) {
|
||||||
events = $.map(events, 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._start = cloneDate(event.start = parseDate(event.start, ignoreTimezone));
|
||||||
event.end = parseDate(event.end, ignoreTimezone);
|
event.end = parseDate(event.end, ignoreTimezone);
|
||||||
if (event.end && event.end <= event.start) {
|
if (event.end && event.end < event.start) {
|
||||||
event.end = null;
|
event.end = event.start;
|
||||||
}
|
}
|
||||||
event._end = event.end ? cloneDate(event.end) : null;
|
event._end = event.end ? cloneDate(event.end) : null;
|
||||||
if (event.allDay === undefined) {
|
if (event.allDay === undefined) {
|
||||||
|
|
|
@ -136,7 +136,7 @@ class Admin::CalendarsController < OrbitAdminController
|
||||||
if !bulletin.nil?
|
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])
|
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
|
end
|
||||||
if @event.update_attributes(p)
|
if @event.update_attributes!(p)
|
||||||
e = @event.to_json
|
e = @event.to_json
|
||||||
e = JSON.parse(e)
|
e = JSON.parse(e)
|
||||||
e["can_edit"] = true
|
e["can_edit"] = true
|
||||||
|
|
|
@ -38,9 +38,9 @@ class CalendarsController < ApplicationController
|
||||||
if params[:start].present? && params[:end].present?
|
if params[:start].present? && params[:end].present?
|
||||||
sdt = Time.at(params[:start].to_i)
|
sdt = Time.at(params[:start].to_i)
|
||||||
edt = Time.at(params[:end].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
|
end
|
||||||
respond_to do |format|
|
respond_to do |format|
|
||||||
format.html # index.html.erb
|
format.html # index.html.erb
|
||||||
format.json { render json: events.to_json }
|
format.json { render json: events.to_json }
|
||||||
|
|
|
@ -46,8 +46,8 @@ class Event
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
########################################
|
########################################
|
||||||
validates_presence_of :title, :message => "Please fill the title of the Event", :unless => lambda { self.title_translations.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", :unless => lambda { self.title.blank? }
|
validates_presence_of :title_translations, :message => "Please fill the title of the Event", :if => lambda { self['title'].blank? }
|
||||||
def title
|
def title
|
||||||
tp = self['title_translations'][I18n.locale]
|
tp = self['title_translations'][I18n.locale]
|
||||||
tp.blank? ? self['title'] : tp
|
tp.blank? ? self['title'] : tp
|
||||||
|
@ -112,57 +112,68 @@ class Event
|
||||||
def self.monthly_event(start_date,end_date)
|
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)
|
self.any_of(:start.gte => start_date, :end.gte => start_date).and(:start.lte => end_date).asc(:start)
|
||||||
end
|
end
|
||||||
|
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)
|
def self.recurring_event(start_date,end_date)
|
||||||
@recurring_events = self.where(:recurring => true)
|
@recurring_events = self.where(:recurring => true)
|
||||||
@recurring = []
|
@recurring = []
|
||||||
@recurring_events.each do |re|
|
@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'
|
when 'Daily'
|
||||||
if (start_date..end_date).cover?(re.start)
|
days = (end_date.to_date-re.start.to_date)
|
||||||
@i = TimeDifference.between(re.start,end_date).in_days.to_i
|
freq = re.frequency.to_i
|
||||||
(1..@i).each do |i|
|
(1..days).each do |i|
|
||||||
|
if i%freq==0
|
||||||
@start_date = re.start + i
|
@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
|
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
|
end
|
||||||
when "Weekly"
|
when "Weekly"
|
||||||
@start_date = re.start
|
@start_date = re.start
|
||||||
@end_date = re.end
|
@end_date = re.end
|
||||||
@i = TimeDifference.between(re.start,end_date).in_weeks.to_i
|
@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)
|
@start_date += (7*re.frequency.to_i)
|
||||||
@end_date += (7*re.frequency.to_i)
|
@end_date += (7*re.frequency.to_i)
|
||||||
|
@recurring << data.merge({:start => @start_date, :end => @end_date})
|
||||||
@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)}
|
|
||||||
end
|
end
|
||||||
when "Monthly"
|
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)
|
if !(start_date..end_date).cover?(re.start)
|
||||||
sd = re.start
|
sd = re.start
|
||||||
ed = re.end
|
ed = re.end
|
||||||
@i = TimeDifference.between(re.start,end_date).in_months.to_i
|
start_datetime = start_date.to_datetime
|
||||||
@start_date = sd
|
end_datetime = end_date.to_datetime
|
||||||
sd = sd >> @i*re.frequency.to_i
|
if start_datetime>sd
|
||||||
ed = ed >> @i*re.frequency.to_i
|
((start_datetime.year-sd.year)..(end_datetime.year-sd.year)).each do |year_diff|
|
||||||
@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)}
|
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
|
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
|
||||||
end
|
end
|
||||||
|
|
||||||
@recurring
|
@recurring
|
||||||
|
|
Loading…
Reference in New Issue