-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathconsole-addButton.js
More file actions
46 lines (37 loc) · 1.36 KB
/
console-addButton.js
File metadata and controls
46 lines (37 loc) · 1.36 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
/**
* Name: Add Button Console Event Handler
* Description: This event handler adds a button to the console whose text displays the value of the "Type" field.
*/
(function (eventNames, convenienceApi) {
var eventHandlers = {};
var getCarValue = (carField) => {
return convenienceApi.fieldHelper.getValue(carField).then(function(value){
return value.Name;
});
};
var getCarName = (carValue) => {
return `${carValue} Button`;
};
eventHandlers[eventNames.CREATE_CONSOLE] = function () {
console.log("Inside CREATE_CONSOLE event handler");
var button = document.createElement("button");
button.id = "testConsoleButton";
const carField = this.fieldNameToFieldIdMap.get("Type");
// Button text is set to the value of the car field once saved
getCarValue(carField).then(function(value) {
button.textContent = getCarName(value);
});
return convenienceApi.console.containersPromise.then(function (containers) {
containers.rootElement.appendChild(button);
});
};
eventHandlers[eventNames.UPDATE_CONSOLE] = function () {
console.log("Inside UPDATE_CONSOLE event handler");
const carField = this.fieldNameToFieldIdMap.get("Type");
var button = document.getElementById("testConsoleButton");
getCarValue(carField).then(function(value) {
button.textContent = getCarName(value);
});
};
return eventHandlers;
}(eventNames, convenienceApi));