Scheduler: Erratic behaviour on creating an event

2 posts, 0 answers
  1. Paul
    Paul avatar
    24 posts
    Member since:
    Aug 2013

    Posted 05 Aug 2014 Link to this post

    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.

  2. Paul
    Paul avatar
    24 posts
    Member since:
    Aug 2013

    Posted 05 Aug 2014 in reply to Paul Link to this post

    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.
Back to Top