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?