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