From 81244aa1feae4e1c3744228231e13267ca712742 Mon Sep 17 00:00:00 2001 From: Dietmar Maurer Date: Tue, 28 Mar 2017 13:00:11 +0200 Subject: [PATCH] button/Button.js: make it work with named scopes and add ability to bind to underlying grid automatically if no selModel specified. --- button/Button.js | 27 +++++++++++++++++++++++---- 1 file changed, 23 insertions(+), 4 deletions(-) diff --git a/button/Button.js b/button/Button.js index 6d55ea7..56bdd85 100644 --- a/button/Button.js +++ b/button/Button.js @@ -24,7 +24,9 @@ Ext.define('Proxmox.button.Button', { var me = this; if (me.handler) { - me.realHandler = me.handler; + + // Note: me.realHandler may be a string (see named scopes) + var realHandler = me.handler; me.handler = function(button, event) { var rec, msg; @@ -50,17 +52,31 @@ Ext.define('Proxmox.button.Button', { if (btn !== 'yes') { return; } - me.realHandler(button, event, rec); + Ext.callback(realHandler, me.scope, [button, event, rec], 0, me); } }); } else { - me.realHandler(button, event, rec); + Ext.callback(realHandler, me.scope, [button, event, rec], 0, me); } }; } me.callParent(); + if (!me.selModel) { + var grid = me.up('grid'); + if (grid && grid.selModel) { + me.selModel = grid.selModel; + if (me.waitMsgTarget === true) { + me.waitMsgTarget = grid; + } + } + } + + if (me.waitMsgTarget === true) { + throw "unable to find waitMsgTarget"; // no grid found + } + if (me.selModel) { me.mon(me.selModel, "selectionchange", function() { @@ -92,6 +108,7 @@ Ext.define('Proxmox.button.StdRemoveButton', { return me.baseurl + '/' + rec.getId(); }, + // also works with names scopes callback: function(options, success, response) {}, getRecordName: function(rec) { return rec.getId() }, @@ -112,7 +129,9 @@ Ext.define('Proxmox.button.StdRemoveButton', { url: me.getUrl(rec), method: 'DELETE', waitMsgTarget: me.waitMsgTarget, - callback: me.callback, + callback: function(options, success, response) { + Ext.callback(me.callback, me.scope, [options, success, response], 0, me); + }, failure: function (response, opts) { Ext.Msg.alert(gettext('Error'), response.htmlStatus); } -- 2.39.2