alchemy-form 0.1.6 → 0.1.9

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.
@@ -0,0 +1,103 @@
1
+ /**
2
+ * The alchemy-query-builder-value custom element
3
+ *
4
+ * @author Jelle De Loecker <jelle@elevenways.be>
5
+ * @since 0.1.7
6
+ * @version 0.1.7
7
+ */
8
+ const QueryBuilderVariable = Function.inherits('Alchemy.Element.Form.QueryBuilderData', 'QueryBuilderVariable');
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.1.7
15
+ * @version 0.1.7
16
+ */
17
+ QueryBuilderVariable.setTemplateFile('form/elements/query_builder_variable');
18
+
19
+ /**
20
+ * A filter of variable definition types
21
+ * (number, string, ...)
22
+ *
23
+ * @author Jelle De Loecker <jelle@elevenways.be>
24
+ * @since 0.1.7
25
+ * @version 0.1.7
26
+ */
27
+ QueryBuilderVariable.setAttribute('variable-types');
28
+
29
+ /**
30
+ * Getter for the value input wrapper
31
+ *
32
+ * @author Jelle De Loecker <jelle@elevenways.be>
33
+ * @since 0.1.7
34
+ * @version 0.1.7
35
+ */
36
+ QueryBuilderVariable.addElementGetter('variable_select', '.qb-variable');
37
+
38
+ /**
39
+ * Get/set the value
40
+ *
41
+ * @author Jelle De Loecker <jelle@elevenways.be>
42
+ * @since 0.1.7
43
+ * @version 0.1.7
44
+ */
45
+ QueryBuilderVariable.setProperty(function value() {
46
+
47
+ let result = {
48
+ type : 'qb_variable',
49
+ variable_type : null,
50
+ };
51
+
52
+ let select = this.variable_select;
53
+
54
+ if (select) {
55
+ result.variable = select.value;
56
+
57
+ if (select.values) {
58
+ let value_def = select.values[result.variable];
59
+
60
+ if (value_def) {
61
+ result.variable_type = value_def.type_name;
62
+ }
63
+ }
64
+ }
65
+
66
+ return result;
67
+ }, function setValue(value) {
68
+ this.assigned_data.value = value;
69
+ });
70
+
71
+ /**
72
+ * Apply the given value
73
+ *
74
+ * @author Jelle De Loecker <jelle@elevenways.be>
75
+ * @since 0.1.7
76
+ * @version 0.1.7
77
+ */
78
+ QueryBuilderVariable.setMethod(async function applyValue(value) {
79
+
80
+ if (!value) {
81
+ return;
82
+ }
83
+
84
+ let select = this.variable_select;
85
+
86
+ if (select) {
87
+ select.value = value.variable;
88
+ }
89
+ });
90
+
91
+ /**
92
+ * Added to the dom
93
+ *
94
+ * @author Jelle De Loecker <jelle@elevenways.be>
95
+ * @since 0.1.7
96
+ * @version 0.1.7
97
+ */
98
+ QueryBuilderVariable.setMethod(async function introduced() {
99
+
100
+ if (this.assigned_data.value) {
101
+ await this.applyValue(this.assigned_data.value);
102
+ }
103
+ });
@@ -154,10 +154,20 @@ VariableDefinition.setStatic(function addLogicalOperator(name, config) {
154
154
  config = {};
155
155
  }
156
156
 
157
- if(!config.title) {
157
+ if (!config.title) {
158
158
  config.title = name.titleize();
159
159
  }
160
160
 
161
+ // By default logical operators have a binary arity:
162
+ // they take 2 operands. The value of the variable + another value.
163
+ if (!config.arity) {
164
+ config.arity = 'binary';
165
+ }
166
+
167
+ if (config.arity != 'unary' && config.arity != 'binary' && config.arity != 'ternary') {
168
+ throw new Error('Unable to add Logical operator "' + name + '" to ' + this.name + ', unknown arity: "' + config.arity);
169
+ }
170
+
161
171
  config.id = name;
162
172
 
163
173
  this.constitute(function _addOperator() {
@@ -185,10 +195,20 @@ VariableDefinition.setStatic(function addAssignmentOperator(name, config) {
185
195
  config = {};
186
196
  }
187
197
 
188
- if(!config.title) {
198
+ if (!config.title) {
189
199
  config.title = name.titleize();
190
200
  }
191
201
 
202
+ // By default assignment operators have a binary arity:
203
+ // they take 2 operands. The value of the variable + another value
204
+ if (!config.arity) {
205
+ config.arity = 'binary';
206
+ }
207
+
208
+ if (config.arity != 'unary' && config.arity != 'binary' && config.arity != 'ternary') {
209
+ throw new Error('Unable to add Assignment operator "' + name + '" to ' + this.name + ', unknown arity: "' + config.arity);
210
+ }
211
+
192
212
  config.id = name;
193
213
 
194
214
  this.constitute(function _addOperator() {
@@ -330,7 +350,7 @@ VariableDefinition.addLogicalOperator('not_equals');
330
350
  * @since 0.1.6
331
351
  * @version 0.1.6
332
352
  */
333
- VariableDefinition.addLogicalOperator('is_empty');
353
+ VariableDefinition.addLogicalOperator('is_empty', {arity: 'unary'});
334
354
 
335
355
  /**
336
356
  * The `is_null` operator
@@ -339,7 +359,7 @@ VariableDefinition.addLogicalOperator('is_empty');
339
359
  * @since 0.1.6
340
360
  * @version 0.1.6
341
361
  */
342
- VariableDefinition.addLogicalOperator('is_null');
362
+ VariableDefinition.addLogicalOperator('is_null', {arity: 'unary'});
343
363
 
344
364
  /**
345
365
  * The `set` operator sets a value
@@ -0,0 +1,38 @@
1
+ /**
2
+ * The List Value Type:
3
+ * Can contain other value types.
4
+ *
5
+ * @constructor
6
+ *
7
+ * @author Jelle De Loecker <jelle@elevenways.be>
8
+ * @since 0.1.7
9
+ * @version 0.1.7
10
+ */
11
+ const ListDefinition = Function.inherits('Alchemy.QueryBuilder.VariableDefinition', 'List');
12
+
13
+ /**
14
+ * The optional type this list holds
15
+ *
16
+ * @author Jelle De Loecker <jelle@elevenways.be>
17
+ * @since 0.1.7
18
+ * @version 0.1.7
19
+ */
20
+ ListDefinition.setProperty('content_type');
21
+
22
+ /**
23
+ * The `contains` operator
24
+ *
25
+ * @author Jelle De Loecker <jelle@elevenways.be>
26
+ * @since 0.1.7
27
+ * @version 0.1.7
28
+ */
29
+ ListDefinition.addLogicalOperator('contains');
30
+
31
+ /**
32
+ * The `add` assignment operator adds an entry
33
+ *
34
+ * @author Jelle De Loecker <jelle@elevenways.be>
35
+ * @since 0.1.7
36
+ * @version 0.1.7
37
+ */
38
+ ListDefinition.addAssignmentOperator('add');
@@ -73,7 +73,7 @@ AlchemyField.enforceProperty(function alchemy_form(new_value) {
73
73
  *
74
74
  * @author Jelle De Loecker <jelle@elevenways.be>
75
75
  * @since 0.1.0
76
- * @version 0.1.4
76
+ * @version 0.1.9
77
77
  */
78
78
  AlchemyField.setMethod(function populateWidget() {
79
79
 
@@ -101,6 +101,10 @@ AlchemyField.setMethod(function populateWidget() {
101
101
  field_el.widget_settings = config.widget_settings;
102
102
  }
103
103
 
104
+ if (config.data_src) {
105
+ field_el.data_src = config.data_src;
106
+ }
107
+
104
108
  this.element.append(field_el);
105
109
  });
106
110
 
@@ -0,0 +1,56 @@
1
+ /**
2
+ * A QueryBuilderVariable field lets you select a specific variable
3
+ * using the QueryBuilder logic
4
+ *
5
+ * @constructor
6
+ *
7
+ * @author Jelle De Loecker <jelle@elevenways.be>
8
+ * @since 0.1.6
9
+ * @version 0.1.6
10
+ */
11
+ const QueryBuilderVariable = Function.inherits('Alchemy.Field.QueryBuilder', 'QueryBuilderVariable');
12
+
13
+ /**
14
+ * Load remote data
15
+ *
16
+ * @author Jelle De Loecker <jelle@elevenways.be>
17
+ * @since 0.1.6
18
+ * @version 0.1.6
19
+ *
20
+ * @param {Object} config
21
+ * @param {HTMLElement} element
22
+ */
23
+ QueryBuilderVariable.setMethod(function loadData(config, element) {
24
+
25
+ if (element) {
26
+ let form = element.queryParents('alchemy-form');
27
+
28
+ if (form) {
29
+ let doc = form.document;
30
+
31
+ if (doc && doc.root_document) {
32
+ doc = doc.root_document;
33
+ }
34
+
35
+ let model_name,
36
+ $pk;
37
+
38
+ if (doc) {
39
+ model_name = doc.$model_name;
40
+ $pk = doc.$pk;
41
+ }
42
+
43
+ return element.hawkejs_helpers.Alchemy.getResource({
44
+ name : 'FormApi#queryBuilderData',
45
+ post : true,
46
+ body : {
47
+ model : model_name,
48
+ $pk : $pk,
49
+ config : config,
50
+ }
51
+ });
52
+ }
53
+ }
54
+
55
+ return [];
56
+ });
package/package.json CHANGED
@@ -1,16 +1,16 @@
1
1
  {
2
2
  "name": "alchemy-form",
3
3
  "description": "Form plugin for Alchemy",
4
- "version": "0.1.6",
4
+ "version": "0.1.9",
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.2.0"
10
+ "alchemymvc" : ">=1.2.0"
11
11
  },
12
12
  "license": "MIT",
13
13
  "engines": {
14
- "node" : ">=12.0.0"
14
+ "node" : ">=14.0.0"
15
15
  }
16
16
  }
@@ -0,0 +1,36 @@
1
+ <label>
2
+ <div class="inputlabel">
3
+ <span class="label" data-he-slot="label"></span>
4
+ <span class="description" data-he-slot="description"></span>
5
+ <hr class="spacer">
6
+ </div>
7
+ <div class="inputbox">
8
+ <input
9
+ name=<% self.getAttribute('input-name') || 'name' %>
10
+ placeholder=<% self.getAttribute('placeholder') %>
11
+ minlength=<% self.getAttribute('min-length') %>
12
+ maxlength=<% self.getAttribute('max-length') %>
13
+ class="input"
14
+ value="<% self.getAttribute('value') || '' %>"
15
+ type="password"
16
+ >
17
+ <i class="icon cross"></i>
18
+ <i class="icon checkmark"></i>
19
+ </div>
20
+ </label>
21
+ <label class="repeat-input-label" hidden>
22
+ <div class="inputbox">
23
+ <input
24
+ placeholder=<% self.getAttribute('repeat-placeholder') %>
25
+ class="input repeat-input"
26
+ value="<% self.getAttribute('value') || '' %>"
27
+ minlength=<% self.getAttribute('min-length') %>
28
+ maxlength=<% self.getAttribute('max-length') %>
29
+ type="password"
30
+ >
31
+ <i class="icon cross"></i>
32
+ <i class="icon checkmark"></i>
33
+ </div>
34
+ <div class="errors"></div>
35
+ <div class="success"></div>
36
+ </label>
@@ -0,0 +1,6 @@
1
+ <alchemy-select
2
+ class="qb-variable"
3
+ #dataprovider={% self %}
4
+ value-item-template="form/select/qb_item"
5
+ option-item-template="form/select/qb_item"
6
+ ></alchemy-select>
@@ -2,6 +2,6 @@
2
2
  class="alchemy-field-value"
3
3
  ><%
4
4
  $0.dataprovider = alchemy_field;
5
- $0.value = value;
6
5
  $0.name = path;
6
+ $0.value = value;
7
7
  %></alchemy-select>
@@ -0,0 +1,5 @@
1
+ <alchemy-code-input
2
+ class="alchemy-field-value"
3
+ form=<% form_id %>
4
+ name=<% path %>
5
+ >{{ value }}</alchemy-code-input>
@@ -0,0 +1,10 @@
1
+ <%
2
+ options = alchemy_field.config.options || {};
3
+ %>
4
+
5
+ <alchemy-query-builder-variable
6
+ class="alchemy-field-value"
7
+ #value={% value %}
8
+ #dataprovider={% alchemy_field %}
9
+ variable-types={% options.variable_types %}
10
+ ></alchemy-query-builder-variable>
@@ -0,0 +1 @@
1
+ <% include('form/inputs/view_inline/datetime') %>
@@ -0,0 +1 @@
1
+ <span class="alchemy-field-value">{{ value }}</span>
@@ -0,0 +1,4 @@
1
+ <time
2
+ class="alchemy-field-value"
3
+ datetime={% value.toISOString() %}
4
+ >{{ value.format('Y‑m‑d H:i') }}</time>
@@ -0,0 +1,6 @@
1
+ {% if value %}
2
+ <img
3
+ !Media={% value %}
4
+ +media-route="Media::thumb"
5
+ >
6
+ {% /if %}
@@ -0,0 +1 @@
1
+ <span class="alchemy-field-value">{{ value }}</span>
@@ -0,0 +1 @@
1
+ <div data-he-name="field"></div>