This commit is contained in:
BoHung Chiu 2022-08-03 19:24:53 +08:00
parent ba79afadd0
commit 51eba82b2a
3 changed files with 80 additions and 15 deletions

View File

@ -196,6 +196,15 @@ var Calendar = function(dom){
var agendaView = new AgendaView(c);
var loadeventsonviewchange = false;
this.success_event = null;
this.eventDataTransform = function(eventData){
if(eventData.allDay && eventData.end){
var tmp = new Date(eventData.end);
tmp.setTime(tmp.getTime() + 86400000); // Add one day for displaying
eventData.end = tmp.toISOString();
//eventData.end = eventData.end;
}
return eventData;
};
this.initialize = function(){
var date = new Date();
var d = date.getDate();
@ -316,14 +325,17 @@ var Calendar = function(dom){
})
$('form[data-remote]').bind("ajax:success",function(evt, data, status){
c.event_create_space.html("").hide();
if(type == "new")
data = c.eventDataTransform(data);
if(type == "new"){
c.renderEvent(data);
if(type == "edit")
c.calendar_dom.fullCalendar("refetchEvents");
}
if(type == "edit"){
c.updateEvent(data);
}
});
c.event_create_space.find("#event_period").change(function(){
// c.event_create_space.find("#event_period").change(function(){
//repeat_function();
})
// })
//repeat_function();
}
c.success_event = success_event;
@ -357,6 +369,7 @@ var Calendar = function(dom){
}
});
},
eventDataTransform: c.eventDataTransform,
// events: 'https://fullcalendar.io/demo-events.json',
headerToolbar: false,
fixedWeekCount: false,
@ -536,13 +549,24 @@ var Calendar = function(dom){
this.updateEvent = function(eventStick){
c.calendar_dom.fullCalendar("updateEvent",eventStick);
}
this.getEventsById = function(id){
var org_events = c.calendar_dom.calendar.getEvents();
return org_events.filter(function(event){
return event.id == id;
})
}
this.cleanEvents = function(id){
var events = this.getEventsById(id);
events.forEach(function(event){
event.remove();
});
}
this.deleteEvent = function(delete_url,_id){
$.ajax({
type : "delete",
url : delete_url,
success : function(){
c.calendar_dom.fullCalendar("removeEvents",[_id]);
c.cleanEvents(_id);
c.dialog.dismiss();
}
})
@ -558,14 +582,34 @@ var Calendar = function(dom){
}
})
}
this.get_single_event = function(id, callback){
var activeRange = c.calendar_dom.calendar.currentData.dateProfile.activeRange;
var start = activeRange.start,
end = activeRange.end;
$.get("/admin/calendars/get_single_event", {
start: Math.round(start.getTime() / 1000),
end: Math.round(end.getTime() / 1000),
id: id
}).done(function(data){
$.each(data, function(i, event){
callback.call(id, event);
})
})
}
this.renderEvent = function(eventStick){
if(eventStick.recurring === true)
c.calendar_dom.calendar.refetchEvents();
else
if(eventStick.recurring === true){
this.get_single_event(eventStick.id, function(eventData){
eventData = c.eventDataTransform(eventData);
c.calendar_dom.calendar.addEvent(eventData);
});
}else{
c.calendar_dom.calendar.addEvent(eventStick);
}
};
this.updateEvent = function(eventStick){
this.cleanEvents(eventStick.id);
this.renderEvent(eventStick);
};
$(document).ready(function() {
c.initialize();
@ -581,7 +625,14 @@ var EventDialog = function(calendar,event){
if(!_event) throw new UserException("EventStick can't be null!");
_event.allDay = _event.event.allDay;
_event._start = _event.event.start;
_event._end = (_event.event.end ? _event.event.end : _event.event.start);
if(_event.event.end){
_event._end = _event.event.end;
if(_event.allDay){
_event._end.setTime(_event._end.getTime() - 86400000);
}
}else{
_event._end = _event.event.start;
}
// var start_date = getDateString(_event._start,calendar_variable.date_format);
// var end_date = getDateString(_event._end,calendar_variable.date_format);
_event.title = _event.event.title;
@ -653,7 +704,7 @@ var EventDialog = function(calendar,event){
}
event_quick_view.html(template).appendTo("body").show();
event_quick_view.find(".event-close-btn").one("click",function(){_t.dismiss();});
event_quick_view.find("a.delete").one("click",function(){calendar.deleteEvent(_this_event.delete_url,_this_event._id);return false;});
event_quick_view.find("a.delete").one("click",function(){calendar.deleteEvent(_this_event.delete_url, _this_event.event.id);return false;});
event_quick_view.find("a.edit").one("click",function(){calendar.editEvent(_this_event.edit_url,_this_event.allDay);return false;});
event_quick_view.find("a.hide_event").off("click").on("click", function(){
var _this = $(this);

View File

@ -34,7 +34,20 @@ class Admin::CalendarsController < OrbitAdminController
end
end
end
def get_single_event
@events = []
if params[:start].present? && params[:end].present?
sdt = Time.at(params[:start].to_i)
edt = Time.at(params[:end].to_i)
allevents = Event.where(:id=>params[:id]).agenda_events(sdt,edt, params[:display_hide] == 'true')
allevents.each do |e|
event_json = e.as_json
event_json["can_edit"] = can_edit_or_delete_event?(e)
@events << event_json
end
end
render :json => @events.to_json
end
# GET /events/1
# GET /events/1.json
def show

View File

@ -58,6 +58,7 @@ Rails.application.routes.draw do
get 'calendar_setting'
post 'update_calendar_setting'
patch 'update_calendar_setting'
get 'get_single_event'
end
end
resources :calendar_types