ui: add PVE.menu.Item

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>
This commit is contained in:
Thomas Lamprecht 2017-10-17 11:48:02 +02:00 committed by Wolfgang Bumiller
parent 41e024ee43
commit e488f98182
2 changed files with 47 additions and 0 deletions

View File

@ -6,6 +6,7 @@ JSSRC= \
Parser.js \
StateProvider.js \
button/Button.js \
menu/MenuItem.js \
button/ConsoleButton.js \
button/Split.js \
button/HelpButton.js \

View File

@ -0,0 +1,46 @@
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);
}
};
}
});