Create, Update, Detsroy transport methods

15 posts, 0 answers
  1. James Hood
    James Hood avatar
    27 posts
    Member since:
    Jun 2012

    Posted 12 Aug 2013 Link to this post

    I am converting an existing calendar system, to this much more robust method.

    The problem I am having right now actually comes from the slightly different ways things work, in the other calendar I was using, when you wanted to delete something, I could get the ID, send that to the controllers, then to the stored procedures in SQL Server to delete that specific item. I would very much prefer to continue this line of coding.,

    So as part of the demo:

    transport: {
      read: {
        dataType: "jsonp"
      },
      update: {
        dataType: "jsonp"
      },
      create: {
        dataType: "jsonp"
      },
      destroy: {
        dataType: "jsonp"
      },
      parameterMap: function(options, operation) {
        if (operation !== "read" && options.models) {
          return {models: kendo.stringify(options.models)};
        }
    So, I either need to get the ID of the event, that has been selected for deletion, and then pass that value to the DB... or?

    I havent actually used a lot of the datasources for this kind of thing just yet, typically we'd actually just use the datasource to display data, then get the ID out of the data source, and do something with that (delete, edit, etc)

    So, little help?
  2. James Hood
    James Hood avatar
    27 posts
    Member since:
    Jun 2012

    Posted 12 Aug 2013 Link to this post

    that was my mistake, I'm not using CRUD (that should have been a duh..)

    im using WebAPI Controllers, so is there a dataitem that I can reference from the event items?
  3. Atanas Korchev
    Admin
    Atanas Korchev avatar
    8462 posts

    Posted 13 Aug 2013 Link to this post

    Hi James,

     The parameterMap function is responsible for sending data to the server-side. The updated events are available in the options.models field (if batch mode is enabled). If batch mode is disabled all event fields are available as fields of the "options" parameter.

     Here is how you can pass the id:

    parameterMap: function(options) {
        return {
              eventId: options.models[0].id
        };
    }

    If you want to send it as JSON:
    parameterMap: function(options) {
        return kendo.stringify({
              eventId: options.models[0].id
        });
    }


    Regards,
    Atanas Korchev
    Telerik
    Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
  4. James Hood
    James Hood avatar
    27 posts
    Member since:
    Jun 2012

    Posted 13 Aug 2013 Link to this post

    I'm giving it a try now, as I said in my ticket i betting I was doing something fairly unexpected (by the control)
  5. James Hood
    James Hood avatar
    27 posts
    Member since:
    Jun 2012

    Posted 13 Aug 2013 Link to this post

    Well my new set up for the scheduler looks like this

    $("#calendar").kendoScheduler({
               batch: true,
               height: 600,
               views: [
               "day",
                   "week",
                   { type: "month", selected: true },
                   "agenda"
               ],
               dataSource: {
                   transport: {
                       read: {
                           url: BaseAPI + "/NewFullCalendar",
                           dataType: "json"
                       },
                       update: {
                           url: "http://demos.kendoui.com/service/tasks/update",
                           dataType: "jsonp"
                       },
                       create: {
                           url: "http://demos.kendoui.com/service/tasks/create",
                           dataType: "jsonp"
                       },
                       destroy: {
                           url: BaseAPI + "/Calendar",
                           datatype: "json",
                       },
                       parameterMap: function (options, operation) {
                           switch (operation) {
                               case "read":
                                   return { location: locationID };
                                   break;
                               case "update":
                                   return
                                   break;
                               case "create":
                                   return
                                   break;
                               case "destroy":
                                   return kendo.stringify({ location: locationID, ID: options.models[0].id });
                                   break;
                           }
     
                       }
                   },
                   schema: {
                       model: {
                           id: "id",
                           fields: {
                               ID: { from: "ID", type: "number" },
                               title: { from: "title", defaultValue: "No title", validation: { required: true } },
                               start: { type: "date", from: "start" },
                               end: { type: "date", from: "end" },
                               description: { from: "Content" },
                               recurrenceId: { from: "recurrenceID" },
                               recurrenceRule: { from: "recurrenceRule" },
                               recurrenceException: { from: "recurrenceException" },
                               isAllDay: { type: "boolean", from: "IsAllDay" }
                           }
                       }
                   }
               }
           });
    I can get it to hit the read, no problem, but upon hitting delete, it actually doesnt even try to call the destroy event. (or create or read, for that matter). I may not be using the parameter map functionality the right way. I am using a slightly modified version that was in the demo (im using a switch instead of an if)

    it goes in and hits read no problem, returning the location ID so that  the webapi controller knows what database to connect to

    this is important to my set up, as this is a template that many MANY locations are currently using (without our network), so each controller that we ever use has to know what database to pull from, hence always sending locationID in, in addition to the ID of the item I am dealing with (in the case of a delete)

    So now that is out of the way, am I still doing something wrong?
  6. James Hood
    James Hood avatar
    27 posts
    Member since:
    Jun 2012

    Posted 13 Aug 2013 Link to this post

    I'm not sure what happened to my other reply, it apparently got flagged as spam or something

    So I have been trying all sorts of ideas to get the parameterMap to work.. I have had some limited success

    $("#calendar").kendoScheduler({
        batch: false,
        height: 600,
        views: [
        "day",
            "week",
            { type: "month", selected: true },
            "agenda"
        ],
        dataSource: {
            transport: {
                create: {
                    url: "http://demos.kendoui.com/service/tasks/create",
                    dataType: "jsonp"
                },
                read: {
                    url: BaseAPI + "/NewFullCalendar",
                    dataType: "json"
                },
                update: {
                    url: "http://demos.kendoui.com/service/tasks/update",
                    dataType: "jsonp"
                },
                destroy: {
                    type: "delete",
                    url: BaseAPI + "/Calendar",
                    datatype: "json",
                },
                parameterMap: function (options, operation) {
                    if (operation == "create") { alert('ive been created'); return { location: locationID }; }
                    if (operation == "read") { alert('Ive been read'); return { location: locationID }; }
                    if (operation == "update") { alert('ive been updated'); return kendo.stringify({ location: locationID, ID: options.models[0].id }); }
                    if (operation == "destroy") { alert('ive been destroyed'); return kendo.stringify({ location: locationID, ID: options.models[0].id }); }
     
     
                }
            },
            schema: {
                model: {
                    id: "id",
                    fields: {
                        ID: { from: "ID", type: "number" },
                        title: { from: "title", defaultValue: "No title", validation: { required: true } },
                        start: { type: "date", from: "start" },
                        end: { type: "date", from: "end" },
                        description: { from: "Content" },
                        recurrenceId: { from: "recurrenceID" },
                        recurrenceRule: { from: "recurrenceRule" },
                        recurrenceException: { from: "recurrenceException" },
                        isAllDay: { type: "boolean", from: "IsAllDay" }
                    }
                }
            }
        }
    });
    when I run this on our test site, once the database is hit with the read method, you see an alert that it was indeed red.. but once I hit delete on the item, and confirm... it alerts that it was created.. so it SEEMS to hit create..So, maybe some help here would be excellent. 

    What I am needing to do is send a global variable in (locationID), which is needed for our controllers (webapi) to know what data base to use/ naturally I would also need to get other information:

    destroy needs to know what database to use, AND what eventID to delete.
    Create needs to know what database to use, and a host of other data
    update needs to know what database to use, what ID we are looking at, and what data to change
    read only needs to know what database to use.
  7. Atanas Korchev
    Admin
    Atanas Korchev avatar
    8462 posts

    Posted 14 Aug 2013 Link to this post

    Hello James,

     I cannot reproduce such problems in this demo: http://jsbin.com/udifit/1/edit
     Deleting an event always hits destroy. Perhaps your scheduler event is not properly configured. Check if all the fields are properly mapped to the response returned by your "read " service.

     Other than that sending the additional field is done via parameterMap just as you have implemented it.

    Regards,
    Atanas Korchev
    Telerik
    Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
  8. James Hood
    James Hood avatar
    27 posts
    Member since:
    Jun 2012

    Posted 14 Aug 2013 Link to this post

    I came to the realization this morning that I am using an internal build that i was instructed to use (as it fixed a lot of the editor tool bar bugs, where the icons werent being properly placed.)


    So I dont know if thats what is causing the issue there or not. I assume when you guys test the problems we post, you test the current version thats in production, and me like an idiot forgot I was using an internal build

    forgive me?


  9. Atanas Korchev
    Admin
    Atanas Korchev avatar
    8462 posts

    Posted 14 Aug 2013 Link to this post

    Hello James,

     No, the problem should be caused by the internal build.

     I noticed another problem - during "read" you are not calling kendo.stringify. WebAPI however needs its parameters to be sent in JSON format. Perhaps adding that would properly pass the parameters.

    The only other thing I can suggest is to attach your actual project so we can run it locally and see what is wrong. 

    Regards,
    Atanas Korchev
    Telerik
    Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
  10. James Hood
    James Hood avatar
    27 posts
    Member since:
    Jun 2012

    Posted 14 Aug 2013 Link to this post

    So the internal build should be causing the problem (or perhaps you didnt add the n't part) your posts makes me think you meant to say "the internal build shouldnt be causing the problem"

    I'll see what I can do about getting you guys a copy of the project, although you wouldnt be able to connect to our web service (due to the way our project works, its a content management system for about 80 different schools within our district)

    So, running it locally probably wouldnt work:

    to get to the page I am working on you have to have an authenticated account within our system, among other problems.

    generally (in my experience with this project) webapi doesnt particularly care if I havent stringified the read statement, unless im using more than one parameter. in the case of this read, I am only sending in locationID (and in fact it actually works, I get to see the events I preloaded into the DB manually)

    something is telling the  scheduler in some way shape or form, that i am creating when I am actually destroying
  11. James Hood
    James Hood avatar
    27 posts
    Member since:
    Jun 2012

    Posted 14 Aug 2013 Link to this post

    havent left for work yet, but here are the two pages in question, the aspx page is just a holder, all the functions happen within the JS file.

    hopefully this will tell you guys something, otherwise its looking like I just cant use the scheduler within our project, which just sucks.

  12. Atanas Korchev
    Admin
    Atanas Korchev avatar
    8462 posts

    Posted 14 Aug 2013 Link to this post

    Hi James,

     Yes, I meant "shouldn't". Sorry for the typo.

     I created a short sample project which shows how to implement CRUD with WebAPI. It uses in memory data but this should not be related. Please find it attached to this thread.

    Regards,
    Atanas Korchev
    Telerik
    Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
  13. James Hood
    James Hood avatar
    27 posts
    Member since:
    Jun 2012

    Posted 14 Aug 2013 Link to this post

    I dont even know what im doing wrong at the moment. Still getting destroy calling create (or read sometimes)

    At one point I had it working, but I wasnt using the transport methods, I was however using save remove and edit.

    the reason I changed off of using those, was because save gets called from edit and new.. so I would have had to determined in some way if the event was a new event, or if it was something that was being edited from the datasource.. and I still had those wonky r is undefined errors.

    We have seperated our web service (api, whatever you call it) into its own entity, so that each site can call back to a single service location, instead of each site having its own service (which is what prevents me from actually debugging this thing properly, unless I have a copy of the service running locally)

    I have seen many different ways to format the parameter map, so its difficult to see which is "the right way" for what I am doing.

    I'll keep trying.
  14. Kiril Nikolov
    Admin
    Kiril Nikolov avatar
    2596 posts

    Posted 16 Aug 2013 Link to this post

    Hi James,

    As we have already attached a working demo, showing a possible implementation of the functionality you are looking for, please check it again and see what differs from the project that you have. I hope you will figure it out.
     
    Regards,
    Kiril Nikolov
    Telerik
    Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
  15. Eric
    Eric avatar
    1 posts
    Member since:
    Apr 2015

    Posted 10 Apr 2015 Link to this post

    I know this forum topic is super old, but thought I would throw this out there as I had a VERY similar issue and it was driving me crazy. Looks like you have the same code issue as I did in your schema

    schema: {
                model: {
                    id: "id",
                    fields: {
                        ID: { from: "ID", type: "number" },
                        title: { from: "title", defaultValue: "No title", validation: { required: true } },
                        start: { type: "date", from: "start" },
                        end: { type: "date", from: "end" },
                        description: { from: "Content" },
                        recurrenceId: { from: "recurrenceID" },
                        recurrenceRule: { from: "recurrenceRule" },
                        recurrenceException: { from: "recurrenceException" },
                        isAllDay: { type: "boolean", from: "IsAllDay" }
                    }
                }
            }
        }
     

    notice, how you reference id: as "id" 

    Well in your fields block it is ID:

    Apparently the case matters ALOT check out the updated below, I made it id: ( lower case in the fields block ) that fixed my issue. Hopefully this helps someone in the future

    schema: {
                       model: {
                           id: "id",
                           fields: {
                               id: { from: "ID", type: "number" },
                               title: { from: "title", defaultValue: "No title", validation: { required: true } },
                               start: { type: "date", from: "start" },
                               end: { type: "date", from: "end" },
                               description: { from: "Content" },
                               recurrenceId: { from: "recurrenceID" },
                               recurrenceRule: { from: "recurrenceRule" },
                               recurrenceException: { from: "recurrenceException" },
                               isAllDay: { type: "boolean", from: "IsAllDay" }
                           }
                       }
                   }
               }

     

Back to Top