-
Notifications
You must be signed in to change notification settings - Fork 672
Scheduler - Replace action enum with onDone/onCancel callbacks in AppointmentPopup #33047
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 6 commits
77cb409
31cd08f
9c52ce8
ab421e7
ab94f41
ce7006b
c6b9fee
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -24,11 +24,11 @@ const POPUP_FULL_SCREEN_MODE_WINDOW_WIDTH_THRESHOLD = 485; | |
|
|
||
| const DAY_IN_MS = dateUtils.dateToMilliseconds('day'); | ||
|
|
||
| export const ACTION_TO_APPOINTMENT = { | ||
| CREATE: 0, | ||
| UPDATE: 1, | ||
| EXCLUDE_FROM_SERIES: 2, | ||
| }; | ||
| export interface AppointmentPopupConfig { | ||
| onDone: (appointment: Record<string, unknown>) => PromiseLike<unknown>; | ||
|
aleksei-semikozov marked this conversation as resolved.
Outdated
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. small sugestion: let's rename
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done |
||
| title: string; | ||
| readOnly: boolean; | ||
| } | ||
|
aleksei-semikozov marked this conversation as resolved.
|
||
|
|
||
| export class AppointmentPopup { | ||
| scheduler: any; | ||
|
|
@@ -41,6 +41,12 @@ export class AppointmentPopup { | |
|
|
||
| state: any; | ||
|
|
||
| private config: AppointmentPopupConfig = { | ||
| onDone: () => Promise.resolve(), | ||
| title: '', | ||
| readOnly: false, | ||
| }; | ||
|
|
||
| get popup(): dxPopup { | ||
| return this._popup as dxPopup; | ||
| } | ||
|
|
@@ -54,7 +60,6 @@ export class AppointmentPopup { | |
| this.form = form; | ||
|
|
||
| this.state = { | ||
| action: null, | ||
| lastEditData: null, | ||
| saveChangesLocker: false, | ||
| appointment: { | ||
|
|
@@ -63,11 +68,9 @@ export class AppointmentPopup { | |
| }; | ||
| } | ||
|
|
||
| show(appointment, config) { | ||
| show(appointment, config: AppointmentPopupConfig) { | ||
| this.state.appointment.data = appointment; | ||
| this.state.action = config.action; | ||
| this.state.allowSaving = config.allowSaving; | ||
| this.state.excludeInfo = config.excludeInfo; | ||
| this.config = config; | ||
|
|
||
| this.disposePopup(); | ||
|
|
||
|
|
@@ -173,16 +176,8 @@ export class AppointmentPopup { | |
| }); | ||
| } | ||
|
|
||
| private isReadOnly(appointmentAdapter: AppointmentAdapter): boolean { | ||
| if (Boolean(appointmentAdapter.source) && appointmentAdapter.disabled) { | ||
| return true; | ||
| } | ||
|
|
||
| if (this.state.action === ACTION_TO_APPOINTMENT.CREATE) { | ||
| return false; | ||
| } | ||
|
|
||
| return !this.scheduler.getEditingConfig().allowUpdating; | ||
| private isReadOnly(): boolean { | ||
| return this.config.readOnly; | ||
| } | ||
|
|
||
| private createAppointmentAdapter(rawAppointment): AppointmentAdapter { | ||
|
|
@@ -200,7 +195,7 @@ export class AppointmentPopup { | |
|
|
||
| const formData = this.createFormData(appointmentAdapter); | ||
|
|
||
| this.form.readOnly = this.isReadOnly(appointmentAdapter); | ||
| this.form.readOnly = this.isReadOnly(); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. minor: let's remove isReadOnly method and directly use the variable: this.form.readOnly = this.config.readOnly;
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done |
||
| this.form.formData = formData; | ||
|
|
||
| this.form.showMainGroup(); | ||
|
|
@@ -286,20 +281,7 @@ export class AppointmentPopup { | |
|
|
||
| const appointment = clonedAdapter.source; | ||
|
|
||
| switch (this.state.action) { | ||
| case ACTION_TO_APPOINTMENT.CREATE: | ||
| this.scheduler.addAppointment(appointment).done(deferred.resolve); | ||
| break; | ||
| case ACTION_TO_APPOINTMENT.UPDATE: | ||
| this.scheduler.updateAppointment(this.state.appointment.data, appointment).done(deferred.resolve); | ||
| break; | ||
| case ACTION_TO_APPOINTMENT.EXCLUDE_FROM_SERIES: | ||
| this.scheduler.updateAppointment(this.state.excludeInfo.sourceAppointment, this.state.excludeInfo.updatedAppointment); | ||
| this.scheduler.addAppointment(appointment).done(deferred.resolve); | ||
| break; | ||
| default: | ||
| break; | ||
| } | ||
| when(this.config.onDone(appointment)).done(deferred.resolve); | ||
|
|
||
| deferred.done(() => { | ||
| hideLoading(); | ||
|
|
@@ -413,13 +395,10 @@ export class AppointmentPopup { | |
| return; | ||
| } | ||
|
|
||
| const isCreating = this.state.action === ACTION_TO_APPOINTMENT.CREATE; | ||
| const formTitleKey = isCreating ? 'dxScheduler-newPopupTitle' : 'dxScheduler-editPopupTitle'; | ||
|
|
||
| const toolbarItems: ToolbarItem[] = [{ | ||
| toolbar: 'top', | ||
| location: 'before', | ||
| text: messageLocalization.format(formTitleKey), | ||
| text: this.config.title, | ||
| cssClass: 'dx-toolbar-label', | ||
| }]; | ||
|
|
||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.