Skip to content

Instantly share code, notes, and snippets.

@joariasl
Last active August 29, 2015 14:17
Show Gist options
  • Save joariasl/aee1f811383cdad7abed to your computer and use it in GitHub Desktop.
Save joariasl/aee1f811383cdad7abed to your computer and use it in GitHub Desktop.
/**
* 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