I have purposed the daypilot scheduler to be able to create shifts for labour. However, I am unable to implement a mutli-copy solution into my instance.
I have initiated an empty array called multiclipboard, that uses the onEventClickhandling to add multiple events as I select them to the multiclipboard array no biggie.
eventClickHandling: 'Enabled',
onEventClick: async (args) => {
if (args.ctrl) {
args.control.multiselect.add(args.e);
console.log("args----------", args.e.data);
multiclipboard.push(args.e.data);
console.log("multiclipboard", multiclipboard);
}
else {
// const selected = [args.e.data];
// console.log(selected)
return;
}
},
Now, when I want to paste the new events on to a new resource or possibly replicate them on the same resource, Im getting a bit of mixed outputs. Am able to paste the first record okay, but the other records are picking the start date as the same for the first record, stacking them starting from the same date. Is it possible that I set new dates banking on number of days between dates (start and end) and some sort of tracking to know which event am dealing with? here’s my paste code so far under context menu selection handling.
{
text: "Paste Multiple",
onClick: (args) => {
if (!multiclipboard) {
alert("Nothing to paste, use Copy first");
return;
}
var totals = 0;
var elapsed = false;
const dp = args.source.calendar;
multiclipboard.map((item) => {
console.log("item", item);
var duration = new Date(item.end).getTime() - new Date(item.start).getTime();
duration = duration / (3600 * 24000);
function addDays(date, days) {
var result = new Date(date);
result.setDate(result.getDate() + days);
return result;
}
console.log("duration", duration);
const newEvent = {
start: elapsed? addDays(args.source.start, duration): args.source.start,
end: elapsed? addDays(args.source.start, totals) : addDays(args.source.start, duration),
id: DayPilot.guid(),
barColor: item.barColor,
resource: args.source.resource,
shift: item.text,
month: item.month,
text: item.text,
hours: item.hours,
days: item.days,
};
totals = totals + duration;
elapsed = true;
console.log("newEvent", newEvent);
dp.events.add(newEvent);
redisSync(newEvent);
})
}
}