-
Notifications
You must be signed in to change notification settings - Fork 32
Expand file tree
/
Copy pathitemProcessingUtils.js
More file actions
58 lines (43 loc) · 1.29 KB
/
itemProcessingUtils.js
File metadata and controls
58 lines (43 loc) · 1.29 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
47
48
49
50
51
52
53
54
55
56
57
58
/* istanbul ignore file */
import moment from 'moment-timezone';
function processFormItem(item) {
if (item.component !== 'FormMultiColumn') {
return item;
}
return item.items.flatMap(processFormItem);
}
export function getItemsFromConfig(config) {
return config
.flatMap(page => page.items)
.flatMap(processFormItem);
}
export function getDefaultValueForItem(item) {
let defaultValue = null;
if (['FormInput', 'FormTextArea', 'FormText'].includes(item.component)) {
defaultValue = '';
}
if (item.component === 'FormCheckbox') {
defaultValue = item.config.initiallyChecked || false;
}
if (item.component === 'FormRecordList') {
defaultValue = [];
}
if (item.component === 'FormDatePicker') {
defaultValue = generateNewDate(item.config.dataFormat);
}
if (item.component === 'FormButton' && item.config.event === 'script') {
defaultValue = 0;
}
return defaultValue;
}
function generateNewDate(dataFormat) {
let timezone = moment.tz.guess();
if (typeof window.ProcessMaker !== 'undefined' && window.ProcessMaker.user && window.ProcessMaker.user.timezone) {
timezone = window.ProcessMaker.user.timezone;
}
const date = moment.tz(timezone);
if (dataFormat !== 'datetime') {
date.startOf('day');
}
return date.toISOString();
}