我想让用户自由地将事件放到allDay到hasTime day或从hasTime day到allDay。
我有这个eventDrop的代码块。
eventDrop: function (event, delta, revertFunc, jsEvent, ui, view, dayDelta, minuteDelta, calEvent, allDay, start, end) {
var cCheck = event.start.toJSON().slice(0,10);
var cToday = new Date().toJSON().slice(0,10);
if(cCheck < cToday){
revertFunc();
alert("You are FORBIDED to drop an event on past dates");
}
else{
if (!confirm("Are you sure you want to move " + event.title + " to this date "+JSON.stringify(event.start)+" ?")) {
revertFunc();
//self.$el.fullCalendar("refetchEvents");
console.log(event);
} else {
var deltaId = event.id;
var deltaStart = event.start;
var deltaEnd = event.end;
var dropDelta = JSON.parse(localStorage["events"]);
for (var i = 0; i < dropDelta.length; i++) {
if(dropDelta[i].id == deltaId){
alert(JSON.stringify(dropDelta[i].id)+"<<<>>>"+deltaId);
alert(JSON.stringify(dropDelta[i].start)+"<<<>>>"+deltaStart);
alert(JSON.stringify(dropDelta[i].end)+"<<<>>>"+deltaEnd);
dropDelta[i].start = deltaStart;
// This is where complicated begins
if(dropDelta[i].allDay == true){
if(deltaEnd == null){
dropDelta[i].allDay == false;
}
else{
dropDelta[i].end = deltaEnd;
}
}
else{
if(deltaEnd == null){
//something happen
}
else{
//something happen
}
}
break;
}
}
localStorage.setItem('events', JSON.stringify(dropDelta));
alert("Successful");
}
}
},
我在if语句上遇到麻烦。我不确定如何使它成为逻辑。我想的越多,我就越困惑。@ _ @
这是我创建的新事件代码。也许这会帮助你们更多地了解我的问题。
select: function (start, end, allDay, event ) {
var cCheck = start._d.toJSON().slice(0,10);
var cToday = new Date().toJSON().slice(0,10);
if(cCheck < cToday){
alert("You are FORBIDED to create event on past dates");
}
else{
var title = prompt('Event Title:');
var index=localStorage.getItem("MaxIndex");
var eventData = [];
if (title) {
eventData = {
id: 'ef'+index++,
title: title,
start: start,
end: end,
//allDay: true,
}
alert(eventData);
self.$el.fullCalendar('renderEvent', eventData, true);
events.push(eventData);
alert(eventData);
localStorage.setItem('MaxIndex', index);
localStorage.setItem('events', JSON.stringify(events));
self.$el.fullCalendar('removeEventSource', eventData );
self.$el.fullCalendar('addEventSource', eventData );
console.log(eventData);
}
}
self.$el.fullCalendar('unselect');
},
附加说明:
我使用if(deltaEnd == null)
是因为每次我将事件从allDay丢弃到非allDay,结束日期变为null。忘了提,我正在使用fullCalendar。