mirror of
https://git.proxmox.com/git/proxmox-widget-toolkit
synced 2025-05-30 16:49:06 +00:00
button/Button.js: imported from pve-manager
This commit is contained in:
parent
c2ea01377e
commit
d1661fde3f
1
Makefile
1
Makefile
@ -24,6 +24,7 @@ JSSRC= \
|
|||||||
form/TextField.js \
|
form/TextField.js \
|
||||||
form/Checkbox.js \
|
form/Checkbox.js \
|
||||||
form/KVComboBox.js \
|
form/KVComboBox.js \
|
||||||
|
button/Button.js \
|
||||||
grid/ObjectGrid.js \
|
grid/ObjectGrid.js \
|
||||||
grid/PendingObjectGrid.js \
|
grid/PendingObjectGrid.js \
|
||||||
panel/InputPanel.js \
|
panel/InputPanel.js \
|
||||||
|
76
button/Button.js
Normal file
76
button/Button.js
Normal 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);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
Loading…
Reference in New Issue
Block a user