Page 1 of 1

Copying blocks

Posted: Thu Dec 08, 2022 8:53 pm
by jk@datapult.dk

Hi there,

Have a look at this video based on this example:
https://bryntum.com/products/scheduler/examples/dragselection/

Expected behavior would be that I assigned Don and Doug an event each not assign both to Don. How would I make that happen?

This would extend so if I pasted onto Sam, it would be Sam and John, respective, getting an event assigned.

Can someone help uncover the to tweak copy/pasting?

Video: https://www.dropbox.com/s/uidrd0egfw62jn7/Screen%20Recording%202022-12-08%20at%2019.49.59.mov?dl=0

Thanks


Re: Copying blocks

Posted: Fri Dec 09, 2022 11:28 am
by johan.isaksson

Hi,

There is not currently any setting to affect that. You could try implementing a beforePaste listener, and handle it all manually in it. Returning false from the listener will prevent the default behaviour.

https://bryntum.com/products/scheduler/docs/api/Scheduler/feature/EventCopyPaste#event-beforePaste


Re: Copying blocks

Posted: Fri Dec 09, 2022 2:16 pm
by jk@datapult.dk
johan.isaksson wrote: Fri Dec 09, 2022 11:28 am

Hi,

There is not currently any setting to affect that. You could try implementing a beforePaste listener, and handle it all manually in it. Returning false from the listener will prevent the default behaviour.

https://bryntum.com/products/scheduler/docs/api/Scheduler/feature/EventCopyPaste#event-beforePaste

Thanks, Johan. Appreciated. Could you kindly copy these lines into your CrudManager example?

This code should always make sure it is same time of day when copy/pasting.

scheduler.on({
    beforePaste: ({source, eventRecords, resourceRecord, date}) => {
      const events = []
      for (let i = 0; i < eventRecords.length; i++) {
        console.log("new Date", date)
        const event = eventRecords[i].copy()
        const startDate = DateHelper.copyTimeValues(date, event.startDate)
        console.log("originalStartDate", event.startDate)
        console.log("startDate", startDate)
        const endDate = DateHelper.copyTimeValues(date, event.endDate)
        event.setStartEndDate(startDate, endDate)
        event.assign(resourceRecord, true)
        events.push(event)
      }
      source.eventStore.add(events)
      return false
    }
  })

  scheduler.crudManager.on({
    'beforesync': ({pack}) => {
      console.log(pack.events.added[0].startDate)
    },
  });

My console reads this when I copy/paste as shown in this video even though my logic should paste into the same time. https://www.dropbox.com/s/vquh7sud7pddlpe/Screen%20Recording%202022-12-09%20at%2013.14.27.mov?dl=0

>    new Date Mon May 21 2018 11:00:00 GMT+0200 (Central European Summer Time)
>    originalStartDate Mon May 21 2018 09:00:00 GMT+0200 (Central European Summer Time)
>    startDate Mon May 21 2018 09:00:00 GMT+0200 (Central European Summer Time)
>    2018-05-21T11:00:00+02:00

I am two hours off when hooking into that event and using pretty standard Bryntum functions.


Re: Copying blocks

Posted: Mon Dec 12, 2022 5:27 am
by alex.l

Could you please describe what do you want to achieve by the code above?
https://bryntum.com/products/scheduler/docs/api/Core/helper/DateHelper#function-copyTimeValues-static
I see you copied time from event.startDate to date and after that copied time from event.endDate to date.
so startDate and endDate contain same link of date object, where you changed time twice.

Just try to log startDate after last modification to see that

for (let i = 0; i < eventRecords.length; i++) {
                console.log("new Date", date)
                const event = eventRecords[i].copy()
                const startDate = DateHelper.copyTimeValues(date, event.startDate)
                console.log("originalStartDate", event.startDate)
                console.log("startDate", startDate)
                const endDate = DateHelper.copyTimeValues(date, event.endDate)
                console.log("startDate", startDate); // here
                console.log("endDate", endDate); // and here - the same date
                event.setStartEndDate(startDate, endDate);
                event.assign(resourceRecord, true)
                events.push(event)
            }

Re: Copying blocks

Posted: Mon Dec 12, 2022 11:04 am
by jk@datapult.dk

If this is the logic of https://bryntum.com/products/scheduler/docs/api/Core/helper/DateHelper#function-copyTimeValues, I believe the the argument names should be reversed or the documentation expanded.


Re: Copying blocks

Posted: Mon Dec 12, 2022 1:45 pm
by alex.l

Sounds correct to me. source is the source where you take data from. target is a target where you apply data to.