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

Scheduler: Erratic behaviour on creating an event

1 Answer 82 Views
Scheduler
This is a migrated thread and some comments may be shown as answers.
Paul
Top achievements
Rank 1
Paul asked on 05 Aug 2014, 12:32 PM
Hi there,

I'm using data binding on the kendo scheduler to call out to our server for reading/creating/updating/destroying events. The only transport url have currently implemented is read, the others just return 404, although I have given paths for them in the scheduler.

I'm currently trying to implement the create event functionality but I'm finding the behaviour of the scheduler erratic.

* When I double click a time-slot to create a new event and just press 'save' without modifying any fields the event is added to the scheduler with no corresponding API call.

* After that, if click again to add a new event (different time slot) and then change the title and press 'save', it calls my 'update' API call (which fails with a 404).

* Lastly, repeating the same thing again (same time slot) results in the scheduler calling my 'create' API call, which is what I would have expected it to do in every case.

Here is the js I'm using to configure the scheduler:

$("#scheduler").kendoScheduler({
             
            date:  new Date("2014-07-17"),
             
            dataSource: {
                batch: true, // Enable batch updates
                transport: {
                    read:
                    {
                        url: "/appointments/get",
                        dataType: "json",
                        type: "POST",
                        contentType: "application/x-www-form-urlencoded",
                    },
                    create:
                    {
                        url: "/appointments/create",
                        dataType: "json",
                        type: "POST",
                        contentType: "application/x-www-form-urlencoded",
                    },
                    update:
                    {
                        url: "/appointments/uodate",
                        dataType: "json",
                        type: "POST",
                        contentType: "application/x-www-form-urlencoded",
                    },
                    destroy:
                    {
                        url: "/appointments/create",
                        dataType: "json",
                        type: "POST",
                        contentType: "application/x-www-form-urlencoded",
                    },
            
                    parameterMap: function (options, operation)
                    {
                        if (operation === "read")
                        {
                            // make sure we send the start and end date to the server in unix time, and urlencode them
                            var scheduler = $("#scheduler").data("kendoScheduler");
 
                            var startDate = DateToUnixTime(scheduler.view().startDate());
                            var endDate = DateToUnixTime(scheduler.view().endDate());
 
                            // if start and end are the same, bump end by 24 hours
                            if (endDate === startDate)
                            {
                                endDate += gPageConstants.kSecondsIn24h;
                            }
 
                            var result = {start_time:startDate, end_time:endDate};
                            return $.param(result);
                        }
                        else if (operation === "create")
                        {
                            console.log(options);
                        }
                        else
                        {
                            return $.param(options);
                        }
                    }
                },
                schema: {
                    model: {
                        id: "uid", // The "id" of the event is the "taskId" field
                        fields: {
                            // Describe the scheduler event fields and map them to the fields returned by the remote service
                            taskId: {
                                from: "uid", // The 'TaskID' server-side field is mapped to the 'taskId' client-side field
                                type: "number"
                            },
                     
                            start: { type: "date", from: "start" },
                            end: { type: "date", from: "end" },
 
                            title: { from: "notes", defaultValue: "No title", validation: { required: true } },
                            description: { from: "Description", defaultValue: "No description" },
                            recurrenceId: { from: "RecurrenceID", defaultValue: null },
                            recurrenceRule: { from: "RecurrenceRule", defaultValue: null },
                            recurrenceException: { from: "RecurrenceException", defaultValue: null },
                            isAllDay: { type: "boolean", from: "IsAllDay", defaultValue: false }
                        }
                    }
                }
            }
        });

I'd appreciate some advice! :)

Cheers, Paul.

1 Answer, 1 is accepted

Sort by
0
Paul
Top achievements
Rank 1
answered on 05 Aug 2014, 04:12 PM
Figured it out - I had misunderstood what the schema->model->id field actually was. It should have been 'taskId' not a reference to the name of the identifier in my dataset.
Tags
Scheduler
Asked by
Paul
Top achievements
Rank 1
Answers by
Paul
Top achievements
Rank 1
Share this question
or