Skip to content

Commit 079576e

Browse files
committed
More fields
1 parent ae7b4d2 commit 079576e

File tree

3 files changed

+111
-0
lines changed

3 files changed

+111
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
import {IAuthoringFieldV2, ICommonFieldConfig} from 'superdesk-api';
2+
import {superdeskApi} from '../../../superdeskApi';
3+
import moment from 'moment';
4+
5+
export const getAllDayDatesField = () => {
6+
return {
7+
fieldId: 'dates',
8+
getField: ({required, id}) => {
9+
const fieldConfig: ICommonFieldConfig = {
10+
required: required,
11+
};
12+
13+
const field: IAuthoringFieldV2 = {
14+
id: id,
15+
name: superdeskApi.localization.gettext('All Day'),
16+
fieldType: 'boolean',
17+
fieldConfig: fieldConfig,
18+
};
19+
20+
return field;
21+
},
22+
storageAdapterEvent: {
23+
storeValue: (item: IEventItem, operationalValue: boolean | undefined) => {
24+
const dates = item.dates ?? {};
25+
let newStart, newEnd;
26+
27+
newStart = moment((dates.start ?? (dates.tz ? moment.tz(dates.tz) : moment())))
28+
.startOf('day');
29+
30+
// If allDay is enabled, then set the event to all day
31+
if (operationalValue) {
32+
newEnd = moment(dates.end ?? (dates.tz ? moment.tz(dates.tz) : moment()))
33+
.endOf('day');
34+
} else {
35+
// If allDay is disabled, then set the new dates to
36+
// the initial values since last save and time to empty
37+
newEnd = moment(dates?.end ?? newStart)
38+
.hour(0)
39+
.minute(1);
40+
}
41+
42+
// TODO: Figure out support for _startTime _endTime, _time_to_be_confirmed fields
43+
return {
44+
...item,
45+
dates: {
46+
...item.dates,
47+
start: newStart,
48+
end: newEnd,
49+
all_day: operationalValue,
50+
}
51+
};
52+
},
53+
retrieveStoredValue: (item: IEventItem) => item.dates.all_day,
54+
}
55+
};
56+
};

client/components/editor-standalone/field-definitions/index.ts

+2
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import {getContactsField} from './contacts';
2121
import {getOccurStatusField} from './occurence-status';
2222
import {getLanguageField} from './lanugage';
2323
import {getCalendarsField} from './calendars';
24+
import {getAllDayDatesField} from './all-day';
2425

2526
export function getFieldDefinitions(profileType: 'event' | 'planning'): IFieldDefinitions {
2627
const {gettext} = superdeskApi.localization;
@@ -94,6 +95,7 @@ export function getFieldDefinitions(profileType: 'event' | 'planning'): IFieldDe
9495
getField: ({required, id}) =>
9596
getTextFieldConfig({id: id, label: gettext('Registration Details'), required: required}),
9697
},
98+
getAllDayDatesField(),
9799
getCalendarsField(),
98100
getLanguageField(),
99101
getOccurStatusField(),
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
import {IAuthoringFieldV2, IDropdownConfigManualSource} from 'superdesk-api';
2+
import {planningApi, superdeskApi} from '../../../superdeskApi';
3+
import {eventOccurStatuses} from '../../../selectors/vocabs';
4+
import {getVocabularyItemFieldTranslated} from '../../../utils/vocabularies';
5+
6+
export const getOccurStatusField = () => ({
7+
fieldId: 'occur_status',
8+
getField: ({required, id}) => {
9+
const vocabularyFromStore = eventOccurStatuses(planningApi.redux.store.getState());
10+
const options = vocabularyFromStore.map(
11+
(option) => ({
12+
id: option.qcode,
13+
label: getVocabularyItemFieldTranslated(
14+
option,
15+
'label',
16+
'en',
17+
'name'
18+
),
19+
})
20+
);
21+
22+
const fieldConfig: IDropdownConfigManualSource = {
23+
source: 'manual-entry',
24+
options: options,
25+
type: 'text',
26+
roundCorners: false,
27+
multiple: false,
28+
required: required,
29+
};
30+
31+
const field: IAuthoringFieldV2 = {
32+
id: id,
33+
name: superdeskApi.localization.gettext('Occurrence Status'),
34+
fieldType: 'dropdown',
35+
fieldConfig: fieldConfig,
36+
};
37+
38+
return field;
39+
},
40+
storageAdapterEvent: {
41+
storeValue: (item, operationalValue: Array<string>) => {
42+
const vocabularyFromStore = eventOccurStatuses(planningApi.redux.store.getState());
43+
44+
return {
45+
...item,
46+
occur_status: vocabularyFromStore.find((x) => x.qcode == operationalValue),
47+
};
48+
},
49+
retrieveStoredValue: (item) => {
50+
return item.occur_status.qcode;
51+
}
52+
}
53+
});

0 commit comments

Comments
 (0)