0

I am currently trying to call the PHP script upon clicking OK button on EXTJS message alert box.

For some reason it doesn't even display the Alert box when I use handler. However when I used Listener it displays the Alert box but doesn't call the php script upon clicking OK button. I read on different blogs and come to know Handler is the best way to go forward

I will appreciate if somebody can help me or point me to the right direction. I am using the latest release of EXTJS4

Below is the EXTJS tree panel code I've written using handler;

var treePanel = Ext.create('Ext.tree.Panel', {
    id: 'tree-panel',
    title: 'Available Database',
    region: 'north',
    split: true,
    height: 360,
    minSize: 150,
    rootVisible: false,
    autoScroll: true,
    store: store,

    handler: function() {
        if (treePanel.getSelectionModel().hasSelection()) {
            var selValue = treePanel.getSelectionModel().getSelection();

            Ext.MessageBox.alert('Press OK to confirm your subscription <br>' + selValue[0].data.text,
                function(btn, text) {
                    if (btn == 'ok') {
                        Ext.Ajax.request({
                            url: 'addSubscription.php',
                            params: {
                                nodetext: text,
                                parentid: selectedNode[0].data.id
                            },
                            success: function(response) {
                                var id = response.responseText;
                                grid.getView().refresh();
                            }
                        })
                    } else {
                        Ext.MessageBox.alert('Record already subscribed');
                    }
                });
        }
    }

});
Narendra Jadhav
  • 10,052
  • 15
  • 33
  • 44
Cortez Ninja
  • 97
  • 3
  • 16

1 Answers1

0

Ext.tree.Panel have not 'handler' property in config. Handler is a function that is executed when you click on some of the components - such as buttons. You can add button on your treePanel toolbar, and use button handler:

...
tbar: [{
    xtype: 'button',
    text: 'Subscribe',
    handler: function(button) {
        ...
    }
}],
...

See on jsfiddle: http://jsfiddle.net/FFvLa/

but doesn't call the php script upon clicking OK button.

The function must be passed as the third argument in Ext.Msg.alert:

http://jsfiddle.net/FFvLa/2/

Vlad
  • 3,626
  • 16
  • 14
  • Thanks for the info but I want to handle this on MessageBox.Alert Dialog box not via creating the button – Cortez Ninja Feb 22 '13 at 14:39
  • @ShoaibSuleman Use listeners (such as 'boxready') and pass callback function as the third argument. Not as 2. Jsfiddle: http://jsfiddle.net/FFvLa/3/ – Vlad Feb 22 '13 at 15:04
  • I make it working with tbar, its good for now as my project UAT date is not far away. But thanks for your help – Cortez Ninja Feb 22 '13 at 15:27