mirror of
https://git.proxmox.com/git/pve-manager
synced 2025-06-03 22:58:50 +00:00

Extend 'Ext.menu.Item' with a simplified handler logic also used in 'PVE.button.Button'. If 'confirmMsg' config is set we wrap the defined handler in a confirm dialog, useful if the menu item just makes an API call and does not has an own (edit) window shown. In contrast to the 'pveButton' we do not have a selection model, enable function and the respective logic here. Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com> Acked-by: Dominik Csapak <d.csapak@proxmox.com>
47 lines
1.1 KiB
JavaScript
47 lines
1.1 KiB
JavaScript
Ext.define('PVE.menu.Item', {
|
|
extend: 'Ext.menu.Item',
|
|
alias: 'widget.pveMenuItem',
|
|
|
|
// set to wrap the handler callback in a confirm dialog showing this text
|
|
confirmMsg: false,
|
|
|
|
// set to focus 'No' instead of 'Yes' button and show a warning symbol
|
|
dangerous: false,
|
|
|
|
initComponent: function() {
|
|
var me = this;
|
|
|
|
if (me.handler) {
|
|
me.setHandler(me.handler, me.scope);
|
|
}
|
|
|
|
me.callParent();
|
|
},
|
|
|
|
setHandler: function(fn, scope) {
|
|
var me = this;
|
|
me.scope = scope;
|
|
me.handler = function(button, e) {
|
|
var rec, msg;
|
|
if (me.confirmMsg) {
|
|
msg = me.confirmMsg;
|
|
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,
|
|
defaultFocus: me.dangerous ? 'no' : 'yes',
|
|
callback: function(btn) {
|
|
if (btn === 'yes') {
|
|
Ext.callback(fn, me.scope, [me, e], 0, me);
|
|
}
|
|
}
|
|
});
|
|
} else {
|
|
Ext.callback(fn, me.scope, [me, e], 0, me);
|
|
}
|
|
};
|
|
}
|
|
});
|