Premium support for our pure JavaScript UI components


Post by jandresampaio »

Hi,

After migrating from 4.0.8 to 4.2.* versions we've noticed that drag to create is not working as expected. While dragging the cursor the event store is notified that a record is created even before the "beforeDragCreateFinalize" is called.
Also, it seems that context.finalize(false) doesn't make any difference, as you can check in the video attached.

Can you point us to the basis for this new behavior?
In our case, which was working before, the drag to create is used to call our "event create popup" (not Bryntum's) and after filling additional info and finalizing the context we would expect the eventStore to be notified about the "add" action

Thanks

Attachments
app.module (2).js
Code to reproduce
(1.72 KiB) Downloaded 64 times
Bryntum Scheduler - Fill ticks demo (1).mp4
(1.99 MiB) Downloaded 79 times

Post by alex.l »

Hi jandresampaio,

While dragging the cursor the event store is notified that a record is created even before the "beforeDragCreateFinalize" is called.

Yes, now an event is added to store when you started dragCreate. This has been changed by some reasons and one of them is to maintain dragcreate on infinite scroll.
Try to use another events, like https://bryntum.com/docs/scheduler/#Scheduler/feature/EventEdit#event-afterEventSave

Also, it seems that context.finalize(false) doesn't make any difference, as you can check in the video attached.

Nope, you forgot to set async flag, see docs: https://bryntum.com/docs/scheduler/#Scheduler/feature/EventDragCreate#event-beforeDragCreateFinalize

Fires on the owning Scheduler to allow implementer to prevent immediate finalization by setting data.context.async = true in the listener, to show a confirmation popup etc.

This code works:

    listeners: {
       beforeDragCreateFinalize: function(e){
            e.context.async = true;
            e.context.finalize(false);
            console.log("beforeDragCreateFinalize:", e)
       },

All the best,
Alex


Post by Animal »

We did not make it clear that this applied to drag create. Sorry about that.

https://www.bryntum.com/products/scheduler/changelog/#release-4.2.0

The EventResize feature now uses the task's data to change the appearance by updating endDate or startDate live but in batched mode so that the changes are not available for server sync until the operation is finished (Fixed #2541)

The DragCreate feature now extends EventResize

The drag create feature now adds a "provisional" new record on mousedown. It then resizes it by actually changing the start or end date (depending on which side of the mousedown point you are dragging).

This means that the normal event rendering process is run and the scheduler layout is always correct.

When beforeDragCreateFinalize is called, the event will already be in the store.

In the handler, if you set the context to be async, then it will not call finalize, it is up to you to call finalize when you need to:

beforeDragCreateFinalize({ context }) {
    // context.finalize will not not now be called by the system. We must call that when we need to.
    context.async = true;
})

Then calling context.finalize(false) should remove the record from the store.


Post by jandresampaio »

Hi,

Note: we're not using Crud Manager and we use listeners on the stores (add, remove, update) and then save them on the server.

I understand that a provisional record is created, then updated, and might me removed in case of finalizing with false.

But this whole process creates a problem for us because we need to save the assignments on our API and it gets very tricky to track that if the store is notified multiple times for a single action.

Can you guide us on this?


Post by mats »

We added a new flag to indicate if a record is being created: https://bryntum.com/docs/scheduler/#Core/data/Model#property-isCreating

You should be able to leverage this to know the state of the model, please let us know if this resolves your issue.


Post by jandresampaio »

Hi,

isCreating seems to work. Thanks. We found previous approach more intuitive to understand, as the record would not be created until the drag finalized. As it is, this is more like a workaround for us.
Maybe our approach of listening to store events to save them on the server is not the best one....any advice on this?

Thanks


Post by alex.l »

This is one of the ways how to do that if you have to use your own services to save/load data.

Generally we suggest to use CrudManager to do that, provide required URLs and enable autoSync option (https://bryntum.com/docs/scheduler/#Scheduler/crud/AbstractCrudManagerMixin#config-autoSync ), in this case all the magic will be done automatically. Read more here https://bryntum.com/docs/scheduler/#Scheduler/guides/data/crud_manager.md

If you want to use your own services to load data, you also can do that using CrudManger and customize it implemented your own https://bryntum.com/docs/scheduler/#Scheduler/crud/transport/AjaxTransport (read the guide I've linked above for more details).

Some info may be found here: viewtopic.php?f=44&t=18809
And in react + redux demo.

All the best,
Alex


Post by jandresampaio »

Thanks.


Post Reply