alchemy-form 0.1.5 → 0.1.8
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 +29 -0
- package/assets/stylesheets/form/alchemy_field_array.scss +4 -0
- package/assets/stylesheets/form/alchemy_select.scss +1 -3
- package/assets/stylesheets/form/alchemy_toggle.scss +2 -0
- package/assets/stylesheets/form/query_builder.scss +185 -0
- package/config/routes.js +8 -0
- package/controller/form_api_controller.js +43 -4
- package/element/20_query_builder_base.js +82 -0
- package/element/25_query_builder_data.js +139 -0
- package/element/alchemy_field.js +31 -7
- package/element/alchemy_select.js +172 -39
- package/element/alchemy_select_item.js +9 -0
- package/element/alchemy_table.js +172 -26
- package/element/query_builder.js +90 -0
- package/element/query_builder_entry.js +388 -0
- package/element/query_builder_group.js +248 -0
- package/element/query_builder_value.js +316 -0
- package/element/query_builder_variable.js +103 -0
- package/helper/form_actions/00_form_action.js +328 -0
- package/helper/form_actions/url_action.js +69 -0
- package/helper/query_builder_variable_definition/00_variable_definition.js +371 -0
- package/helper/query_builder_variable_definition/boolean_variable_definition.js +24 -0
- package/helper/query_builder_variable_definition/list_variable_definition.js +38 -0
- package/helper/query_builder_variable_definition/number_variable_definition.js +106 -0
- package/helper/query_builder_variable_definition/string_variable_definition.js +46 -0
- package/helper_field/query_builder_assignment.js +11 -0
- package/helper_field/query_builder_field.js +91 -0
- package/helper_field/query_builder_value.js +56 -0
- package/helper_field/query_builder_variable.js +56 -0
- package/package.json +2 -2
- package/view/form/elements/alchemy_field_array.hwk +3 -1
- package/view/form/elements/alchemy_field_array_entry.hwk +3 -1
- package/view/form/elements/alchemy_select_item.hwk +6 -1
- package/view/form/elements/query_builder.hwk +1 -0
- package/view/form/elements/query_builder_entry.hwk +33 -0
- package/view/form/elements/query_builder_group.hwk +64 -0
- package/view/form/elements/query_builder_value.hwk +10 -0
- package/view/form/elements/query_builder_variable.hwk +6 -0
- package/view/form/inputs/edit/belongs_to.hwk +1 -1
- package/view/form/inputs/edit/html.hwk +5 -0
- package/view/form/inputs/edit/query_builder.hwk +5 -0
- package/view/form/inputs/edit/query_builder_assignment.hwk +6 -0
- package/view/form/inputs/edit/query_builder_value.hwk +11 -0
- package/view/form/inputs/edit/query_builder_variable.hwk +10 -0
- package/view/form/inputs/view/string.hwk +1 -0
- package/view/form/inputs/view_inline/string.hwk +1 -0
- package/view/form/select/qb_item.hwk +7 -0
- package/view/form/wrappers/view_inline/default.hwk +1 -0
|
@@ -0,0 +1,328 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Form actions
|
|
3
|
+
*
|
|
4
|
+
* @constructor
|
|
5
|
+
*
|
|
6
|
+
* @author Jelle De Loecker <jelle@elevenways.be>
|
|
7
|
+
* @since 0.1.6
|
|
8
|
+
* @version 0.1.6
|
|
9
|
+
*
|
|
10
|
+
* @param {Object} config
|
|
11
|
+
*/
|
|
12
|
+
const FormAction = Function.inherits('Alchemy.Base', 'Alchemy.Form.Action', function Action(config) {
|
|
13
|
+
this.extra_config = {};
|
|
14
|
+
this.applyConfig(config);
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Make this an abtract class
|
|
19
|
+
*/
|
|
20
|
+
FormAction.makeAbstractClass();
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* This class starts a new group
|
|
24
|
+
*/
|
|
25
|
+
FormAction.startNewGroup('alchemy_form_actions');
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Add a configuration property
|
|
30
|
+
*
|
|
31
|
+
* @author Jelle De Loecker <jelle@elevenways.be>
|
|
32
|
+
* @since 0.1.6
|
|
33
|
+
* @version 0.1.6
|
|
34
|
+
*/
|
|
35
|
+
FormAction.setStatic(function addConfigProperty(name) {
|
|
36
|
+
|
|
37
|
+
this.constitute(function addProperty() {
|
|
38
|
+
|
|
39
|
+
if (!this.config_properties) {
|
|
40
|
+
this.config_properties = [];
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
this.config_properties.push(name);
|
|
44
|
+
|
|
45
|
+
this.setProperty(name, function getConfigValue() {
|
|
46
|
+
return this.extra_config[name];
|
|
47
|
+
}, function setConfigValue(value) {
|
|
48
|
+
return this.extra_config[name] = value;
|
|
49
|
+
});
|
|
50
|
+
});
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* The machine-readable name of the action
|
|
55
|
+
*
|
|
56
|
+
* @author Jelle De Loecker <jelle@elevenways.be>
|
|
57
|
+
* @since 0.1.6
|
|
58
|
+
* @version 0.1.6
|
|
59
|
+
*/
|
|
60
|
+
FormAction.setProperty('name');
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* The icon to use for this action
|
|
64
|
+
*
|
|
65
|
+
* @author Jelle De Loecker <jelle@elevenways.be>
|
|
66
|
+
* @since 0.1.6
|
|
67
|
+
* @version 0.1.6
|
|
68
|
+
*/
|
|
69
|
+
FormAction.setProperty('icon');
|
|
70
|
+
|
|
71
|
+
/**
|
|
72
|
+
* The description of the action
|
|
73
|
+
*
|
|
74
|
+
* @author Jelle De Loecker <jelle@elevenways.be>
|
|
75
|
+
* @since 0.1.6
|
|
76
|
+
* @version 0.1.6
|
|
77
|
+
*/
|
|
78
|
+
FormAction.setProperty('description');
|
|
79
|
+
|
|
80
|
+
/**
|
|
81
|
+
* The placement of the action
|
|
82
|
+
*
|
|
83
|
+
* @author Jelle De Loecker <jelle@elevenways.be>
|
|
84
|
+
* @since 0.1.6
|
|
85
|
+
* @version 0.1.6
|
|
86
|
+
*/
|
|
87
|
+
FormAction.enforceProperty(function placement(new_value) {
|
|
88
|
+
|
|
89
|
+
if (!new_value) {
|
|
90
|
+
new_value = [];
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
return new_value;
|
|
94
|
+
});
|
|
95
|
+
|
|
96
|
+
/**
|
|
97
|
+
* The human-readable title of this action
|
|
98
|
+
*
|
|
99
|
+
* @author Jelle De Loecker <jelle@elevenways.be>
|
|
100
|
+
* @since 0.1.6
|
|
101
|
+
* @version 0.1.6
|
|
102
|
+
*/
|
|
103
|
+
FormAction.enforceProperty(function title(new_value) {
|
|
104
|
+
|
|
105
|
+
if (!new_value && this.name) {
|
|
106
|
+
new_value = this.name.titleize();
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
return new_value;
|
|
110
|
+
});
|
|
111
|
+
|
|
112
|
+
/**
|
|
113
|
+
* Get the type_name from the constructor
|
|
114
|
+
*
|
|
115
|
+
* @author Jelle De Loecker <jelle@elevenways.be>
|
|
116
|
+
* @since 0.1.6
|
|
117
|
+
* @version 0.1.6
|
|
118
|
+
*/
|
|
119
|
+
FormAction.setProperty(function type_name() {
|
|
120
|
+
return this.constructor.type_name;
|
|
121
|
+
});
|
|
122
|
+
|
|
123
|
+
/**
|
|
124
|
+
* Apply configuration
|
|
125
|
+
*
|
|
126
|
+
* @author Jelle De Loecker <jelle@elevenways.be>
|
|
127
|
+
* @since 0.1.6
|
|
128
|
+
* @version 0.1.6
|
|
129
|
+
*/
|
|
130
|
+
FormAction.setMethod(function applyConfig(config) {
|
|
131
|
+
Object.assign(this, config);
|
|
132
|
+
});
|
|
133
|
+
|
|
134
|
+
/**
|
|
135
|
+
* Is this action allowed to appear in the given placement?
|
|
136
|
+
*
|
|
137
|
+
* @author Jelle De Loecker <jelle@elevenways.be>
|
|
138
|
+
* @since 0.1.6
|
|
139
|
+
* @version 0.1.6
|
|
140
|
+
*
|
|
141
|
+
* @param {String} placement
|
|
142
|
+
*
|
|
143
|
+
* @return {Boolean}
|
|
144
|
+
*/
|
|
145
|
+
FormAction.setMethod(function isAllowedIn(placement) {
|
|
146
|
+
return this.placement.indexOf(placement) > -1;
|
|
147
|
+
});
|
|
148
|
+
|
|
149
|
+
/**
|
|
150
|
+
* Return an simple object for JSON-ifying
|
|
151
|
+
*
|
|
152
|
+
* @author Jelle De Loecker <jelle@elevenways.be>
|
|
153
|
+
* @since 0.1.6
|
|
154
|
+
* @version 0.1.6
|
|
155
|
+
*
|
|
156
|
+
* @return {Object}
|
|
157
|
+
*/
|
|
158
|
+
FormAction.setMethod(function toJSON() {
|
|
159
|
+
|
|
160
|
+
let result = {
|
|
161
|
+
type : this.type_name,
|
|
162
|
+
name : this.name,
|
|
163
|
+
title : this.title,
|
|
164
|
+
description : this.description,
|
|
165
|
+
placement : this.placement,
|
|
166
|
+
icon : this.icon,
|
|
167
|
+
};
|
|
168
|
+
|
|
169
|
+
if (this.constructor.config_properties && this.constructor.config_properties.length) {
|
|
170
|
+
|
|
171
|
+
let key;
|
|
172
|
+
|
|
173
|
+
for (key of this.constructor.config_properties) {
|
|
174
|
+
result[key] = this[key];
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
return result;
|
|
179
|
+
});
|
|
180
|
+
|
|
181
|
+
/**
|
|
182
|
+
* Return an object for json-drying this object
|
|
183
|
+
*
|
|
184
|
+
* @author Jelle De Loecker <jelle@elevenways.be>
|
|
185
|
+
* @since 0.1.6
|
|
186
|
+
* @version 0.1.6
|
|
187
|
+
*
|
|
188
|
+
* @return {Object}
|
|
189
|
+
*/
|
|
190
|
+
FormAction.setMethod(function toDry() {
|
|
191
|
+
return {
|
|
192
|
+
value : this.toJSON(),
|
|
193
|
+
};
|
|
194
|
+
});
|
|
195
|
+
|
|
196
|
+
/**
|
|
197
|
+
* Get an element representation
|
|
198
|
+
*
|
|
199
|
+
* @author Jelle De Loecker <jelle@elevenways.be>
|
|
200
|
+
* @since 0.1.6
|
|
201
|
+
* @version 0.1.6
|
|
202
|
+
*
|
|
203
|
+
* @param {Renderer|Element}
|
|
204
|
+
*
|
|
205
|
+
* @return {HTMLElement}
|
|
206
|
+
*/
|
|
207
|
+
FormAction.setMethod(function constructElement(renderer) {
|
|
208
|
+
|
|
209
|
+
if (renderer && renderer instanceof Blast.Classes.Hawkejs.Element.Element) {
|
|
210
|
+
renderer = renderer.hawkejs_renderer;
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
if (!renderer && typeof hawkejs != 'undefined') {
|
|
214
|
+
renderer = hawkejs.scene.general_renderer;
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
if (!renderer) {
|
|
218
|
+
return;
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
return this._constructElement(renderer);
|
|
222
|
+
});
|
|
223
|
+
|
|
224
|
+
/**
|
|
225
|
+
* Get an element representation
|
|
226
|
+
*
|
|
227
|
+
* @author Jelle De Loecker <jelle@elevenways.be>
|
|
228
|
+
* @since 0.1.6
|
|
229
|
+
* @version 0.1.6
|
|
230
|
+
*
|
|
231
|
+
* @return {HTMLElement}
|
|
232
|
+
*/
|
|
233
|
+
FormAction.setMethod(function _constructElement(renderer) {
|
|
234
|
+
|
|
235
|
+
let span = renderer.createElement('span');
|
|
236
|
+
span.textContent = this.title;
|
|
237
|
+
return span;
|
|
238
|
+
});
|
|
239
|
+
|
|
240
|
+
/**
|
|
241
|
+
* Execute this action programatically
|
|
242
|
+
*
|
|
243
|
+
* @author Jelle De Loecker <jelle@elevenways.be>
|
|
244
|
+
* @since 0.1.6
|
|
245
|
+
* @version 0.1.6
|
|
246
|
+
*
|
|
247
|
+
* @param {Event} event Optional event
|
|
248
|
+
*/
|
|
249
|
+
FormAction.setMethod(function execute(event) {
|
|
250
|
+
console.log('Should perform', this.type, 'event');
|
|
251
|
+
});
|
|
252
|
+
|
|
253
|
+
/**
|
|
254
|
+
* Add this action to a context menu
|
|
255
|
+
*
|
|
256
|
+
* @author Jelle De Loecker <jelle@elevenways.be>
|
|
257
|
+
* @since 0.1.6
|
|
258
|
+
* @version 0.1.6
|
|
259
|
+
*
|
|
260
|
+
* @param {HeContextMenu} menu The menu to add this action to
|
|
261
|
+
*
|
|
262
|
+
* @return {HTMLElement}
|
|
263
|
+
*/
|
|
264
|
+
FormAction.setMethod(function addToContextMenu(menu) {
|
|
265
|
+
|
|
266
|
+
if (!menu) {
|
|
267
|
+
return;
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
let config = {
|
|
271
|
+
name : this.name,
|
|
272
|
+
title : this.title,
|
|
273
|
+
icon : this.icon,
|
|
274
|
+
};
|
|
275
|
+
|
|
276
|
+
menu.addEntry(config, click_event => {
|
|
277
|
+
this.execute(click_event);
|
|
278
|
+
});
|
|
279
|
+
});
|
|
280
|
+
|
|
281
|
+
/**
|
|
282
|
+
* Create the correct action instance
|
|
283
|
+
*
|
|
284
|
+
* @author Jelle De Loecker <jelle@elevenways.be>
|
|
285
|
+
* @since 0.1.6
|
|
286
|
+
* @version 0.1.6
|
|
287
|
+
*/
|
|
288
|
+
FormAction.setStatic(function cast(entry) {
|
|
289
|
+
|
|
290
|
+
if (!entry) {
|
|
291
|
+
return null;
|
|
292
|
+
}
|
|
293
|
+
|
|
294
|
+
if (entry instanceof FormAction) {
|
|
295
|
+
return entry;
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
if (!entry.type) {
|
|
299
|
+
return null;
|
|
300
|
+
}
|
|
301
|
+
|
|
302
|
+
let constructor = FormAction.getMember(entry.type);
|
|
303
|
+
|
|
304
|
+
if (!constructor && entry.type == 'action') {
|
|
305
|
+
constructor = this;
|
|
306
|
+
}
|
|
307
|
+
|
|
308
|
+
if (!constructor) {
|
|
309
|
+
return null;
|
|
310
|
+
}
|
|
311
|
+
|
|
312
|
+
let result = new constructor(entry);
|
|
313
|
+
|
|
314
|
+
return result;
|
|
315
|
+
});
|
|
316
|
+
|
|
317
|
+
/**
|
|
318
|
+
* unDry an object
|
|
319
|
+
*
|
|
320
|
+
* @author Jelle De Loecker <jelle@elevenways.be>
|
|
321
|
+
* @since 0.1.6
|
|
322
|
+
* @version 0.1.6
|
|
323
|
+
*
|
|
324
|
+
* @return {VariableDefinition}
|
|
325
|
+
*/
|
|
326
|
+
FormAction.setStatic(function unDry(obj) {
|
|
327
|
+
return new this(obj);
|
|
328
|
+
});
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The Url action
|
|
3
|
+
*
|
|
4
|
+
* @constructor
|
|
5
|
+
*
|
|
6
|
+
* @author Jelle De Loecker <jelle@elevenways.be>
|
|
7
|
+
* @since 0.1.6
|
|
8
|
+
* @version 0.1.6
|
|
9
|
+
*/
|
|
10
|
+
const UrlAction = Function.inherits('Alchemy.Form.Action', 'Url');
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Add the url config property
|
|
14
|
+
*
|
|
15
|
+
* @author Jelle De Loecker <jelle@elevenways.be>
|
|
16
|
+
* @since 0.1.6
|
|
17
|
+
* @version 0.1.6
|
|
18
|
+
*/
|
|
19
|
+
UrlAction.addConfigProperty('url');
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Get an element representation
|
|
23
|
+
*
|
|
24
|
+
* @author Jelle De Loecker <jelle@elevenways.be>
|
|
25
|
+
* @since 0.1.6
|
|
26
|
+
* @version 0.1.6
|
|
27
|
+
*
|
|
28
|
+
* @return {HTMLElement}
|
|
29
|
+
*/
|
|
30
|
+
UrlAction.setMethod(function _constructElement(renderer) {
|
|
31
|
+
|
|
32
|
+
let anchor = renderer.createElement('a');
|
|
33
|
+
|
|
34
|
+
anchor.dataset.name = this.name;
|
|
35
|
+
|
|
36
|
+
if (this.icon) {
|
|
37
|
+
let alico = renderer.createElement('al-ico');
|
|
38
|
+
alico.setAttribute('type', this.icon);
|
|
39
|
+
anchor.append(alico);
|
|
40
|
+
} else {
|
|
41
|
+
anchor.textContent = this.title || this.name;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
anchor.setAttribute('href', this.url);
|
|
45
|
+
|
|
46
|
+
return anchor;
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* Execute this action programatically
|
|
51
|
+
*
|
|
52
|
+
* @author Jelle De Loecker <jelle@elevenways.be>
|
|
53
|
+
* @since 0.1.6
|
|
54
|
+
* @version 0.1.6
|
|
55
|
+
*
|
|
56
|
+
* @param {Event} event Optional event
|
|
57
|
+
*/
|
|
58
|
+
UrlAction.setMethod(function execute(event) {
|
|
59
|
+
|
|
60
|
+
if (event) {
|
|
61
|
+
event.preventDefault();
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
if (!Blast.isBrowser || !this.url) {
|
|
65
|
+
return;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
hawkejs.scene.openUrl(this.url);
|
|
69
|
+
});
|