-
Notifications
You must be signed in to change notification settings - Fork 36
/
Copy pathall-day.ts
56 lines (50 loc) · 2.01 KB
/
all-day.ts
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
import {IAuthoringFieldV2, ICommonFieldConfig} from 'superdesk-api';
import {superdeskApi} from '../../../superdeskApi';
import moment from 'moment';
export const getAllDayDatesField = () => {
return {
fieldId: 'dates',
getField: ({required, id}) => {
const fieldConfig: ICommonFieldConfig = {
required: required,
};
const field: IAuthoringFieldV2 = {
id: id,
name: superdeskApi.localization.gettext('All Day'),
fieldType: 'boolean',
fieldConfig: fieldConfig,
};
return field;
},
storageAdapterEvent: {
storeValue: (item: IEventItem, operationalValue: boolean | undefined) => {
const dates = item.dates ?? {};
let newStart, newEnd;
newStart = moment((dates.start ?? (dates.tz ? moment.tz(dates.tz) : moment())))
.startOf('day');
// If allDay is enabled, then set the event to all day
if (operationalValue) {
newEnd = moment(dates.end ?? (dates.tz ? moment.tz(dates.tz) : moment()))
.endOf('day');
} else {
// If allDay is disabled, then set the new dates to
// the initial values since last save and time to empty
newEnd = moment(dates?.end ?? newStart)
.hour(0)
.minute(1);
}
// TODO: Figure out support for _startTime _endTime, _time_to_be_confirmed fields
return {
...item,
dates: {
...item.dates,
start: newStart,
end: newEnd,
all_day: operationalValue,
}
};
},
retrieveStoredValue: (item: IEventItem) => item.dates.all_day,
}
};
};