@componyx/ui 0.0.0-stage → 1.0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/AppSkin/AppSkin.css +1268 -0
- package/AppSkin/AppSkin.js +2748 -0
- package/AppSkin/Themes/Default.css +241 -0
- package/Base/Base.js +3407 -0
- package/Base/ComponentIcons.css +66 -0
- package/Base/Font/ComponentIcons.woff +0 -0
- package/Base/Font/UI.woff +0 -0
- package/Base/Library.js +8432 -0
- package/Base/NavigationManager.js +462 -0
- package/Base/ResponsiveTemplates.js +371 -0
- package/Base/Sanitizer.js +288 -0
- package/Base/Themes/Default.css +255 -0
- package/Base/UI.css +618 -0
- package/Base/UIResourcePath.js +6 -0
- package/Bindary/Bindary.js +2011 -0
- package/Bindary/Modules/Connection.js +216 -0
- package/Bindary/Modules/Core.js +854 -0
- package/Bindary/Modules/DataUpdater.js +351 -0
- package/Bindary/Modules/ExpressionEngine.js +347 -0
- package/Bindary/Modules/ProxyManager.js +482 -0
- package/Bindary/Modules/Renderer.js +605 -0
- package/Bindary/Modules/Router.js +291 -0
- package/Bindary/Modules/Scroller.js +89 -0
- package/Bindary/Modules/Template.js +1273 -0
- package/BookmarkSpy/BookmarkSpy.js +430 -0
- package/Box/Box.css +36 -0
- package/Box/Box.js +1685 -0
- package/Button/Button.css +470 -0
- package/Button/Button.js +1398 -0
- package/Button/Themes/Default.css +200 -0
- package/Carousel/Carousel.css +273 -0
- package/Carousel/Carousel.js +607 -0
- package/ColorButton/ColorButton.css +39 -0
- package/ColorButton/ColorButton.js +336 -0
- package/ColorPicker/ColorPicker.css +359 -0
- package/ColorPicker/ColorPicker.js +972 -0
- package/ComboBox/ComboBox.css +357 -0
- package/ComboBox/ComboBox.js +2342 -0
- package/ComboBox/Themes/Default.css +23 -0
- package/DataPager/DataPager.css +72 -0
- package/DataPager/DataPager.js +674 -0
- package/DatePicker/DatePicker.css +227 -0
- package/DatePicker/DatePicker.js +1531 -0
- package/DatePicker/Themes/Default.css +26 -0
- package/Dialog/Dialog.css +106 -0
- package/Dialog/Dialog.js +572 -0
- package/Dialog/Themes/Default.css +10 -0
- package/Editor/Data/Emoji.json +8285 -0
- package/Editor/Data/Special.json +1042 -0
- package/Editor/Editor.css +1562 -0
- package/Editor/Editor.js +4058 -0
- package/Editor/Font/Editor.woff +0 -0
- package/Editor/Modules/ComponentFactory.js +565 -0
- package/Editor/Modules/ContentManager.js +748 -0
- package/Editor/Modules/DialogManager.js +1234 -0
- package/Editor/Modules/EventManager.js +458 -0
- package/Editor/Modules/Format.js +950 -0
- package/Editor/Modules/History.js +191 -0
- package/Editor/Modules/LayoutState.js +379 -0
- package/Editor/Modules/ListManager.js +296 -0
- package/Editor/Modules/MenuManager.js +388 -0
- package/Editor/Modules/NodeManager.js +681 -0
- package/Editor/Modules/ParagraphButtons.js +122 -0
- package/Editor/Modules/Resizer.js +176 -0
- package/Editor/Modules/SelectionRange.js +564 -0
- package/Editor/Modules/SourceViewBuilder.js +212 -0
- package/Editor/Modules/SymbolPicker.js +208 -0
- package/Editor/Modules/Table.js +2327 -0
- package/Editor/Modules/TableDialog.js +757 -0
- package/Editor/Modules/Toolbar.js +375 -0
- package/Editor/Modules/TooltipMenu.js +125 -0
- package/Editor/Modules/Utility.js +131 -0
- package/Editor/Themes/Default.css +204 -0
- package/FileUpload/FileUpload.css +156 -0
- package/FileUpload/FileUpload.js +898 -0
- package/FileUpload/Themes/Default.css +17 -0
- package/Form/Form.css +1934 -0
- package/Form/Form.js +4943 -0
- package/Form/Modules/ActionManager.js +368 -0
- package/Form/Modules/BuildPanelManager.js +319 -0
- package/Form/Modules/ComponentFactory.js +468 -0
- package/Form/Modules/ComponentPanel.js +265 -0
- package/Form/Modules/ConfigPanelManager.js +685 -0
- package/Form/Modules/DataBinder.js +602 -0
- package/Form/Modules/DataObserver.js +717 -0
- package/Form/Modules/Draggable.js +756 -0
- package/Form/Modules/OptionsPanel.js +342 -0
- package/Form/Modules/Renderer.js +1889 -0
- package/Form/Modules/RuleEngine.js +585 -0
- package/Form/Modules/RulesPanel.js +1158 -0
- package/Form/Modules/Types.js +1709 -0
- package/Form/Modules/ValidationManager.js +194 -0
- package/Form/Themes/Default.css +216 -0
- package/FormField/FormField.css +468 -0
- package/FormField/FormField.js +576 -0
- package/FormField/Themes/Default.css +99 -0
- package/Grid/Grid.css +544 -0
- package/Grid/Grid.js +3761 -0
- package/Grid/Themes/Default.css +43 -0
- package/LICENSE +126 -0
- package/MaskedTextBox/MaskedTextBox.css +28 -0
- package/MaskedTextBox/MaskedTextBox.js +642 -0
- package/MaskedTextBox/Themes/Default.css +6 -0
- package/Menu/Menu.css +328 -0
- package/Menu/Menu.js +2386 -0
- package/Menu/Themes/Default.css +24 -0
- package/NumericBox/NumericBox.css +120 -0
- package/NumericBox/NumericBox.js +984 -0
- package/PanelBar/PanelBar.css +123 -0
- package/PanelBar/PanelBar.js +505 -0
- package/PanelBar/Themes/Default.css +51 -0
- package/PieChart/PieChart.css +95 -0
- package/PieChart/PieChart.js +820 -0
- package/PieChart/Themes/Default.css +9 -0
- package/README.md +178 -3
- package/Slider/Slider.css +348 -0
- package/Slider/Slider.js +1306 -0
- package/Slider/Themes/Default.css +44 -0
- package/TabStrip/TabStrip.css +52 -0
- package/TabStrip/TabStrip.js +362 -0
- package/TabStrip/Themes/Default.css +35 -0
- package/TimePicker/Themes/Default.css +30 -0
- package/TimePicker/TimePicker.css +253 -0
- package/TimePicker/TimePicker.js +1485 -0
- package/TooltipManager/Themes/Default.css +21 -0
- package/TooltipManager/TooltipManager.css +227 -0
- package/TooltipManager/TooltipManager.js +791 -0
- package/Validator/Validator.css +54 -0
- package/Validator/Validator.js +2508 -0
- package/componyx.html-data.json +619 -0
- package/index.js +27 -0
- package/package.json +43 -4
- package/types/AppSkin.d.ts +842 -0
- package/types/Base.d.ts +1034 -0
- package/types/Bindary.d.ts +1196 -0
- package/types/BookmarkSpy.d.ts +112 -0
- package/types/Box.d.ts +374 -0
- package/types/Button.d.ts +455 -0
- package/types/Carousel.d.ts +136 -0
- package/types/ColorButton.d.ts +120 -0
- package/types/ColorPicker.d.ts +225 -0
- package/types/ComboBox.d.ts +507 -0
- package/types/DataPager.d.ts +152 -0
- package/types/DatePicker.d.ts +354 -0
- package/types/Dialog.d.ts +160 -0
- package/types/Editor.d.ts +1289 -0
- package/types/FileUpload.d.ts +206 -0
- package/types/Form.d.ts +3078 -0
- package/types/FormField.d.ts +204 -0
- package/types/Grid.d.ts +911 -0
- package/types/Library.d.ts +1899 -0
- package/types/MaskedTextBox.d.ts +91 -0
- package/types/Menu.d.ts +577 -0
- package/types/NumericBox.d.ts +310 -0
- package/types/PanelBar.d.ts +223 -0
- package/types/PieChart.d.ts +224 -0
- package/types/ResponsiveTemplates.d.ts +108 -0
- package/types/Slider.d.ts +227 -0
- package/types/TabStrip.d.ts +185 -0
- package/types/TimePicker.d.ts +265 -0
- package/types/TooltipManager.d.ts +178 -0
- package/types/UI.d.ts +29 -0
- package/types/Validator.d.ts +653 -0
- package/types/index.d.ts +59 -0
- package/ui.css +11783 -0
- package/ui.js +79477 -0
- package/ui.min.css +138 -0
- package/ui.min.js +264 -0
- package/ui.min.js.map +1 -0
|
@@ -0,0 +1,342 @@
|
|
|
1
|
+
/*! Componyx.UI | (c) E.H. Daanen / Componyx | BUSL-1.1 | componyx.com/license */
|
|
2
|
+
componyx.UI.form_modules = componyx.UI.form_modules || {};
|
|
3
|
+
|
|
4
|
+
componyx.UI.form_modules.OptionsPanel = class OptionsPanel
|
|
5
|
+
{
|
|
6
|
+
#updateOptionsTimerId;
|
|
7
|
+
constructor(form, configPanelManager)
|
|
8
|
+
{
|
|
9
|
+
this.form = form;
|
|
10
|
+
this.cf = form.componentFactory;
|
|
11
|
+
this.cpm = configPanelManager;
|
|
12
|
+
this.InputTypeOption = this.cpm.InputTypeOption;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
render(field)
|
|
16
|
+
{
|
|
17
|
+
const panelId = 'FieldOptionsPanel',
|
|
18
|
+
templateId = field.panelTemplates?.[panelId] ?? panelId,
|
|
19
|
+
panel = this.cpm.panelBar.panels.find(p => p.id === panelId),
|
|
20
|
+
contentEl = panel.contentElement,
|
|
21
|
+
idPrefix = `${this.form.id}_${panelId}_`,
|
|
22
|
+
hasDataSource = this.form.dataSources.some(ds => [ds.inputType].flat().includes(field.inputType)),
|
|
23
|
+
groups = [
|
|
24
|
+
['options'],
|
|
25
|
+
['dataSourceId', 'dataSourcePreview']
|
|
26
|
+
],
|
|
27
|
+
onChange = () =>
|
|
28
|
+
{
|
|
29
|
+
if ($lib(`#${idPrefix}optionsType_static_input`).checked)
|
|
30
|
+
{
|
|
31
|
+
this.form.getFields().find(f => f.id === field.id).dataSourceId = null;
|
|
32
|
+
this.form.dataObserver.shouldProcessChanges = true;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
this.#toggleFieldsDisplay(contentEl, idPrefix, 'optionsType', groups);
|
|
36
|
+
},
|
|
37
|
+
fields = [
|
|
38
|
+
{
|
|
39
|
+
id: 'optionsType', label: this.form.labels.fieldOptionsType, type: 'radio', name: 'optionsType',
|
|
40
|
+
config: { cssClass: this.cpm.getCssClass(this.cpm.classOption.FIELD_OPTIONS_TYPE) },
|
|
41
|
+
options: [
|
|
42
|
+
{ value: 'static', label: this.form.labels.fieldOptionsTypeStatic, checked: $lib.isEmpty(field.dataSourceId), events: { onchange: onChange } },
|
|
43
|
+
{ value: 'dataSource', label: this.form.labels.fieldOptionsTypeDataSource, checked: !$lib.isEmpty(field.dataSourceId), disabled: !hasDataSource, events: { onchange: onChange } }
|
|
44
|
+
],
|
|
45
|
+
disableDataBinding: true
|
|
46
|
+
}
|
|
47
|
+
],
|
|
48
|
+
previewComboId = `${idPrefix}dataSourcePreview_input`,
|
|
49
|
+
events = this.cpm.createBindingEvents(field);
|
|
50
|
+
|
|
51
|
+
if (hasDataSource)
|
|
52
|
+
{
|
|
53
|
+
const showing = !$lib.isEmpty(field.dataSourceId);
|
|
54
|
+
const dataSourceEvents = { ...events };
|
|
55
|
+
|
|
56
|
+
fields.push({
|
|
57
|
+
id: 'dataSourceId',
|
|
58
|
+
fieldElement: this.cpm.createDataSourceCombo(`${idPrefix}dataSourceId_input`, field.inputType, 'dataSourceId', dataSourceEvents),
|
|
59
|
+
config: { showing }
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
if (field.dataSourcePreview)
|
|
63
|
+
{
|
|
64
|
+
const previewConfig = showing ? this.cf.configureComboBox(field) : { disabled: true };
|
|
65
|
+
fields.push({
|
|
66
|
+
id: 'dataSourcePreview',
|
|
67
|
+
fieldElement: this.#createPreviewCombo(previewComboId, field, previewConfig),
|
|
68
|
+
config: { showing }
|
|
69
|
+
});
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
if (field.inputType !== this.InputTypeOption.COMBOBOX)
|
|
74
|
+
{
|
|
75
|
+
fields.push({
|
|
76
|
+
id: 'inlineOptions', label: this.form.labels.fieldInlineOptions, type: 'checkbox',
|
|
77
|
+
events: { onchange: (e) => { this.cpm.toggleFieldDisplay(idPrefix, 'optionWidth', e.target.checked); } },
|
|
78
|
+
config: { switch: true }
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
fields.push({
|
|
82
|
+
id: 'optionWidth', label: this.form.labels.fieldOptionWidth,
|
|
83
|
+
fieldElement: this.#createOptionWidthCombo(`${idPrefix}optionWidth`, events),
|
|
84
|
+
config: { showing: field.inlineOptions }
|
|
85
|
+
});
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
fields.push({
|
|
89
|
+
id: 'options',
|
|
90
|
+
fieldElement: this.#createOptions(field, panel),
|
|
91
|
+
config: { showing: $lib.isEmpty(field.dataSourceId) }
|
|
92
|
+
});
|
|
93
|
+
|
|
94
|
+
this.cpm.renderPanel(field, contentEl, fields, templateId, idPrefix);
|
|
95
|
+
this.cpm.bindProperties(field, contentEl);
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
#createOptionWidthCombo(id, events)
|
|
99
|
+
{
|
|
100
|
+
return this.cf.createComboBox(this.form, id, this.form.fieldOptionWidthComboBoxId, {
|
|
101
|
+
name: 'optionWidth',
|
|
102
|
+
placeholder: this.form.labels.comboBoxDefaultHint,
|
|
103
|
+
allowInput: false,
|
|
104
|
+
itemList: [{ id: '0', text: this.form.labels.fieldOptionWidthAuto, value: 'auto' },
|
|
105
|
+
{ id: '1', text: this.form.labels.fieldOptionWidth2PerRow, value: '50%' },
|
|
106
|
+
{ id: '2', text: this.form.labels.fieldOptionWidth3PerRow, value: '33%' },
|
|
107
|
+
{ id: '3', text: this.form.labels.fieldOptionWidth4PerRow, value: '25%' }],
|
|
108
|
+
events
|
|
109
|
+
}).element;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
#createPreviewCombo(id, field, config)
|
|
113
|
+
{
|
|
114
|
+
const comboBox = this.cf.createComboBox(this.form, id, this.form.previewComboBoxId,
|
|
115
|
+
{
|
|
116
|
+
name: 'dataSourcePreview',
|
|
117
|
+
allowInput: false,
|
|
118
|
+
_disableDataBinding: true,
|
|
119
|
+
_mustRender: false,
|
|
120
|
+
multiSelect: field.inputType === this.InputTypeOption.CHECKBOX || field.inputType === this.InputTypeOption.SWITCH || (field.componentSettings && field.componentSettings.multiSelect)
|
|
121
|
+
});
|
|
122
|
+
|
|
123
|
+
$lib.clone(comboBox, config, true, true, true, true, true, null);
|
|
124
|
+
comboBox.render();
|
|
125
|
+
|
|
126
|
+
return comboBox.element;
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
#createOptions(field, panel)
|
|
130
|
+
{
|
|
131
|
+
const isCheckBox = field.inputType === this.InputTypeOption.CHECKBOX || field.inputType === this.InputTypeOption.SWITCH,
|
|
132
|
+
isComboBox = field.inputType === this.InputTypeOption.COMBOBOX,
|
|
133
|
+
multiSelect = isCheckBox || (isComboBox && field.componentSettings && field.componentSettings.multiSelect),
|
|
134
|
+
grid = $lib.element(null, null, 'div', null, '', { className: this.cpm.getCssClass(this.cpm.classOption.FIELD_OPTIONS) }),
|
|
135
|
+
headerRow = $lib.element(grid, null, 'div', null, '', { className: this.cpm.getCssClass(this.cpm.classOption.FIELD_OPTIONS_HEADER) });
|
|
136
|
+
|
|
137
|
+
$lib.element(headerRow, null); // empty first cell
|
|
138
|
+
$lib.element(headerRow, null, 'div', this.form.labels.fieldOptionLabelHeader, { title: this.form.labels.fieldOptionLabelHeader });
|
|
139
|
+
$lib.element(headerRow, null, 'div', this.form.labels.fieldOptionValueHeader, { title: this.form.labels.fieldOptionValueHeader });
|
|
140
|
+
$lib.element(headerRow, null, 'div', this.form.labels.fieldOptionSelectedHeader, { title: this.form.labels.fieldOptionSelectedHeader });
|
|
141
|
+
$lib.element(headerRow, null, 'div', this.form.labels.fieldOptionDisabledHeader, { title: this.form.labels.fieldOptionDisabledHeader });
|
|
142
|
+
$lib.element(headerRow, null); // action column
|
|
143
|
+
|
|
144
|
+
if (field.options)
|
|
145
|
+
{
|
|
146
|
+
field.options.forEach(option =>
|
|
147
|
+
{
|
|
148
|
+
this.#createOption(grid, field, option, multiSelect, panel);
|
|
149
|
+
});
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
this.#createOption(grid, field, new this.form.constructor.FieldOption(), multiSelect, panel);
|
|
153
|
+
|
|
154
|
+
grid.addEventListener('input', (e) =>
|
|
155
|
+
{
|
|
156
|
+
if (e.target && e.target.tagName.toLowerCase() === 'input')
|
|
157
|
+
{
|
|
158
|
+
const input = e.target,
|
|
159
|
+
row = input.closest(`.${this.cpm.getCssClass(this.cpm.classOption.FIELD_OPTIONS_ITEM)}`),
|
|
160
|
+
option = row._option,
|
|
161
|
+
inputs = row.querySelectorAll('input'),
|
|
162
|
+
labelInput = inputs[0],
|
|
163
|
+
valueInput = inputs[1];
|
|
164
|
+
|
|
165
|
+
if (!option) return;
|
|
166
|
+
|
|
167
|
+
const isNew = !field.options.some(o => o.id === option.id);
|
|
168
|
+
|
|
169
|
+
if (e.target === labelInput)
|
|
170
|
+
valueInput.value = labelInput.value.trim();
|
|
171
|
+
|
|
172
|
+
if (isNew && !input.value.trim()) return;
|
|
173
|
+
|
|
174
|
+
this.#saveOption(field, option, row);
|
|
175
|
+
}
|
|
176
|
+
});
|
|
177
|
+
|
|
178
|
+
return grid;
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
#createOption(container, field, option, multiSelect, panel)
|
|
182
|
+
{
|
|
183
|
+
const isNew = $lib.isEmpty(option.id),
|
|
184
|
+
baseCssClass = this.cpm.getCssClass(this.cpm.classOption.FIELD_OPTIONS_ITEM),
|
|
185
|
+
cssClass = isNew ? `${baseCssClass} ${this.cpm.getCssClass(this.cpm.classOption.FIELD_OPTIONS_ITEM_NEW)}` : baseCssClass,
|
|
186
|
+
isRadio = field.inputType === this.InputTypeOption.RADIO || !multiSelect,
|
|
187
|
+
labelPlaceholder = this.form.labels.newItemPrefix + this.form.labels.fieldOption,
|
|
188
|
+
valuePlaceholder = this.form.labels.newItemPrefix + this.form.labels.fieldOptionValue,
|
|
189
|
+
idPrefix = `${this.form.id}_${panel.id}_`;
|
|
190
|
+
|
|
191
|
+
this.form.ensureItemId(option);
|
|
192
|
+
|
|
193
|
+
const selectInput = isRadio ? this.cf.createRadio(`${idPrefix}${option.id}_select`, 'selected', '', option.selected) : this.cf.createCheckbox('', 'selected', '', option.selected),
|
|
194
|
+
row = $lib.element({ container, tag: 'div', props: { className: cssClass, "_option": option } });
|
|
195
|
+
|
|
196
|
+
$lib.element(row, null); // drag cell
|
|
197
|
+
$lib.element(row, null, 'div', this.cf.createTextInput(`${idPrefix}${option.id}_label`, 'label', option.label, labelPlaceholder));
|
|
198
|
+
$lib.element(row, null, 'div', this.cf.createTextInput(`${idPrefix}${option.id}_value`, 'value', option.value, valuePlaceholder));
|
|
199
|
+
$lib.element(row, null, 'div', selectInput);
|
|
200
|
+
$lib.element(row, null, 'div', this.cf.createCheckbox(`${idPrefix}${option.id}_disable`, 'disabled', '', option.disabled));
|
|
201
|
+
$lib.element(row, null);
|
|
202
|
+
|
|
203
|
+
if (!isNew)
|
|
204
|
+
{
|
|
205
|
+
this.#makeDraggable(row, field, option, panel);
|
|
206
|
+
this.#createRemoveButton(row, field, option);
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
#addOption(field)
|
|
211
|
+
{
|
|
212
|
+
const panel = this.cpm.panelBar.panels.find(p => p.id === 'FieldOptionsPanel'),
|
|
213
|
+
isCheckBox = field.inputType === this.InputTypeOption.CHECKBOX || field.inputType === this.InputTypeOption.SWITCH,
|
|
214
|
+
isComboBox = field.inputType === this.InputTypeOption.COMBOBOX,
|
|
215
|
+
multiSelect = isCheckBox || (isComboBox && field.componentSettings?.multiSelect),
|
|
216
|
+
container = panel.contentElement.querySelector('.' + this.cpm.getCssClass(this.cpm.classOption.FIELD_OPTIONS));
|
|
217
|
+
|
|
218
|
+
this.#createOption(container, field, new this.form.constructor.FieldOption(), multiSelect, panel);
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
#saveOption(field, option, row)
|
|
222
|
+
{
|
|
223
|
+
const inputs = row.querySelectorAll('input'),
|
|
224
|
+
index = field.options.findIndex(o => o.id === option.id);
|
|
225
|
+
|
|
226
|
+
if (index > -1)
|
|
227
|
+
option = field.options[index];
|
|
228
|
+
|
|
229
|
+
this.form.dataObserver.shouldProcessChanges = true;
|
|
230
|
+
|
|
231
|
+
if (field.inputType === this.InputTypeOption.RADIO || (field.inputType === this.InputTypeOption.COMBOBOX && !field.componentSettings?.multiSelect))
|
|
232
|
+
{
|
|
233
|
+
const selectionChanged = Array.from(inputs).some(input => input.name === 'selected' && input.checked);
|
|
234
|
+
|
|
235
|
+
if (selectionChanged)
|
|
236
|
+
field.options.forEach(opt => { opt.selected = false; });
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
inputs.forEach(input =>
|
|
240
|
+
{
|
|
241
|
+
if (input.name === 'label')
|
|
242
|
+
option.label = input.value.trim();
|
|
243
|
+
else if (input.name === 'value')
|
|
244
|
+
option.value = input.value.trim();
|
|
245
|
+
else if (input.name === 'selected')
|
|
246
|
+
option.selected = input.checked;
|
|
247
|
+
else if (input.name === 'disabled')
|
|
248
|
+
option.disabled = input.checked;
|
|
249
|
+
});
|
|
250
|
+
|
|
251
|
+
if (!option.label)
|
|
252
|
+
option.label = `${this.form.labels.fieldOption} ${index > -1 ? index : field.options.length}`;
|
|
253
|
+
|
|
254
|
+
if (!option.value)
|
|
255
|
+
option.value = this.form.getValidFieldNameFromLabel(option.label);
|
|
256
|
+
|
|
257
|
+
if (index == -1)
|
|
258
|
+
{
|
|
259
|
+
field.options.push(option);
|
|
260
|
+
this.#addOption(field);
|
|
261
|
+
|
|
262
|
+
$lib.removeClass(row, this.cpm.getCssClass(this.cpm.classOption.FIELD_OPTIONS_ITEM_NEW));
|
|
263
|
+
row.classList.add(this.cpm.getCssClass(this.cpm.classOption.FIELD_OPTIONS_ITEM));
|
|
264
|
+
row._option = option;
|
|
265
|
+
this.#makeDraggable(row, field, option);
|
|
266
|
+
this.#createRemoveButton(row, field, option);
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
this.#updateOptions(field);
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
#createRemoveButton(row, field, option)
|
|
273
|
+
{
|
|
274
|
+
const idPrefix = `${this.form.id}_FieldOptionsPanel_options_`,
|
|
275
|
+
cells = Array.from(row.children),
|
|
276
|
+
lastCell = cells[5];
|
|
277
|
+
|
|
278
|
+
const button = this.cf.createButton(lastCell, `${idPrefix}_${option.id}_remove`, this.form.removeFieldOptionButtonId,
|
|
279
|
+
{
|
|
280
|
+
hasIcon: true,
|
|
281
|
+
cssClassIcon: 'ico-bin',
|
|
282
|
+
cssClass: this.cpm.getCssClass(this.cpm.classOption.REMOVE),
|
|
283
|
+
});
|
|
284
|
+
|
|
285
|
+
button.command = this.#removeOption.bind(this, field, option, button);
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
#removeOption(field, option, button)
|
|
289
|
+
{
|
|
290
|
+
const index = field.options.findIndex(o => o.id === option.id);
|
|
291
|
+
if (index !== -1)
|
|
292
|
+
field.options.splice(index, 1);
|
|
293
|
+
|
|
294
|
+
const row = button.element.closest('.' + this.cpm.getCssClass(this.cpm.classOption.FIELD_OPTIONS_ITEM));
|
|
295
|
+
row.parentElement.removeChild(row);
|
|
296
|
+
|
|
297
|
+
this.#updateOptions(field);
|
|
298
|
+
}
|
|
299
|
+
|
|
300
|
+
#updateOptions(field)
|
|
301
|
+
{
|
|
302
|
+
clearTimeout(this.#updateOptionsTimerId);
|
|
303
|
+
this.#updateOptionsTimerId = setTimeout(() =>
|
|
304
|
+
{
|
|
305
|
+
this.form.updateFieldOptions(field);
|
|
306
|
+
}, 0);
|
|
307
|
+
}
|
|
308
|
+
|
|
309
|
+
#makeDraggable(row, field, option, panel)
|
|
310
|
+
{
|
|
311
|
+
const firstCell = row.querySelector('div');
|
|
312
|
+
|
|
313
|
+
if (!panel)
|
|
314
|
+
panel = this.cpm.panelBar.panels.find(p => p.id === 'FieldOptionsPanel');
|
|
315
|
+
|
|
316
|
+
this.cf.createDragHandle(firstCell);
|
|
317
|
+
this.cpm.draggable.createDraggableOption({ element: row, field, option, panel });
|
|
318
|
+
}
|
|
319
|
+
|
|
320
|
+
#toggleFieldsDisplay(contentEl, idPrefix, name, groups)
|
|
321
|
+
{
|
|
322
|
+
// find which radio (by index) is checked
|
|
323
|
+
const radios = Array.from(contentEl.querySelectorAll(`input[name="${name}"]`)),
|
|
324
|
+
index = radios.findIndex(r => r.checked);
|
|
325
|
+
|
|
326
|
+
// hide *all* keys
|
|
327
|
+
groups.flat().forEach(key =>
|
|
328
|
+
{
|
|
329
|
+
$UI.store[`${idPrefix + key}_field`]?.hide();
|
|
330
|
+
});
|
|
331
|
+
|
|
332
|
+
// show only the matched group
|
|
333
|
+
(groups[index] || []).forEach(key =>
|
|
334
|
+
{
|
|
335
|
+
$UI.store[`${idPrefix + key}_field`]?.show();
|
|
336
|
+
});
|
|
337
|
+
}
|
|
338
|
+
};
|
|
339
|
+
|
|
340
|
+
var OptionsPanel = componyx.UI.form_modules.OptionsPanel;
|
|
341
|
+
|
|
342
|
+
export { OptionsPanel as default };
|