Commit fe212ada authored by Dietmar Maurer's avatar Dietmar Maurer

implement our own button class

Button features:

- observe selection changes to enable/disable the button using enableFn()

- pop up confirmation dialog using confirmMsg()
parent 781dc419
......@@ -4,6 +4,7 @@ JSSRC= \
Utils.js \
Parser.js \
StateProvider.js \
button/Button.js \
qemu/SendKeyMenu.js \
VNCConsole.js \
data/TimezoneStore.js \
......
/* Button features:
* - observe selection changes to enable/disable the button using enableFn()
* - pop up confirmation dialog using confirmMsg()
*/
Ext.define('PVE.button.Button', {
extend: 'Ext.button.Button',
alias: 'widget.pveButton',
// 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,
initComponent: function() {
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) {
var msg = me.confirmMsg;
if (Ext.isFunction(me.confirmMsg)) {
msg = me.confirmMsg(rec);
}
Ext.Msg.confirm('Confirmation', msg, 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];
var enable = me.enableFn(rec);
if (Ext.isDefined(enable)) {
me.setDisabled(!enable);
}
});
}
}
});
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment