Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
Clear All
new posts

    RestDataSource and dataURL tweak

    Hi,

    I am currently on SmartClient Version: v10.0p_2014-10-10/EVAL Development Only

    I try to to setup a RestDataSource with REST server app : Django REST Framework.

    While it was easy to fetch records or create a new one, I can't find a way to get my RestDataSource to work for others operationType.

    To edit or delete a record I need to add the primary key (id) to the dataURL. I am currently focused on the "remove" operation.

    dataURL is "/rapi/clients/" and I need to have "/rapi/clients/<id>" when I want to edit/delete a record.

    Code:
    isc.RestDataSource.create({
        ID:"client",
        fields: [
            {name:"id", type:"integer", title:"id"},
            {name:"name", type:"text", title:"Nom", required:true}
        ],
        dataFormat:"json", DSDataFormat:"json",
        sendMetaData: false,
        recordXPath: "data",
        dataURL:"/rapi/clients/",
        transformRequest: function(dsRequest) {
            dsRequest.httpHeaders = {"Accept":"application/json", "X-CSRFToken": CSRFToken};
    
    
    
            if(dsRequest.operationType == "remove") {
                // Add the id to dataURL, how ?
            }
    
            return this.Super("transformRequest", arguments);
        },
        operationBindings:[
            {operationType:"remove", dataProtocol:"getParams", requestProperties:{httpMethod:"DELETE"}}
        ]
    });
    Thank you

    #2
    That's a very bad design, because it prevents combining multiple operations, such as a mixture of updates and adds, into a single HTTP call. Avoid using this design if you can.

    If you have no choice, you can simply modify the dataURL on the dsRequest (dsRequest.dataURL = ...).

    Comment


      #3
      Thanks you, it's working !

      I know it's not the better way to do this. Hopefully I don't need to combine multiple operations for now, and I need to migrate the UI, and just the UI.

      If I have success with my app and smartclient I will probably migrate to smartclient on the server side too later ;)

      Comment

      Working...
      X