dbm 1.4.6 → 1.4.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/core/BaseObject.js +35 -0
- package/core/LifeCycleObject.js +13 -1
- package/dbm.js +2 -2
- package/flow/ExternalObjectUpdater.js +65 -0
- package/flow/FlowProperty.js +40 -2
- package/flow/index.js +14 -5
- package/flow/updatefunctions/basic/SetProperty.js +30 -0
- package/flow/updatefunctions/basic/index.js +12 -0
- package/form/Field.js +76 -0
- package/form/Form.js +87 -0
- package/form/index.js +6 -0
- package/form/validation/Validation.js +23 -0
- package/form/validation/ValidationFunctions.js +23 -0
- package/form/validation/index.js +4 -0
- package/graphapi/webclient/WebSocketConnection.js +6 -2
- package/loading/FontLoader.js +47 -0
- package/loading/index.js +21 -0
- package/node/communication/PostmarkApiClient.js +5 -0
- package/node/communication/index.js +48 -4
- package/node/index.js +4 -0
- package/package.json +1 -1
- package/react/BaseObject.js +27 -0
- package/react/area/SwitchableArea.js +1 -1
- package/react/area/index.js +11 -0
- package/react/blocks/index.js +18 -0
- package/react/form/FormField.js +18 -1
- package/react/form/index.js +26 -1
- package/repository/index.js +24 -1
- package/startup/index.js +11 -1
- package/tracking/Controller.js +8 -8
- package/tracking/DataLayerTracker.js +23 -4
- package/tracking/index.js +5 -3
- package/utils/KeywordReplace.js +102 -0
- package/utils/index.js +1 -0
package/core/BaseObject.js
CHANGED
|
@@ -20,4 +20,39 @@ export default class BaseObject extends Dbm.core.LifeCycleObject {
|
|
|
20
20
|
|
|
21
21
|
return this;
|
|
22
22
|
}
|
|
23
|
+
|
|
24
|
+
_getScopedCallFunctionCommand(aFunction, aArguments = []) {
|
|
25
|
+
let CallFunction = Dbm.objectPath(Dbm.getRepositoryItem("library"), "Dbm/commands/CallFunction");
|
|
26
|
+
let command = new CallFunction();
|
|
27
|
+
command.item.scopeObject = this;
|
|
28
|
+
command.item.callFunction = aFunction;
|
|
29
|
+
command.item.callArguments = aArguments;
|
|
30
|
+
|
|
31
|
+
return command;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
_propertyOrName(aPropertyOrName) {
|
|
35
|
+
if(typeof(aPropertyOrName) === "string") {
|
|
36
|
+
return this.item.properties[aPropertyOrName];
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
return aPropertyOrName;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
addUpdateCall(aPropertyOrName, aFunction, aArguments = []) {
|
|
43
|
+
this._propertyOrName(aPropertyOrName).addUpdate(this._getScopedCallFunctionCommand(aFunction, aArguments));
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
addUpdateCallWhenMatched(aPropertyOrName, aMatchValue, aFunction, aArguments = []) {
|
|
47
|
+
console.log(this._propertyOrName(aPropertyOrName), aPropertyOrName, this);
|
|
48
|
+
this._propertyOrName(aPropertyOrName).addUpdateWhenMatched(aMatchValue, this._getScopedCallFunctionCommand(aFunction, aArguments));
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
destroy() {
|
|
52
|
+
if(this._item) {
|
|
53
|
+
//METODO: destroy item
|
|
54
|
+
}
|
|
55
|
+
this._item = null;
|
|
56
|
+
super.destroy();
|
|
57
|
+
}
|
|
23
58
|
}
|
package/core/LifeCycleObject.js
CHANGED
|
@@ -19,7 +19,19 @@ export default class LifeCycleObject {
|
|
|
19
19
|
|
|
20
20
|
}
|
|
21
21
|
|
|
22
|
-
|
|
22
|
+
retain() {
|
|
23
|
+
//METODO
|
|
24
|
+
|
|
25
|
+
return this;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
release() {
|
|
23
29
|
//METODO
|
|
24
30
|
}
|
|
31
|
+
|
|
32
|
+
destroy() {
|
|
33
|
+
if(process.env.NODE_ENV === "development") {
|
|
34
|
+
this._debugId = null;
|
|
35
|
+
}
|
|
36
|
+
}
|
|
25
37
|
}
|
package/dbm.js
CHANGED
|
@@ -6,7 +6,6 @@ export const setupGlobalInstance = function(aObject, aPath) {
|
|
|
6
6
|
}
|
|
7
7
|
}
|
|
8
8
|
|
|
9
|
-
|
|
10
9
|
export const getInstance = function() {
|
|
11
10
|
return globalThis.dbm;
|
|
12
11
|
}
|
|
@@ -114,4 +113,5 @@ export * as startup from "./startup/index.js";
|
|
|
114
113
|
export * as site from "./site/index.js";
|
|
115
114
|
export * as tracking from "./tracking/index.js";
|
|
116
115
|
export * as ecommerce from "./ecommerce/index.js";
|
|
117
|
-
export * as node from "./node/index.js";
|
|
116
|
+
export * as node from "./node/index.js";
|
|
117
|
+
export * as form from "./form/index.js";
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import Dbm from "../index.js";
|
|
2
|
+
|
|
3
|
+
export default class ExternalObjectUpdater extends Dbm.core.BaseObject {
|
|
4
|
+
_construct() {
|
|
5
|
+
super._construct();
|
|
6
|
+
|
|
7
|
+
this.item.requireProperty("object", null);
|
|
8
|
+
this.item.requireProperty("updateFunctions", []);
|
|
9
|
+
this.item.requireProperty("running", true);
|
|
10
|
+
|
|
11
|
+
this.addUpdateCallWhenMatched("running", true, this.start);
|
|
12
|
+
this.addUpdateCallWhenMatched("running", false, this.stop);
|
|
13
|
+
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
get object() {
|
|
17
|
+
return this.item.object;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
addProperty(aName, aValue, aPath = null) {
|
|
21
|
+
if(!aPath) {
|
|
22
|
+
aPath = aName;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
let property = this.item.requireProperty(aName, null);
|
|
26
|
+
property.setOrConnect(aValue);
|
|
27
|
+
let updateFunction = Dbm.flow.updatefunctions.basic.setProperty(this.item.properties.object, aPath, property);
|
|
28
|
+
this.item.setValue("update/" + aName, updateFunction);
|
|
29
|
+
this.item.addToArray("updateFunctions", updateFunction);
|
|
30
|
+
|
|
31
|
+
if(this.item.running) {
|
|
32
|
+
updateFunction.output.properties.value.startUpdating();
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
return property;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
start() {
|
|
39
|
+
let currentArray = this.item.updateFunctions;
|
|
40
|
+
let currentArrayLength = currentArray.length;
|
|
41
|
+
for(let i = 0; i < currentArrayLength; i++) {
|
|
42
|
+
let updateFunction = currentArray[i];
|
|
43
|
+
updateFunction.output.properties.value.startUpdating();
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
return this;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
stop() {
|
|
50
|
+
let currentArray = this.item.updateFunctions;
|
|
51
|
+
let currentArrayLength = currentArray.length;
|
|
52
|
+
for(let i = 0; i < currentArrayLength; i++) {
|
|
53
|
+
let updateFunction = currentArray[i];
|
|
54
|
+
updateFunction.output.properties.value.stopUpdating();
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
return this;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
destroy() {
|
|
61
|
+
this.stop();
|
|
62
|
+
|
|
63
|
+
super.destroy();
|
|
64
|
+
}
|
|
65
|
+
}
|
package/flow/FlowProperty.js
CHANGED
|
@@ -137,12 +137,12 @@ export default class FlowProperty extends Dbm.flow.FlowBaseObject {
|
|
|
137
137
|
}
|
|
138
138
|
|
|
139
139
|
startUpdating() {
|
|
140
|
-
Dbm.
|
|
140
|
+
Dbm.getRepositoryItem("propertyUpdater").controller.addProperty(this);
|
|
141
141
|
return this;
|
|
142
142
|
}
|
|
143
143
|
|
|
144
144
|
stopUpdating() {
|
|
145
|
-
Dbm.
|
|
145
|
+
Dbm.getRepositoryItem("propertyUpdater").controller.removeProperty(this);
|
|
146
146
|
return this;
|
|
147
147
|
}
|
|
148
148
|
|
|
@@ -155,4 +155,42 @@ export default class FlowProperty extends Dbm.flow.FlowBaseObject {
|
|
|
155
155
|
this._upstreamConnection = null;
|
|
156
156
|
}
|
|
157
157
|
}
|
|
158
|
+
|
|
159
|
+
addUpdate(aCommand) {
|
|
160
|
+
let addUpdateCommand = Dbm.objectPath(Dbm.getRepositoryItem("library"), "Dbm/flow/addUpdateCommand");
|
|
161
|
+
addUpdateCommand(this, aCommand);
|
|
162
|
+
|
|
163
|
+
return this;
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
addUpdateWhenMatched(aMatchValue, aCommand) {
|
|
167
|
+
let addUpdateCommandWhenMatched = Dbm.objectPath(Dbm.getRepositoryItem("library"), "Dbm/flow/addUpdateCommandWhenMatched");
|
|
168
|
+
addUpdateCommandWhenMatched(this, aMatchValue, aCommand);
|
|
169
|
+
|
|
170
|
+
return this;
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
createCondition(aMatchValue, aCompareType = "===") {
|
|
174
|
+
let UpdateFunctionClass = Dbm.objectPath(Dbm.getRepositoryItem("library"), "Dbm/flow/updatefunctions/logic/Condition");
|
|
175
|
+
let updateFunction = new UpdateFunctionClass();
|
|
176
|
+
updateFunction.input.properties.input1.connectInput(this);
|
|
177
|
+
updateFunction.input.input2 = aMatchValue;
|
|
178
|
+
updateFunction.input.operation = aCompareType;
|
|
179
|
+
|
|
180
|
+
return updateFunction.output.properties.result;
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
createSwitch(aDefaultValue, aValues) {
|
|
184
|
+
let UpdateFunctionClass = Dbm.objectPath(Dbm.getRepositoryItem("library"), "Dbm/flow/updatefunctions/logic/Switch");
|
|
185
|
+
let updateFunction = new UpdateFunctionClass();
|
|
186
|
+
updateFunction.input.properties.value.connectInput(this);
|
|
187
|
+
updateFunction.setDefaultValue(aDefaultValue);
|
|
188
|
+
|
|
189
|
+
//METODO: do better normalization
|
|
190
|
+
for(let objectName in aValues) {
|
|
191
|
+
updateFunction.addCase(objectName, aValues[objectName]);
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
return updateFunction.output.properties.value;
|
|
195
|
+
}
|
|
158
196
|
}
|
package/flow/index.js
CHANGED
|
@@ -7,6 +7,7 @@ export {default as UpdateFunctionInputs} from "./UpdateFunctionInputs.js";
|
|
|
7
7
|
export {default as UpdateFunctionOutputs} from "./UpdateFunctionOutputs.js";
|
|
8
8
|
export {default as DirtyCommands} from "./DirtyCommands.js";
|
|
9
9
|
export {default as FlowPropertyWithExternalInput} from "./FlowPropertyWithExternalInput.js";
|
|
10
|
+
export {default as ExternalObjectUpdater} from "./ExternalObjectUpdater.js";
|
|
10
11
|
|
|
11
12
|
export * as updatefunctions from "./updatefunctions/index.js";
|
|
12
13
|
export * as controllers from "./controllers/index.js";
|
|
@@ -17,7 +18,7 @@ export const addUpdateCommand = function(aProperty, aCommand) {
|
|
|
17
18
|
updateFunction.input.command = aCommand;
|
|
18
19
|
updateFunction.noFirstTriggger();
|
|
19
20
|
|
|
20
|
-
let updatePropertyCommand = Dbm.commands.callFunction(Dbm.
|
|
21
|
+
let updatePropertyCommand = Dbm.commands.callFunction(Dbm.repository.getControllerIfExists("propertyUpdater").addSinglePropertyUpdateBound, [Dbm.core.source.staticObject(updateFunction.output.properties.value)]);
|
|
21
22
|
|
|
22
23
|
let dirtyCommands = new Dbm.flow.DirtyCommands();
|
|
23
24
|
updateFunction.output.properties.value.connectOutput(dirtyCommands);
|
|
@@ -42,13 +43,13 @@ export const addDirectUpdateCommand = function(aProperty, aCommand) {
|
|
|
42
43
|
}
|
|
43
44
|
|
|
44
45
|
export const addUpdateCommandWhenMatched = function(aProperty, aMatchValue, aCommand) {
|
|
45
|
-
let
|
|
46
|
+
let matchUpdateFunction = Dbm.flow.updatefunctions.logic.whenMatched(aProperty, aMatchValue);
|
|
46
47
|
|
|
47
|
-
let updateData = Dbm.flow.addUpdateCommand(
|
|
48
|
+
let updateData = Dbm.flow.addUpdateCommand(matchUpdateFunction.output.properties.value, aCommand);
|
|
48
49
|
|
|
49
|
-
updateData["
|
|
50
|
+
updateData["matchUpdateFunction"] = matchUpdateFunction;
|
|
50
51
|
|
|
51
|
-
return
|
|
52
|
+
return updateData;
|
|
52
53
|
}
|
|
53
54
|
|
|
54
55
|
export const runWhenMatched = function(aProperty, aMatchValue, aCommand) {
|
|
@@ -83,4 +84,12 @@ export const animateValue = function(aValue, aTime = 0.5, aEasing = null) {
|
|
|
83
84
|
returnObject.setValue("updateCommand", updateCommand);
|
|
84
85
|
|
|
85
86
|
return returnObject;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
export const externalObject = function(aObject) {
|
|
90
|
+
let returnObject = new Dbm.flow.ExternalObjectUpdater();
|
|
91
|
+
|
|
92
|
+
returnObject.item.properties.object.setOrConnect(aObject);
|
|
93
|
+
|
|
94
|
+
return returnObject;
|
|
86
95
|
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import Dbm from "../../../index.js";
|
|
2
|
+
|
|
3
|
+
export default class SetProperty extends Dbm.flow.FlowUpdateFunction {
|
|
4
|
+
|
|
5
|
+
_construct() {
|
|
6
|
+
super._construct();
|
|
7
|
+
|
|
8
|
+
this.input.register("value", "");
|
|
9
|
+
this.input.register("object", null);
|
|
10
|
+
this.input.register("propertyName", null);
|
|
11
|
+
|
|
12
|
+
this.output.register("value", null);
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
_update() {
|
|
16
|
+
//console.log("_update");
|
|
17
|
+
|
|
18
|
+
let value = this.input.value;
|
|
19
|
+
|
|
20
|
+
let propertyName = this.input.propertyName;
|
|
21
|
+
let object = this.input.object;
|
|
22
|
+
|
|
23
|
+
if(propertyName && object) {
|
|
24
|
+
Dbm.setAtObjectPath(object, propertyName, value);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
this.output.value = value;
|
|
29
|
+
}
|
|
30
|
+
}
|
|
@@ -7,6 +7,7 @@ export {default as PropertyOf} from "./PropertyOf.js";
|
|
|
7
7
|
export {default as PropertyOfWithDefault} from "./PropertyOfWithDefault.js";
|
|
8
8
|
export {default as MappedList} from "./MappedList.js";
|
|
9
9
|
export {default as Translation} from "./Translation.js";
|
|
10
|
+
export {default as SetProperty} from "./SetProperty.js";
|
|
10
11
|
|
|
11
12
|
export const runCommand = function(aValue, aCommand) {
|
|
12
13
|
let updateFunction = new Dbm.flow.updatefunctions.basic.RunCommand();
|
|
@@ -123,4 +124,15 @@ export const translationProperty = function(aId, aDefaultValue = null, aPath = n
|
|
|
123
124
|
let updateFunction = translation(aId, aDefaultValue, aPath, aAdditionalPath, aTranslations);
|
|
124
125
|
|
|
125
126
|
return updateFunction.output.properties.value;
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
export const setProperty = function(aObject, aPropertyName, aValue = null) {
|
|
130
|
+
let updateFunction = new Dbm.flow.updatefunctions.basic.SetProperty();
|
|
131
|
+
|
|
132
|
+
let properties = updateFunction.input.properties;
|
|
133
|
+
properties.value.setOrConnect(aValue);
|
|
134
|
+
properties.object.setOrConnect(aObject);
|
|
135
|
+
properties.propertyName.setOrConnect(aPropertyName);
|
|
136
|
+
|
|
137
|
+
return updateFunction;
|
|
126
138
|
}
|
package/form/Field.js
ADDED
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import Dbm from "../index.js";
|
|
2
|
+
|
|
3
|
+
export default class Field extends Dbm.core.BaseObject {
|
|
4
|
+
_construct() {
|
|
5
|
+
super._construct();
|
|
6
|
+
|
|
7
|
+
let changeCommand = this._getScopedCallFunctionCommand(this._changed);
|
|
8
|
+
let focusChangedCommand = this._getScopedCallFunctionCommand(this._focusChanged);
|
|
9
|
+
let validationChangedCommand = this._getScopedCallFunctionCommand(this._validationActiveChange);
|
|
10
|
+
|
|
11
|
+
this.item.requireProperty("value", null).addUpdate(changeCommand);
|
|
12
|
+
|
|
13
|
+
let validation = new Dbm.form.validation.Validation();
|
|
14
|
+
validation.item.field = this.item;
|
|
15
|
+
validation.item.properties.active.addUpdate(validationChangedCommand);
|
|
16
|
+
validation.item.properties.validationFunction.addUpdate(validationChangedCommand);
|
|
17
|
+
|
|
18
|
+
this.item.requireProperty("validation", validation.item);
|
|
19
|
+
this.item.requireProperty("editing", false).addUpdate(focusChangedCommand);
|
|
20
|
+
this.item.requireProperty("valid", true);
|
|
21
|
+
this.item.requireProperty("validationState", "notValidated");
|
|
22
|
+
this.item.requireProperty("validationMode", null);
|
|
23
|
+
this.item.requireProperty("focusMode", "reset");
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
validate() {
|
|
27
|
+
if(this.item.validation.active) {
|
|
28
|
+
let newState = this.item.valid ? "valid" : "invalid";
|
|
29
|
+
this.item.validationState = newState;
|
|
30
|
+
}
|
|
31
|
+
else {
|
|
32
|
+
this.item.valid = true;
|
|
33
|
+
this.item.validationState = "notValidated";
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
return this.item.valid;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
getValue() {
|
|
40
|
+
return this.item.value;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
_validationActiveChange() {
|
|
44
|
+
//console.log("_validationActiveChange");
|
|
45
|
+
if(this.item.validation.active) {
|
|
46
|
+
this._changed();
|
|
47
|
+
}
|
|
48
|
+
else {
|
|
49
|
+
this.item.valid = true;
|
|
50
|
+
this.item.validationState = "notValidated";
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
_changed() {
|
|
55
|
+
//console.log("_changed");
|
|
56
|
+
this.item.valid = this.item.validation.controller.validate();
|
|
57
|
+
|
|
58
|
+
if(this.item.validationMode === "onChange") {
|
|
59
|
+
this.validate();
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
_focusChanged() {
|
|
64
|
+
//console.log("_focus");
|
|
65
|
+
if(this.item.editing) {
|
|
66
|
+
if(this.item.focusMode === "reset") {
|
|
67
|
+
this.item.validationState = "notValidated";
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
else {
|
|
71
|
+
if(this.item.validationMode === "onBlur") {
|
|
72
|
+
this.validate();
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
}
|
package/form/Form.js
ADDED
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
import Dbm from "../index.js";
|
|
2
|
+
|
|
3
|
+
export default class Form extends Dbm.core.BaseObject {
|
|
4
|
+
_construct() {
|
|
5
|
+
super._construct();
|
|
6
|
+
|
|
7
|
+
let all = Dbm.flow.updatefunctions.logic.all();
|
|
8
|
+
this.item.requireProperty("all", all);
|
|
9
|
+
|
|
10
|
+
this.item.requireProperty("valid", true).connectInput(all.output.properties.value);
|
|
11
|
+
this.item.requireProperty("fields", new Dbm.repository.Item());
|
|
12
|
+
this.item.requireProperty("fieldNames", []);
|
|
13
|
+
this.item.requireProperty("defaultValidationMode", "onBlur");
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
addExistingField(aName, aField) {
|
|
17
|
+
this.item.fields.setValue(aName, aField.item);
|
|
18
|
+
this.item.all.addCheck(aField.item.properties.valid);
|
|
19
|
+
this.item.addToArray("fieldNames", aName);
|
|
20
|
+
|
|
21
|
+
return this;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
createField(aName, aValue = null, aValidationFunction = null, aValidationActive = null) {
|
|
25
|
+
|
|
26
|
+
if(this.item.fields[aName]) {
|
|
27
|
+
console.error("Field " + aName + " already exists");
|
|
28
|
+
return this.item.fields[aName].controller;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
let newField = new Dbm.form.Field();
|
|
32
|
+
newField.item.value = aValue;
|
|
33
|
+
newField.item.validationMode = this.item.defaultValidationMode;
|
|
34
|
+
if(aValidationFunction) {
|
|
35
|
+
newField.item.validation.validationFunction = aValidationFunction;
|
|
36
|
+
}
|
|
37
|
+
if(aValidationActive) {
|
|
38
|
+
newField.item.validation.properties.active.setOrConnect(aValidationActive);
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
this.addExistingField(aName, newField);
|
|
42
|
+
|
|
43
|
+
return newField;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
createGroup(aName) {
|
|
47
|
+
let newForm = new Dbm.form.Form();
|
|
48
|
+
newForm.item.defaultValidationMode = this.item.defaultValidationMode;
|
|
49
|
+
|
|
50
|
+
this.addExistingField(aName, newForm);
|
|
51
|
+
|
|
52
|
+
return newForm;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
validate() {
|
|
56
|
+
console.log("validate");
|
|
57
|
+
|
|
58
|
+
let currentArray = this.item.fieldNames;
|
|
59
|
+
let currentArrayLength = currentArray.length;
|
|
60
|
+
for(let i = 0; i < currentArrayLength; i++) {
|
|
61
|
+
let currentName = currentArray[i];
|
|
62
|
+
|
|
63
|
+
let result = this.item.fields[currentName].controller.validate();
|
|
64
|
+
|
|
65
|
+
if(!result) {
|
|
66
|
+
console.log("Field " + currentName + " is not valid.", this.item.fields[currentName]);
|
|
67
|
+
}
|
|
68
|
+
//METODO: return the result in some format
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
return this.item.valid;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
getValue() {
|
|
75
|
+
let returnObject = {};
|
|
76
|
+
|
|
77
|
+
let currentArray = this.item.fieldNames;
|
|
78
|
+
let currentArrayLength = currentArray.length;
|
|
79
|
+
for(let i = 0; i < currentArrayLength; i++) {
|
|
80
|
+
let currentName = currentArray[i];
|
|
81
|
+
|
|
82
|
+
returnObject[currentName] = this.item.fields[currentName].controller.getValue();
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
return returnObject;
|
|
86
|
+
}
|
|
87
|
+
}
|
package/form/index.js
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import Dbm from "../../index.js";
|
|
2
|
+
|
|
3
|
+
export default class Validation extends Dbm.core.BaseObject {
|
|
4
|
+
_construct() {
|
|
5
|
+
super._construct();
|
|
6
|
+
|
|
7
|
+
this.item.requireProperty("field", null);
|
|
8
|
+
this.item.requireProperty("active", true);
|
|
9
|
+
this.item.requireProperty("validationFunction", Dbm.form.validation.ValidationFunctions.noValidation);
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
validate() {
|
|
13
|
+
if(!this.item.active) {
|
|
14
|
+
return true;
|
|
15
|
+
}
|
|
16
|
+
let validationFunction = this.item.validationFunction;
|
|
17
|
+
return validationFunction(this.item);
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
static noValidation(aValidation) {
|
|
21
|
+
return true;
|
|
22
|
+
}
|
|
23
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import Dbm from "../../index.js";
|
|
2
|
+
|
|
3
|
+
export const noValidation = function(aValidation) {
|
|
4
|
+
return true;
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
export const notEmpty = function(aValidation) {
|
|
8
|
+
//console.log("notEmpty");
|
|
9
|
+
|
|
10
|
+
if(aValidation.field.value && aValidation.field.value.length > 0) {
|
|
11
|
+
return true;
|
|
12
|
+
}
|
|
13
|
+
return false;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export const checked = function(aValidation) {
|
|
17
|
+
//console.log("notEmpty");
|
|
18
|
+
|
|
19
|
+
if(aValidation.field.value) {
|
|
20
|
+
return true;
|
|
21
|
+
}
|
|
22
|
+
return false;
|
|
23
|
+
}
|
|
@@ -294,7 +294,9 @@ export default class WebSocketConnection extends Dbm.core.BaseObject {
|
|
|
294
294
|
{
|
|
295
295
|
let item = repository.getItem(data["requestId"]);
|
|
296
296
|
if(data["id"]) {
|
|
297
|
-
|
|
297
|
+
let userItem = repository.getItem(data["user"]);
|
|
298
|
+
userItem.setValue("roles", data["roles"]);
|
|
299
|
+
item.setValue("user", userItem);
|
|
298
300
|
}
|
|
299
301
|
else {
|
|
300
302
|
item.setValue("user", null);
|
|
@@ -307,7 +309,9 @@ export default class WebSocketConnection extends Dbm.core.BaseObject {
|
|
|
307
309
|
case "connectionReady":
|
|
308
310
|
{
|
|
309
311
|
if(data["user"]) {
|
|
310
|
-
|
|
312
|
+
let userItem = repository.getItem(data["user"]);
|
|
313
|
+
userItem.setValue("roles", data["roles"]);
|
|
314
|
+
repository.getItem("site").currentUser = userItem;
|
|
311
315
|
}
|
|
312
316
|
else {
|
|
313
317
|
repository.getItem("site").currentUser = null;
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import Dbm from "../index.js";
|
|
2
|
+
|
|
3
|
+
export default class FontLoader extends Dbm.core.BaseObject {
|
|
4
|
+
constructor() {
|
|
5
|
+
super();
|
|
6
|
+
|
|
7
|
+
this._url = null;
|
|
8
|
+
this._fontName = null;
|
|
9
|
+
this._element = null;
|
|
10
|
+
this._promise = null;
|
|
11
|
+
|
|
12
|
+
this.item.setValue("status", Dbm.loading.LoadingStatus.NOT_STARTED);
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
setUrl(aUrl) {
|
|
16
|
+
this._url = aUrl;
|
|
17
|
+
return this;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
setFontName(aFontName) {
|
|
21
|
+
this._fontName = aFontName;
|
|
22
|
+
return this;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
load() {
|
|
26
|
+
|
|
27
|
+
if(!this._element) {
|
|
28
|
+
this.item.setValue("status", Dbm.loading.LoadingStatus.LOADING);
|
|
29
|
+
|
|
30
|
+
let element = document.createElement("link");
|
|
31
|
+
element.href = this._url;
|
|
32
|
+
element.rel = "stylesheet";
|
|
33
|
+
|
|
34
|
+
this._element = element;
|
|
35
|
+
|
|
36
|
+
document.head.appendChild(element);
|
|
37
|
+
|
|
38
|
+
this._promise = document.fonts.load("16px " + JSON.stringify(this._fontName));
|
|
39
|
+
this._promise.then(() => {
|
|
40
|
+
this.item.setValue("status", Dbm.loading.LoadingStatus.LOADED);
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
return this;
|
|
46
|
+
}
|
|
47
|
+
}
|
package/loading/index.js
CHANGED
|
@@ -4,6 +4,7 @@ export {default as ScriptLoader} from "./ScriptLoader.js";
|
|
|
4
4
|
export {default as JsonLoader} from "./JsonLoader.js";
|
|
5
5
|
export {default as ImageLoader} from "./ImageLoader.js";
|
|
6
6
|
export {default as LoadingSequence} from "./LoadingSequence.js";
|
|
7
|
+
export {default as FontLoader} from "./FontLoader.js";
|
|
7
8
|
|
|
8
9
|
export * as LoadingStatus from "./LoadingStatus.js";
|
|
9
10
|
|
|
@@ -52,5 +53,25 @@ export const loadImage = function(aUrl) {
|
|
|
52
53
|
let loader = getImageLoader(aUrl);
|
|
53
54
|
loader.load();
|
|
54
55
|
|
|
56
|
+
return loader;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
export const loadFont = function(aUrl, aFontName) {
|
|
60
|
+
let loaderName = "loader-" + aUrl;
|
|
61
|
+
let loaderItem = Dbm.getInstance().repository.getItemIfExists(loaderName);
|
|
62
|
+
|
|
63
|
+
let loader;
|
|
64
|
+
if(!loaderItem) {
|
|
65
|
+
loader = new Dbm.loading.FontLoader();
|
|
66
|
+
loader.item.register(loaderName);
|
|
67
|
+
loader.setUrl(aUrl);
|
|
68
|
+
loader.setFontName(aFontName);
|
|
69
|
+
}
|
|
70
|
+
else {
|
|
71
|
+
loader = loaderItem.controller;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
loader.load();
|
|
75
|
+
|
|
55
76
|
return loader;
|
|
56
77
|
}
|
|
@@ -33,6 +33,11 @@ export default class PostmarkApiClient extends Dbm.core.BaseObject {
|
|
|
33
33
|
TextBody: aMessageItem.textContent,
|
|
34
34
|
};
|
|
35
35
|
|
|
36
|
+
let replyTo = Dbm.objectPath(aMessageItem, "additionalData.replyTo");
|
|
37
|
+
if(replyTo) {
|
|
38
|
+
emailData["ReplyTo"] = replyTo;
|
|
39
|
+
}
|
|
40
|
+
|
|
36
41
|
let response = await fetch('https://api.postmarkapp.com/email', {
|
|
37
42
|
method: 'POST',
|
|
38
43
|
headers: {
|
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
import Dbm from "../../index.js";
|
|
2
|
+
import fs from "node:fs";
|
|
3
|
+
|
|
2
4
|
export {default as PostmarkApiClient} from "./PostmarkApiClient.js";
|
|
3
5
|
export {default as EmailMessage} from "./EmailMessage.js";
|
|
4
6
|
|
|
@@ -22,17 +24,59 @@ export const createEmailAction = async function(aTo, aSubject, aHtmlContent, aTe
|
|
|
22
24
|
return action;
|
|
23
25
|
}
|
|
24
26
|
|
|
25
|
-
export const sendUnformattedEmail =
|
|
27
|
+
export const sendUnformattedEmail = function(aTo, aSubject, aBody, aFrom = null, aAdditionalData = null) {
|
|
26
28
|
return createEmailAction(aTo, aSubject, null, aBody, aFrom, aAdditionalData);
|
|
27
29
|
}
|
|
28
30
|
|
|
29
|
-
export const sendEmail =
|
|
30
|
-
|
|
31
|
-
let textBody = aBody; //METODO: strip tags
|
|
31
|
+
export const sendEmail = function(aTo, aSubject, aBody, aFrom = null, aAdditionalData = null) {
|
|
32
32
|
|
|
33
|
+
let textBody = null;
|
|
34
|
+
let textConverter = Dbm.repository.getControllerIfExists("htmlToTextConverter");
|
|
35
|
+
if(textConverter) {
|
|
36
|
+
textBody = textConverter.convertToText(aBody);
|
|
37
|
+
}
|
|
38
|
+
|
|
33
39
|
return createEmailAction(aTo, aSubject, aBody, textBody, aFrom, aAdditionalData);
|
|
34
40
|
}
|
|
35
41
|
|
|
42
|
+
export const sendEmailTemplate = async function(aTemplateIdentifer, aTo, aKeywordReplace, aLanguage = "default", aDesignFilePath = null, aFrom = null, aAdditionalData = null) {
|
|
43
|
+
let emailTemplate = await Dbm.node.getDatabase().getIdentifiableObjectIfExists("emailTemplate", aTemplateIdentifer);
|
|
44
|
+
|
|
45
|
+
if(emailTemplate) {
|
|
46
|
+
await Dbm.node.forAll(emailTemplate.loadFields(), emailTemplate.loadFieldTranslations("title", "content"));
|
|
47
|
+
|
|
48
|
+
let subject = aKeywordReplace.replaceKeywords(emailTemplate.getTranslatedFieldValue("title", aLanguage));
|
|
49
|
+
let content = aKeywordReplace.replaceKeywords(emailTemplate.getTranslatedFieldValue("content", aLanguage));
|
|
50
|
+
|
|
51
|
+
if(!aDesignFilePath) {
|
|
52
|
+
aDesignFilePath = Dbm.repository.getValueIfExists("emailDesigns", "default/" + aLanguage);
|
|
53
|
+
|
|
54
|
+
if(!aDesignFilePath && (aLanguage !== "default")) {
|
|
55
|
+
aDesignFilePath = Dbm.repository.getValueIfExists("emailDesigns", "default/default");
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
if(aDesignFilePath) {
|
|
60
|
+
//let assetsDir = Dbm.getInstance().repository.getItem("site").assetsDir;
|
|
61
|
+
let mailContent = await fs.promises.readFile(aDesignFilePath, 'utf8');
|
|
62
|
+
|
|
63
|
+
let designKeywordReplace = new Dbm.utils.KeywordReplace();
|
|
64
|
+
designKeywordReplace.addKeyword("subject", subject);
|
|
65
|
+
designKeywordReplace.addKeyword("content", content);
|
|
66
|
+
designKeywordReplace.addKeyword("language", (aLanguage !== "default") ? aLanguage : ""); //MENOTE: get default language
|
|
67
|
+
|
|
68
|
+
//MENOTE: should we have keywords from settings here
|
|
69
|
+
|
|
70
|
+
content = designKeywordReplace.replaceKeywords(mailContent);
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
await sendEmail(aTo, subject, content, aFrom, aAdditionalData);
|
|
74
|
+
}
|
|
75
|
+
else {
|
|
76
|
+
console.warn("No email template " + aTemplateIdentifer);
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
|
|
36
80
|
export const createPostmarkClient = function(aToken, aDefaultFromEmail = null) {
|
|
37
81
|
let client = new Dbm.node.communication.PostmarkApiClient();
|
|
38
82
|
|
package/node/index.js
CHANGED
package/package.json
CHANGED
package/react/BaseObject.js
CHANGED
|
@@ -227,6 +227,33 @@ export default class BaseObject extends Component {
|
|
|
227
227
|
|
|
228
228
|
return createElement.apply(null, callArray);
|
|
229
229
|
}
|
|
230
|
+
|
|
231
|
+
_getScopedCallFunctionCommand(aFunction, aArguments = []) {
|
|
232
|
+
let CallFunction = Dbm.objectPath(Dbm.getRepositoryItem("library"), "Dbm/commands/CallFunction");
|
|
233
|
+
let command = new CallFunction();
|
|
234
|
+
command.item.scopeObject = this;
|
|
235
|
+
command.item.callFunction = aFunction;
|
|
236
|
+
command.item.callArguments = aArguments;
|
|
237
|
+
|
|
238
|
+
return command;
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
_propertyOrName(aPropertyOrName) {
|
|
242
|
+
if(typeof(aPropertyOrName) === "string") {
|
|
243
|
+
return this.item.properties[aPropertyOrName];
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
return aPropertyOrName;
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
addUpdateCall(aPropertyOrName, aFunction, aArguments = []) {
|
|
250
|
+
this._propertyOrName(aPropertyOrName).addUpdate(this._getScopedCallFunctionCommand(aFunction, aArguments));
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
addUpdateCallWhenMatched(aPropertyOrName, aMatchValue, aFunction, aArguments = []) {
|
|
254
|
+
console.log(this._propertyOrName(aPropertyOrName), aPropertyOrName);
|
|
255
|
+
this._propertyOrName(aPropertyOrName).addUpdateWhenMatched(aMatchValue, this._getScopedCallFunctionCommand(aFunction, aArguments));
|
|
256
|
+
}
|
|
230
257
|
}
|
|
231
258
|
|
|
232
259
|
BaseObject.contextType = Context;
|
|
@@ -27,7 +27,7 @@ export default class SwitchableArea extends Dbm.react.BaseObject {
|
|
|
27
27
|
slotElement = mainChildren;
|
|
28
28
|
}
|
|
29
29
|
|
|
30
|
-
this.item.element = React.createElement(React.Fragment, {key:
|
|
30
|
+
this.item.element = React.createElement(React.Fragment, {key: area}, slotElement);
|
|
31
31
|
}
|
|
32
32
|
|
|
33
33
|
_renderMainElement() {
|
package/react/area/index.js
CHANGED
|
@@ -29,4 +29,15 @@ export const centeredFlexDiv = function(aChildren) {
|
|
|
29
29
|
return React.createElement("div", {className: "flex-row justify-center"},
|
|
30
30
|
React.createElement("div", {className: "flex-row-item"}, aChildren)
|
|
31
31
|
);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export const processStateElement = function(aState, aIdleElement, aProcessingElement, aCompletedElement) {
|
|
35
|
+
let updateFunction = Dbm.flow.updatefunctions.logic.switchValue(aState);
|
|
36
|
+
updateFunction.setDefaultValue(aIdleElement);
|
|
37
|
+
updateFunction.addCase(Dbm.loading.LoadingStatus.LOADING, aProcessingElement);
|
|
38
|
+
updateFunction.addCase(Dbm.loading.LoadingStatus.LOADED, aCompletedElement);
|
|
39
|
+
|
|
40
|
+
let element = React.createElement(Dbm.react.area.InsertElement, {"element": updateFunction.output.properties.value});
|
|
41
|
+
|
|
42
|
+
return updateFunction;
|
|
32
43
|
}
|
package/react/blocks/index.js
CHANGED
|
@@ -591,7 +591,25 @@ export let registerAllBlocks = function() {
|
|
|
591
591
|
pageEditors.push(newEditor);
|
|
592
592
|
}
|
|
593
593
|
|
|
594
|
+
{
|
|
595
|
+
let objectTypeEditor = Dbm.getInstance().repository.getItem("admin/objectTypeEditors/emailTemplate");
|
|
596
|
+
if(!objectTypeEditor.editors) {
|
|
597
|
+
objectTypeEditor.setValue("editors", []);
|
|
598
|
+
}
|
|
599
|
+
|
|
600
|
+
let newArray = [].concat(objectTypeEditor.editors);
|
|
601
|
+
newArray.push(Dbm.getInstance().repository.getItem("admin/itemEditors/name"));
|
|
602
|
+
newArray.push(Dbm.getInstance().repository.getItem("admin/itemEditors/identifier"));
|
|
603
|
+
newArray.push(Dbm.getInstance().repository.getItem("admin/itemEditors/title"));
|
|
594
604
|
|
|
605
|
+
{
|
|
606
|
+
let itemEditor = new Dbm.repository.Item();
|
|
607
|
+
itemEditor.setValue("element", createElement(Dbm.react.admin.objects.itemeditors.RichTextFieldWithTranslations, {"label": "Content", "fieldName": "content"}));
|
|
608
|
+
newArray.push(itemEditor);
|
|
609
|
+
}
|
|
610
|
+
|
|
611
|
+
objectTypeEditor.editors = newArray;
|
|
612
|
+
}
|
|
595
613
|
|
|
596
614
|
admin.pageEditors = pageEditors;
|
|
597
615
|
|
package/react/form/FormField.js
CHANGED
|
@@ -6,9 +6,12 @@ export default class FormField extends Dbm.react.BaseObject {
|
|
|
6
6
|
super._construct();
|
|
7
7
|
|
|
8
8
|
this.getDynamicProp("value", "");
|
|
9
|
+
this.getDynamicPropWithoutState("editing", false);
|
|
9
10
|
this.state["formUpdate"] = 0;
|
|
10
11
|
|
|
11
12
|
this._callback_changeBound = this._callback_change.bind(this);
|
|
13
|
+
this._callback_focusBound = this._callback_focus.bind(this);
|
|
14
|
+
this._callback_blurBound = this._callback_blur.bind(this);
|
|
12
15
|
}
|
|
13
16
|
|
|
14
17
|
_callback_change(aEvent) {
|
|
@@ -21,11 +24,25 @@ export default class FormField extends Dbm.react.BaseObject {
|
|
|
21
24
|
this.setState({"formUpdate": this.state.formUpdate}); //MENOTE: trigger change direct to not lose focus on input
|
|
22
25
|
}
|
|
23
26
|
|
|
27
|
+
_callback_focus(aEvent) {
|
|
28
|
+
//console.log("_callback_focus");
|
|
29
|
+
//console.log(aEvent);
|
|
30
|
+
|
|
31
|
+
this.getDynamicProp("editing").getMostUpstreamProperty().setValue(true);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
_callback_blur(aEvent) {
|
|
35
|
+
//console.log("_callback_blur");
|
|
36
|
+
//console.log(aEvent);
|
|
37
|
+
|
|
38
|
+
this.getDynamicProp("editing").getMostUpstreamProperty().setValue(false);
|
|
39
|
+
}
|
|
40
|
+
|
|
24
41
|
_renderMainElement() {
|
|
25
42
|
|
|
26
43
|
let value = this.getDynamicProp("value").value;
|
|
27
44
|
|
|
28
|
-
return this._createMainElement("input", {"value": value, onChange: this._callback_changeBound});
|
|
45
|
+
return this._createMainElement("input", {"value": value, onChange: this._callback_changeBound, onFocus: this._callback_focusBound, onBlur: this._callback_blurBound});
|
|
29
46
|
}
|
|
30
47
|
}
|
|
31
48
|
|
package/react/form/index.js
CHANGED
|
@@ -1,3 +1,6 @@
|
|
|
1
|
+
import Dbm from "../../index.js";
|
|
2
|
+
import React from "react";
|
|
3
|
+
|
|
1
4
|
export {default as Checkbox} from "./Checkbox.js";
|
|
2
5
|
export {default as FormField} from "./FormField.js";
|
|
3
6
|
export {default as LabelledArea} from "./LabelledArea.js";
|
|
@@ -12,4 +15,26 @@ export {default as EditObjectProperty} from "./EditObjectProperty.js";
|
|
|
12
15
|
export {default as Form} from "./Form.js";
|
|
13
16
|
export {default as Option} from "./Option.js";
|
|
14
17
|
export {default as Dropdown} from "./Dropdown.js";
|
|
15
|
-
export {default as GraphApiObjectOptions} from "./GraphApiObjectOptions.js";
|
|
18
|
+
export {default as GraphApiObjectOptions} from "./GraphApiObjectOptions.js";
|
|
19
|
+
|
|
20
|
+
export const validationStateClassName = function(aChildren) {
|
|
21
|
+
return React.createElement(Dbm.react.AddProps, {className: Dbm.react.source.contextVariable("field.properties.validationState")},
|
|
22
|
+
aChildren
|
|
23
|
+
)
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export const fieldWithValidation = function(aFieldName, aPlaceHolderText = null, aClasses = "standard-field standard-field-padding full-width") {
|
|
27
|
+
let returnElement = React.createElement(Dbm.react.context.AddItemToContext, {item: Dbm.react.source.contextVariable("form.fields." + aFieldName), as: "field"},
|
|
28
|
+
validationStateClassName(
|
|
29
|
+
React.createElement(Dbm.react.form.FormField, {
|
|
30
|
+
value: Dbm.react.source.contextVariable("field.properties.value"),
|
|
31
|
+
editing: Dbm.react.source.contextVariable("field.properties.editing"),
|
|
32
|
+
className: aClasses,
|
|
33
|
+
placeholder: aPlaceHolderText
|
|
34
|
+
})
|
|
35
|
+
)
|
|
36
|
+
)
|
|
37
|
+
|
|
38
|
+
return returnElement;
|
|
39
|
+
}
|
|
40
|
+
|
package/repository/index.js
CHANGED
|
@@ -1,2 +1,25 @@
|
|
|
1
|
+
import Dbm from "../index.js";
|
|
2
|
+
|
|
1
3
|
export {default as Item} from "./Item.js";
|
|
2
|
-
export {default as Repository} from "./Repository.js";
|
|
4
|
+
export {default as Repository} from "./Repository.js";
|
|
5
|
+
|
|
6
|
+
export const getItem = function(aName) {
|
|
7
|
+
return Dbm.getInstance().repository.getItem(aName);
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export const getItemIfExists = function(aName) {
|
|
11
|
+
return Dbm.getInstance().repository.getItemIfExists(aName);
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export const getValueIfExists = function(aObjectName, aPropertyName) {
|
|
15
|
+
let object = getItemIfExists(aObjectName);
|
|
16
|
+
if(!object) {
|
|
17
|
+
return null;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
return Dbm.objectPath(object, aPropertyName);
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export const getControllerIfExists = function(aObjectName) {
|
|
24
|
+
return getValueIfExists(aObjectName, "controller");
|
|
25
|
+
}
|
package/startup/index.js
CHANGED
|
@@ -3,7 +3,7 @@ import Dbm from "../index.js";
|
|
|
3
3
|
export {default as Runner} from "./Runner.js";
|
|
4
4
|
export {default as Controller} from "./Controller.js";
|
|
5
5
|
|
|
6
|
-
export
|
|
6
|
+
export const runStartup = function(aGlobalScope = "dbmstartup", aModulesName = "modules") {
|
|
7
7
|
if(!window[aGlobalScope][aModulesName].isSetup) {
|
|
8
8
|
let controller = new Dbm.startup.Controller();
|
|
9
9
|
|
|
@@ -25,4 +25,14 @@ export let runStartup = function(aGlobalScope = "dbmstartup", aModulesName = "mo
|
|
|
25
25
|
|
|
26
26
|
currentArray.splice(0, currentArrayLength);
|
|
27
27
|
}
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export const setupLibrary = function() {
|
|
31
|
+
let library = Dbm.getRepositoryItem("library");
|
|
32
|
+
library.setValue("Dbm/commands/CallFunction", Dbm.commands.CallFunction);
|
|
33
|
+
library.setValue("Dbm/flow/addUpdateCommand", Dbm.flow.addUpdateCommand);
|
|
34
|
+
library.setValue("Dbm/flow/addUpdateCommandWhenMatched", Dbm.flow.addUpdateCommandWhenMatched);
|
|
35
|
+
library.setValue("Dbm/flow/updatefunctions/logic/Condition", Dbm.flow.updatefunctions.logic.Condition);
|
|
36
|
+
library.setValue("Dbm/flow/updatefunctions/logic/Switch", Dbm.flow.updatefunctions.logic.Switch);
|
|
37
|
+
|
|
28
38
|
}
|
package/tracking/Controller.js
CHANGED
|
@@ -120,7 +120,7 @@ export default class Controller extends Dbm.core.BaseObject {
|
|
|
120
120
|
}
|
|
121
121
|
}
|
|
122
122
|
|
|
123
|
-
trackEvent(aEventName, aData) {
|
|
123
|
+
trackEvent(aEventName, aData, aDataStructure = null) {
|
|
124
124
|
console.log("trackEvent");
|
|
125
125
|
console.log(aEventName, aData);
|
|
126
126
|
|
|
@@ -128,7 +128,7 @@ export default class Controller extends Dbm.core.BaseObject {
|
|
|
128
128
|
let currentArray = this.item.trackers;
|
|
129
129
|
let currentArrayLength = currentArray.length;
|
|
130
130
|
for(let i = 0; i < currentArrayLength; i++) {
|
|
131
|
-
currentArray[i].controller.trackEvent(aEventName, aData);
|
|
131
|
+
currentArray[i].controller.trackEvent(aEventName, aData, aDataStructure);
|
|
132
132
|
}
|
|
133
133
|
}
|
|
134
134
|
|
|
@@ -184,7 +184,7 @@ export default class Controller extends Dbm.core.BaseObject {
|
|
|
184
184
|
items: items
|
|
185
185
|
}
|
|
186
186
|
|
|
187
|
-
this.trackEvent("Product view", data);
|
|
187
|
+
this.trackEvent("Product view", data, "ecommerce");
|
|
188
188
|
}
|
|
189
189
|
|
|
190
190
|
trackAddedToCart(aProductOrProducts) {
|
|
@@ -196,7 +196,7 @@ export default class Controller extends Dbm.core.BaseObject {
|
|
|
196
196
|
items: items
|
|
197
197
|
}
|
|
198
198
|
|
|
199
|
-
this.trackEvent("Added to cart", data);
|
|
199
|
+
this.trackEvent("Added to cart", data, "ecommerce");
|
|
200
200
|
|
|
201
201
|
}
|
|
202
202
|
|
|
@@ -209,7 +209,7 @@ export default class Controller extends Dbm.core.BaseObject {
|
|
|
209
209
|
items: items
|
|
210
210
|
}
|
|
211
211
|
|
|
212
|
-
this.trackEvent("Checkout started", data);
|
|
212
|
+
this.trackEvent("Checkout started", data, "ecommerce");
|
|
213
213
|
}
|
|
214
214
|
|
|
215
215
|
trackAddShipping(aProductOrProducts) {
|
|
@@ -221,7 +221,7 @@ export default class Controller extends Dbm.core.BaseObject {
|
|
|
221
221
|
items: items
|
|
222
222
|
}
|
|
223
223
|
|
|
224
|
-
this.trackEvent("Add shipping", data);
|
|
224
|
+
this.trackEvent("Add shipping", data, "ecommerce");
|
|
225
225
|
}
|
|
226
226
|
|
|
227
227
|
trackAddPayment(aProductOrProducts) {
|
|
@@ -233,7 +233,7 @@ export default class Controller extends Dbm.core.BaseObject {
|
|
|
233
233
|
items: items
|
|
234
234
|
}
|
|
235
235
|
|
|
236
|
-
this.trackEvent("Add payment", data);
|
|
236
|
+
this.trackEvent("Add payment", data, "ecommerce");
|
|
237
237
|
}
|
|
238
238
|
|
|
239
239
|
trackPurchase(aTransactionId, aProductOrProducts) {
|
|
@@ -246,7 +246,7 @@ export default class Controller extends Dbm.core.BaseObject {
|
|
|
246
246
|
items: items
|
|
247
247
|
}
|
|
248
248
|
|
|
249
|
-
this.trackEvent("Purchase", data);
|
|
249
|
+
this.trackEvent("Purchase", data, "ecommerce");
|
|
250
250
|
}
|
|
251
251
|
|
|
252
252
|
createProductItemData(aId, aName, aPrice, aQuantity = 1, aAddtionalData = {}) {
|
|
@@ -6,6 +6,9 @@ export default class DataLayerTracker extends Dbm.core.BaseObject {
|
|
|
6
6
|
|
|
7
7
|
this._statisticsTracking = false;
|
|
8
8
|
this._marketingTracking = false;
|
|
9
|
+
|
|
10
|
+
this.item.setValue("ecommerceDataWrapper", null);
|
|
11
|
+
this.item.setValue("eventNameMap", new Dbm.repository.Item());
|
|
9
12
|
}
|
|
10
13
|
|
|
11
14
|
addToDataLayer(aData) {
|
|
@@ -67,18 +70,34 @@ export default class DataLayerTracker extends Dbm.core.BaseObject {
|
|
|
67
70
|
return this;
|
|
68
71
|
}
|
|
69
72
|
|
|
70
|
-
trackEvent(aEventName, aData) {
|
|
73
|
+
trackEvent(aEventName, aData, aDataStructure = null) {
|
|
71
74
|
console.log("trackEvent");
|
|
72
|
-
console.log(aEventName, aData);
|
|
75
|
+
console.log(aEventName, aData, aDataStructure);
|
|
76
|
+
|
|
77
|
+
let translatedEventName = this.item.eventNameMap[aEventName];
|
|
78
|
+
if(translatedEventName) {
|
|
79
|
+
aEventName = translatedEventName;
|
|
80
|
+
}
|
|
73
81
|
|
|
74
82
|
if(this._statisticsTracking) {
|
|
75
83
|
this.addToDataLayer({"event": "trackEvent", "value": {"name": aEventName, "data": aData}});
|
|
76
|
-
|
|
84
|
+
if(aDataStructure === "ecommerce" && this.item.ecommerceDataWrapper) {
|
|
85
|
+
this.addToDataLayer({"event": aEventName, [this.item.ecommerceDataWrapper]: aData});
|
|
86
|
+
}
|
|
87
|
+
else {
|
|
88
|
+
this._gtag("event", aEventName, aData);
|
|
89
|
+
}
|
|
90
|
+
|
|
77
91
|
}
|
|
78
92
|
|
|
79
93
|
if(this._marketingTracking) {
|
|
80
94
|
this.addToDataLayer({"event": "trackMarketingEvent", "value": {"name": aEventName, "data": aData}});
|
|
81
|
-
|
|
95
|
+
if(aDataStructure === "ecommerce" && this.item.ecommerceDataWrapper) {
|
|
96
|
+
this.addToDataLayer({"event": "Marketing / " + aEventName, [this.item.ecommerceDataWrapper]: aData});
|
|
97
|
+
}
|
|
98
|
+
else {
|
|
99
|
+
this._gtag("event", "Marketing / " + aEventName, aData);
|
|
100
|
+
}
|
|
82
101
|
}
|
|
83
102
|
}
|
|
84
103
|
|
package/tracking/index.js
CHANGED
|
@@ -14,22 +14,24 @@ export const setup = function() {
|
|
|
14
14
|
controller.start();
|
|
15
15
|
|
|
16
16
|
let dataLayerTracker = new Dbm.tracking.DataLayerTracker();
|
|
17
|
+
dataLayerTracker.item.register("tracking/dataLayerTracker");
|
|
17
18
|
controller.addTracker(dataLayerTracker.item);
|
|
18
19
|
}
|
|
19
20
|
|
|
20
21
|
export const addMetaPixel = function(aPixelId) {
|
|
21
22
|
let tracker = new Dbm.tracking.MetaPixelTracker();
|
|
22
23
|
tracker.item.pixelId = aPixelId;
|
|
23
|
-
|
|
24
|
+
tracker.item.register("tracking/metaPixelTracker");
|
|
25
|
+
Dbm.getRepositoryItem("trackingController").controller.addTracker(tracker.item);
|
|
24
26
|
}
|
|
25
27
|
|
|
26
28
|
export const setCurrency = function(aCurrency) {
|
|
27
|
-
Dbm.
|
|
29
|
+
Dbm.getRepositoryItem("trackingController").currency = aCurrency;
|
|
28
30
|
}
|
|
29
31
|
|
|
30
32
|
export const addTagManagerTracking = function(aId) {
|
|
31
33
|
//console.log("addTagManagerTracking");
|
|
32
34
|
let tracker = new Dbm.tracking.TagManagerTracker();
|
|
33
35
|
tracker.item.tagManagerId = aId;
|
|
34
|
-
Dbm.
|
|
36
|
+
Dbm.getRepositoryItem("trackingController").controller.addTracker(tracker.item);
|
|
35
37
|
}
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
import Dbm from "../index.js";
|
|
2
|
+
|
|
3
|
+
export default class KeywordReplace extends Dbm.core.BaseObject {
|
|
4
|
+
|
|
5
|
+
_construct() {
|
|
6
|
+
super._construct();
|
|
7
|
+
|
|
8
|
+
this.item.setValue("keywordStart", "{{");
|
|
9
|
+
this.item.setValue("keywordMatch", "[^\\{\\}]*");
|
|
10
|
+
this.item.setValue("keywordEnd", "}}");
|
|
11
|
+
|
|
12
|
+
this.item.setValue("keywordProviders", []);
|
|
13
|
+
this.addKeywordProvider("default", {});
|
|
14
|
+
|
|
15
|
+
return this;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
addKeyword(aKeyword, aValue) {
|
|
19
|
+
this.item["keywordProvider/default"][aKeyword.toLowerCase()] = aValue;
|
|
20
|
+
|
|
21
|
+
return this;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
addKeywordProvider(aName, aKeywordProvider) {
|
|
25
|
+
this.item.addToArray("keywordProviders", aKeywordProvider);
|
|
26
|
+
this.item.setValue("keywordProvider/" + aName.toLowerCase(), aKeywordProvider);
|
|
27
|
+
|
|
28
|
+
return this;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
escapeRegex(aText) {
|
|
32
|
+
return aText.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
_getRegex() {
|
|
36
|
+
let keywordStart = this.escapeRegex(this.item.keywordStart);
|
|
37
|
+
let keywordEnd = this.escapeRegex(this.item.keywordEnd);
|
|
38
|
+
|
|
39
|
+
let regex = new RegExp(keywordStart + "\\s*(" + this.item.keywordMatch + ")\\s*" + keywordEnd, "g");
|
|
40
|
+
|
|
41
|
+
return regex;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
_trimRegexKey(aRegexResult) {
|
|
45
|
+
let normalizedKey = aRegexResult[1].replace(/\s+/g, "").toLowerCase();
|
|
46
|
+
return normalizedKey;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
findKeywords(aText) {
|
|
50
|
+
|
|
51
|
+
let regex = this._getRegex();
|
|
52
|
+
|
|
53
|
+
let keywords = [...regex].map(this._trimRegexKey);
|
|
54
|
+
|
|
55
|
+
return keywords;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
getKeywordValue(aKeyword) {
|
|
59
|
+
|
|
60
|
+
let index = aKeyword.indexOf(":");
|
|
61
|
+
if(index === -1) {
|
|
62
|
+
let currentArray = this.item.keywordProviders;
|
|
63
|
+
let currentArrayLength = currentArray.length;
|
|
64
|
+
for(let i = 0; i < currentArrayLength; i++) {
|
|
65
|
+
let provider = currentArray[i];
|
|
66
|
+
let value = Dbm.objectPath(provider, aKeyword);
|
|
67
|
+
if(value !== undefined) {
|
|
68
|
+
return value;
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
else {
|
|
73
|
+
let group = aKeyword.substring(0, index);
|
|
74
|
+
let keyword = aKeyword.substring(index+1);
|
|
75
|
+
|
|
76
|
+
let value = Dbm.objectPath(this.item["keywordProvider/" + group.toLowerCase()], keyword.toLowerCase());
|
|
77
|
+
if(value !== undefined) {
|
|
78
|
+
return value;
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
return null;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
_regexReplaceKeyword(aFullMatch, aKey) {
|
|
86
|
+
let normalizedKey = aKey.replace(/\s+/g, "");
|
|
87
|
+
|
|
88
|
+
let newValue = this.getKeywordValue(normalizedKey);
|
|
89
|
+
if(newValue) {
|
|
90
|
+
return newValue;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
return aFullMatch;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
replaceKeywords(aText) {
|
|
97
|
+
let newText = aText.replace(this._getRegex(), this._regexReplaceKeyword.bind(this));
|
|
98
|
+
|
|
99
|
+
console.log(newText);
|
|
100
|
+
return newText;
|
|
101
|
+
}
|
|
102
|
+
}
|
package/utils/index.js
CHANGED
|
@@ -9,6 +9,7 @@ export * as ObjectFunctions from "./ObjectFunctions.js";
|
|
|
9
9
|
|
|
10
10
|
export {default as MultidimensionalArrayHolder} from "./MultidimensionalArrayHolder.js";
|
|
11
11
|
export {default as ArrayOperationResult} from "./ArrayOperationResult.js";
|
|
12
|
+
export {default as KeywordReplace} from "./KeywordReplace.js";
|
|
12
13
|
|
|
13
14
|
export * as thirdparty from "./thirdparty/index.js";
|
|
14
15
|
export * as svg from "./svg/index.js";
|