gridx lazyedit calling grid.model.save() with a Dojo.JsonRest resolves on a 500 put response

232 views Asked by At

I'm trying to use a dojo.gridx and dojo.JsonRest as my memory store. I'm using the lazyEdit feature due to some constraints of a row needs to be entirely filled out before submission.

I have a button and deferred object defined as follows

        grid.startup();
  //  var gridDeferred = new Deferred(function(reason){
        // do something when the Deferred is cancelled
    //    alert("canceled");
   // });


    var saveButton = new Button({
        label: "Save All Changes",
        onClick: function(){
            gridDeferred =  grid.model.save();
          //  gridDeferred = grid.model.when();
            gridDeferred.then(function(value){
                alert("done");
            },function(err){
                alert("err");
            }, function(update){
                alert("update");
            });

        }
    }, "Update").startup();

I have also tried to un-commenting out my deferred object before the onclick event on the button but still no luck.

this is the response headers I get back from the server

HTTP/1.1 500 Internal Server Error
Cache-Control: private, s-maxage=0
Pragma: no-cache
Content-Type: application/json; charset=utf-8
Expires: -1
Server:   "removed by McFrank"
X-AspNetMvc-Version: 5.2
X-AspNet-Version: 4.0.30319
Set-Cookie:  "removed by McFrank"
X-Powered-By: "removed by McFrank"
Date: "removed by McFrank"
Content-Length: 46

Am I forgetting to add on a header so that the dojo core library will reject the request? I can see the follow error thrown in my debugger as well.

PUT http://localhost:36348/admin/sales/1 500 (Internal Server Error)xhr
@dojo.js:15dojo.xhr 
@ dojo.js:15_4.put 
@ JsonRest.js:33_60c.around.advice 
@ dojo.js:15_607.(anonymous function)._60c 
@ dojo.js:15declare._saveRow 
@ Modify.js:412(anonymous function) 
@ Modify.js:249_5b5.forEach 
@ dojo.js:15declare.save 
@ Modify.js:248declare._call 
@ _Extension.js:67declare._call 
@ _Extension.js:67declare._call 
@ _Extension.js:67declare._call 
@ _Extension.js:67declare._mixinAPI.api 
@ _Extension.js:76Button.onClick 
@ salesdata:540_1._onClick 
@ _ButtonMixin.js:16(anonymous function) 
@ dojo.js:15_1.__onClick 
@ _ButtonMixin.js:7(anonymous function) 
@ dojo.js:15

I also get this error as well

_5aa {message: "Unable to load /admin/sales/1 status: 500", response: Object, status: 500, responseText: "DealershipProductID:System.Web.Mvc.ModelError,", xhr: XMLHttpRequest}message: "Unable to load /admin/sales/1 status: 500"response: ObjectresponseText: "DealershipProductID:System.Web.Mvc.ModelError,"stack: (...)get stack: () { [native code] }set stack: () { [native code] }status: 500xhr: XMLHttpRequest__proto__: _5aa_4c3 @ dojo.js:15(anonymous function) @ dojo.js:15_1fe @ dojo.js:15_1fc @ dojo.js:15dojo.Deferred.reject.errback @ dojo.js:15_1fe @ dojo.js:15_1fc @ dojo.js:15dojo.Deferred.reject.errback @ dojo.js:15(anonymous function) @ dojo.js:15_4ec @ dojo.js:15_4e6 @ dojo.js:15_504.reject @ dojo.js:15_4f2 @ dojo.js:15_4ec @ dojo.js:15_4e6 @ dojo.js:15_504.reject @ dojo.js:15_4f2 @ dojo.js:15_4ec @ dojo.js:15_4e6 @ dojo.js:15_504.reject @ dojo.js:15_4f2 @ dojo.js:15_4ec @ dojo.js:15_4e6 @ dojo.js:15_504.reject @ dojo.js:15_4f2 @ dojo.js:15_4ec @ dojo.js:15_4e6 @ dojo.js:15_504.reject @ dojo.js:15_40b @ dojo.js:15_417 @ dojo.js:15

I have also attempted to get the dojo xhr request to error out which it does with the following request

  xhr.put("http://localhost:36348/admin/sales/1", {
        data:{"Id":1,"ProductID": null,"AccountExecName":"something","NetCommissionAmount":13625},
        handleAs:"json"
}).then(function(data){
    alert("testDone")
},function(err){
    alert("testerror");
}, function(evt){
    alert("testxhr");
}
        )
1

There are 1 answers

0
McFrank On

craftmans on github posted this response. I have not tried or tested his methods.

https://github.com/oria/gridx/issues/218

In gridx/core/model/extensions/Modify.js, save function two options:

  1. at line #252 change dl = new DeferredList(da); to dl = new DeferredList(da, false, true); now error callback can be called
  2. at line #260 change d.callback(); to d.callback(arguments);

Now in the callback function, you can use the arguments to detect which row is updated successfully and which row is updated in error.

The arguments are produced by DeferredList which is an array, each item is an array contains 2 subitems, first subitem is a boolean value, which is indicate update state success or error

The second subitem is the object that you updated when update success, otherwise the second subitem is the ErrorCtor object represent the error, and you can resolve the error message from it