@sprucelabs/spruce-calendar-components 20.0.1 → 20.1.2
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/build/esm/toolBelt/states/AbstractCalendarEventToolBeltState.d.ts +2 -0
- package/build/esm/toolBelt/states/AbstractCalendarEventToolBeltState.js +4 -1
- package/build/esm/types/calendar.types.d.ts +2 -0
- package/build/esm/viewControllers/Calendar.vc.d.ts +1 -0
- package/build/esm/viewControllers/Calendar.vc.js +9 -4
- package/build/esm/viewControllers/EventControlsCard.vc.d.ts +5 -1
- package/build/esm/viewControllers/EventControlsCard.vc.js +13 -3
- package/build/esm/viewControllers/EventDateTimeTool.vc.d.ts +5 -1
- package/build/esm/viewControllers/EventDateTimeTool.vc.js +24 -0
- package/build/toolBelt/states/AbstractCalendarEventToolBeltState.d.ts +2 -0
- package/build/toolBelt/states/AbstractCalendarEventToolBeltState.js +4 -1
- package/build/types/calendar.types.d.ts +2 -0
- package/build/viewControllers/Calendar.vc.d.ts +1 -0
- package/build/viewControllers/Calendar.vc.js +9 -4
- package/build/viewControllers/EventControlsCard.vc.d.ts +5 -1
- package/build/viewControllers/EventControlsCard.vc.js +13 -3
- package/build/viewControllers/EventDateTimeTool.vc.d.ts +5 -1
- package/build/viewControllers/EventDateTimeTool.vc.js +22 -0
- package/package.json +1 -1
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { SpruceSchemas, ToolBeltState, ViewControllerId } from '@sprucelabs/heartwood-view-controllers';
|
|
2
2
|
import { CalendarTool, CalendarToolBeltContext, CalendarToolBeltStateMachine, GetPersonFromEventHandler } from '../../types/calendar.types';
|
|
3
|
+
import EventControlsCardViewController from '../../viewControllers/EventControlsCard.vc';
|
|
3
4
|
declare type Tool = SpruceSchemas.HeartwoodViewControllers.v2021_02_11.ToolBeltTool;
|
|
4
5
|
export declare type AddToolOptions = Omit<Tool, 'card'> & {
|
|
5
6
|
cardVcId: ViewControllerId;
|
|
@@ -26,6 +27,7 @@ export default abstract class AbstractCalendarEventToolBeltState implements Tool
|
|
|
26
27
|
removeTool(id: string): void;
|
|
27
28
|
getPendingContextChanges(): Partial<CalendarToolBeltContext>;
|
|
28
29
|
getVcForTool(toolId: string): CalendarTool | undefined;
|
|
30
|
+
getControlsVc(): EventControlsCardViewController;
|
|
29
31
|
destroy(): Promise<void>;
|
|
30
32
|
}
|
|
31
33
|
export {};
|
|
@@ -22,7 +22,7 @@ export default class AbstractCalendarEventToolBeltState {
|
|
|
22
22
|
this.sm = sm;
|
|
23
23
|
this.toolBeltVc = sm.getToolBeltVc();
|
|
24
24
|
this._isLoaded = true;
|
|
25
|
-
this.controlsVc = sm.Controller('calendar.event-controls-card', Object.assign({ onCancel: this.clearPendingContextChanges.bind(this), onSave: this.handleClickSave.bind(this) }, this.buildVcConstructorOptions('controls')));
|
|
25
|
+
this.controlsVc = sm.Controller('calendar.event-controls-card', Object.assign(Object.assign({ onCancel: this.clearPendingContextChanges.bind(this), onSave: this.handleClickSave.bind(this) }, this.buildVcConstructorOptions('controls')), { onCancelEvent: this.sm.getContext().cancelEvent }));
|
|
26
26
|
this.toolBeltVc.clearTools();
|
|
27
27
|
this.toolBeltVc.setStickyTool({
|
|
28
28
|
card: this.controlsVc.render(),
|
|
@@ -152,6 +152,9 @@ export default class AbstractCalendarEventToolBeltState {
|
|
|
152
152
|
var _a;
|
|
153
153
|
return (_a = this.vcs.find((v) => v.toolId === toolId)) === null || _a === void 0 ? void 0 : _a.vc;
|
|
154
154
|
}
|
|
155
|
+
getControlsVc() {
|
|
156
|
+
return this.controlsVc;
|
|
157
|
+
}
|
|
155
158
|
destroy() {
|
|
156
159
|
return __awaiter(this, void 0, void 0, function* () {
|
|
157
160
|
yield this.sm.off('did-update-context', this.handleDidUpdateContext);
|
|
@@ -18,6 +18,7 @@ declare type Card = SpruceSchemas.HeartwoodViewControllers.v2021_02_11.Card;
|
|
|
18
18
|
export declare type CalendarToolBeltContext = SkillViewControllerLoadOptions & {
|
|
19
19
|
event: CalendarEvent;
|
|
20
20
|
calendarVc: CalendarViewController;
|
|
21
|
+
cancelEvent: CancelEventHandler;
|
|
21
22
|
};
|
|
22
23
|
export declare type CalendarToolBeltStateMachine = ToolBeltStateMachine<CalendarToolBeltContext>;
|
|
23
24
|
export interface RemoteCalendarTool extends CalendarTool {
|
|
@@ -35,6 +36,7 @@ export declare type UpdateCalendarToolBeltContextHandler = (context: Partial<Cal
|
|
|
35
36
|
export declare type GetCalendarToolBeltContextHandler = () => CalendarToolBeltContext;
|
|
36
37
|
export declare type GetPersonFromEventHandler = () => Promise<Person | null>;
|
|
37
38
|
export declare type GetHasPendingContextChangesHandler = () => boolean;
|
|
39
|
+
export declare type CancelEventHandler = (eventId: string) => boolean | Promise<boolean | void> | void;
|
|
38
40
|
export interface CalendarToolOptions {
|
|
39
41
|
updateContext: UpdateCalendarToolBeltContextHandler;
|
|
40
42
|
getContext: GetCalendarToolBeltContextHandler;
|
|
@@ -30,6 +30,7 @@ export default class CalendarViewController extends CoreCalendarViewController {
|
|
|
30
30
|
private eventSwappedHandler?;
|
|
31
31
|
private dropEventHandler?;
|
|
32
32
|
private isSwapping;
|
|
33
|
+
private lastSwappedId?;
|
|
33
34
|
constructor(options: ViewControllerOptions & CalendarViewControllerOptions);
|
|
34
35
|
private handleDropEvent;
|
|
35
36
|
getCalendarVc(): this;
|
|
@@ -186,10 +186,15 @@ export default class CalendarViewController extends CoreCalendarViewController {
|
|
|
186
186
|
if (!saved) {
|
|
187
187
|
return;
|
|
188
188
|
}
|
|
189
|
-
if (
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
189
|
+
if (id !== saved.id) {
|
|
190
|
+
if (this.lastSwappedId === id) {
|
|
191
|
+
this.updateEvent(saved.id, saved);
|
|
192
|
+
}
|
|
193
|
+
else {
|
|
194
|
+
this.lastSwappedId = id;
|
|
195
|
+
yield this.swapEvent(event, saved);
|
|
196
|
+
yield ((_b = this.eventSwappedHandler) === null || _b === void 0 ? void 0 : _b.call(this, saved));
|
|
197
|
+
}
|
|
193
198
|
}
|
|
194
199
|
else {
|
|
195
200
|
_super.updateEvent.call(this, saved.id, { isBusy, error: undefined });
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import { AbstractViewController, SpruceSchemas, ViewControllerOptions } from '@sprucelabs/heartwood-view-controllers';
|
|
2
|
-
import { CalendarTool, CalendarToolOptions } from '../types/calendar.types';
|
|
2
|
+
import { CalendarTool, CalendarToolOptions, CancelEventHandler } from '../types/calendar.types';
|
|
3
3
|
declare type Card = SpruceSchemas.HeartwoodViewControllers.v2021_02_11.Card;
|
|
4
4
|
export interface EventControlsCardOptions extends CalendarToolOptions {
|
|
5
5
|
onCancel: () => Promise<void | boolean> | void | boolean;
|
|
6
|
+
onCancelEvent: CancelEventHandler;
|
|
6
7
|
onSave: () => Promise<void | boolean> | void | boolean;
|
|
7
8
|
}
|
|
8
9
|
export default class EventControlsCardViewController extends AbstractViewController<Card> implements CalendarTool {
|
|
@@ -12,10 +13,13 @@ export default class EventControlsCardViewController extends AbstractViewControl
|
|
|
12
13
|
private cancelHandler;
|
|
13
14
|
private getHasPendingContextChangesHandler;
|
|
14
15
|
private getContext;
|
|
16
|
+
private cancelEventHandler;
|
|
15
17
|
constructor(options: ViewControllerOptions & EventControlsCardOptions);
|
|
18
|
+
private CardVc;
|
|
16
19
|
private handleClickCancel;
|
|
17
20
|
private handleClickSave;
|
|
18
21
|
handleUpdateContext(): void;
|
|
22
|
+
private optionallyDropInCancelButton;
|
|
19
23
|
render(): SpruceSchemas.HeartwoodViewControllers.v2021_02_11.Card;
|
|
20
24
|
}
|
|
21
25
|
export {};
|
|
@@ -13,17 +13,23 @@ import draftEventGenerator from '../utilities/draftGenerator.js';
|
|
|
13
13
|
export default class EventControlsCardViewController extends AbstractViewController {
|
|
14
14
|
constructor(options) {
|
|
15
15
|
super(options);
|
|
16
|
-
const { onSave, onCancel, getHasPendingContextChanges, getContext } = assertOptions(options, [
|
|
16
|
+
const { onSave, onCancel, getHasPendingContextChanges, getContext, onCancelEvent, } = assertOptions(options, [
|
|
17
17
|
'onCancel',
|
|
18
18
|
'onSave',
|
|
19
|
+
'onCancelEvent',
|
|
19
20
|
'getHasPendingContextChanges',
|
|
20
21
|
'getContext',
|
|
21
22
|
]);
|
|
22
23
|
this.saveHandler = onSave;
|
|
23
24
|
this.cancelHandler = onCancel;
|
|
25
|
+
this.cancelEventHandler = onCancelEvent;
|
|
24
26
|
this.getHasPendingContextChangesHandler = getHasPendingContextChanges;
|
|
25
27
|
this.getContext = getContext;
|
|
26
|
-
this.cardVc = this.
|
|
28
|
+
this.cardVc = this.CardVc();
|
|
29
|
+
this.optionallyDropInCancelButton();
|
|
30
|
+
}
|
|
31
|
+
CardVc() {
|
|
32
|
+
return this.Controller('card', {
|
|
27
33
|
footer: {
|
|
28
34
|
isEnabled: false,
|
|
29
35
|
isBusy: false,
|
|
@@ -58,13 +64,16 @@ export default class EventControlsCardViewController extends AbstractViewControl
|
|
|
58
64
|
});
|
|
59
65
|
}
|
|
60
66
|
handleUpdateContext() {
|
|
61
|
-
var _a;
|
|
62
67
|
if (this.getHasPendingContextChangesHandler()) {
|
|
63
68
|
this.cardVc.enableFooter();
|
|
64
69
|
}
|
|
65
70
|
else {
|
|
66
71
|
this.cardVc.disableFooter();
|
|
67
72
|
}
|
|
73
|
+
this.optionallyDropInCancelButton();
|
|
74
|
+
}
|
|
75
|
+
optionallyDropInCancelButton() {
|
|
76
|
+
var _a;
|
|
68
77
|
const { event } = this.getContext();
|
|
69
78
|
if ((event === null || event === void 0 ? void 0 : event.id) && !draftEventGenerator.isDraftId(event.id)) {
|
|
70
79
|
this.cardVc.setBody({
|
|
@@ -75,6 +84,7 @@ export default class EventControlsCardViewController extends AbstractViewControl
|
|
|
75
84
|
id: 'cancel-event',
|
|
76
85
|
label: `Cancel ${(_a = event.eventTypeSlug) !== null && _a !== void 0 ? _a : 'event'}`,
|
|
77
86
|
type: 'destructive',
|
|
87
|
+
onClick: () => this.cancelEventHandler(this.getContext().event.id),
|
|
78
88
|
},
|
|
79
89
|
],
|
|
80
90
|
},
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { AbstractViewController, FormViewController, SpruceSchemas, ViewControllerOptions } from '@sprucelabs/heartwood-view-controllers';
|
|
1
|
+
import { AbstractViewController, CalendarViewController, FormViewController, SpruceSchemas, ViewControllerOptions } from '@sprucelabs/heartwood-view-controllers';
|
|
2
2
|
import { CalendarTool, CalendarToolBeltContext, CalendarToolOptions } from '../types/calendar.types';
|
|
3
3
|
declare type Card = SpruceSchemas.HeartwoodViewControllers.v2021_02_11.Card;
|
|
4
4
|
export default class EventDateTimeToolViewController extends AbstractViewController<Card> implements CalendarTool {
|
|
@@ -8,8 +8,12 @@ export default class EventDateTimeToolViewController extends AbstractViewControl
|
|
|
8
8
|
private formVc;
|
|
9
9
|
private updateContext;
|
|
10
10
|
private getContext;
|
|
11
|
+
private calendarVc;
|
|
11
12
|
constructor(options: ViewControllerOptions & CalendarToolOptions);
|
|
13
|
+
private handleSelectDateFromCalendar;
|
|
14
|
+
private getSelectedDate;
|
|
12
15
|
private CardVc;
|
|
16
|
+
getCalendarVc(): CalendarViewController;
|
|
13
17
|
private FormVc;
|
|
14
18
|
handleUpdateContext(context: CalendarToolBeltContext): Promise<void>;
|
|
15
19
|
private handleChangeForm;
|
|
@@ -7,6 +7,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
7
7
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
8
|
});
|
|
9
9
|
};
|
|
10
|
+
import { dateUtil } from '@sprucelabs/calendar-utils';
|
|
10
11
|
import { AbstractViewController, buildForm, } from '@sprucelabs/heartwood-view-controllers';
|
|
11
12
|
import { buildSchema } from '@sprucelabs/schema';
|
|
12
13
|
const schema = buildSchema({
|
|
@@ -24,9 +25,25 @@ export default class EventDateTimeToolViewController extends AbstractViewControl
|
|
|
24
25
|
this.shouldPersistContextChangesImmediately = true;
|
|
25
26
|
this.updateContext = options.updateContext;
|
|
26
27
|
this.getContext = options.getContext;
|
|
28
|
+
this.calendarVc = this.Controller('calendar', {
|
|
29
|
+
view: 'month',
|
|
30
|
+
selectedDates: [this.getSelectedDate()],
|
|
31
|
+
onClick: this.handleSelectDateFromCalendar.bind(this),
|
|
32
|
+
});
|
|
27
33
|
this.formVc = this.FormVc();
|
|
28
34
|
this.cardVc = this.CardVc();
|
|
29
35
|
}
|
|
36
|
+
handleSelectDateFromCalendar({ dateTimeMs, }) {
|
|
37
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
38
|
+
const { hour, minute } = dateUtil.splitDate(this.getContext().event.startDateTimeMs);
|
|
39
|
+
yield this.formVc.setValue('startDateTime', dateUtil.setTimeOfDay(dateTimeMs, hour, minute, 0, 0));
|
|
40
|
+
this.calendarVc.setSelectedDates([this.getSelectedDate(dateTimeMs)]);
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
getSelectedDate(dateTimeMs) {
|
|
44
|
+
const { year, month, day } = dateUtil.splitDate(dateTimeMs !== null && dateTimeMs !== void 0 ? dateTimeMs : this.getContext().event.startDateTimeMs);
|
|
45
|
+
return { year, month, day };
|
|
46
|
+
}
|
|
30
47
|
CardVc() {
|
|
31
48
|
return this.Controller('card', {
|
|
32
49
|
header: {
|
|
@@ -34,6 +51,9 @@ export default class EventDateTimeToolViewController extends AbstractViewControl
|
|
|
34
51
|
},
|
|
35
52
|
body: {
|
|
36
53
|
sections: [
|
|
54
|
+
{
|
|
55
|
+
calendar: this.calendarVc.render(),
|
|
56
|
+
},
|
|
37
57
|
{
|
|
38
58
|
form: this.formVc.render(),
|
|
39
59
|
},
|
|
@@ -41,6 +61,9 @@ export default class EventDateTimeToolViewController extends AbstractViewControl
|
|
|
41
61
|
},
|
|
42
62
|
});
|
|
43
63
|
}
|
|
64
|
+
getCalendarVc() {
|
|
65
|
+
return this.calendarVc;
|
|
66
|
+
}
|
|
44
67
|
FormVc() {
|
|
45
68
|
return this.Controller('form', buildForm({
|
|
46
69
|
schema,
|
|
@@ -59,6 +82,7 @@ export default class EventDateTimeToolViewController extends AbstractViewControl
|
|
|
59
82
|
handleUpdateContext(context) {
|
|
60
83
|
return __awaiter(this, void 0, void 0, function* () {
|
|
61
84
|
yield this.formVc.setValue('startDateTime', context.event.startDateTimeMs);
|
|
85
|
+
this.calendarVc.setSelectedDates([this.getSelectedDate()]);
|
|
62
86
|
});
|
|
63
87
|
}
|
|
64
88
|
handleChangeForm({ values }) {
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { SpruceSchemas, ToolBeltState, ViewControllerId } from '@sprucelabs/heartwood-view-controllers';
|
|
2
2
|
import { CalendarTool, CalendarToolBeltContext, CalendarToolBeltStateMachine, GetPersonFromEventHandler } from '../../types/calendar.types';
|
|
3
|
+
import EventControlsCardViewController from '../../viewControllers/EventControlsCard.vc';
|
|
3
4
|
declare type Tool = SpruceSchemas.HeartwoodViewControllers.v2021_02_11.ToolBeltTool;
|
|
4
5
|
export declare type AddToolOptions = Omit<Tool, 'card'> & {
|
|
5
6
|
cardVcId: ViewControllerId;
|
|
@@ -26,6 +27,7 @@ export default abstract class AbstractCalendarEventToolBeltState implements Tool
|
|
|
26
27
|
removeTool(id: string): void;
|
|
27
28
|
getPendingContextChanges(): Partial<CalendarToolBeltContext>;
|
|
28
29
|
getVcForTool(toolId: string): CalendarTool | undefined;
|
|
30
|
+
getControlsVc(): EventControlsCardViewController;
|
|
29
31
|
destroy(): Promise<void>;
|
|
30
32
|
}
|
|
31
33
|
export {};
|
|
@@ -17,7 +17,7 @@ class AbstractCalendarEventToolBeltState {
|
|
|
17
17
|
this.sm = sm;
|
|
18
18
|
this.toolBeltVc = sm.getToolBeltVc();
|
|
19
19
|
this._isLoaded = true;
|
|
20
|
-
this.controlsVc = sm.Controller('calendar.event-controls-card', Object.assign({ onCancel: this.clearPendingContextChanges.bind(this), onSave: this.handleClickSave.bind(this) }, this.buildVcConstructorOptions('controls')));
|
|
20
|
+
this.controlsVc = sm.Controller('calendar.event-controls-card', Object.assign(Object.assign({ onCancel: this.clearPendingContextChanges.bind(this), onSave: this.handleClickSave.bind(this) }, this.buildVcConstructorOptions('controls')), { onCancelEvent: this.sm.getContext().cancelEvent }));
|
|
21
21
|
this.toolBeltVc.clearTools();
|
|
22
22
|
this.toolBeltVc.setStickyTool({
|
|
23
23
|
card: this.controlsVc.render(),
|
|
@@ -130,6 +130,9 @@ class AbstractCalendarEventToolBeltState {
|
|
|
130
130
|
var _a;
|
|
131
131
|
return (_a = this.vcs.find((v) => v.toolId === toolId)) === null || _a === void 0 ? void 0 : _a.vc;
|
|
132
132
|
}
|
|
133
|
+
getControlsVc() {
|
|
134
|
+
return this.controlsVc;
|
|
135
|
+
}
|
|
133
136
|
async destroy() {
|
|
134
137
|
await this.sm.off('did-update-context', this.handleDidUpdateContext);
|
|
135
138
|
}
|
|
@@ -18,6 +18,7 @@ declare type Card = SpruceSchemas.HeartwoodViewControllers.v2021_02_11.Card;
|
|
|
18
18
|
export declare type CalendarToolBeltContext = SkillViewControllerLoadOptions & {
|
|
19
19
|
event: CalendarEvent;
|
|
20
20
|
calendarVc: CalendarViewController;
|
|
21
|
+
cancelEvent: CancelEventHandler;
|
|
21
22
|
};
|
|
22
23
|
export declare type CalendarToolBeltStateMachine = ToolBeltStateMachine<CalendarToolBeltContext>;
|
|
23
24
|
export interface RemoteCalendarTool extends CalendarTool {
|
|
@@ -35,6 +36,7 @@ export declare type UpdateCalendarToolBeltContextHandler = (context: Partial<Cal
|
|
|
35
36
|
export declare type GetCalendarToolBeltContextHandler = () => CalendarToolBeltContext;
|
|
36
37
|
export declare type GetPersonFromEventHandler = () => Promise<Person | null>;
|
|
37
38
|
export declare type GetHasPendingContextChangesHandler = () => boolean;
|
|
39
|
+
export declare type CancelEventHandler = (eventId: string) => boolean | Promise<boolean | void> | void;
|
|
38
40
|
export interface CalendarToolOptions {
|
|
39
41
|
updateContext: UpdateCalendarToolBeltContextHandler;
|
|
40
42
|
getContext: GetCalendarToolBeltContextHandler;
|
|
@@ -30,6 +30,7 @@ export default class CalendarViewController extends CoreCalendarViewController {
|
|
|
30
30
|
private eventSwappedHandler?;
|
|
31
31
|
private dropEventHandler?;
|
|
32
32
|
private isSwapping;
|
|
33
|
+
private lastSwappedId?;
|
|
33
34
|
constructor(options: ViewControllerOptions & CalendarViewControllerOptions);
|
|
34
35
|
private handleDropEvent;
|
|
35
36
|
getCalendarVc(): this;
|
|
@@ -163,10 +163,15 @@ class CalendarViewController extends heartwood_view_controllers_1.CalendarViewCo
|
|
|
163
163
|
if (!saved) {
|
|
164
164
|
return;
|
|
165
165
|
}
|
|
166
|
-
if (
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
166
|
+
if (id !== saved.id) {
|
|
167
|
+
if (this.lastSwappedId === id) {
|
|
168
|
+
this.updateEvent(saved.id, saved);
|
|
169
|
+
}
|
|
170
|
+
else {
|
|
171
|
+
this.lastSwappedId = id;
|
|
172
|
+
await this.swapEvent(event, saved);
|
|
173
|
+
await ((_b = this.eventSwappedHandler) === null || _b === void 0 ? void 0 : _b.call(this, saved));
|
|
174
|
+
}
|
|
170
175
|
}
|
|
171
176
|
else {
|
|
172
177
|
super.updateEvent(saved.id, { isBusy, error: undefined });
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import { AbstractViewController, SpruceSchemas, ViewControllerOptions } from '@sprucelabs/heartwood-view-controllers';
|
|
2
|
-
import { CalendarTool, CalendarToolOptions } from '../types/calendar.types';
|
|
2
|
+
import { CalendarTool, CalendarToolOptions, CancelEventHandler } from '../types/calendar.types';
|
|
3
3
|
declare type Card = SpruceSchemas.HeartwoodViewControllers.v2021_02_11.Card;
|
|
4
4
|
export interface EventControlsCardOptions extends CalendarToolOptions {
|
|
5
5
|
onCancel: () => Promise<void | boolean> | void | boolean;
|
|
6
|
+
onCancelEvent: CancelEventHandler;
|
|
6
7
|
onSave: () => Promise<void | boolean> | void | boolean;
|
|
7
8
|
}
|
|
8
9
|
export default class EventControlsCardViewController extends AbstractViewController<Card> implements CalendarTool {
|
|
@@ -12,10 +13,13 @@ export default class EventControlsCardViewController extends AbstractViewControl
|
|
|
12
13
|
private cancelHandler;
|
|
13
14
|
private getHasPendingContextChangesHandler;
|
|
14
15
|
private getContext;
|
|
16
|
+
private cancelEventHandler;
|
|
15
17
|
constructor(options: ViewControllerOptions & EventControlsCardOptions);
|
|
18
|
+
private CardVc;
|
|
16
19
|
private handleClickCancel;
|
|
17
20
|
private handleClickSave;
|
|
18
21
|
handleUpdateContext(): void;
|
|
22
|
+
private optionallyDropInCancelButton;
|
|
19
23
|
render(): SpruceSchemas.HeartwoodViewControllers.v2021_02_11.Card;
|
|
20
24
|
}
|
|
21
25
|
export {};
|
|
@@ -9,17 +9,23 @@ const draftGenerator_1 = __importDefault(require("../utilities/draftGenerator"))
|
|
|
9
9
|
class EventControlsCardViewController extends heartwood_view_controllers_1.AbstractViewController {
|
|
10
10
|
constructor(options) {
|
|
11
11
|
super(options);
|
|
12
|
-
const { onSave, onCancel, getHasPendingContextChanges, getContext } = (0, schema_1.assertOptions)(options, [
|
|
12
|
+
const { onSave, onCancel, getHasPendingContextChanges, getContext, onCancelEvent, } = (0, schema_1.assertOptions)(options, [
|
|
13
13
|
'onCancel',
|
|
14
14
|
'onSave',
|
|
15
|
+
'onCancelEvent',
|
|
15
16
|
'getHasPendingContextChanges',
|
|
16
17
|
'getContext',
|
|
17
18
|
]);
|
|
18
19
|
this.saveHandler = onSave;
|
|
19
20
|
this.cancelHandler = onCancel;
|
|
21
|
+
this.cancelEventHandler = onCancelEvent;
|
|
20
22
|
this.getHasPendingContextChangesHandler = getHasPendingContextChanges;
|
|
21
23
|
this.getContext = getContext;
|
|
22
|
-
this.cardVc = this.
|
|
24
|
+
this.cardVc = this.CardVc();
|
|
25
|
+
this.optionallyDropInCancelButton();
|
|
26
|
+
}
|
|
27
|
+
CardVc() {
|
|
28
|
+
return this.Controller('card', {
|
|
23
29
|
footer: {
|
|
24
30
|
isEnabled: false,
|
|
25
31
|
isBusy: false,
|
|
@@ -50,13 +56,16 @@ class EventControlsCardViewController extends heartwood_view_controllers_1.Abstr
|
|
|
50
56
|
this.cardVc.disableFooter();
|
|
51
57
|
}
|
|
52
58
|
handleUpdateContext() {
|
|
53
|
-
var _a;
|
|
54
59
|
if (this.getHasPendingContextChangesHandler()) {
|
|
55
60
|
this.cardVc.enableFooter();
|
|
56
61
|
}
|
|
57
62
|
else {
|
|
58
63
|
this.cardVc.disableFooter();
|
|
59
64
|
}
|
|
65
|
+
this.optionallyDropInCancelButton();
|
|
66
|
+
}
|
|
67
|
+
optionallyDropInCancelButton() {
|
|
68
|
+
var _a;
|
|
60
69
|
const { event } = this.getContext();
|
|
61
70
|
if ((event === null || event === void 0 ? void 0 : event.id) && !draftGenerator_1.default.isDraftId(event.id)) {
|
|
62
71
|
this.cardVc.setBody({
|
|
@@ -67,6 +76,7 @@ class EventControlsCardViewController extends heartwood_view_controllers_1.Abstr
|
|
|
67
76
|
id: 'cancel-event',
|
|
68
77
|
label: `Cancel ${(_a = event.eventTypeSlug) !== null && _a !== void 0 ? _a : 'event'}`,
|
|
69
78
|
type: 'destructive',
|
|
79
|
+
onClick: () => this.cancelEventHandler(this.getContext().event.id),
|
|
70
80
|
},
|
|
71
81
|
],
|
|
72
82
|
},
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { AbstractViewController, FormViewController, SpruceSchemas, ViewControllerOptions } from '@sprucelabs/heartwood-view-controllers';
|
|
1
|
+
import { AbstractViewController, CalendarViewController, FormViewController, SpruceSchemas, ViewControllerOptions } from '@sprucelabs/heartwood-view-controllers';
|
|
2
2
|
import { CalendarTool, CalendarToolBeltContext, CalendarToolOptions } from '../types/calendar.types';
|
|
3
3
|
declare type Card = SpruceSchemas.HeartwoodViewControllers.v2021_02_11.Card;
|
|
4
4
|
export default class EventDateTimeToolViewController extends AbstractViewController<Card> implements CalendarTool {
|
|
@@ -8,8 +8,12 @@ export default class EventDateTimeToolViewController extends AbstractViewControl
|
|
|
8
8
|
private formVc;
|
|
9
9
|
private updateContext;
|
|
10
10
|
private getContext;
|
|
11
|
+
private calendarVc;
|
|
11
12
|
constructor(options: ViewControllerOptions & CalendarToolOptions);
|
|
13
|
+
private handleSelectDateFromCalendar;
|
|
14
|
+
private getSelectedDate;
|
|
12
15
|
private CardVc;
|
|
16
|
+
getCalendarVc(): CalendarViewController;
|
|
13
17
|
private FormVc;
|
|
14
18
|
handleUpdateContext(context: CalendarToolBeltContext): Promise<void>;
|
|
15
19
|
private handleChangeForm;
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const calendar_utils_1 = require("@sprucelabs/calendar-utils");
|
|
3
4
|
const heartwood_view_controllers_1 = require("@sprucelabs/heartwood-view-controllers");
|
|
4
5
|
const schema_1 = require("@sprucelabs/schema");
|
|
5
6
|
const schema = (0, schema_1.buildSchema)({
|
|
@@ -17,9 +18,23 @@ class EventDateTimeToolViewController extends heartwood_view_controllers_1.Abstr
|
|
|
17
18
|
this.shouldPersistContextChangesImmediately = true;
|
|
18
19
|
this.updateContext = options.updateContext;
|
|
19
20
|
this.getContext = options.getContext;
|
|
21
|
+
this.calendarVc = this.Controller('calendar', {
|
|
22
|
+
view: 'month',
|
|
23
|
+
selectedDates: [this.getSelectedDate()],
|
|
24
|
+
onClick: this.handleSelectDateFromCalendar.bind(this),
|
|
25
|
+
});
|
|
20
26
|
this.formVc = this.FormVc();
|
|
21
27
|
this.cardVc = this.CardVc();
|
|
22
28
|
}
|
|
29
|
+
async handleSelectDateFromCalendar({ dateTimeMs, }) {
|
|
30
|
+
const { hour, minute } = calendar_utils_1.dateUtil.splitDate(this.getContext().event.startDateTimeMs);
|
|
31
|
+
await this.formVc.setValue('startDateTime', calendar_utils_1.dateUtil.setTimeOfDay(dateTimeMs, hour, minute, 0, 0));
|
|
32
|
+
this.calendarVc.setSelectedDates([this.getSelectedDate(dateTimeMs)]);
|
|
33
|
+
}
|
|
34
|
+
getSelectedDate(dateTimeMs) {
|
|
35
|
+
const { year, month, day } = calendar_utils_1.dateUtil.splitDate(dateTimeMs !== null && dateTimeMs !== void 0 ? dateTimeMs : this.getContext().event.startDateTimeMs);
|
|
36
|
+
return { year, month, day };
|
|
37
|
+
}
|
|
23
38
|
CardVc() {
|
|
24
39
|
return this.Controller('card', {
|
|
25
40
|
header: {
|
|
@@ -27,6 +42,9 @@ class EventDateTimeToolViewController extends heartwood_view_controllers_1.Abstr
|
|
|
27
42
|
},
|
|
28
43
|
body: {
|
|
29
44
|
sections: [
|
|
45
|
+
{
|
|
46
|
+
calendar: this.calendarVc.render(),
|
|
47
|
+
},
|
|
30
48
|
{
|
|
31
49
|
form: this.formVc.render(),
|
|
32
50
|
},
|
|
@@ -34,6 +52,9 @@ class EventDateTimeToolViewController extends heartwood_view_controllers_1.Abstr
|
|
|
34
52
|
},
|
|
35
53
|
});
|
|
36
54
|
}
|
|
55
|
+
getCalendarVc() {
|
|
56
|
+
return this.calendarVc;
|
|
57
|
+
}
|
|
37
58
|
FormVc() {
|
|
38
59
|
return this.Controller('form', (0, heartwood_view_controllers_1.buildForm)({
|
|
39
60
|
schema,
|
|
@@ -51,6 +72,7 @@ class EventDateTimeToolViewController extends heartwood_view_controllers_1.Abstr
|
|
|
51
72
|
}
|
|
52
73
|
async handleUpdateContext(context) {
|
|
53
74
|
await this.formVc.setValue('startDateTime', context.event.startDateTimeMs);
|
|
75
|
+
this.calendarVc.setSelectedDates([this.getSelectedDate()]);
|
|
54
76
|
}
|
|
55
77
|
async handleChangeForm({ values }) {
|
|
56
78
|
var _a;
|