vendredi 31 octobre 2014

Confirmation message to save changes before closing a window

Hello all,

I have an editable window. When the user tries to close the window, I need to check if any changes are made in the window. If there are no changes, the window should close. If there any changes I need to prompt the user if the changes needs to be saved. If the user says yes, the changes will be saved and window closes else the window closes without the changes. For this I wrote my code in the controller layer of my code. When the user clicks on the close button in the window, everything is working fine as expected. But the problem comes only when the user tries to close the window by clicking the default [X] in the upper right corner of the window. I am trying to call my method when user clicks on this but due to the async nature of extjs the window closes initially and then the method gets called. I tried using the beforeclose event but of no use.


Here is my piece of code in the view layer.


Ext.define('MyApp.view.MyWindow',

{

extend: 'Ext.window.Window',


requires: [

'ABC.controller.myDetail.myDetailController'

],

cls:'windowPopup myDetail',

title : 'ABC Detail',

layout: 'fit',

minimizable: true,

maximizable: true,

constrain: true,

controller: null,

initComponent: function() {

this.items = [ --------------------- ]

this.setTitle('ABC Detail - ' + this.config.myDetail.referenceNum);

var userNotification = '';

var bodyStyle = 'color: #000000;'

this.dockedItems = [

{

xtype: 'toolbar', dock: 'bottom', ui: 'footer',

items: [

{

iconCls: 'icon-save',

cls:'blackButton',

itemId: 'updateAndClose',

text: 'Update & Close',

action: 'updateClose'

},

{

iconCls: 'icon-reset',

cls:'blackButton',

text: 'Update',

action: 'update',

itemId: 'update'

},

{

iconCls: 'icon-reset',

cls:'blackButton',

itemId: 'composeEmail',

text: 'Compose Email',

action: 'composeEmail'

},

{

iconCls: 'icon-reset',

cls:'blackButton',

text: 'Refresh',

action: 'refresh',

itemId: 'refresh'

},

{

iconCls: 'icon-reset',

text: 'Close',

cls:'blackButton',

scope: this,

itemId: 'closeBtn'

}

] }];

this.callParent(arguments);

this.controller = Ext.create(XYZ.controller.mydetail.myDetailController', {view:this,identifier:this.identifier}); }

});

I am handling the buttons in the contoller layer, so if a user clicks on the close button then the contoller will check if any changes are made and then acts accordingly.


In the contoller, I am using the


this.on('closeBtn', 'click', this.confirmSaveBeforeClose, this);

this.on(null, 'close', this.confirmSaveBeforeClose, this);


Here the closeBtn event works fine but the problem comes only with the default windows close option.


Can someone give me an idea of how I can point to the method in the contoller when the user clicks on the [x] button as well.

Thanks..






Confirmation message to save changes before closing a window

Aucun commentaire:

Enregistrer un commentaire