Gelmiş geçmiş en büyük porno sitemiz olan 2pe de her zaman en kaliteli pornoları sunmayı hedefledik. Diğer video sitemiz olan vuam da ise hd porno ağırlıklı çalışmalara başladık.

  1. #1
    Sencha User
    Join Date
    Jun 2011
    Posts
    14
    Vote Rating
    -1
    hornfrog is an unknown quantity at this point

      0  

    Default ExtJS 4 Sync and success/failure processing

    ExtJS 4 Sync and success/failure processing


    It appears the recommended way to update a store is to use the sync() function, which in turn utilizes the model proxy to to perform the server requests for create/update/destroy. The only way I can see to track the response is via the model's "exception" event. I find that a bit anemic, and it doesn't handle the success scenario.

    How do you wire up success and failure listeners to the sync() processing to capture the response, similar to performing a classic form.submit()? It would be nice to be able to report "success" to a user, and to apply returned field-level errors and various other data that was available with the older failure callback feature.

  2. #2
    Sencha User
    Join Date
    Jun 2011
    Posts
    14
    Vote Rating
    -1
    hornfrog is an unknown quantity at this point

      -1  

    Post Is there a better method?

    Is there a better method?


    Since I'm working with one record at a time, I fell back to the model/record save() method.

    This save() method will take a callback. It appears you can specify a single, generic "callback" function, or "success" and failure" functions. In all cases, it appears the only parameter you receive back is the operation object. There is not much in the operation object to use in reporting/processing the result.

    I've a kludge of a workaround:

    first, supply a success callback to the save operation to report success to the user:

    Code:
    var form = myFormVar.getForm(); if (form.isValid()) { var record = form.getRecord(), values = form.getFieldValues(); form.updateRecord(record); record.save({ success: function (a, operation, c) { Ext.Msg.alert('Saved'); }
    second, add a listener to the model to catch the exception. Since this callback provides a proxy and a response, you can actually pull out your errors from the returned json and apply to the form

    Code:
              ...
              // model definition...
              ...
               listeners: {
                    exception: function (proxy, response, operation) {
                        var json = Ext.decode(response.responseText);
                        if (json) {
                            detl.getForm().markInvalid(json.errors);
                            Ext.MessageBox.show({
                                title: 'Save Failed',
                                msg: json.message,
                                icon: Ext.MessageBox.ERROR,
                                buttons: Ext.Msg.OK
                            });
                        } else
                        Ext.MessageBox.show({
                            title: 'EXCEPTION',
                            msg: operation.getError(),
                            icon: Ext.MessageBox.ERROR,
                            buttons: Ext.Msg.OK
                        });
                    }
                }
    There has got to be a cleaner way.

    I was going to use a standard form.submit() with its traditional facility for handling success and failure, but it was only posting non-empty values to the server. As an example, this means if you uncheck a checkbox initialized as true, it would not send 'false' to the server. According to other posts, this is because "that is how HTML works". I find this unacceptable for a client side framework. I think the functionality should be to submit every field, or changed fields - user choice. Further, there should be an option to include the entire model/record associated with the form in the submit, not just the fields used in the form. You can do this using the save() and sync() functions, but they of course don't have the same logical way of handling success and failure.

    I am new to this framework so I may be missing something. Please enlighten me.

  3. #3
    Sencha User
    Join Date
    Jun 2009
    Location
    Heidelberg, Germany
    Posts
    52
    Vote Rating
    1
    kleins is on a distinguished road

      0  

    Default


    Thanks for sharing your approach, hornfrog. Very helpful to me!

    I have been looking into this myself and I think you're right: You cannot get to the actual server response in the callbacks to save(). It would be helpful to be able to access the response object here. But I followed its trail and in case of a failure it is not passed on after Ext.data.proxy.Server.processResponse.

    I tried to get your approach to work (which, btw, I like and it doesn't seem so much of a kludge to me), but I am having trouble trying to attach the event listener to the model. First I got a "me.events is undefined" error which I believe is due to a bug in Observable. I fixed that, but now the listener is simply not triggered. Did you define the listener in the actual model definition? The API doesn't say anything about the model triggering any events. According to the API exception is triggered by the proxy, not the model.

    Also, I was wondering how you access the form from the listener. Where does that "detl" object in your code come from? I guess I can pass the form through the operation, but maybe you have got a better solution?

    Thanks in advance for any pointers!

  4. #4
    Ext JS Premium Member powellke's Avatar
    Join Date
    Sep 2008
    Location
    Huntsville, AL
    Posts
    37
    Vote Rating
    5
    powellke is on a distinguished road

      3  

    Default


    You can get access to the returned json data from the operation argument to the success and failure functions. For example, when I call save on a "user" record and the save fails on the server side, I can return the failure json:


    { "success": "false", "message": "Error message goes here." }


    and get it from the op:


    user.save({
    success: function(rec, op) {
    // do something
    },
    failure: function(rec, op) {
    Ext.Msg.alert("Failed",op.request.scope.reader.jsonData["message"]);
    }
    });


    It took a little digging to find that, but it's there.

  5. #5
    Sencha User
    Join Date
    Mar 2011
    Location
    Germany
    Posts
    198
    Vote Rating
    1
    Nickname is on a distinguished road

      0  

    Default


    Just as an information: The missing error handling for store.sync() was reported in this thread.
    The thread is marked as fixed, I will request an update on that issue in the mentioned thread.

  6. #6
    Sencha User
    Join Date
    Jun 2011
    Posts
    3
    Vote Rating
    0
    Sebulba is on a distinguished road

      0  

    Default


    I was just working on the same problem, but I found a different solution. You can use the afterRequest callback function on the proxy object. Using the success boolean and the request object data you should be able to detect any operation that has happened in the store and whether or not it was successful.

  7. #7
    Sencha User
    Join Date
    Mar 2011
    Posts
    208
    Vote Rating
    0
    bee is on a distinguished road

      0  

    Default


    can you post some code please ?

  8. #8
    Sencha User
    Join Date
    Aug 2011
    Posts
    15
    Vote Rating
    0
    vikaskale is on a distinguished road

      0  

    Default


    Hi Sebulba,

    Please paste some code.

  9. #9
    Sencha User
    Join Date
    Jun 2011
    Posts
    3
    Vote Rating
    0
    Sebulba is on a distinguished road

      0  

    Default


    Here is a simple PUT example.

    Code:
    proxy: {
                        type: 'rest',
                        url: '/your_resource',
                        reader: {
                            type: 'json',
                            root: 'data'
                        },
                        writer: {
                            type: 'json'
                        },
                        afterRequest:function(request,success){
                            if(request.method = 'PUT'){
                                 // your code
                            }
                        }
    }

  10. #10
    Sencha User
    Join Date
    Aug 2011
    Posts
    15
    Vote Rating
    0
    vikaskale is on a distinguished road

      0  

    Default


    Thanks Sebulba.