]>
Commit | Line | Data |
---|---|---|
9afdea76 TL |
1 | // Pop-up a message window where the user has to manually enter the resource ID to enable the |
2 | // destroy confirmation button to ensure that they got the correct resource selected for. | |
8d86570c HL |
3 | Ext.define('Proxmox.window.SafeDestroy', { |
4 | extend: 'Ext.window.Window', | |
cca5fa0a | 5 | alias: 'widget.proxmoxSafeDestroy', |
8d86570c HL |
6 | |
7 | title: gettext('Confirm'), | |
8 | modal: true, | |
9 | buttonAlign: 'center', | |
10 | bodyPadding: 10, | |
11 | width: 450, | |
90cb5faf | 12 | layout: { type: 'hbox' }, |
8d86570c HL |
13 | defaultFocus: 'confirmField', |
14 | showProgress: false, | |
15 | ||
14889076 FE |
16 | additionalItems: [], |
17 | ||
68152254 DC |
18 | // gets called if we have a progress bar or taskview and it detected that |
19 | // the task finished. function(success) | |
20 | taskDone: Ext.emptyFn, | |
21 | ||
22 | // gets called when the api call is finished, right at the beginning | |
23 | // function(success, response, options) | |
24 | apiCallDone: Ext.emptyFn, | |
25 | ||
8d86570c HL |
26 | config: { |
27 | item: { | |
28 | id: undefined, | |
8d86570c HL |
29 | }, |
30 | url: undefined, | |
12159d2c | 31 | note: undefined, |
b8b160d6 | 32 | taskName: undefined, |
90cb5faf | 33 | params: {}, |
8d86570c HL |
34 | }, |
35 | ||
36 | getParams: function() { | |
cbb36e75 | 37 | let me = this; |
2b1f7bb0 | 38 | |
8d86570c HL |
39 | if (Ext.Object.isEmpty(me.params)) { |
40 | return ''; | |
41 | } | |
42 | return '?' + Ext.Object.toQueryString(me.params); | |
43 | }, | |
44 | ||
45 | controller: { | |
46 | ||
47 | xclass: 'Ext.app.ViewController', | |
48 | ||
49 | control: { | |
50 | 'field[name=confirm]': { | |
51 | change: function(f, value) { | |
cbb36e75 HL |
52 | const view = this.getView(); |
53 | const removeButton = this.lookupReference('removeButton'); | |
8d86570c HL |
54 | if (value === view.getItem().id.toString()) { |
55 | removeButton.enable(); | |
56 | } else { | |
57 | removeButton.disable(); | |
58 | } | |
59 | }, | |
90cb5faf | 60 | specialkey: function(field, event) { |
cbb36e75 | 61 | const removeButton = this.lookupReference('removeButton'); |
90cb5faf | 62 | if (!removeButton.isDisabled() && event.getKey() === event.ENTER) { |
8d86570c HL |
63 | removeButton.fireEvent('click', removeButton, event); |
64 | } | |
90cb5faf | 65 | }, |
8d86570c HL |
66 | }, |
67 | 'button[reference=removeButton]': { | |
68 | click: function() { | |
cbb36e75 | 69 | const view = this.getView(); |
8d86570c HL |
70 | Proxmox.Utils.API2Request({ |
71 | url: view.getUrl() + view.getParams(), | |
72 | method: 'DELETE', | |
73 | waitMsgTarget: view, | |
74 | failure: function(response, opts) { | |
68152254 | 75 | view.apiCallDone(false, response, opts); |
8d86570c HL |
76 | view.close(); |
77 | Ext.Msg.alert('Error', response.htmlStatus); | |
78 | }, | |
79 | success: function(response, options) { | |
cbb36e75 | 80 | const hasProgressBar = !!(view.showProgress && |
90cb5faf | 81 | response.result.data); |
8d86570c | 82 | |
68152254 DC |
83 | view.apiCallDone(true, response, options); |
84 | ||
8d86570c HL |
85 | if (hasProgressBar) { |
86 | // stay around so we can trigger our close events | |
87 | // when background action is completed | |
88 | view.hide(); | |
89 | ||
cbb36e75 HL |
90 | const upid = response.result.data; |
91 | const win = Ext.create('Proxmox.window.TaskProgress', { | |
8d86570c | 92 | upid: upid, |
68152254 | 93 | taskDone: view.taskDone, |
8d86570c | 94 | listeners: { |
90cb5faf | 95 | destroy: function() { |
8d86570c | 96 | view.close(); |
90cb5faf HL |
97 | }, |
98 | }, | |
8d86570c HL |
99 | }); |
100 | win.show(); | |
101 | } else { | |
102 | view.close(); | |
103 | } | |
90cb5faf | 104 | }, |
8d86570c | 105 | }); |
90cb5faf HL |
106 | }, |
107 | }, | |
108 | }, | |
8d86570c HL |
109 | }, |
110 | ||
8d86570c HL |
111 | buttons: [ |
112 | { | |
113 | reference: 'removeButton', | |
114 | text: gettext('Remove'), | |
90cb5faf HL |
115 | disabled: true, |
116 | }, | |
8d86570c HL |
117 | ], |
118 | ||
90cb5faf | 119 | initComponent: function() { |
cbb36e75 | 120 | let me = this; |
8d86570c | 121 | |
14889076 FE |
122 | me.items = [ |
123 | { | |
124 | xtype: 'component', | |
66cc6d92 TL |
125 | cls: [ |
126 | Ext.baseCSSPrefix + 'message-box-icon', | |
127 | Ext.baseCSSPrefix + 'message-box-warning', | |
128 | Ext.baseCSSPrefix + 'dlg-icon', | |
129 | ], | |
14889076 FE |
130 | }, |
131 | { | |
132 | xtype: 'container', | |
133 | flex: 1, | |
134 | layout: { | |
135 | type: 'vbox', | |
136 | align: 'stretch', | |
137 | }, | |
138 | items: [ | |
139 | { | |
140 | xtype: 'component', | |
141 | reference: 'messageCmp', | |
142 | }, | |
143 | { | |
144 | itemId: 'confirmField', | |
145 | reference: 'confirmField', | |
146 | xtype: 'textfield', | |
147 | name: 'confirm', | |
148 | labelWidth: 300, | |
149 | hideTrigger: true, | |
150 | allowBlank: false, | |
151 | }, | |
f2d18cd7 TL |
152 | ] |
153 | .concat(me.additionalItems) | |
154 | .concat([ | |
14889076 FE |
155 | { |
156 | xtype: 'container', | |
157 | reference: 'noteContainer', | |
158 | flex: 1, | |
159 | hidden: true, | |
160 | layout: { | |
161 | type: 'vbox', | |
14889076 | 162 | }, |
14889076 FE |
163 | items: [ |
164 | { | |
165 | xtype: 'component', | |
166 | reference: 'noteCmp', | |
cd7e37fa | 167 | userCls: 'pmx-hint', |
14889076 FE |
168 | }, |
169 | ], | |
170 | }, | |
171 | ]), | |
172 | }, | |
173 | ]; | |
174 | ||
8d86570c HL |
175 | me.callParent(); |
176 | ||
f2d18cd7 TL |
177 | const itemId = me.getItem().id; |
178 | if (!Ext.isDefined(itemId)) { | |
8d86570c HL |
179 | throw "no ID specified"; |
180 | } | |
181 | ||
12159d2c | 182 | if (Ext.isDefined(me.getNote())) { |
f2d18cd7 | 183 | me.lookupReference('noteCmp').setHtml(`<span title="${me.getNote()}">${me.getNote()}</span>`); |
12159d2c HL |
184 | const noteContainer = me.lookupReference('noteContainer'); |
185 | noteContainer.setHidden(false); | |
186 | noteContainer.setDisabled(false); | |
187 | } | |
188 | ||
f2d18cd7 TL |
189 | let taskName = me.getTaskName(); |
190 | if (Ext.isDefined(taskName)) { | |
191 | me.lookupReference('messageCmp').setHtml( | |
192 | Proxmox.Utils.format_task_description(taskName, itemId), | |
193 | ); | |
8d86570c | 194 | } else { |
b8b160d6 | 195 | throw "no task name specified"; |
8d86570c HL |
196 | } |
197 | ||
f2d18cd7 TL |
198 | me.lookupReference('confirmField') |
199 | .setFieldLabel(`${gettext('Please enter the ID to confirm')} (${itemId})`); | |
90cb5faf | 200 | }, |
8d86570c | 201 | }); |