[SOLVED][2.0]TreePanel beforenodedrop

  • Hi,

    I'd like to issue a message to the user that would conditionally affect whether the node drag is completed or reverted. I tried the following listener on my TreePanel, but it completes the drop as soon as the message is shown.


    beforenodedrop : function ( dropEvent ){

    //Fires when a DD object is dropped on a node in this tree for preprocessing.
    // Return false to cancel the drop. The dropEvent passed to handlers has the following properties:
    // * tree - The TreePanel
    // * target - The node being targeted for the drop
    // * data - The drag data from the drag source
    // * point - The point of the drop - append, above or below
    // * source - The drag source
    // * rawEvent - Raw mouse event
    // * dropNode - Drop node(s) provided by the source OR you can supply node(s) to be inserted by setting them on this object.
    // * cancel - Set this to true to cancel the drop.

    sourceText = dropEvent.dropNode.text;
    sourceType = dropEvent.dropNode.attributes.iconCls.substr(5);
    sourceID = dropEvent.dropNode.id;
    destText = dropEvent.target.text;
    destType = dropEvent.target.attributes.iconCls.substr(5);
    destID = dropEvent.target.id;

    return Ext.Msg.show({
    title : 'Please confirm',
    msg : 'Really move ' + sourceText + ' to the ' + destText + ' ' + destType + '?',
    minWidth : 140,
    buttons : Ext.Msg.OKCANCEL,
    icon : Ext.MessageBox.WARNING,
    fn : function(btn){
    if(btn === 'ok'){
    api.body.mask('Saving');
    Ext.Ajax.request({
    url : 'Common/Ajax/json.aspx?req=dragTree&sourceID='+sourceID+'&destID='+destID,
    success : function(response) {
    // show the confirmed message
    api.body.mask('Saved!');
    setTimeout(function(){
    api.body.unmask();
    }, 250);
    },
    failure:function(response) {
    // show the failure message
    }
    });
    }
    return false;
    }
    });
    }


    Does anyone see what I'm doing wrong?

    Thanks,
    Joshua


  • thanks for the note Stefan. I removed the 'return' from the line : 'return Ext.Msg.show({' and it still drops the node as soon as the messagebox is shown.

    Any ideas?


  • To prevent the drop process chain to continue you will have to return FALSE from your "beforenodedrop" handler and source the actual action to be taken out to a follow up handler. The following line in your code

    return Ext.Msg.show({

    always returns an Ext.MessageBox which will never evaluate to FALSE.


  • Just removing the return statement from the specified line alone won't help. Your "beforenodedrop" handler will always have to return FALSE after initiating the Ajax.request.
    The drawback is that you will have to do everything that comes afterwards manually because the automatic drop handling will be terminated after an unsuccessful "beforenodedrop".


  • That makes a lot of sense. Thanks for the quick responses Stefan. It helped a lot. :)







  • #If you have any other info about this subject , Please add it free.#
    Your name:
    E-mail:
    Telphone:

    Your comments:


    If you have any other info about [SOLVED][2.0]TreePanel beforenodedrop , Please add it free.