]>
git.proxmox.com Git - proxmox-widget-toolkit.git/blob - button/Button.js
2 * - observe selection changes to enable/disable the button using enableFn()
3 * - pop up confirmation dialog using confirmMsg()
5 Ext
.define('Proxmox.button.Button', {
6 extend
: 'Ext.button.Button',
7 alias
: 'widget.proxmoxButton',
9 // the selection model to observe
12 // if 'false' handler will not be called (button disabled)
13 enableFn: function(record
) {
14 // return undefined by default
17 // function(record) or text
20 // take special care in confirm box (select no as default).
23 // is used to get the parent container for its selection model
26 initComponent: function() {
30 // Note: me.realHandler may be a string (see named scopes)
31 let realHandler
= me
.handler
;
33 me
.handler = function(button
, event
) {
36 rec
= me
.selModel
.getSelection()[0];
37 if (!rec
|| me
.enableFn(rec
) === false) {
44 if (Ext
.isFunction(me
.confirmMsg
)) {
45 msg
= me
.confirmMsg(rec
);
47 Ext
.MessageBox
.defaultButton
= me
.dangerous
? 2 : 1;
49 title
: gettext('Confirm'),
50 icon
: me
.dangerous
? Ext
.Msg
.WARNING
: Ext
.Msg
.QUESTION
,
52 buttons
: Ext
.Msg
.YESNO
,
53 defaultFocus
: me
.dangerous
? 'no' : 'yes',
54 callback: function(btn
) {
58 Ext
.callback(realHandler
, me
.scope
, [button
, event
, rec
], 0, me
);
62 Ext
.callback(realHandler
, me
.scope
, [button
, event
, rec
], 0, me
);
70 if (!me
.selModel
&& me
.selModel
!== null && me
.selModel
!== false) {
71 let parent
= me
.up(me
.parentXType
);
72 if (parent
&& parent
.selModel
) {
73 me
.selModel
= parent
.selModel
;
77 if (me
.waitMsgTarget
=== true) {
80 me
.waitMsgTarget
= grid
;
82 throw "unable to find waitMsgTarget";
87 me
.mon(me
.selModel
, "selectionchange", function() {
88 let rec
= me
.selModel
.getSelection()[0];
89 if (!rec
|| me
.enableFn(rec
) === false) {
92 me
.setDisabled(false);
100 Ext
.define('Proxmox.button.StdRemoveButton', {
101 extend
: 'Proxmox.button.Button',
102 alias
: 'widget.proxmoxStdRemoveButton',
104 text
: gettext('Remove'),
108 // time to wait for removal task to finish
115 getUrl: function(rec
) {
119 return me
.baseurl
+ '/' + rec
.getId();
125 // also works with names scopes
126 callback: function(options
, success
, response
) {
127 // do nothing by default
130 getRecordName
: (rec
) => rec
.getId(),
132 confirmMsg: function(rec
) {
135 let name
= me
.getRecordName(rec
);
136 return Ext
.String
.format(gettext('Are you sure you want to remove entry {0}'), `'${name}'`);
139 handler: function(btn
, event
, rec
) {
142 let url
= me
.getUrl(rec
);
144 if (typeof me
.delay
!== 'undefined' && me
.delay
>= 0) {
145 url
+= "?delay=" + me
.delay
;
148 Proxmox
.Utils
.API2Request({
151 waitMsgTarget
: me
.waitMsgTarget
,
152 callback: function(options
, success
, response
) {
153 Ext
.callback(me
.callback
, me
.scope
, [options
, success
, response
], 0, me
);
155 failure: function(response
, opts
) {
156 Ext
.Msg
.alert(gettext('Error'), response
.htmlStatus
);
160 initComponent: function() {
163 // enable by default if no seleModel is there and disabled not set
164 if (me
.initialConfig
.disabled
=== undefined &&
165 (me
.selModel
=== null || me
.selModel
=== false)) {