This is a migrated thread and some comments may be shown as answers.

Cancelling changes twice in a row causes events to disappear

3 Answers 95 Views
Scheduler
This is a migrated thread and some comments may be shown as answers.
Tom
Top achievements
Rank 1
Iron
Tom asked on 08 Sep 2017, 12:29 PM

I have implemented some server-side validation to prevent overlaps from occurring, but if an event fails twice in a row, it disappears entirely from the scheduler.

My scheduler is as follows:

@(Html.Kendo().Scheduler<MyEventViewModel>()
            .Name("Scheduler")
            .Date(DateTime.Today)
            .StartTime(DateTime.Today.AddHours(8))
            .Height(500)
            .Views(v => {
                v.DayView();
                v.WeekView();
                v.CustomView("TwoWeekView");
            })
            .Group(g =>
            {
                g.Resources("Labour");
                g.Date(true);
            })
            .Resources(resources => resources
                .Add(m=>m.LabourId)
                .Name("Labour")
                .Title("Labour")
                .DataValueField("Id")
                .DataTextField("FullName")
                .DataSource(dataSource => dataSource
                    .Read(read => read
                        .Action("LabourResourcesList", "Scheduler")
                        .Type(HttpVerbs.Post)
                        .Data("LabourResourceSelection")
                    )
                    .Events(e=>e.Change("RefreshSchedulerView"))
                )
            )
            .DataSource(dataSource => dataSource
                .Read(read => read
                    .Action("ScheduledEvents", "Scheduler")
                    .Type(HttpVerbs.Post)
                    .Data("LabourResourceSelection")
                )
                .Update("UpdateSchedule","Scheduler")
                .Model(m =>
                {
                    m.Field(f => f.Id);
                    m.Field(f => f.LabourId);
                    m.Field(f => f.Start);
                    m.Field(f => f.End);
                    m.Field(f => f.Description);
                    m.Field(f => f.JobCode);
                    m.Field(f => f.Title);
                })
                .Custom()
                .Type("aspnetmvc-ajax")
                .Schema(schema =>
                    schema.Model(model =>
                    {
                        model.Id(f => f.Id);
                        model.Field(f => f.LabourId);
                        model.Field("title", typeof(string)).From("Description");
                        model.Field("start", typeof(DateTime)).From("Start");
                        model.Field("end", typeof(DateTime)).From("End");
                        model.Field("description", typeof(string)).From("Description");
                        model.Field("LabourId", typeof(int)).From("LabourId");
                    })
                )
                .Events(e => e.RequestEnd("ValidationChecker"))
            )
            .AllDaySlot(false)
            .AutoBind(false)
        )

So as you can see I am grouping by "Labour",and each event has a corresponding "LabourId".

Updates are sent to the UpdateSchedule action in the SchedulerController, and I have added some server-side validation there to prevent each Labour resource having overlapping events. If all is well I return a null, and the scheduler does what it wants, if there is an overlap I return a JSON with some data to explain that the change is not possible. In the scheduler datasource you can see on the RequestEnd event I call a function "ValidationChecker", which checks the response data, and when the UpdateSchedule action indicates the change cannot be made, I do the following:

var scheduler = $("#Scheduler").data("kendoScheduler");
        scheduler.dataSource.cancelChanges();
        e.preventDefault();

This works, but it only works once consecutively. If I overlap two events, the change is rejected by the validation, and the event that was moved is snapped back to its original place. I can move it around some more and try again, and it will fail again. If two updates fail in a row, the event disappears entirely. I am not sure what is happening here.

Is there a correct way to cancel an update?

...also is there a way to specify a title for a custom view in the MVC scheduler?

3 Answers, 1 is accepted

Sort by
0
Plamen
Telerik team
answered on 12 Sep 2017, 10:16 AM
Hi,

In such scenarios we recommend referring to this online demo where a similar case is implemented correctly.

As for the question about the  title for a custom view - you can refer to this article where a similar issue is implemented in a sample.

Regards,
Plamen
Progress Telerik
Try our brand new, jQuery-free Angular 2 components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
0
Tom
Top achievements
Rank 1
Iron
answered on 12 Sep 2017, 10:58 AM

Sorry, but that demo does not contain a correct implementation of what I am trying to achieve here. The demo implements client-side filtering, not server-side validation.

The key differences here are that in the online demo, these events are called before the event is ever sent to the server. Take a look at the events demo: http://demos.telerik.com/aspnet-mvc/scheduler/events

...so I am catching the RequestEnd event of the dataSource, rather than the DragEnd or MoveEnd events of the scheduler. The issue that follows is that after the drag or resize events have ended, the dataSource of the scheduler must contain the change to send with the sync. Naturally if the server rejects the change, I don't want the dataSource to retain it; if I do not cancelChanges then the dataSource will simply try again whenever the sync method is called. ...so I cancel the changes when it is appropriate, and the dataSource behaves as expected. The scheduler however, seems to lose track of the event after two consecutive cancels.

So again: Is there a correct way to cancel a change?

With regards to the custom view title, thanks, this was the little bit that I couldn't find documented:

.Views(v => { CustomView("MyCustomView", view => view.Title("Custom View Title")); })
0
Plamen
Telerik team
answered on 14 Sep 2017, 06:21 AM
Hi,

Unfortunately we don't have such ready solution with Kendo Scheduler - that is why in such case we will need a sample runnable project so that we could inspect it and be more helpful with a possible solution. 

Regards,
Plamen
Progress Telerik
Try our brand new, jQuery-free Angular 2 components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
Tags
Scheduler
Asked by
Tom
Top achievements
Rank 1
Iron
Answers by
Plamen
Telerik team
Tom
Top achievements
Rank 1
Iron
Share this question
or