]>
Commit | Line | Data |
---|---|---|
32f469f3 EK |
1 | /* Popup a message window |
2 | * where the user has to manually enter the ressource ID | |
3 | * to enable the destroy button | |
4 | */ | |
5 | Ext.define('PVE.window.SafeDestroy', { | |
6 | extend: 'Ext.window.Window', | |
7 | alias: 'widget.pveSafeDestroy', | |
bcecf280 | 8 | |
16152937 | 9 | title: gettext('Confirm'), |
32f469f3 EK |
10 | modal: true, |
11 | buttonAlign: 'center', | |
bcecf280 DM |
12 | bodyPadding: 10, |
13 | width: 450, | |
ec0bd652 | 14 | layout: { type:'hbox' }, |
7b572e6d | 15 | defaultFocus: 'confirmField', |
bcecf280 | 16 | |
bcecf280 DM |
17 | config: { |
18 | item: { | |
19 | id: undefined, | |
20 | type: undefined | |
21 | }, | |
22 | url: undefined | |
23 | }, | |
24 | ||
bcecf280 DM |
25 | controller: { |
26 | ||
27 | xclass: 'Ext.app.ViewController', | |
28 | ||
29 | control: { | |
30 | 'field[name=confirm]': { | |
31 | change: function(f, value) { | |
32 | var view = this.getView(); | |
33 | var removeButton = this.lookupReference('removeButton'); | |
34 | if (value === view.getItem().id) { | |
35 | removeButton.enable(); | |
36 | } else { | |
37 | removeButton.disable(); | |
38 | } | |
7b572e6d EK |
39 | }, |
40 | specialkey: function (field, event) { | |
41 | var removeButton = this.lookupReference('removeButton'); | |
42 | if (!removeButton.isDisabled() && event.getKey() == event.ENTER) { | |
43 | removeButton.fireEvent('click', removeButton, event); | |
44 | } | |
bcecf280 DM |
45 | } |
46 | }, | |
7667066d | 47 | 'button[reference=removeButton]': { |
bcecf280 DM |
48 | click: function() { |
49 | var view = this.getView(); | |
50 | PVE.Utils.API2Request({ | |
51 | url: view.getUrl(), | |
52 | method: 'DELETE', | |
53 | waitMsgTarget: view, | |
54 | failure: function(response, opts) { | |
55 | Ext.Msg.alert('Error', response.htmlStatus); | |
56 | }, | |
57 | callback: function() { | |
58 | view.close(); | |
59 | } | |
60 | }); | |
61 | } | |
62 | } | |
63 | } | |
64 | }, | |
32f469f3 EK |
65 | |
66 | items: [ | |
fd8a2eea | 67 | { |
bcecf280 DM |
68 | xtype: 'component', |
69 | cls: [ Ext.baseCSSPrefix + 'message-box-icon', | |
70 | Ext.baseCSSPrefix + 'message-box-warning', | |
22f2f9d6 | 71 | Ext.baseCSSPrefix + 'dlg-icon'] |
bcecf280 DM |
72 | }, |
73 | { | |
fd8a2eea | 74 | xtype: 'container', |
bcecf280 | 75 | flex: 1, |
fd8a2eea DM |
76 | layout: { |
77 | type: 'vbox', | |
78 | align: 'stretch' | |
79 | }, | |
80 | items: [ | |
81 | { | |
bcecf280 | 82 | xtype: 'component', |
763ec2ec | 83 | reference: 'messageCmp' |
fd8a2eea | 84 | }, |
32f469f3 | 85 | { |
7b572e6d | 86 | itemId: 'confirmField', |
763ec2ec | 87 | reference: 'confirmField', |
fd8a2eea | 88 | xtype: 'numberfield', |
bcecf280 DM |
89 | name: 'confirm', |
90 | labelWidth: 300, | |
bcecf280 DM |
91 | hideTrigger: true, |
92 | allowBlank: false | |
32f469f3 | 93 | } |
22f2f9d6 | 94 | ] |
fd8a2eea DM |
95 | } |
96 | ], | |
32f469f3 EK |
97 | buttons: [ |
98 | { | |
bcecf280 | 99 | reference: 'removeButton', |
32f469f3 | 100 | text: gettext('Remove'), |
bcecf280 | 101 | disabled: true |
32f469f3 | 102 | } |
763ec2ec DM |
103 | ], |
104 | ||
105 | initComponent : function() { | |
106 | var me = this; | |
107 | ||
108 | me.callParent(); | |
109 | ||
110 | var item = me.getItem(); | |
111 | ||
112 | if (!Ext.isDefined(item.id)) { | |
113 | throw "no ID specified"; | |
114 | } | |
115 | ||
116 | if (!Ext.isDefined(item.type)) { | |
117 | throw "no VM type specified"; | |
118 | } | |
119 | ||
120 | var messageCmp = me.lookupReference('messageCmp'); | |
121 | var msg; | |
122 | ||
123 | if (item.type === 'VM') { | |
124 | msg = PVE.Utils.format_task_description('qmdestroy', item.id); | |
125 | } else if (item.type === 'CT') { | |
126 | msg = PVE.Utils.format_task_description('vzdestroy', item.id); | |
127 | } else { | |
128 | throw "unknown VM type specified"; | |
129 | } | |
130 | ||
131 | messageCmp.setHtml(msg); | |
132 | ||
133 | var confirmField = me.lookupReference('confirmField'); | |
134 | msg = gettext('Please enter the ID to confirm') + | |
135 | ' (' + item.id + ')'; | |
136 | confirmField.setFieldLabel(msg); | |
137 | } | |
fd8a2eea | 138 | }); |