我需要在同一天检测其他事件。我希望能够做到的是,如果eventClass X的事件与eventClass Y的被删除事件同一天存在,则会发现。如果不是,它会警告用户,eventClass X不存在,否则允许用户放弃这个活动。
这可能吗?
答案 0 :(得分:4)
经过对文档的探讨和一些小实验,我使用clientEvents方法找到了解决方案:
eventDrop: function( event, dayDelta, minuteDelta, allDay,
revertFunc, jsEvent, ui, view )
{
// see if its a concept class event
if (event.className == 'conceptclass'){
// create a new date object from the start of the event
var eventDate = new Date(event.start);
// zero its time
eventDate.setHours(0);
eventDate.setMinutes(0);
eventDate.setSeconds(0);
eventDate.setMilliseconds(0);
// now find all the events currently displayed in the calendar
var pulledEvents = $('#calendar').fullCalendar( 'clientEvents');
var meetingDay = false; // until a meeting is found
for(var i = 0; i < pulledEvents.length; i++){
// if the pulled event is of the meeting class
if(pulledEvents[i].className == 'meetingclass'){
// create a new date object from the start of the pulled event
var testEventDate = new Date(pulledEvents[i].start);
// zero its time for comparison
testEventDate.setHours(0);
testEventDate.setMinutes(0);
testEventDate.setSeconds(0);
testEventDate.setMilliseconds(0);
// if meeting event found in the day
// OK a little wierdness here, even though the dates were equal
// they would not return a valid comparison. So I get the time value.
if(testEventDate.getTime() == eventDate.getTime()){
meetingDay = true;
break;
}
}
}
if(!meetingDay){
alert("Tried to drop a Concept into Day without Scheduled Review Meeting!");
revertFunc(); // back to where it came!
}
}
答案 1 :(得分:1)
另一种选择是解决这个服务器端,因为你也应该检查它是否有效。
当“概念”事件被拖到当天时,将Ajax请求发送到服务器以更新“概念”事件的日期,如果它无效,请调用revertFunc()
以重新放置事件。
eventDrop: function(event, dayDelta, minuteDelta, allDay,
revertFunc, jsEvent, ui, view) {
$.post("/concep_update/", { id: event.id, delta: dayDelta },
function(data) {
if(data!="true") {
revertFunc();
}
}, "text"});
}
在服务器上,检查同一天是否有“会议”事件,如果是,请更新“concept”事件并返回“true”,否则返回“false”。
@require_POST @login_required
def concept_update(request):
concept = get_object_or_404(Concept.objects.all(),
id=int(request.POST.get("id","0")))
concept.date = concept.date + timedelta(days=int(request.POST.get("delta","0")))
meetings = Meeting.objects.filter(date=concept.date)
if meetings.count() > 0:
concept.save()
return HttpResponse("true", status=200, content_type="text/plain")
else:
return HttpResponse("false", status=200, content_type="text/plain")
答案 2 :(得分:0)
var e1start = new Date(startDate);
var e1end = endDate == null ? e1start : new Date(endDate);
for (var d = e1start; d <= e1end; d.setDate(d.getDate() + 1)) {
var eventsInDay = getEventsInDay(d);
// ...
}
function getEventsInDay(date){
return $('#fr-calendar').fullCalendar('clientEvents', function(event){
if(date >= event.start && date <= event.end){
return true;
}
});
}