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