]>
git.proxmox.com Git - proxmox-widget-toolkit.git/blob - button/Button.js
0d65d57f52846f1b19205dd2186431c24f9f8b3e
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
) { },
15 // function(record) or text
18 // take special care in confirm box (select no as default).
21 initComponent: function() {
22 /*jslint confusion: true */
28 // Note: me.realHandler may be a string (see named scopes)
29 var realHandler
= me
.handler
;
31 me
.handler = function(button
, event
) {
34 rec
= me
.selModel
.getSelection()[0];
35 if (!rec
|| (me
.enableFn(rec
) === false)) {
42 if (Ext
.isFunction(me
.confirmMsg
)) {
43 msg
= me
.confirmMsg(rec
);
45 Ext
.MessageBox
.defaultButton
= me
.dangerous
? 2 : 1;
47 title
: gettext('Confirm'),
48 icon
: me
.dangerous
? Ext
.Msg
.WARNING
: Ext
.Msg
.QUESTION
,
50 buttons
: Ext
.Msg
.YESNO
,
51 defaultFocus
: me
.dangerous
? 'no' : 'yes',
52 callback: function(btn
) {
56 Ext
.callback(realHandler
, me
.scope
, [button
, event
, rec
], 0, me
);
60 Ext
.callback(realHandler
, me
.scope
, [button
, event
, rec
], 0, me
);
67 if (!me
.selModel
&& me
.selModel
!== null) {
68 var grid
= me
.up('grid');
69 if (grid
&& grid
.selModel
) {
70 me
.selModel
= grid
.selModel
;
74 if (me
.waitMsgTarget
=== true) {
75 var grid
= me
.up('grid');
77 me
.waitMsgTarget
= grid
;
79 throw "unable to find waitMsgTarget";
85 me
.mon(me
.selModel
, "selectionchange", function() {
86 var rec
= me
.selModel
.getSelection()[0];
87 if (!rec
|| (me
.enableFn(rec
) === false)) {
90 me
.setDisabled(false);
98 Ext
.define('Proxmox.button.StdRemoveButton', {
99 extend
: 'Proxmox.button.Button',
100 alias
: 'widget.proxmoxStdRemoveButton',
102 text
: gettext('Remove'),
110 getUrl: function(rec
) {
113 return me
.baseurl
+ '/' + rec
.getId();
116 // also works with names scopes
117 callback: function(options
, success
, response
) {},
119 getRecordName: function(rec
) { return rec
.getId() },
121 confirmMsg: function (rec
) {
124 var name
= me
.getRecordName(rec
);
125 return Ext
.String
.format(
126 gettext('Are you sure you want to remove entry {0}'),
130 handler: function(btn
, event
, rec
) {
133 Proxmox
.Utils
.API2Request({
136 waitMsgTarget
: me
.waitMsgTarget
,
137 callback: function(options
, success
, response
) {
138 Ext
.callback(me
.callback
, me
.scope
, [options
, success
, response
], 0, me
);
140 failure: function (response
, opts
) {
141 Ext
.Msg
.alert(gettext('Error'), response
.htmlStatus
);