]> git.proxmox.com Git - proxmox-widget-toolkit.git/blame - src/panel/InputPanel.js
reader: JsonObject: whitespace fixes
[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
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
79 initComponent: function() {
05a977a2 80 let me = this;
89796c1a 81
05a977a2 82 let items;
89796c1a
DM
83
84 if (me.items) {
89796c1a
DM
85 items = [
86 {
89796c1a 87 layout: 'anchor',
01031528
TL
88 items: me.items,
89 },
89796c1a
DM
90 ];
91 me.items = undefined;
cc315e82 92 } else if (me.column4) {
455f5fe5
TL
93 items = [];
94 if (me.columnT) {
95 items.push({
96 padding: '0 0 0 0',
97 layout: 'anchor',
98 items: me.columnT,
99 });
100 }
101 items.push(
cc315e82 102 {
71d53165
AL
103 layout: 'hbox',
104 defaults: {
105 border: false,
106 layout: 'anchor',
107 flex: 1,
108 },
109 items: [
110 {
111 padding: '0 10 0 0',
112 items: me.column1,
113 },
114 {
115 padding: '0 10 0 0',
116 items: me.column2,
117 },
118 {
119 padding: '0 10 0 0',
120 items: me.column3,
121 },
122 {
123 padding: '0 0 0 10',
124 items: me.column4,
125 },
126 ],
01031528 127 },
455f5fe5 128 );
cc315e82
DM
129 if (me.columnB) {
130 items.push({
cc315e82
DM
131 padding: '10 0 0 0',
132 layout: 'anchor',
01031528 133 items: me.columnB,
cc315e82
DM
134 });
135 }
89796c1a 136 } else if (me.column1) {
455f5fe5
TL
137 items = [];
138 if (me.columnT) {
139 items.push({
140 padding: '0 0 10 0',
141 layout: 'anchor',
142 items: me.columnT,
143 });
144 }
145 items.push(
89796c1a 146 {
71d53165
AL
147 layout: 'hbox',
148 defaults: {
149 border: false,
150 layout: 'anchor',
151 flex: 1,
152 },
153 items: [
154 {
155 padding: '0 10 0 0',
156 items: me.column1,
157 },
158 {
159 padding: '0 0 0 10',
160 items: me.column2 || [], // allow empty column
161 },
162 ],
01031528 163 },
455f5fe5 164 );
89796c1a
DM
165 if (me.columnB) {
166 items.push({
89796c1a
DM
167 padding: '10 0 0 0',
168 layout: 'anchor',
01031528 169 items: me.columnB,
89796c1a
DM
170 });
171 }
172 } else {
173 throw "unsupported config";
174 }
175
05a977a2 176 let advItems;
33a4fc35
DC
177 if (me.advancedItems) {
178 advItems = [
179 {
33a4fc35 180 layout: 'anchor',
01031528
TL
181 items: me.advancedItems,
182 },
33a4fc35
DC
183 ];
184 me.advancedItems = undefined;
9beeadc7 185 } else if (me.advancedColumn1 || me.advancedColumn2 || me.advancedColumnB) {
33a4fc35
DC
186 advItems = [
187 {
71d53165
AL
188 layout: {
189 type: 'hbox',
190 align: 'begin',
191 },
192 defaults: {
193 border: false,
194 layout: 'anchor',
195 flex: 1,
196 },
197 items: [
198 {
199 padding: '0 10 0 0',
9beeadc7 200 items: me.advancedColumn1 || [], // allow empty column
71d53165
AL
201 },
202 {
203 padding: '0 0 0 10',
204 items: me.advancedColumn2 || [], // allow empty column
205 },
206 ],
01031528 207 },
33a4fc35
DC
208 ];
209
210 me.advancedColumn1 = undefined;
211 me.advancedColumn2 = undefined;
212
213 if (me.advancedColumnB) {
214 advItems.push({
33a4fc35
DC
215 padding: '10 0 0 0',
216 layout: 'anchor',
01031528 217 items: me.advancedColumnB,
33a4fc35
DC
218 });
219 me.advancedColumnB = undefined;
220 }
221 }
222
223 if (advItems) {
224 me.hasAdvanced = true;
225 advItems.unshift({
33a4fc35
DC
226 xtype: 'box',
227 hidden: false,
228 border: true,
229 autoEl: {
01031528
TL
230 tag: 'hr',
231 },
33a4fc35
DC
232 });
233 items.push({
33a4fc35
DC
234 xtype: 'container',
235 itemId: 'advancedContainer',
236 hidden: !me.showAdvanced,
33a4fc35 237 defaults: {
01031528 238 border: false,
33a4fc35 239 },
01031528 240 items: advItems,
33a4fc35
DC
241 });
242 }
243
71a084c2
AL
244 Ext.apply(me, {
245 layout: {
246 type: 'vbox',
247 align: 'stretch',
248 },
249 defaultType: 'container',
250 items: items,
251 });
89796c1a
DM
252
253 me.callParent();
01031528 254 },
89796c1a 255});