1. #1
    Sencha Premium Member sencha-dev2's Avatar
    Join Date
    Jun 2012
    Location
    France
    Posts
    59
    Vote Rating
    0
    Answers
    2
    sencha-dev2 is on a distinguished road

      0  

    Default Unanswered: Beforeclose Listener

    Unanswered: Beforeclose Listener


    Hi, I am listening to a panel's beforeclose event. It is a form I check updates in. I send an Ext.MessageBox.confirm when it was updated. Then I have three possibilities :
    • If they click on Yes, I save the changes, and close the panel.
    • If they click on No, I simply close the panel.
    • If they click on Cancel, I have to block panel's closure and let the user continue in this panel.
    This is for the third point I have difficulties : I don't know how to stop the closure. It is said on docs that I must return false from a listener, but I can't manage to do it. So if you know how to do that, please help !

  2. #2
    Sencha - Community Support Team friend's Avatar
    Join Date
    Apr 2011
    Posts
    895
    Vote Rating
    27
    Answers
    106
    friend has a spectacular aura about friend has a spectacular aura about

      0  

    Default


    Keep in mind that Ext.Msg.confirm(<...>) is asynchronous and doesn't halt execution, so you're most likely falling straight on through the beforeclose event handling code, which returns a true by default.

  3. #3
    Sencha Premium Member sencha-dev2's Avatar
    Join Date
    Jun 2012
    Location
    France
    Posts
    59
    Vote Rating
    0
    Answers
    2
    sencha-dev2 is on a distinguished road

      0  

    Default


    Thanks for your answer. Do you know then how to configure beforeclose event so it can return 'false' to stop the close event ?

  4. #4
    Sencha - Community Support Team friend's Avatar
    Join Date
    Apr 2011
    Posts
    895
    Vote Rating
    27
    Answers
    106
    friend has a spectacular aura about friend has a spectacular aura about

      0  

    Default


    It sounds like you may need to rethink your event handling and where/when you present the MessageBox to the user.

    Can you provide a pared-down code sample which more clearly illustrates what you're trying to accomplish?

  5. #5
    Sencha Premium Member sencha-dev2's Avatar
    Join Date
    Jun 2012
    Location
    France
    Posts
    59
    Vote Rating
    0
    Answers
    2
    sencha-dev2 is on a distinguished road

      0  

    Default


    Here it is :

    Code:
    var storeCompEC = Ext.create('Ext.data.Store', {    fields: [
            {name: 'idCivilite', type: 'integer'},
            {name: 'patronyme', type: 'string'},
            {name: 'nomIndividu', type: 'string'},
            {name: 'prenom', type: 'string'},
            {name: 'dateNaissance', type: 'date'},
            {name: 'sexe', type: 'string'},
            {name: 'idPCS', type: 'integer'},
            {name: 'idSituationFamiliale', type: 'integer'},
            {name: 'idPays', type: 'integer'},
            {name: 'NIR', type: 'string'},
            {name: 'dateDeces', type: 'date'},
            {name: 'idJustificatifDeces', type: 'integer'}
        ]
    });
    
    Ext.define('Infologis.controller.Beneficiaire', {
        extend: 'Ext.app.Controller',
    
    
        //Les vues contrôlées
        views: [
             ...
        ],
    
        init: function() {
            ctrler=this;        this.control({
                'panel[action="closeEC"]':
                {
                    beforeclose: this.saveEC
                }
            });
        },
    
        saveEC: function(pan)
        {
            var modif = false;
            var comp = storeCompEC.data.items[0].data;
            var data = pan.child('form[name="centre"]').getValues();
            var nomsCps = storeCompEC.model.getFields();
            for (var i in nomsCps) {
                var nam = nomsCps[i].name;
                if(data[nam] != comp[nam]) {
                    modif = true;
                }
            }
            if(modif) {
                Ext.MessageBox.confirm({
                    title: 'Confirmer',
                    msg: 'L\'enregistrement a été modifié.\nVoulez-vous enregistrer les modifications ?',
                    buttons: Ext.MessageBox.YESNOCANCEL,
                    fn: function(btn) {
                        if(btn == 'yes') {
                            Ext.Ajax.request({
                                url: 'individu/update-etat-civil',
                                params: data,
                                success: function() {
                                    Ext.MessageBox.alert('Succes !', 'Les changements ont ete enregistres.');
                                                                    // let panel's closure go
                                },
                                failure: function() {
                                    Ext.MessageBox.alert('Erreur !', 'Une erreur est survenue durant l\'operation de mise à jour.');
                                    // stop panel's closure
                                }
                            });
                        } else if(btn == 'cancel') {
                            // stop panel's closure
                        }
                    }
                });
            }
        }
    I hope it'll help you helping me