alchemy-form 0.1.12 → 0.2.1
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 +24 -0
- package/assets/stylesheets/form/alchemy_form.scss +2 -16
- package/assets/stylesheets/form/elements/_button.scss +52 -0
- package/assets/stylesheets/form/{alchemy_code_input.scss → elements/_code_input.scss} +1 -1
- package/assets/stylesheets/form/{alchemy_feedback_input.scss → elements/_feedback_input.scss} +6 -8
- package/assets/stylesheets/form/{alchemy_field.scss → elements/_field.scss} +1 -1
- package/assets/stylesheets/form/{alchemy_field_array.scss → elements/_field_array.scss} +2 -2
- package/assets/stylesheets/form/{alchemy_field_translatable.scss → elements/_field_translatable.scss} +1 -1
- package/assets/stylesheets/form/elements/_form.scss +16 -0
- package/assets/stylesheets/form/{alchemy_pager.scss → elements/_pager.scss} +1 -1
- package/assets/stylesheets/form/{query_builder.scss → elements/_query_builder.scss} +14 -8
- package/assets/stylesheets/form/{alchemy_select.scss → elements/_select.scss} +2 -2
- package/assets/stylesheets/form/elements/_state.scss +8 -0
- package/assets/stylesheets/form/{alchemy_table.scss → elements/_table.scss} +2 -2
- package/assets/stylesheets/form/elements/_tabs.scss +47 -0
- package/assets/stylesheets/form/{alchemy_toggle.scss → elements/_toggle.scss} +1 -1
- package/assets/stylesheets/form/elements/index.scss +14 -0
- package/controller/form_api_controller.js +6 -2
- package/element/00_form_base.js +16 -8
- package/element/05_feedback_input.js +4 -13
- package/element/10_alchemy_field_custom.js +13 -15
- package/element/10_dataprovider.js +282 -0
- package/element/15_alchemy_field_entry.js +8 -10
- package/element/20_query_builder_base.js +4 -13
- package/element/25_query_builder_data.js +2 -2
- package/element/30_tab_base.js +29 -0
- package/element/40_stateful.js +125 -0
- package/element/al_button.js +147 -0
- package/element/{code_input.js → al_code_input.js} +1 -10
- package/element/{alchemy_field.js → al_field.js} +18 -25
- package/element/{alchemy_field_array.js → al_field_array.js} +7 -18
- package/element/{alchemy_field_array_entry.js → al_field_array_entry.js} +7 -9
- package/element/{alchemy_field_schema.js → al_field_schema.js} +3 -3
- package/element/{alchemy_field_translatable.js → al_field_translatable.js} +6 -17
- package/element/{alchemy_field_translatable_entry.js → al_field_translatable_entry.js} +2 -4
- package/element/{alchemy_form.js → al_form.js} +11 -18
- package/element/{alchemy_label.js → al_label.js} +1 -10
- package/element/{number_input.js → al_number_input.js} +2 -2
- package/element/{alchemy_pager.js → al_pager.js} +49 -41
- package/element/{alchemy_password_input.js → al_password_input.js} +0 -0
- package/element/{query_builder.js → al_query_builder.js} +3 -12
- package/element/{query_builder_entry.js → al_query_builder_entry.js} +52 -16
- package/element/{query_builder_group.js → al_query_builder_group.js} +7 -7
- package/element/{query_builder_value.js → al_query_builder_value.js} +16 -7
- package/element/{query_builder_variable.js → al_query_builder_variable.js} +1 -1
- package/element/{alchemy_select.js → al_select.js} +64 -118
- package/element/{alchemy_select_item.js → al_select_item.js} +15 -9
- package/element/al_state.js +26 -0
- package/element/{string_input.js → al_string_input.js} +2 -2
- package/element/al_tab_button.js +138 -0
- package/element/al_tab_context.js +102 -0
- package/element/al_tab_list.js +66 -0
- package/element/al_tab_panel.js +44 -0
- package/element/{alchemy_table.js → al_table.js} +187 -174
- package/element/{alchemy_toggle.js → al_toggle.js} +1 -10
- package/helper/form_actions/00_form_action.js +15 -4
- package/helper/form_actions/url_action.js +3 -2
- package/helper/query_builder_variable_definition/boolean_variable_definition.js +1 -1
- package/helper_field/query_builder_field.js +2 -2
- package/package.json +2 -2
- package/view/form/elements/alchemy_button.hwk +1 -0
- package/view/form/elements/alchemy_field.hwk +4 -4
- package/view/form/elements/alchemy_field_array.hwk +2 -2
- package/view/form/elements/alchemy_field_schema.hwk +2 -2
- package/view/form/elements/alchemy_field_translatable.hwk +2 -2
- package/view/form/elements/alchemy_field_translatable_entry.hwk +2 -2
- package/view/form/elements/query_builder.hwk +1 -1
- package/view/form/elements/query_builder_entry.hwk +20 -11
- package/view/form/elements/query_builder_value.hwk +2 -2
- package/view/form/elements/query_builder_variable.hwk +2 -2
- package/view/form/inputs/edit/belongs_to.hwk +2 -2
- package/view/form/inputs/edit/boolean.hwk +2 -2
- package/view/form/inputs/edit/enum.hwk +2 -2
- package/view/form/inputs/edit/has_and_belongs_to_many.hwk +2 -2
- package/view/form/inputs/edit/html.hwk +2 -2
- package/view/form/inputs/edit/query_builder.hwk +2 -2
- package/view/form/inputs/edit/query_builder_assignment.hwk +2 -2
- package/view/form/inputs/edit/query_builder_value.hwk +2 -2
- package/view/form/inputs/edit/query_builder_variable.hwk +2 -2
- package/view/form/inputs/edit/schema.hwk +2 -2
- package/view/form/inputs/edit/sourcecode.hwk +2 -2
- package/view/form/inputs/edit_inline/boolean.hwk +2 -2
- package/view/form/inputs/view/string.hwk +6 -1
- package/view/form/inputs/view_inline/datetime.hwk +8 -4
- package/view/form/inputs/view_inline/string.hwk +6 -1
- package/view/form/wrappers/default/default.hwk +2 -2
- package/helper/widgets/alchemy_field_widget.js +0 -112
- package/helper/widgets/alchemy_form_widget.js +0 -183
- package/helper/widgets/alchemy_table_widget.js +0 -67
|
@@ -0,0 +1,282 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The base form element with dataproviders
|
|
3
|
+
*
|
|
4
|
+
* @author Jelle De Loecker <jelle@elevenways.be>
|
|
5
|
+
* @since 0.2.0
|
|
6
|
+
* @version 0.2.0
|
|
7
|
+
*/
|
|
8
|
+
const WithDataprovider = Function.inherits('Alchemy.Element.Form.Base', 'WithDataprovider');
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* This is a static class (so it won't be registered)
|
|
12
|
+
*
|
|
13
|
+
* @author Jelle De Loecker <jelle@elevenways.be>
|
|
14
|
+
* @since 0.2.0
|
|
15
|
+
* @version 0.2.0
|
|
16
|
+
*/
|
|
17
|
+
WithDataprovider.makeAbstractClass();
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* The method to use for src requests
|
|
21
|
+
*
|
|
22
|
+
* @author Jelle De Loecker <jelle@elevenways.be>
|
|
23
|
+
* @since 0.2.0
|
|
24
|
+
* @version 0.2.0
|
|
25
|
+
*/
|
|
26
|
+
WithDataprovider.setAttribute('method');
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* The page attribute
|
|
30
|
+
*
|
|
31
|
+
* @author Jelle De Loecker <jelle@elevenways.be>
|
|
32
|
+
* @since 0.2.0
|
|
33
|
+
* @version 0.2.0
|
|
34
|
+
*/
|
|
35
|
+
WithDataprovider.setAttribute('page', {number: true});
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* The page-size attribute
|
|
39
|
+
*
|
|
40
|
+
* @author Jelle De Loecker <jelle@elevenways.be>
|
|
41
|
+
* @since 0.2.0
|
|
42
|
+
* @version 0.2.0
|
|
43
|
+
*/
|
|
44
|
+
WithDataprovider.setAttribute('page-size', {number: true});
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* Keep track of the loadRemote calls
|
|
48
|
+
*
|
|
49
|
+
* @author Jelle De Loecker <jelle@elevenways.be>
|
|
50
|
+
* @since 0.2.0
|
|
51
|
+
* @version 0.2.0
|
|
52
|
+
*/
|
|
53
|
+
WithDataprovider.setProperty('load_remote_counter', 0);
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* The dataprovider is an instance of something that will load
|
|
57
|
+
* the remote data for this element
|
|
58
|
+
*
|
|
59
|
+
* @author Jelle De Loecker <jelle@elevenways.be>
|
|
60
|
+
* @since 0.2.0
|
|
61
|
+
* @version 0.2.0
|
|
62
|
+
*/
|
|
63
|
+
WithDataprovider.setAssignedProperty('dataprovider');
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* The records property
|
|
67
|
+
*
|
|
68
|
+
* @author Jelle De Loecker <jelle@elevenways.be>
|
|
69
|
+
* @since 0.2.0
|
|
70
|
+
* @version 0.2.0
|
|
71
|
+
*/
|
|
72
|
+
WithDataprovider.setAssignedProperty('recordsource', null, function onRecordsource(value) {
|
|
73
|
+
this.setRecordsource(value);
|
|
74
|
+
return value;
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
/**
|
|
78
|
+
* Look for a new src value
|
|
79
|
+
*
|
|
80
|
+
* @author Jelle De Loecker <jelle@elevenways.be>
|
|
81
|
+
* @since 0.2.0
|
|
82
|
+
* @version 0.2.0
|
|
83
|
+
*/
|
|
84
|
+
WithDataprovider.enforceProperty(function src(new_value, old_value) {
|
|
85
|
+
|
|
86
|
+
if (new_value == old_value) {
|
|
87
|
+
return new_value;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
this.setAttributeSilent('src', new_value);
|
|
91
|
+
|
|
92
|
+
return new_value;
|
|
93
|
+
});
|
|
94
|
+
|
|
95
|
+
/**
|
|
96
|
+
* Can we fetch remote data?
|
|
97
|
+
*
|
|
98
|
+
* @author Jelle De Loecker <jelle@elevenways.be>
|
|
99
|
+
* @since 0.2.0
|
|
100
|
+
* @version 0.2.0
|
|
101
|
+
*/
|
|
102
|
+
WithDataprovider.setProperty(function can_fetch_remote_data() {
|
|
103
|
+
return !!(this.src || this.dataprovider);
|
|
104
|
+
});
|
|
105
|
+
|
|
106
|
+
/**
|
|
107
|
+
* Observe SRC attribute
|
|
108
|
+
*
|
|
109
|
+
* @author Jelle De Loecker <jelle@elevenways.be>
|
|
110
|
+
* @since 0.2.0
|
|
111
|
+
* @version 0.2.0
|
|
112
|
+
*/
|
|
113
|
+
WithDataprovider.addObservedAttribute('src', function onSource(src) {
|
|
114
|
+
this.src = src;
|
|
115
|
+
});
|
|
116
|
+
|
|
117
|
+
/**
|
|
118
|
+
* The method to construct the config object used for fetching data
|
|
119
|
+
*
|
|
120
|
+
* @author Jelle De Loecker <jelle@elevenways.be>
|
|
121
|
+
* @since 0.2.0
|
|
122
|
+
* @version 0.2.0
|
|
123
|
+
*/
|
|
124
|
+
WithDataprovider.setAbstractMethod('getRemoteFetchConfig');
|
|
125
|
+
|
|
126
|
+
/**
|
|
127
|
+
* Apply the fetched data to this element
|
|
128
|
+
*
|
|
129
|
+
* @author Jelle De Loecker <jelle@elevenways.be>
|
|
130
|
+
* @since 0.2.0
|
|
131
|
+
* @version 0.2.0
|
|
132
|
+
*/
|
|
133
|
+
WithDataprovider.setAbstractMethod('applyFetchedData');
|
|
134
|
+
|
|
135
|
+
/**
|
|
136
|
+
* Set the recordsource
|
|
137
|
+
*
|
|
138
|
+
* @author Jelle De Loecker <jelle@elevenways.be>
|
|
139
|
+
* @since 0.2.0
|
|
140
|
+
* @version 0.2.0
|
|
141
|
+
*
|
|
142
|
+
* @param {*} config
|
|
143
|
+
*/
|
|
144
|
+
WithDataprovider.setMethod(function setRecordsource(config) {
|
|
145
|
+
|
|
146
|
+
let url;
|
|
147
|
+
|
|
148
|
+
if (typeof config == 'object') {
|
|
149
|
+
let route_config = alchemy.routeConfig(config.route);
|
|
150
|
+
|
|
151
|
+
if (route_config?.methods && !this.method) {
|
|
152
|
+
if (route_config.methods.indexOf('post') > -1) {
|
|
153
|
+
this.method = 'post';
|
|
154
|
+
} else {
|
|
155
|
+
this.method = route_config.methods[0];
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
url = alchemy.routeUrl(config.route, config.parameters);
|
|
160
|
+
} else {
|
|
161
|
+
url = config;
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
if (url == '#') {
|
|
165
|
+
let current_url = this.getCurrentUrl();
|
|
166
|
+
|
|
167
|
+
if (current_url) {
|
|
168
|
+
url = ''+current_url;
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
this.src = url;
|
|
173
|
+
|
|
174
|
+
this.loadRemoteData();
|
|
175
|
+
});
|
|
176
|
+
|
|
177
|
+
/**
|
|
178
|
+
* Get the wanted page
|
|
179
|
+
*
|
|
180
|
+
* @author Jelle De Loecker <jelle@elevenways.be>
|
|
181
|
+
* @since 0.2.0
|
|
182
|
+
* @version 0.2.0
|
|
183
|
+
*
|
|
184
|
+
* @return {Number}
|
|
185
|
+
*/
|
|
186
|
+
WithDataprovider.setMethod(function getWantedPage() {
|
|
187
|
+
|
|
188
|
+
let page = this.page;
|
|
189
|
+
|
|
190
|
+
if (page) {
|
|
191
|
+
return page;
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
return 1;
|
|
195
|
+
});
|
|
196
|
+
|
|
197
|
+
/**
|
|
198
|
+
* Load the remote data and apply it
|
|
199
|
+
*
|
|
200
|
+
* @author Jelle De Loecker <jelle@elevenways.be>
|
|
201
|
+
* @since 0.2.0
|
|
202
|
+
* @version 0.2.0
|
|
203
|
+
*
|
|
204
|
+
* @param {Object} fetch_config
|
|
205
|
+
*/
|
|
206
|
+
WithDataprovider.setMethod(function loadRemoteData(fetch_config) {
|
|
207
|
+
|
|
208
|
+
let pledge = new Classes.Pledge();
|
|
209
|
+
|
|
210
|
+
let config = this.getRemoteFetchConfig();
|
|
211
|
+
|
|
212
|
+
if (fetch_config) {
|
|
213
|
+
Object.assign(config, fetch_config);
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
if (!config) {
|
|
217
|
+
pledge.resolve(false);
|
|
218
|
+
return pledge;
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
let load_remote_id = ++this.load_remote_counter;
|
|
222
|
+
|
|
223
|
+
this.delayAssemble(async () => {
|
|
224
|
+
|
|
225
|
+
if (load_remote_id != this.load_remote_counter) {
|
|
226
|
+
pledge.resolve(false);
|
|
227
|
+
return;
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
let result,
|
|
231
|
+
error;
|
|
232
|
+
|
|
233
|
+
try {
|
|
234
|
+
result = await this.fetchRemoteData(config);
|
|
235
|
+
} catch (err) {
|
|
236
|
+
error = err;
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
if (load_remote_id != this.load_remote_counter) {
|
|
240
|
+
pledge.resolve(false);
|
|
241
|
+
return;
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
this.applyFetchedData(error, result, config);
|
|
245
|
+
|
|
246
|
+
pledge.resolve(true);
|
|
247
|
+
});
|
|
248
|
+
|
|
249
|
+
return pledge;
|
|
250
|
+
});
|
|
251
|
+
|
|
252
|
+
/**
|
|
253
|
+
* Actually fetch the remote data
|
|
254
|
+
*
|
|
255
|
+
* @author Jelle De Loecker <jelle@elevenways.be>
|
|
256
|
+
* @since 0.2.0
|
|
257
|
+
* @version 0.2.0
|
|
258
|
+
*
|
|
259
|
+
* @param {Object} config
|
|
260
|
+
*
|
|
261
|
+
* @return {Pledge}
|
|
262
|
+
*/
|
|
263
|
+
WithDataprovider.setMethod(function fetchRemoteData(config) {
|
|
264
|
+
|
|
265
|
+
let pledge;
|
|
266
|
+
|
|
267
|
+
if (this.dataprovider) {
|
|
268
|
+
pledge = Pledge.cast(this.dataprovider.loadData(config, this));
|
|
269
|
+
} else {
|
|
270
|
+
|
|
271
|
+
let method = (this.method || 'get').toLowerCase();
|
|
272
|
+
|
|
273
|
+
let fetch_options = {
|
|
274
|
+
href : this.src,
|
|
275
|
+
[method] : config,
|
|
276
|
+
};
|
|
277
|
+
|
|
278
|
+
pledge = this.hawkejs_helpers.Alchemy.getResource(fetch_options);
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
return pledge;
|
|
282
|
+
});
|
|
@@ -1,15 +1,13 @@
|
|
|
1
1
|
var VALUE = Symbol('value');
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
|
-
* The
|
|
4
|
+
* The al-field-entry element
|
|
5
5
|
*
|
|
6
6
|
* @author Jelle De Loecker <jelle@elevenways.be>
|
|
7
7
|
* @since 0.1.0
|
|
8
8
|
* @version 0.1.0
|
|
9
9
|
*/
|
|
10
|
-
|
|
11
|
-
FieldEntry.super.call(this);
|
|
12
|
-
});
|
|
10
|
+
const FieldEntry = Function.inherits('Alchemy.Element.Form.FieldCustom', 'FieldEntry');
|
|
13
11
|
|
|
14
12
|
/**
|
|
15
13
|
* Don't register this as a custom element,
|
|
@@ -17,9 +15,9 @@ var FieldEntry = Function.inherits('Alchemy.Element.Form.FieldCustom', function
|
|
|
17
15
|
*
|
|
18
16
|
* @author Jelle De Loecker <jelle@elevenways.be>
|
|
19
17
|
* @since 0.1.0
|
|
20
|
-
* @version 0.
|
|
18
|
+
* @version 0.2.0
|
|
21
19
|
*/
|
|
22
|
-
FieldEntry.
|
|
20
|
+
FieldEntry.makeAbstractClass();
|
|
23
21
|
|
|
24
22
|
/**
|
|
25
23
|
* Get the live value
|
|
@@ -55,16 +53,16 @@ FieldEntry.setProperty(function value() {
|
|
|
55
53
|
*
|
|
56
54
|
* @author Jelle De Loecker <jelle@elevenways.be>
|
|
57
55
|
* @since 0.1.0
|
|
58
|
-
* @version 0.
|
|
56
|
+
* @version 0.2.0
|
|
59
57
|
*/
|
|
60
58
|
FieldEntry.setProperty(function value_element() {
|
|
61
59
|
|
|
62
60
|
let input;
|
|
63
61
|
|
|
64
|
-
if (this.is_array && this.tagName != '
|
|
65
|
-
input = this.querySelector('
|
|
62
|
+
if (this.is_array && this.tagName != 'AL-FIELD-ARRAY' && this.tagName != 'AL-FIELD-ARRAY-ENTRY') {
|
|
63
|
+
input = this.querySelector('al-field-array');
|
|
66
64
|
} else {
|
|
67
|
-
input = this.querySelector('
|
|
65
|
+
input = this.querySelector('al-field-schema, .alchemy-field-value');
|
|
68
66
|
}
|
|
69
67
|
|
|
70
68
|
return input;
|
|
@@ -13,18 +13,9 @@ const QueryBuilderBase = Function.inherits('Alchemy.Element.Form.Base', 'QueryBu
|
|
|
13
13
|
*
|
|
14
14
|
* @author Jelle De Loecker <jelle@elevenways.be>
|
|
15
15
|
* @since 0.1.6
|
|
16
|
-
* @version 0.
|
|
16
|
+
* @version 0.2.0
|
|
17
17
|
*/
|
|
18
|
-
QueryBuilderBase.
|
|
19
|
-
|
|
20
|
-
/**
|
|
21
|
-
* The stylesheet to load for this element
|
|
22
|
-
*
|
|
23
|
-
* @author Jelle De Loecker <jelle@elevenways.be>
|
|
24
|
-
* @since 0.1.6
|
|
25
|
-
* @version 0.1.6
|
|
26
|
-
*/
|
|
27
|
-
QueryBuilderBase.setStylesheetFile('form/query_builder');
|
|
18
|
+
QueryBuilderBase.makeAbstractClass();
|
|
28
19
|
|
|
29
20
|
/**
|
|
30
21
|
* Get the dataprovider
|
|
@@ -53,10 +44,10 @@ QueryBuilderBase.enforceProperty(function dataprovider(new_value) {
|
|
|
53
44
|
*
|
|
54
45
|
* @author Jelle De Loecker <jelle@elevenways.be>
|
|
55
46
|
* @since 0.1.6
|
|
56
|
-
* @version 0.
|
|
47
|
+
* @version 0.2.0
|
|
57
48
|
*/
|
|
58
49
|
QueryBuilderBase.setProperty(function root_query_builder() {
|
|
59
|
-
return this.queryParents('
|
|
50
|
+
return this.queryParents('al-query-builder');
|
|
60
51
|
});
|
|
61
52
|
|
|
62
53
|
/**
|
|
@@ -13,9 +13,9 @@ const QueryBuilderData = Function.inherits('Alchemy.Element.Form.QueryBuilderBas
|
|
|
13
13
|
*
|
|
14
14
|
* @author Jelle De Loecker <jelle@elevenways.be>
|
|
15
15
|
* @since 0.1.7
|
|
16
|
-
* @version 0.
|
|
16
|
+
* @version 0.2.0
|
|
17
17
|
*/
|
|
18
|
-
QueryBuilderData.
|
|
18
|
+
QueryBuilderData.makeAbstractClass();
|
|
19
19
|
|
|
20
20
|
/**
|
|
21
21
|
* Check a filter
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The base class for tab elements
|
|
3
|
+
*
|
|
4
|
+
* @author Jelle De Loecker <jelle@elevenways.be>
|
|
5
|
+
* @since 0.2.0
|
|
6
|
+
* @version 0.2.0
|
|
7
|
+
*/
|
|
8
|
+
const TabBase = Function.inherits('Alchemy.Element.Form.Base', 'TabBase');
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Don't register this as a custom element,
|
|
12
|
+
* but don't let child classes inherit this
|
|
13
|
+
*
|
|
14
|
+
* @author Jelle De Loecker <jelle@elevenways.be>
|
|
15
|
+
* @since 0.2.0
|
|
16
|
+
* @version 0.2.0
|
|
17
|
+
*/
|
|
18
|
+
TabBase.makeAbstractClass();
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Get the context element
|
|
22
|
+
*
|
|
23
|
+
* @author Jelle De Loecker <jelle@elevenways.be>
|
|
24
|
+
* @since 0.2.0
|
|
25
|
+
* @version 0.2.0
|
|
26
|
+
*/
|
|
27
|
+
TabBase.setProperty(function tab_context() {
|
|
28
|
+
return this.queryUp('al-tab-context');
|
|
29
|
+
});
|
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
const STATE_COUNT = Symbol('state_count');
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* The base stateful element
|
|
5
|
+
*
|
|
6
|
+
* @author Jelle De Loecker <jelle@elevenways.be>
|
|
7
|
+
* @since 0.2.0
|
|
8
|
+
* @version 0.2.0
|
|
9
|
+
*/
|
|
10
|
+
const Stateful = Function.inherits('Alchemy.Element.Form.Base', 'Stateful');
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* The current state
|
|
14
|
+
*
|
|
15
|
+
* @author Jelle De Loecker <jelle@elevenways.be>
|
|
16
|
+
* @since 0.2.0
|
|
17
|
+
* @version 0.2.0
|
|
18
|
+
*/
|
|
19
|
+
Stateful.setAttribute('state', {default: 'default'});
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Add a state listener to all child classes
|
|
23
|
+
*
|
|
24
|
+
* @author Jelle De Loecker <jelle@elevenways.be>
|
|
25
|
+
* @since 0.2.0
|
|
26
|
+
* @version 0.2.0
|
|
27
|
+
*/
|
|
28
|
+
Stateful.addObservedAttribute('state', function onChange(state) {
|
|
29
|
+
this.refresh();
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* The current state counter
|
|
34
|
+
*
|
|
35
|
+
* @author Jelle De Loecker <jelle@elevenways.be>
|
|
36
|
+
* @since 0.2.0
|
|
37
|
+
* @version 0.2.0
|
|
38
|
+
*/
|
|
39
|
+
Stateful.setProperty(STATE_COUNT, 0);
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* Set the state of the state (for a specific time)
|
|
43
|
+
*
|
|
44
|
+
* @author Jelle De Loecker <jelle@elevenways.be>
|
|
45
|
+
* @since 0.2.0
|
|
46
|
+
* @version 0.2.0
|
|
47
|
+
*
|
|
48
|
+
* @param {String} state_name
|
|
49
|
+
* @param {Number} duration_in_ms
|
|
50
|
+
* @param {String} final_state
|
|
51
|
+
*/
|
|
52
|
+
Stateful.setMethod(function setState(state_name, duration_in_ms, final_state) {
|
|
53
|
+
|
|
54
|
+
let old_state = this.state,
|
|
55
|
+
state_count = ++this[STATE_COUNT];
|
|
56
|
+
|
|
57
|
+
this.state = state_name;
|
|
58
|
+
|
|
59
|
+
if (duration_in_ms > 0 && Blast.isBrowser) {
|
|
60
|
+
|
|
61
|
+
if (final_state == null) {
|
|
62
|
+
final_state = old_state;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
setTimeout(() => {
|
|
66
|
+
if (this[STATE_COUNT] != state_count) {
|
|
67
|
+
return;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
this.state = final_state;
|
|
71
|
+
}, duration_in_ms);
|
|
72
|
+
}
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
/**
|
|
76
|
+
* Create a state scheduler function.
|
|
77
|
+
* This will only call the callback if the state count remains the same
|
|
78
|
+
*
|
|
79
|
+
* @author Jelle De Loecker <jelle@elevenways.be>
|
|
80
|
+
* @since 0.2.0
|
|
81
|
+
* @version 0.2.0
|
|
82
|
+
*/
|
|
83
|
+
Stateful.setMethod(function wrapForCurrentState(callback) {
|
|
84
|
+
|
|
85
|
+
let count = this[STATE_COUNT];
|
|
86
|
+
|
|
87
|
+
return () => {
|
|
88
|
+
|
|
89
|
+
if (this[STATE_COUNT] != count) {
|
|
90
|
+
return false;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
callback();
|
|
94
|
+
|
|
95
|
+
return true;
|
|
96
|
+
}
|
|
97
|
+
});
|
|
98
|
+
|
|
99
|
+
/**
|
|
100
|
+
* Refresh all the children
|
|
101
|
+
*
|
|
102
|
+
* @author Jelle De Loecker <jelle@elevenways.be>
|
|
103
|
+
* @since 0.2.0
|
|
104
|
+
* @version 0.2.0
|
|
105
|
+
*/
|
|
106
|
+
Stateful.setMethod(function refresh() {
|
|
107
|
+
|
|
108
|
+
let current_state = this.state,
|
|
109
|
+
state_parent,
|
|
110
|
+
children = this.queryAllNotNested('[state-name]'),
|
|
111
|
+
child,
|
|
112
|
+
i;
|
|
113
|
+
|
|
114
|
+
for (i = 0; i < children.length; i++) {
|
|
115
|
+
child = children[i];
|
|
116
|
+
|
|
117
|
+
state_parent = child.queryParents('[state]');
|
|
118
|
+
|
|
119
|
+
if (state_parent != this) {
|
|
120
|
+
continue;
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
child.active = child.state_name == current_state;
|
|
124
|
+
}
|
|
125
|
+
});
|
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The al-button element
|
|
3
|
+
*
|
|
4
|
+
* @author Jelle De Loecker <jelle@elevenways.be>
|
|
5
|
+
* @since 0.2.0
|
|
6
|
+
* @version 0.2.0
|
|
7
|
+
*/
|
|
8
|
+
const Button = Function.inherits('Alchemy.Element.Form.Stateful', 'Button');
|
|
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.2.0
|
|
15
|
+
* @version 0.2.0
|
|
16
|
+
*/
|
|
17
|
+
Button.setTemplateFile('form/elements/alchemy_button');
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Set the ARIA role of the element
|
|
21
|
+
*
|
|
22
|
+
* @author Jelle De Loecker <jelle@elevenways.be>
|
|
23
|
+
* @since 0.2.0
|
|
24
|
+
* @version 0.2.0
|
|
25
|
+
*/
|
|
26
|
+
Button.setRole('button');
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Make it tabable
|
|
30
|
+
*
|
|
31
|
+
* @author Jelle De Loecker <jelle@elevenways.be>
|
|
32
|
+
* @since 0.2.0
|
|
33
|
+
* @version 0.2.0
|
|
34
|
+
*/
|
|
35
|
+
Button.setAttribute('tabindex', {default: 0});
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* The allowed activatable states
|
|
39
|
+
*
|
|
40
|
+
* @author Jelle De Loecker <jelle@elevenways.be>
|
|
41
|
+
* @since 0.2.0
|
|
42
|
+
* @version 0.2.0
|
|
43
|
+
*/
|
|
44
|
+
Button.setAttribute('activatable-states', {type: 'token_list'});
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* Preconfigured behaviours
|
|
48
|
+
*
|
|
49
|
+
* @author Jelle De Loecker <jelle@elevenways.be>
|
|
50
|
+
* @since 0.2.1
|
|
51
|
+
* @version 0.2.1
|
|
52
|
+
*/
|
|
53
|
+
Button.setAttribute('behaviour', {type: 'token_list'});
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* Action instances
|
|
57
|
+
*
|
|
58
|
+
* @author Jelle De Loecker <jelle@elevenways.be>
|
|
59
|
+
* @since 0.2.0
|
|
60
|
+
* @version 0.2.0
|
|
61
|
+
*/
|
|
62
|
+
Button.setAssignedProperty('action_instance');
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* Emit the activate event
|
|
66
|
+
*
|
|
67
|
+
* @author Jelle De Loecker <jelle@elevenways.be>
|
|
68
|
+
* @since 0.2.0
|
|
69
|
+
* @version 0.2.1
|
|
70
|
+
*/
|
|
71
|
+
Button.setMethod(function activate() {
|
|
72
|
+
|
|
73
|
+
let allowed_states = this.activatable_states;
|
|
74
|
+
|
|
75
|
+
if (!allowed_states.length) {
|
|
76
|
+
allowed_states = ['default', 'ready', 'idle'];
|
|
77
|
+
} else {
|
|
78
|
+
allowed_states = allowed_states.values();
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
if (allowed_states.indexOf(this.state) == -1) {
|
|
82
|
+
return;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
let event = this.emit('activate');
|
|
86
|
+
|
|
87
|
+
if (event.defaultPrevented) {
|
|
88
|
+
return;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
if (this.action_instance) {
|
|
92
|
+
this.action_instance.execute(event);
|
|
93
|
+
} else if (this.behaviour.contains('submit')) {
|
|
94
|
+
let form = this.queryUp('al-form, form');
|
|
95
|
+
|
|
96
|
+
if (form) {
|
|
97
|
+
let pledge = form.submit();
|
|
98
|
+
|
|
99
|
+
if (Pledge.isThenable(pledge)) {
|
|
100
|
+
let old_state = this.state;
|
|
101
|
+
this.setState('busy');
|
|
102
|
+
|
|
103
|
+
Pledge.done(pledge, err => {
|
|
104
|
+
|
|
105
|
+
let temp_state,
|
|
106
|
+
duration;
|
|
107
|
+
|
|
108
|
+
if (err) {
|
|
109
|
+
temp_state = 'error';
|
|
110
|
+
duration = 2500;
|
|
111
|
+
} else {
|
|
112
|
+
temp_state = 'done';
|
|
113
|
+
duration = 1000;
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
this.setState(temp_state, duration, old_state);
|
|
117
|
+
});
|
|
118
|
+
} else {
|
|
119
|
+
this.setState('busy', 1000);
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
});
|
|
124
|
+
|
|
125
|
+
/**
|
|
126
|
+
* The element has been added to the dom for the first time
|
|
127
|
+
*
|
|
128
|
+
* @author Jelle De Loecker <jelle@elevenways.be>
|
|
129
|
+
* @since 0.2.0
|
|
130
|
+
* @version 0.2.0
|
|
131
|
+
*/
|
|
132
|
+
Button.setMethod(function introduced() {
|
|
133
|
+
|
|
134
|
+
this.addEventListener('click', e => {
|
|
135
|
+
this.activate();
|
|
136
|
+
});
|
|
137
|
+
|
|
138
|
+
this.addEventListener('keyup', e => {
|
|
139
|
+
|
|
140
|
+
switch (e.key) {
|
|
141
|
+
case ' ':
|
|
142
|
+
case 'Enter':
|
|
143
|
+
this.activate();
|
|
144
|
+
break;
|
|
145
|
+
}
|
|
146
|
+
});
|
|
147
|
+
});
|
|
@@ -16,15 +16,6 @@ const CodeInput = Function.inherits('Alchemy.Element.Form.Base', 'CodeInput');
|
|
|
16
16
|
*/
|
|
17
17
|
CodeInput.setTemplateFile('form/elements/code_input');
|
|
18
18
|
|
|
19
|
-
/**
|
|
20
|
-
* The stylesheet to load for this element
|
|
21
|
-
*
|
|
22
|
-
* @author Jelle De Loecker <jelle@elevenways.be>
|
|
23
|
-
* @since 0.1.0
|
|
24
|
-
* @version 0.1.0
|
|
25
|
-
*/
|
|
26
|
-
CodeInput.setStylesheetFile('form/alchemy_code_input');
|
|
27
|
-
|
|
28
19
|
/**
|
|
29
20
|
* Get/set the value
|
|
30
21
|
*
|
|
@@ -82,7 +73,7 @@ CodeInput.setMethod(async function introduced() {
|
|
|
82
73
|
editor.session.setUseWrapMode(true);
|
|
83
74
|
editor.setFontSize(16);
|
|
84
75
|
|
|
85
|
-
let parent_field = this.queryParents('
|
|
76
|
+
let parent_field = this.queryParents('al-field');
|
|
86
77
|
|
|
87
78
|
if (parent_field && parent_field.widget_settings && parent_field.widget_settings.language_mode) {
|
|
88
79
|
|