1. #1
    Ext User
    Join Date
    Jun 2010
    Posts
    17
    Vote Rating
    0
    gr_great_2000 is on a distinguished road

      0  

    Default How to cancel a drop after an Ajax failure

    How to cancel a drop after an Ajax failure


    Hello everybody,

    I cannot cancel a drop event after an Ajax failure, e.g.

    function dropHandler(dropEvent) {
    ...
    dropEvent.cancel = false;
    Ext.Ajax.request {
    ...
    failure: {
    dropEvent.cancel = true;
    alert("On failure: "+dropEvent.cancel);
    }
    }
    alert("After request: "+dropEvent.cancel);
    }

    First the "After request: false" message is printed, then the "On failure: true" but it is late. How can I affectively cancel the drop on ajax failure? Any tips?

    Thanks in advance
    George

  2. #2
    jay@moduscreate.com's Avatar
    Join Date
    Mar 2007
    Location
    Frederick MD, NYC, DC
    Posts
    16,353
    Vote Rating
    79
    jay@moduscreate.com is a name known to all jay@moduscreate.com is a name known to all jay@moduscreate.com is a name known to all jay@moduscreate.com is a name known to all jay@moduscreate.com is a name known to all jay@moduscreate.com is a name known to all

      0  

    Default


    George,


    What UI widget are you using?

  3. #3
    Sencha - Ext JS Dev Team Animal's Avatar
    Join Date
    Mar 2007
    Location
    Notts/Redwood City
    Posts
    30,502
    Vote Rating
    47
    Animal has a spectacular aura about Animal has a spectacular aura about

      0  

    Default


    Asynchronous!

  4. #4
    Ext User
    Join Date
    Jun 2010
    Posts
    17
    Vote Rating
    0
    gr_great_2000 is on a distinguished road

      0  

    Default


    I guess I am using asynchronous widgets. I use nodeType: 'async' in my trees, if this is what you are asking. I understand the fact that ajax request is asynchronous, but how can you handle such cases when you want to cancel a drop after an synchronous ajax request?

  5. #5
    Sencha - Ext JS Dev Team Animal's Avatar
    Join Date
    Mar 2007
    Location
    Notts/Redwood City
    Posts
    30,502
    Vote Rating
    47
    Animal has a spectacular aura about Animal has a spectacular aura about

      0  

    Default


    You can't! The drop happened aeons (In processor time) before the Ajax request creeps back along the wire!

  6. #6
    jay@moduscreate.com's Avatar
    Join Date
    Mar 2007
    Location
    Frederick MD, NYC, DC
    Posts
    16,353
    Vote Rating
    79
    jay@moduscreate.com is a name known to all jay@moduscreate.com is a name known to all jay@moduscreate.com is a name known to all jay@moduscreate.com is a name known to all jay@moduscreate.com is a name known to all jay@moduscreate.com is a name known to all

      0  

    Default


    I would say, return false from onNotifyDrop, cache the drop event, if the ajax event is successful, complete the drop. I've done this before and it works.

  7. #7
    Ext User
    Join Date
    Jun 2010
    Posts
    17
    Vote Rating
    0
    gr_great_2000 is on a distinguished road

      0  

    Default


    Thanks for your help! I will try to implement what your are suggesting.

  8. #8
    Ext User
    Join Date
    Jun 2010
    Posts
    17
    Vote Rating
    0
    gr_great_2000 is on a distinguished road

      0  

    Default


    I tried to follow your instructions but it didn't work. Maybe I didn't do it properly. When an 'beforenodedrop' event is fired at my tree, the handler -that it is called- does not wait for Ajax to return (either success or failure). When this function returns, game is over (no matter if I cache the event and try to fire the event again or call some other function). Am I missing something here?

  9. #9
    Sencha - Ext JS Dev Team Animal's Avatar
    Join Date
    Mar 2007
    Location
    Notts/Redwood City
    Posts
    30,502
    Vote Rating
    47
    Animal has a spectacular aura about Animal has a spectacular aura about

      0  

    Default


    Yes.

    You have to forget about the drop doing the business.

    record what is being dropped where. CANCEL the drop event.

    Then, in your Ajax success handler, perform the removal of the dragged "thing" (was it a treenode, I forgot), and the addition to wherever the drop point was.

  10. #10
    Ext User
    Join Date
    Jun 2010
    Posts
    17
    Vote Rating
    0
    gr_great_2000 is on a distinguished road

      0  

    Default


    Thank you both Jesus and Animal for your help! I think that you -more or less- say the same thing. But you helped me a lot to figure out a solution to this:

    I always return true in case of a valid drop. I also cache the drop event and in case of an Ajax failure, I just remove the node that has been dropped (special care needed for the node ids). I could also do it the other way around. Always reject a drop, but in case of an ajax success to add the drop node. It turned out to be easier than I thought...

Similar Threads

  1. Cancel drop event in tree
    By MaxT in forum Ext 1.x: Help & Discussion
    Replies: 1
    Last Post: 1 Nov 2011, 12:34 AM
  2. cancel drop event
    By fother in forum Ext GWT: Help & Discussion (1.x)
    Replies: 5
    Last Post: 3 Jun 2009, 5:55 AM
  3. How to cancel a drag drop of panel
    By red900 in forum Ext 2.x: Help & Discussion
    Replies: 1
    Last Post: 10 Sep 2008, 11:56 AM
  4. How to cancel AJAX requests?
    By 72 in forum Ext 2.x: Help & Discussion
    Replies: 1
    Last Post: 7 Nov 2007, 6:38 PM

Thread Participants: 2