alchemy-form 0.2.10 → 0.3.0-alpha.2
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/CHANGELOG.md +16 -0
- package/assets/stylesheets/form/alchemy_form.scss +1 -2
- package/assets/stylesheets/form/elements/_badge.scss +41 -0
- package/assets/stylesheets/form/elements/_button.scss +4 -31
- package/assets/stylesheets/form/elements/_code_input.scss +0 -1
- package/assets/stylesheets/form/elements/_feedback_input.scss +2 -0
- package/assets/stylesheets/form/elements/_field.scss +29 -23
- package/assets/stylesheets/form/elements/_form.scss +7 -2
- package/assets/stylesheets/form/elements/_settings_editor.scss +62 -0
- package/assets/stylesheets/form/elements/_table.scss +12 -3
- package/assets/stylesheets/form/elements/index.scss +19 -17
- package/assets/stylesheets/form/general/index.scss +2 -2
- package/config/routes.js +3 -3
- package/controller/form_api_controller.js +2 -4
- package/element/00_form_base.js +21 -0
- package/element/10_dataprovider.js +2 -2
- package/element/al_code_input.js +51 -13
- package/element/al_field.js +89 -24
- package/element/al_form.js +9 -2
- package/element/al_select.js +2 -1
- package/element/al_settings_editor.js +367 -0
- package/element/al_table.js +11 -6
- package/package.json +4 -3
- package/view/form/elements/al_settings_editor.hwk +36 -0
- package/view/form/elements/alchemy_field.hwk +1 -12
- package/view/form/inputs/edit/object.hwk +9 -0
- package/view/form/inputs/edit/settings.hwk +5 -0
- package/view/form/inputs/view/string.hwk +14 -1
- package/view/form/inputs/view_inline/boolean.hwk +24 -17
- package/view/form/inputs/view_inline/datetime.hwk +31 -24
- package/view/form/inputs/view_inline/enum.hwk +32 -1
- package/view/form/inputs/view_inline/objectid.hwk +9 -1
- package/view/form/inputs/view_inline/string.hwk +11 -3
- package/view/form/wrappers/default/default.hwk +18 -2
- /package/element/{al_string_input.js → 50-al_string_input.js} +0 -0
package/element/al_field.js
CHANGED
|
@@ -77,9 +77,17 @@ Field.setAttribute('wrapper-view');
|
|
|
77
77
|
*
|
|
78
78
|
* @author Jelle De Loecker <jelle@elevenways.be>
|
|
79
79
|
* @since 0.1.2
|
|
80
|
-
* @version 0.
|
|
80
|
+
* @version 0.3.0
|
|
81
81
|
*/
|
|
82
|
-
Field.setAttribute('readonly',
|
|
82
|
+
Field.setAttribute('readonly', function getReadonlyValue(current_value) {
|
|
83
|
+
|
|
84
|
+
if (current_value == null) {
|
|
85
|
+
current_value = this.alchemy_form?.readonly;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
return current_value;
|
|
89
|
+
|
|
90
|
+
}, {boolean: true});
|
|
83
91
|
|
|
84
92
|
/**
|
|
85
93
|
* Widget settings for use in the views
|
|
@@ -585,14 +593,20 @@ Field.setProperty(function value_element() {
|
|
|
585
593
|
*
|
|
586
594
|
* @author Jelle De Loecker <jelle@elevenways.be>
|
|
587
595
|
* @since 0.1.0
|
|
588
|
-
* @version 0.
|
|
596
|
+
* @version 0.3.0
|
|
589
597
|
*/
|
|
590
598
|
Field.setProperty(function value() {
|
|
591
599
|
|
|
592
600
|
let element = this.value_element;
|
|
593
601
|
|
|
594
602
|
if (element) {
|
|
595
|
-
|
|
603
|
+
let value = element.value;
|
|
604
|
+
|
|
605
|
+
if (this.config) {
|
|
606
|
+
value = this.config.castContainedValues(value);
|
|
607
|
+
}
|
|
608
|
+
|
|
609
|
+
return value;
|
|
596
610
|
}
|
|
597
611
|
|
|
598
612
|
return this.value_to_render;
|
|
@@ -636,8 +650,72 @@ Field.setProperty(function value_to_render() {
|
|
|
636
650
|
}
|
|
637
651
|
});
|
|
638
652
|
|
|
653
|
+
/**
|
|
654
|
+
* Get the placeholder for empty values (if any)
|
|
655
|
+
*
|
|
656
|
+
* @author Jelle De Loecker <jelle@elevenways.be>
|
|
657
|
+
* @since 0.3.0
|
|
658
|
+
* @version 0.3.0
|
|
659
|
+
*/
|
|
660
|
+
Field.setProperty(function allow_empty_value_placeholder() {
|
|
661
|
+
return !!(this.applied_options?.empty_value_placeholder ?? true);
|
|
662
|
+
});
|
|
663
|
+
|
|
664
|
+
/**
|
|
665
|
+
* Create the empty value placeholder text
|
|
666
|
+
*
|
|
667
|
+
* @author Jelle De Loecker <jelle@elevenways.be>
|
|
668
|
+
* @since 0.3.0
|
|
669
|
+
* @version 0.3.0
|
|
670
|
+
*
|
|
671
|
+
* @return {string|HTMLElement|Microcopy}
|
|
672
|
+
*/
|
|
673
|
+
Field.setMethod(function createEmptyValuePlaceholderText() {
|
|
674
|
+
|
|
675
|
+
let microcopy = this.applied_options?.empty_value_placeholder;
|
|
676
|
+
|
|
677
|
+
if (microcopy) {
|
|
678
|
+
return microcopy;
|
|
679
|
+
}
|
|
680
|
+
|
|
681
|
+
microcopy = Classes.Alchemy.Microcopy('empty-value-placeholder', {
|
|
682
|
+
field_name : this.field_name,
|
|
683
|
+
model_name : this.model,
|
|
684
|
+
field_type : this.field_type,
|
|
685
|
+
zone : this.zone,
|
|
686
|
+
path : this.config?.path_in_document,
|
|
687
|
+
});
|
|
688
|
+
|
|
689
|
+
return microcopy;
|
|
690
|
+
});
|
|
691
|
+
|
|
692
|
+
/**
|
|
693
|
+
* Get variables needed to render this
|
|
694
|
+
*
|
|
695
|
+
* @author Jelle De Loecker <jelle@elevenways.be>
|
|
696
|
+
* @since 0.3.0
|
|
697
|
+
* @version 0.3.0
|
|
698
|
+
*/
|
|
699
|
+
Field.setMethod(function prepareRenderVariables() {
|
|
700
|
+
|
|
701
|
+
let value = this.value_to_render,
|
|
702
|
+
value_is_empty = value == null || value === '' || (Array.isArray(value) ? value.length == 0 : false);
|
|
703
|
+
|
|
704
|
+
let result = {
|
|
705
|
+
alchemy_field : this,
|
|
706
|
+
field_context : this,
|
|
707
|
+
view_files : this.view_files,
|
|
708
|
+
wrapper_files : this.wrapper_files,
|
|
709
|
+
value,
|
|
710
|
+
value_is_empty,
|
|
711
|
+
};
|
|
712
|
+
|
|
713
|
+
return result;
|
|
714
|
+
});
|
|
715
|
+
|
|
639
716
|
/**
|
|
640
717
|
* Apply options
|
|
718
|
+
* (Like options from a FieldConfig instance)
|
|
641
719
|
*
|
|
642
720
|
* @author Jelle De Loecker <jelle@elevenways.be>
|
|
643
721
|
* @since 0.1.12
|
|
@@ -1043,32 +1121,19 @@ Field.setMethod(async function loadData(config, element) {
|
|
|
1043
1121
|
*
|
|
1044
1122
|
* @author Jelle De Loecker <jelle@elevenways.be>
|
|
1045
1123
|
* @since 0.2.9
|
|
1046
|
-
* @version 0.
|
|
1124
|
+
* @version 0.3.0
|
|
1047
1125
|
*
|
|
1048
|
-
* @param {Object} constraints
|
|
1126
|
+
* @param {Criteria|Object} constraints
|
|
1127
|
+
*
|
|
1128
|
+
* @param {Object}
|
|
1049
1129
|
*/
|
|
1050
1130
|
Field.setMethod(function resolveConstraintInstruction(constraints) {
|
|
1051
1131
|
|
|
1052
|
-
let context
|
|
1053
|
-
result = {},
|
|
1054
|
-
value,
|
|
1055
|
-
key;
|
|
1056
|
-
|
|
1057
|
-
for (key in constraints) {
|
|
1058
|
-
value = constraints[key];
|
|
1132
|
+
let context = {$0: this.alchemy_form.getValueAsDocument()};
|
|
1059
1133
|
|
|
1060
|
-
|
|
1061
|
-
if (value instanceof Classes.Alchemy.PathEvaluator) {
|
|
1062
|
-
if (!context && this.alchemy_form) {
|
|
1063
|
-
context = this.alchemy_form.getValueAsDocument();
|
|
1064
|
-
}
|
|
1134
|
+
constraints = Classes.Alchemy.Criteria.Criteria.cast(constraints);
|
|
1065
1135
|
|
|
1066
|
-
|
|
1067
|
-
}
|
|
1068
|
-
} else {
|
|
1069
|
-
result[key] = value;
|
|
1070
|
-
}
|
|
1071
|
-
}
|
|
1136
|
+
let result = constraints.compileToConditions(context);
|
|
1072
1137
|
|
|
1073
1138
|
return result;
|
|
1074
1139
|
});
|
package/element/al_form.js
CHANGED
|
@@ -34,6 +34,15 @@ Form.setAttribute('method');
|
|
|
34
34
|
*/
|
|
35
35
|
Form.setAttribute('model');
|
|
36
36
|
|
|
37
|
+
/**
|
|
38
|
+
* Is this a read only form?
|
|
39
|
+
*
|
|
40
|
+
* @author Jelle De Loecker <jelle@elevenways.be>
|
|
41
|
+
* @since 0.3.0
|
|
42
|
+
* @version 0.3.0
|
|
43
|
+
*/
|
|
44
|
+
Form.setAttribute('readonly', {boolean: true});
|
|
45
|
+
|
|
37
46
|
/**
|
|
38
47
|
* Should the entire document be submitted?
|
|
39
48
|
*
|
|
@@ -249,8 +258,6 @@ Form.setMethod(function setDocument(document) {
|
|
|
249
258
|
// Set the current document
|
|
250
259
|
this.document = document;
|
|
251
260
|
|
|
252
|
-
console.log('Setting document', document);
|
|
253
|
-
|
|
254
261
|
for (let key in current_value) {
|
|
255
262
|
let original_value = current_value[key],
|
|
256
263
|
new_value = document[key];
|
package/element/al_select.js
CHANGED
|
@@ -951,12 +951,13 @@ AlchemySelect.setMethod(function getRemoteFetchConfig() {
|
|
|
951
951
|
*
|
|
952
952
|
* @author Jelle De Loecker <jelle@elevenways.be>
|
|
953
953
|
* @since 0.2.0
|
|
954
|
-
* @version 0.
|
|
954
|
+
* @version 0.3.0
|
|
955
955
|
*/
|
|
956
956
|
AlchemySelect.setMethod(function applyFetchedData(err, result, config) {
|
|
957
957
|
|
|
958
958
|
if (err) {
|
|
959
959
|
this.loading_dropdown = false;
|
|
960
|
+
alchemy.handleError(err);
|
|
960
961
|
return;
|
|
961
962
|
}
|
|
962
963
|
|
|
@@ -0,0 +1,367 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The settings editor
|
|
3
|
+
*
|
|
4
|
+
* @author Jelle De Loecker <jelle@elevenways.be>
|
|
5
|
+
* @since 0.3.0
|
|
6
|
+
* @version 0.3.0
|
|
7
|
+
*/
|
|
8
|
+
const SettingsEditor = Function.inherits('Alchemy.Element.Form.Base', 'SettingsEditor');
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* The template to use for the content of this element
|
|
12
|
+
*
|
|
13
|
+
* @author Jelle De Loecker <jelle@elevenways.be>
|
|
14
|
+
* @since 0.3.0
|
|
15
|
+
* @version 0.3.0
|
|
16
|
+
*/
|
|
17
|
+
SettingsEditor.setTemplateFile('form/elements/al_settings_editor');
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* The actual settings and their values
|
|
21
|
+
*
|
|
22
|
+
* @author Jelle De Loecker <jelle@elevenways.be>
|
|
23
|
+
* @since 0.3.0
|
|
24
|
+
* @version 0.3.0
|
|
25
|
+
*/
|
|
26
|
+
SettingsEditor.setAssignedProperty('settings_config');
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Address to send updates t
|
|
30
|
+
*
|
|
31
|
+
* @author Jelle De Loecker <jelle@elevenways.be>
|
|
32
|
+
* @since 0.3.0
|
|
33
|
+
* @version 0.3.0
|
|
34
|
+
*/
|
|
35
|
+
SettingsEditor.setAttribute('src');
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* Get the current value
|
|
39
|
+
*
|
|
40
|
+
* @author Jelle De Loecker <jelle@elevenways.be>
|
|
41
|
+
* @since 1.3.0
|
|
42
|
+
* @version 1.3.0
|
|
43
|
+
*/
|
|
44
|
+
SettingsEditor.setProperty(function value() {
|
|
45
|
+
|
|
46
|
+
let result = {};
|
|
47
|
+
|
|
48
|
+
let root_key,
|
|
49
|
+
elements = this.querySelectorAll('.al-settings-setting'),
|
|
50
|
+
element,
|
|
51
|
+
field,
|
|
52
|
+
i;
|
|
53
|
+
|
|
54
|
+
for (i = 0; i < elements.length; i++) {
|
|
55
|
+
element = elements[i];
|
|
56
|
+
|
|
57
|
+
field = element.querySelector('al-field');
|
|
58
|
+
|
|
59
|
+
if (!field) {
|
|
60
|
+
continue;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
if (!root_key) {
|
|
64
|
+
root_key = element.dataset.id.split('.')[0];
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
Object.setPath(result, element.dataset.id, field.value);
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
return result[root_key];
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* Populate the settings container
|
|
75
|
+
*
|
|
76
|
+
* @author Jelle De Loecker <jelle@elevenways.be>
|
|
77
|
+
* @since 1.3.0
|
|
78
|
+
* @version 1.3.0
|
|
79
|
+
*/
|
|
80
|
+
SettingsEditor.setMethod(function populateSettingsContainer(container) {
|
|
81
|
+
|
|
82
|
+
if (!container) {
|
|
83
|
+
container = this.querySelector('.al-settings-container');
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
Hawkejs.removeChildren(container);
|
|
87
|
+
|
|
88
|
+
this._addGroupToContainer(container, this.settings_config);
|
|
89
|
+
});
|
|
90
|
+
|
|
91
|
+
/**
|
|
92
|
+
* Create an id
|
|
93
|
+
*
|
|
94
|
+
* @author Jelle De Loecker <jelle@elevenways.be>
|
|
95
|
+
* @since 1.3.0
|
|
96
|
+
* @version 1.3.0
|
|
97
|
+
*
|
|
98
|
+
* @param {string} suffix
|
|
99
|
+
*
|
|
100
|
+
* @return {string}
|
|
101
|
+
*/
|
|
102
|
+
SettingsEditor.setMethod(function createId(suffix) {
|
|
103
|
+
|
|
104
|
+
let id = this.id;
|
|
105
|
+
|
|
106
|
+
if (!id) {
|
|
107
|
+
id = 'settings-editor';
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
id += '-' + suffix.slug().underscore();
|
|
111
|
+
|
|
112
|
+
return id;
|
|
113
|
+
});
|
|
114
|
+
|
|
115
|
+
/**
|
|
116
|
+
* Add the given group to the container
|
|
117
|
+
*
|
|
118
|
+
* @author Jelle De Loecker <jelle@elevenways.be>
|
|
119
|
+
* @since 1.3.0
|
|
120
|
+
* @version 1.3.0
|
|
121
|
+
*
|
|
122
|
+
* @param {HTMLElement} container
|
|
123
|
+
* @param {Object} group
|
|
124
|
+
*/
|
|
125
|
+
SettingsEditor.setMethod(function _addGroupToContainer(container, group) {
|
|
126
|
+
|
|
127
|
+
if (!group) {
|
|
128
|
+
return;
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
if (!container) {
|
|
132
|
+
throw new Error('No container given');
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
let add_group = false;
|
|
136
|
+
|
|
137
|
+
if (group.settings?.length) {
|
|
138
|
+
add_group = true;
|
|
139
|
+
} else if (group.children?.length) {
|
|
140
|
+
// If the root group has no settings, don't add it
|
|
141
|
+
if (!group.is_root) {
|
|
142
|
+
add_group = true;
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
if (add_group) {
|
|
147
|
+
let group_element = this.createElement('div');
|
|
148
|
+
group_element.classList.add('al-settings-group');
|
|
149
|
+
group_element.dataset.id = group.group_id;
|
|
150
|
+
group_element.id = this.createId(group.group_id);
|
|
151
|
+
|
|
152
|
+
let header_element = this.createElement('header');
|
|
153
|
+
header_element.classList.add('al-settings-group-header');
|
|
154
|
+
|
|
155
|
+
let title_element = this.createElement('div');
|
|
156
|
+
title_element.classList.add('al-settings-group-title');
|
|
157
|
+
title_element.dataset.toc_level = group.group_id.count('.');
|
|
158
|
+
|
|
159
|
+
let group_title_microcopy = this.createElement('micro-copy');
|
|
160
|
+
group_title_microcopy.key = 'settings.title.group:' + group.group_id;
|
|
161
|
+
group_title_microcopy.fallback = group.name.titleize();
|
|
162
|
+
|
|
163
|
+
title_element.append(group_title_microcopy);
|
|
164
|
+
header_element.append(title_element);
|
|
165
|
+
group_element.append(header_element);
|
|
166
|
+
|
|
167
|
+
let settings_container = this.createElement('div');
|
|
168
|
+
settings_container.classList.add('al-settings-settings-container');
|
|
169
|
+
|
|
170
|
+
for (let setting of group.settings) {
|
|
171
|
+
this._addSettingToGroupElement(settings_container, setting);
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
group_element.append(settings_container);
|
|
175
|
+
container.append(group_element);
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
for (let child_group of group.children) {
|
|
179
|
+
this._addGroupToContainer(container, child_group);
|
|
180
|
+
}
|
|
181
|
+
});
|
|
182
|
+
|
|
183
|
+
/**
|
|
184
|
+
* Add the given setting to the container
|
|
185
|
+
*
|
|
186
|
+
* @author Jelle De Loecker <jelle@elevenways.be>
|
|
187
|
+
* @since 1.3.0
|
|
188
|
+
* @version 1.3.0
|
|
189
|
+
*
|
|
190
|
+
* @param {HTMLElement} settings_container_element
|
|
191
|
+
* @param {Object} setting
|
|
192
|
+
*/
|
|
193
|
+
SettingsEditor.setMethod(function _addSettingToGroupElement(settings_container_element, setting) {
|
|
194
|
+
|
|
195
|
+
if (!setting?.schema) {
|
|
196
|
+
return;
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
let value_field = setting.schema.get('value');
|
|
200
|
+
|
|
201
|
+
if (!value_field) {
|
|
202
|
+
return;
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
let settings_element = this.createElement('div');
|
|
206
|
+
|
|
207
|
+
let id = this.createId(setting.setting_id);
|
|
208
|
+
|
|
209
|
+
// Set the IDs
|
|
210
|
+
settings_element.dataset.id = setting.setting_id;
|
|
211
|
+
settings_element.id = id;
|
|
212
|
+
|
|
213
|
+
// Add the CSS class
|
|
214
|
+
settings_element.classList.add('al-settings-setting');
|
|
215
|
+
|
|
216
|
+
// Create the title element
|
|
217
|
+
let header_element = this.createElement('header');
|
|
218
|
+
header_element.classList.add('al-settings-setting-header');
|
|
219
|
+
|
|
220
|
+
let title_element = this.createElement('div');
|
|
221
|
+
title_element.classList.add('al-settings-setting-title');
|
|
222
|
+
|
|
223
|
+
let title_microcopy = this.createElement('micro-copy');
|
|
224
|
+
title_microcopy.key = 'settings.title:' + setting.setting_id;
|
|
225
|
+
title_microcopy.fallback = setting.name.titleize();
|
|
226
|
+
|
|
227
|
+
header_element.append(title_element);
|
|
228
|
+
title_element.append(title_microcopy);
|
|
229
|
+
|
|
230
|
+
if (setting.show_description !== false) {
|
|
231
|
+
let description_element = this.createElement('div');
|
|
232
|
+
description_element.classList.add('al-settings-setting-description');
|
|
233
|
+
|
|
234
|
+
let description_microcopy = this.createElement('micro-copy');
|
|
235
|
+
description_microcopy.key = 'settings.description:' + setting.setting_id;
|
|
236
|
+
description_microcopy.fallback = setting.description || '';
|
|
237
|
+
|
|
238
|
+
header_element.append(description_element);
|
|
239
|
+
description_element.append(description_microcopy);
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
settings_element.append(header_element);
|
|
243
|
+
|
|
244
|
+
let input_wrapper = this.createElement('div');
|
|
245
|
+
|
|
246
|
+
let al_field = this.createElement('al-field');
|
|
247
|
+
al_field.id = 'af-' + id;
|
|
248
|
+
al_field.config = value_field;
|
|
249
|
+
al_field.value = setting.current_value;
|
|
250
|
+
al_field.mode = 'inline';
|
|
251
|
+
|
|
252
|
+
this.hawkejs_view.registerElementInstance(al_field);
|
|
253
|
+
|
|
254
|
+
if (setting.locked) {
|
|
255
|
+
al_field.readonly = true;
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
input_wrapper.append(al_field);
|
|
259
|
+
|
|
260
|
+
settings_element.append(input_wrapper);
|
|
261
|
+
|
|
262
|
+
settings_container_element.append(settings_element);
|
|
263
|
+
});
|
|
264
|
+
|
|
265
|
+
/**
|
|
266
|
+
* This element has been added to the DOM for the first time
|
|
267
|
+
*
|
|
268
|
+
* @author Jelle De Loecker <jelle@elevenways.be>
|
|
269
|
+
* @since 1.3.0
|
|
270
|
+
* @version 1.3.0
|
|
271
|
+
*/
|
|
272
|
+
SettingsEditor.setMethod(function introduced() {
|
|
273
|
+
|
|
274
|
+
let save_button = this.querySelector('.save-changes');
|
|
275
|
+
|
|
276
|
+
save_button.addEventListener('activate', async e => {
|
|
277
|
+
|
|
278
|
+
let old_state = save_button.state;
|
|
279
|
+
|
|
280
|
+
save_button.setState('saving');
|
|
281
|
+
|
|
282
|
+
try {
|
|
283
|
+
await this.save();
|
|
284
|
+
} catch (err) {
|
|
285
|
+
save_button.setState('error', 2500, old_state);
|
|
286
|
+
return;
|
|
287
|
+
}
|
|
288
|
+
|
|
289
|
+
save_button.setState('saved', 1000, old_state);
|
|
290
|
+
});
|
|
291
|
+
|
|
292
|
+
save_button.hidden = !this.src;
|
|
293
|
+
});
|
|
294
|
+
|
|
295
|
+
/**
|
|
296
|
+
* Get the changes
|
|
297
|
+
*
|
|
298
|
+
* @author Jelle De Loecker <jelle@elevenways.be>
|
|
299
|
+
* @since 1.3.0
|
|
300
|
+
* @version 1.3.0
|
|
301
|
+
*/
|
|
302
|
+
SettingsEditor.setMethod(function getChanges() {
|
|
303
|
+
|
|
304
|
+
let result = {};
|
|
305
|
+
|
|
306
|
+
let new_value,
|
|
307
|
+
original_value,
|
|
308
|
+
elements = this.querySelectorAll('.al-settings-setting'),
|
|
309
|
+
element,
|
|
310
|
+
field,
|
|
311
|
+
i;
|
|
312
|
+
|
|
313
|
+
for (i = 0; i < elements.length; i++) {
|
|
314
|
+
element = elements[i];
|
|
315
|
+
|
|
316
|
+
field = element.querySelector('al-field');
|
|
317
|
+
|
|
318
|
+
if (!field) {
|
|
319
|
+
continue;
|
|
320
|
+
}
|
|
321
|
+
|
|
322
|
+
new_value = field.value;
|
|
323
|
+
original_value = field.original_value;
|
|
324
|
+
|
|
325
|
+
if (Object.alike(new_value, original_value) || new_value == original_value) {
|
|
326
|
+
continue;
|
|
327
|
+
}
|
|
328
|
+
|
|
329
|
+
// Ignore empty values that were not set before
|
|
330
|
+
if (new_value === '' && original_value == null) {
|
|
331
|
+
continue;
|
|
332
|
+
}
|
|
333
|
+
|
|
334
|
+
// Ignore empty values that were not set before
|
|
335
|
+
if (new_value === false && original_value == null) {
|
|
336
|
+
continue;
|
|
337
|
+
}
|
|
338
|
+
|
|
339
|
+
result[element.dataset.id] = new_value;
|
|
340
|
+
}
|
|
341
|
+
|
|
342
|
+
return result;
|
|
343
|
+
});
|
|
344
|
+
|
|
345
|
+
/**
|
|
346
|
+
* Save the changes
|
|
347
|
+
*
|
|
348
|
+
* @author Jelle De Loecker <jelle@elevenways.be>
|
|
349
|
+
* @since 1.3.0
|
|
350
|
+
* @version 1.3.0
|
|
351
|
+
*/
|
|
352
|
+
SettingsEditor.setMethod(async function save() {
|
|
353
|
+
|
|
354
|
+
if (!this.src) {
|
|
355
|
+
return;
|
|
356
|
+
}
|
|
357
|
+
|
|
358
|
+
let changes = this.getChanges();
|
|
359
|
+
|
|
360
|
+
let result;
|
|
361
|
+
|
|
362
|
+
try {
|
|
363
|
+
result = await alchemy.fetch(this.src, {post: changes});
|
|
364
|
+
} catch (err) {
|
|
365
|
+
throw err;
|
|
366
|
+
}
|
|
367
|
+
});
|
package/element/al_table.js
CHANGED
|
@@ -597,7 +597,7 @@ Table.setMethod(function showPagination() {
|
|
|
597
597
|
*
|
|
598
598
|
* @author Jelle De Loecker <jelle@elevenways.be>
|
|
599
599
|
* @since 0.1.8
|
|
600
|
-
* @version 0.
|
|
600
|
+
* @version 0.3.0
|
|
601
601
|
*
|
|
602
602
|
* @param {FieldConfig} field_config The config on how to display the field
|
|
603
603
|
* @param {Object} container The container where the field should be in
|
|
@@ -640,6 +640,7 @@ Table.setMethod(function getFieldConfigView(field_config, container) {
|
|
|
640
640
|
alchemy_field.field_name = field.name;
|
|
641
641
|
alchemy_field.config = field;
|
|
642
642
|
alchemy_field.original_value = value;
|
|
643
|
+
alchemy_field.model = field?.schema?.model_name;
|
|
643
644
|
|
|
644
645
|
return alchemy_field;
|
|
645
646
|
});
|
|
@@ -677,7 +678,7 @@ Table.setMethod(function addDataRow(entry) {
|
|
|
677
678
|
*
|
|
678
679
|
* @author Jelle De Loecker <jelle@elevenways.be>
|
|
679
680
|
* @since 0.1.0
|
|
680
|
-
* @version 0.
|
|
681
|
+
* @version 0.3.0
|
|
681
682
|
*
|
|
682
683
|
* @param {Object} entry
|
|
683
684
|
*
|
|
@@ -705,6 +706,10 @@ Table.setMethod(function createDataRow(entry) {
|
|
|
705
706
|
tr.dataset.pk = id;
|
|
706
707
|
}
|
|
707
708
|
|
|
709
|
+
if (!this.fieldset) {
|
|
710
|
+
throw new Error('No fieldset has been defined for this table yet');
|
|
711
|
+
}
|
|
712
|
+
|
|
708
713
|
for (field_set_config of this.fieldset) {
|
|
709
714
|
|
|
710
715
|
let create_new_contents = true,
|
|
@@ -907,7 +912,7 @@ Table.setMethod(function attachContextMenus() {
|
|
|
907
912
|
*
|
|
908
913
|
* @author Jelle De Loecker <jelle@elevenways.be>
|
|
909
914
|
* @since 0.1.0
|
|
910
|
-
* @version 0.
|
|
915
|
+
* @version 0.3.0
|
|
911
916
|
*/
|
|
912
917
|
Table.setMethod(function onFieldsetAssignment(value, old_value) {
|
|
913
918
|
|
|
@@ -935,7 +940,7 @@ Table.setMethod(function onFieldsetAssignment(value, old_value) {
|
|
|
935
940
|
}
|
|
936
941
|
|
|
937
942
|
for (field of value) {
|
|
938
|
-
col = this.createElement('
|
|
943
|
+
col = this.createElement('th');
|
|
939
944
|
span = this.createElement('span');
|
|
940
945
|
span.textContent = field.title;
|
|
941
946
|
|
|
@@ -980,10 +985,10 @@ Table.setMethod(function onFieldsetAssignment(value, old_value) {
|
|
|
980
985
|
}
|
|
981
986
|
|
|
982
987
|
if (this.has_actions) {
|
|
983
|
-
col = this.createElement('
|
|
988
|
+
col = this.createElement('th');
|
|
984
989
|
names_row.append(col);
|
|
985
990
|
|
|
986
|
-
col = this.createElement('
|
|
991
|
+
col = this.createElement('th');
|
|
987
992
|
filter_row.append(col);
|
|
988
993
|
}
|
|
989
994
|
|
package/package.json
CHANGED
|
@@ -1,14 +1,15 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "alchemy-form",
|
|
3
3
|
"description": "Form plugin for Alchemy",
|
|
4
|
-
"version": "0.2
|
|
4
|
+
"version": "0.3.0-alpha.2",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type" : "git",
|
|
7
7
|
"url" : "https://github.com/11ways/alchemy-form.git"
|
|
8
8
|
},
|
|
9
9
|
"peerDependencies": {
|
|
10
|
-
"alchemymvc" : ">=1.
|
|
11
|
-
"alchemy-media" : ">=0.
|
|
10
|
+
"alchemymvc" : ">=1.4.0||>=1.4.0-alpha",
|
|
11
|
+
"alchemy-media" : ">=0.9.0||>=0.9.0-alpha",
|
|
12
|
+
"alchemy-styleboost": ">=0.5.0||>=0.5.0-alpha"
|
|
12
13
|
},
|
|
13
14
|
"license": "MIT",
|
|
14
15
|
"engines": {
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
<div class="al-settings-sidebar">
|
|
2
|
+
<al-toc
|
|
3
|
+
container-element="ul"
|
|
4
|
+
entry-element="li"
|
|
5
|
+
parent-selector="al-settings-editor"
|
|
6
|
+
children-selector=".al-settings-container"
|
|
7
|
+
elements-selector=".al-settings-group"
|
|
8
|
+
title-selector=".al-settings-group-title"
|
|
9
|
+
></al-toc>
|
|
10
|
+
</div>
|
|
11
|
+
<div class="al-settings-main">
|
|
12
|
+
<div class="al-settings-container"><% self.populateSettingsContainer($0) %></div>
|
|
13
|
+
<div class="al-settings-actions">
|
|
14
|
+
<al-button class="save-changes" state="ready" hidden>
|
|
15
|
+
<al-state state-name="saving">
|
|
16
|
+
<al-icon icon-style="duotone" icon-name="spinner" icon-flags="spin"></al-icon>
|
|
17
|
+
{%t "saving" %}
|
|
18
|
+
</al-state>
|
|
19
|
+
|
|
20
|
+
<al-state state-name="saved">
|
|
21
|
+
<al-icon icon-style="duotone" icon-name="badge-check" icon-flags="beat"></al-icon>
|
|
22
|
+
{%t "saved" %}
|
|
23
|
+
</al-state>
|
|
24
|
+
|
|
25
|
+
<al-state state-name="error">
|
|
26
|
+
<al-icon icon-style="duotone" icon-name="skull" icon-flags="shake"></al-icon>
|
|
27
|
+
{%t "error" action="save" %}
|
|
28
|
+
</al-state>
|
|
29
|
+
|
|
30
|
+
<al-state state-name="ready">
|
|
31
|
+
<al-icon icon-style="duotone" icon-name="floppy-disk-circle-arrow-right"></al-icon>
|
|
32
|
+
{%t "save" %}
|
|
33
|
+
</al-state>
|
|
34
|
+
</al-button>
|
|
35
|
+
</div>
|
|
36
|
+
</div>
|
|
@@ -1,16 +1,5 @@
|
|
|
1
|
-
<% wrapper_files = self.wrapper_files %>
|
|
2
|
-
<% view_files = self.view_files %>
|
|
3
|
-
<%
|
|
4
|
-
variables = {
|
|
5
|
-
alchemy_field : self,
|
|
6
|
-
field_context : self,
|
|
7
|
-
view_files : view_files,
|
|
8
|
-
value : self.value_to_render,
|
|
9
|
-
}
|
|
10
|
-
%>
|
|
11
|
-
|
|
12
1
|
<% if (wrapper_files) { %>
|
|
13
|
-
<% include(wrapper_files
|
|
2
|
+
<% include(wrapper_files) %>
|
|
14
3
|
<% } %>
|
|
15
4
|
|
|
16
5
|
<% if (wrapper_files) start('field') %>
|