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