Last active
August 29, 2015 14:17
-
-
Save joariasl/aee1f811383cdad7abed to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Add confirm message to Window | |
* @param {Ext.window.Window} win | |
* @returns {Boolean} | |
*/ | |
windowCloseConfirm: function(win) { | |
// Dado a que no es asíncrono | |
if(win.closeConfirm){ | |
win.closeConfirm = false;// Revertir estado para no mantener confirmación | |
return true; | |
} | |
Ext.Msg.confirm( | |
'Confirmar', | |
'Perderá los cambios que no haya guardado', | |
function(btn) { | |
if(btn === 'yes'){ | |
win.closeConfirm = true; | |
win.close();// Debe volver a llamarse a función, ya que no es asíncrono | |
} | |
} | |
); | |
// Always cancel closing if we get here | |
return false; | |
} | |
/* How use */ | |
Ext.create('Ext.window.Window', { | |
title: 'Window', | |
layout: 'fit', | |
constrain: true, | |
closable: true, | |
//resizable: false, | |
maximizable: true, | |
width: 800, | |
//animateTarget: this, | |
items: [ ], | |
listeners: { | |
beforeclose: windowCloseConfirm | |
} | |
}).show(); | |
/* or */ | |
// ... | |
listeners: { | |
beforeclose: function(win){ | |
if(this.down('form').isDirty()){// Check form is changed to show confirm | |
return windowCloseConfirm(win); | |
} | |
} | |
} | |
// ... |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment