]>
Commit | Line | Data |
---|---|---|
89796c1a DM |
1 | Ext.define('Proxmox.panel.InputPanel', { |
2 | extend: 'Ext.panel.Panel', | |
3 | alias: ['widget.inputpanel'], | |
4 | listeners: { | |
5 | activate: function() { | |
6 | // notify owning container that it should display a help button | |
7 | if (this.onlineHelp) { | |
4b23ab88 | 8 | Ext.GlobalEvents.fireEvent('proxmoxShowHelp', this.onlineHelp); |
89796c1a DM |
9 | } |
10 | }, | |
11 | deactivate: function() { | |
12 | if (this.onlineHelp) { | |
4b23ab88 | 13 | Ext.GlobalEvents.fireEvent('proxmoxHideHelp', this.onlineHelp); |
89796c1a | 14 | } |
01031528 | 15 | }, |
89796c1a DM |
16 | }, |
17 | border: false, | |
18 | ||
19 | // override this with an URL to a relevant chapter of the pve manual | |
20 | // setting this will display a help button in our parent panel | |
21 | onlineHelp: undefined, | |
22 | ||
33a4fc35 DC |
23 | // will be set if the inputpanel has advanced items |
24 | hasAdvanced: false, | |
25 | ||
26 | // if the panel has advanced items, | |
27 | // this will determine if they are shown by default | |
28 | showAdvanced: false, | |
29 | ||
89796c1a DM |
30 | // overwrite this to modify submit data |
31 | onGetValues: function(values) { | |
32 | return values; | |
33 | }, | |
34 | ||
35 | getValues: function(dirtyOnly) { | |
05a977a2 | 36 | let me = this; |
89796c1a DM |
37 | |
38 | if (Ext.isFunction(me.onGetValues)) { | |
39 | dirtyOnly = false; | |
40 | } | |
41 | ||
05a977a2 | 42 | let values = {}; |
89796c1a DM |
43 | |
44 | Ext.Array.each(me.query('[isFormField]'), function(field) { | |
68689d73 TL |
45 | if (!dirtyOnly || field.isDirty()) { |
46 | Proxmox.Utils.assemble_field_data(values, field.getSubmitData()); | |
89796c1a DM |
47 | } |
48 | }); | |
49 | ||
50 | return me.onGetValues(values); | |
51 | }, | |
52 | ||
33a4fc35 | 53 | setAdvancedVisible: function(visible) { |
05a977a2 TL |
54 | let me = this; |
55 | let advItems = me.getComponent('advancedContainer'); | |
33a4fc35 DC |
56 | if (advItems) { |
57 | advItems.setVisible(visible); | |
58 | } | |
59 | }, | |
60 | ||
89796c1a | 61 | setValues: function(values) { |
05a977a2 | 62 | let me = this; |
89796c1a | 63 | |
05a977a2 | 64 | let form = me.up('form'); |
89796c1a DM |
65 | |
66 | Ext.iterate(values, function(fieldId, val) { | |
50e8bf44 TL |
67 | let fields = me.query('[isFormField][name=' + fieldId + ']'); |
68 | for (const field of fields) { | |
69 | if (field) { | |
70 | field.setValue(val); | |
71 | if (form.trackResetOnLoad) { | |
72 | field.resetOriginalValue(); | |
73 | } | |
68689d73 TL |
74 | } |
75 | } | |
89796c1a DM |
76 | }); |
77 | }, | |
78 | ||
bcc48f06 DJ |
79 | /** |
80 | * inputpanel, vbox | |
81 | * +---------------------------------------------------------------------+ | |
82 | * | columnT | | |
83 | * +---------------------------------------------------------------------+ | |
84 | * | container, hbox | | |
85 | * | +---------------+---------------+---------------+---------------+ | | |
86 | * | | column1 | column2 | column3 | column4 | | | |
87 | * | | panel, anchor | panel, anchor | panel, anchor | panel, anchor | | | |
88 | * | +---------------+---------------+---------------+---------------+ | | |
89 | * +---------------------------------------------------------------------+ | |
90 | * | columnB | | |
91 | * +---------------------------------------------------------------------+ | |
92 | */ | |
89796c1a | 93 | initComponent: function() { |
05a977a2 | 94 | let me = this; |
89796c1a | 95 | |
05a977a2 | 96 | let items; |
89796c1a DM |
97 | |
98 | if (me.items) { | |
89796c1a DM |
99 | items = [ |
100 | { | |
89796c1a | 101 | layout: 'anchor', |
01031528 TL |
102 | items: me.items, |
103 | }, | |
89796c1a DM |
104 | ]; |
105 | me.items = undefined; | |
cc315e82 | 106 | } else if (me.column4) { |
455f5fe5 TL |
107 | items = []; |
108 | if (me.columnT) { | |
109 | items.push({ | |
110 | padding: '0 0 0 0', | |
111 | layout: 'anchor', | |
112 | items: me.columnT, | |
113 | }); | |
114 | } | |
115 | items.push( | |
cc315e82 | 116 | { |
71d53165 AL |
117 | layout: 'hbox', |
118 | defaults: { | |
119 | border: false, | |
120 | layout: 'anchor', | |
121 | flex: 1, | |
122 | }, | |
123 | items: [ | |
124 | { | |
125 | padding: '0 10 0 0', | |
126 | items: me.column1, | |
127 | }, | |
128 | { | |
129 | padding: '0 10 0 0', | |
130 | items: me.column2, | |
131 | }, | |
132 | { | |
133 | padding: '0 10 0 0', | |
134 | items: me.column3, | |
135 | }, | |
136 | { | |
137 | padding: '0 0 0 10', | |
138 | items: me.column4, | |
139 | }, | |
140 | ], | |
01031528 | 141 | }, |
455f5fe5 | 142 | ); |
cc315e82 DM |
143 | if (me.columnB) { |
144 | items.push({ | |
cc315e82 DM |
145 | padding: '10 0 0 0', |
146 | layout: 'anchor', | |
01031528 | 147 | items: me.columnB, |
cc315e82 DM |
148 | }); |
149 | } | |
89796c1a | 150 | } else if (me.column1) { |
455f5fe5 TL |
151 | items = []; |
152 | if (me.columnT) { | |
153 | items.push({ | |
154 | padding: '0 0 10 0', | |
155 | layout: 'anchor', | |
156 | items: me.columnT, | |
157 | }); | |
158 | } | |
159 | items.push( | |
89796c1a | 160 | { |
71d53165 AL |
161 | layout: 'hbox', |
162 | defaults: { | |
163 | border: false, | |
164 | layout: 'anchor', | |
165 | flex: 1, | |
166 | }, | |
167 | items: [ | |
168 | { | |
169 | padding: '0 10 0 0', | |
170 | items: me.column1, | |
171 | }, | |
172 | { | |
173 | padding: '0 0 0 10', | |
174 | items: me.column2 || [], // allow empty column | |
175 | }, | |
176 | ], | |
01031528 | 177 | }, |
455f5fe5 | 178 | ); |
89796c1a DM |
179 | if (me.columnB) { |
180 | items.push({ | |
89796c1a DM |
181 | padding: '10 0 0 0', |
182 | layout: 'anchor', | |
01031528 | 183 | items: me.columnB, |
89796c1a DM |
184 | }); |
185 | } | |
186 | } else { | |
187 | throw "unsupported config"; | |
188 | } | |
189 | ||
05a977a2 | 190 | let advItems; |
33a4fc35 DC |
191 | if (me.advancedItems) { |
192 | advItems = [ | |
193 | { | |
33a4fc35 | 194 | layout: 'anchor', |
01031528 TL |
195 | items: me.advancedItems, |
196 | }, | |
33a4fc35 DC |
197 | ]; |
198 | me.advancedItems = undefined; | |
9beeadc7 | 199 | } else if (me.advancedColumn1 || me.advancedColumn2 || me.advancedColumnB) { |
33a4fc35 DC |
200 | advItems = [ |
201 | { | |
71d53165 AL |
202 | layout: { |
203 | type: 'hbox', | |
204 | align: 'begin', | |
205 | }, | |
206 | defaults: { | |
207 | border: false, | |
208 | layout: 'anchor', | |
209 | flex: 1, | |
210 | }, | |
211 | items: [ | |
212 | { | |
213 | padding: '0 10 0 0', | |
9beeadc7 | 214 | items: me.advancedColumn1 || [], // allow empty column |
71d53165 AL |
215 | }, |
216 | { | |
217 | padding: '0 0 0 10', | |
218 | items: me.advancedColumn2 || [], // allow empty column | |
219 | }, | |
220 | ], | |
01031528 | 221 | }, |
33a4fc35 DC |
222 | ]; |
223 | ||
224 | me.advancedColumn1 = undefined; | |
225 | me.advancedColumn2 = undefined; | |
226 | ||
227 | if (me.advancedColumnB) { | |
228 | advItems.push({ | |
33a4fc35 DC |
229 | padding: '10 0 0 0', |
230 | layout: 'anchor', | |
01031528 | 231 | items: me.advancedColumnB, |
33a4fc35 DC |
232 | }); |
233 | me.advancedColumnB = undefined; | |
234 | } | |
235 | } | |
236 | ||
237 | if (advItems) { | |
238 | me.hasAdvanced = true; | |
239 | advItems.unshift({ | |
33a4fc35 DC |
240 | xtype: 'box', |
241 | hidden: false, | |
242 | border: true, | |
243 | autoEl: { | |
01031528 TL |
244 | tag: 'hr', |
245 | }, | |
33a4fc35 DC |
246 | }); |
247 | items.push({ | |
33a4fc35 DC |
248 | xtype: 'container', |
249 | itemId: 'advancedContainer', | |
250 | hidden: !me.showAdvanced, | |
33a4fc35 | 251 | defaults: { |
01031528 | 252 | border: false, |
33a4fc35 | 253 | }, |
01031528 | 254 | items: advItems, |
33a4fc35 DC |
255 | }); |
256 | } | |
257 | ||
71a084c2 AL |
258 | Ext.apply(me, { |
259 | layout: { | |
260 | type: 'vbox', | |
261 | align: 'stretch', | |
262 | }, | |
263 | defaultType: 'container', | |
264 | items: items, | |
265 | }); | |
89796c1a DM |
266 | |
267 | me.callParent(); | |
01031528 | 268 | }, |
89796c1a | 269 | }); |