1. #1
    Sencha User Misiu's Avatar
    Join Date
    Jun 2012
    Location
    Poland
    Posts
    257
    Vote Rating
    58
    Answers
    6
    Misiu is a jewel in the rough Misiu is a jewel in the rough Misiu is a jewel in the rough

      0  

    Default Answered: MessageBox pass extra param to handler

    Answered: MessageBox pass extra param to handler


    I've created context menu for a control like so:
    Code:
    onEventContextMenu: function (s, rec, e) {
            e.stopEvent();
    
            if (!s.ctx) {
                s.ctx = new Ext.menu.Menu({
                    items: [{
                        text: 'Delete event',
                        iconCls: 'icon-delete',
                        scope: this,
                        handler : function() {
                        Ext.MessageBox.show({
                                        title : 'Reason',
                                        msg : 'place reason:',
                                        width : 300,
                                        buttons : Ext.MessageBox.OKCANCEL,
                                        multiline : true,
                                        fn : this.showResultText(buttonId, text, rec)//how to pass rec to handler?
                                    });
                        }
                    },{
                                text : 'Accept',
                                iconCls : 'accept',
                                handler : function() {
                                    alert(rec.get('Title'));
                                }
                            }, 
                    ]
                });
            }
            s.ctx.rec = rec;
            s.ctx.showAt(e.getXY());
        },
        
        showResultText : function (btn, text, record){
        alert(btn);
            if (btn == 'cancel') {
                alert(text + ' cancel');
            }
            if (btn == 'ok') {
                alert(record.get('Title'));
            }
        },
    I can access rec in second option. But when user choose first option he gets messageBox to enter some text, after than I would like to access rec from showResultText function.
    How to do that? Add extra parameter? If yes, then how?

  2. I've changed a bit my code:
    Code:
        onEventContextMenu: function (s, rec, e) {
            e.stopEvent();
    
            if (!s.ctx) {
                s.ctx = new Ext.menu.Menu({
                    items: [{
                        text: 'Delete event',
                        iconCls: 'icon-delete',
                        scope: this,
                        handler : function() {
                        Ext.MessageBox.show({
                                        title : 'Reason',
                                        msg : 'place reason:',
                                        width : 300,
                                        buttons : Ext.MessageBox.OKCANCEL,
                                        multiline : true,
                                        scope: this,
                                        fn : function(btn,text){ if (btn == 'ok') this.showResultText(rec);}
                                        //fn : this.showResultText(buttonId, text, rec)
                                    });
                        }
                    },{
                                text : 'Accept',
                                iconCls : 'accept',
                                handler : function() {
                                    alert(rec.getName());
                                }
                            }, 
                    ]
                });
            }
            s.ctx.rec = rec;
            s.ctx.showAt(e.getXY());
        },
        
        showResultText : function (record, reason){
                alert(record.getName());
        },
    Now I can access record from my function, but if anyone knows how to pass extra param to handler function please let me know

  3. #2
    Sencha User Misiu's Avatar
    Join Date
    Jun 2012
    Location
    Poland
    Posts
    257
    Vote Rating
    58
    Answers
    6
    Misiu is a jewel in the rough Misiu is a jewel in the rough Misiu is a jewel in the rough

      0  

    Default


    I've changed a bit my code:
    Code:
        onEventContextMenu: function (s, rec, e) {
            e.stopEvent();
    
            if (!s.ctx) {
                s.ctx = new Ext.menu.Menu({
                    items: [{
                        text: 'Delete event',
                        iconCls: 'icon-delete',
                        scope: this,
                        handler : function() {
                        Ext.MessageBox.show({
                                        title : 'Reason',
                                        msg : 'place reason:',
                                        width : 300,
                                        buttons : Ext.MessageBox.OKCANCEL,
                                        multiline : true,
                                        scope: this,
                                        fn : function(btn,text){ if (btn == 'ok') this.showResultText(rec);}
                                        //fn : this.showResultText(buttonId, text, rec)
                                    });
                        }
                    },{
                                text : 'Accept',
                                iconCls : 'accept',
                                handler : function() {
                                    alert(rec.getName());
                                }
                            }, 
                    ]
                });
            }
            s.ctx.rec = rec;
            s.ctx.showAt(e.getXY());
        },
        
        showResultText : function (record, reason){
                alert(record.getName());
        },
    Now I can access record from my function, but if anyone knows how to pass extra param to handler function please let me know