button/Button.js: imported from pve-manager

This commit is contained in:
Dietmar Maurer 2017-02-25 14:35:29 +01:00
parent c2ea01377e
commit d1661fde3f
2 changed files with 77 additions and 0 deletions

View File

@ -24,6 +24,7 @@ JSSRC= \
form/TextField.js \
form/Checkbox.js \
form/KVComboBox.js \
button/Button.js \
grid/ObjectGrid.js \
grid/PendingObjectGrid.js \
panel/InputPanel.js \

76
button/Button.js Normal file
View File

@ -0,0 +1,76 @@
/* Button features:
* - observe selection changes to enable/disable the button using enableFn()
* - pop up confirmation dialog using confirmMsg()
*/
Ext.define('Proxmox.button.Button', {
extend: 'Ext.button.Button',
alias: 'widget.proxmoxButton',
// the selection model to observe
selModel: undefined,
// if 'false' handler will not be called (button disabled)
enableFn: function(record) { },
// function(record) or text
confirmMsg: false,
// take special care in confirm box (select no as default).
dangerous: false,
initComponent: function() {
/*jslint confusion: true */
var me = this;
if (me.handler) {
me.realHandler = me.handler;
me.handler = function(button, event) {
var rec, msg;
if (me.selModel) {
rec = me.selModel.getSelection()[0];
if (!rec || (me.enableFn(rec) === false)) {
return;
}
}
if (me.confirmMsg) {
msg = me.confirmMsg;
if (Ext.isFunction(me.confirmMsg)) {
msg = me.confirmMsg(rec);
}
Ext.MessageBox.defaultButton = me.dangerous ? 2 : 1;
Ext.Msg.show({
title: gettext('Confirm'),
icon: me.dangerous ? Ext.Msg.WARNING : Ext.Msg.QUESTION,
msg: msg,
buttons: Ext.Msg.YESNO,
callback: function(btn) {
if (btn !== 'yes') {
return;
}
me.realHandler(button, event, rec);
}
});
} else {
me.realHandler(button, event, rec);
}
};
}
me.callParent();
if (me.selModel) {
me.mon(me.selModel, "selectionchange", function() {
var rec = me.selModel.getSelection()[0];
if (!rec || (me.enableFn(rec) === false)) {
me.setDisabled(true);
} else {
me.setDisabled(false);
}
});
}
}
});