-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Scheduler: update Appointment Edit Form how-to #8742
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
Open
vladaskorohodova
wants to merge
6
commits into
DevExpress:25_2
Choose a base branch
from
vladaskorohodova:scheduler-preserve-unsaved-changes25_2
base: 25_2
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 1 commit
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
f5423e1
Scheduler: update Appointment Edit Form how-to
vladaskorohodova 287fa97
Add Recreate the Legacy Form Layout
vladaskorohodova ec0ba69
Apply suggestions from code review
vladaskorohodova e9e4082
Update after review
vladaskorohodova 90da5d3
Merge branch 'scheduler-preserve-unsaved-changes25_2' of https://gith…
vladaskorohodova 59c1e37
add links
vladaskorohodova File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
10 changes: 10 additions & 0 deletions
10
applications/UIWidgets/Guides/SchedulerPreserveChanges/index.css
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| #scheduler { | ||
| height: 600px; | ||
| } | ||
|
|
||
| /* "Discard Changes" button inside the appointment edit form */ | ||
| .discard-btn-item { | ||
| padding-top: 8px !important; | ||
| border-top: 1px solid #eee; | ||
| margin-top: 4px; | ||
| } |
1 change: 1 addition & 0 deletions
1
applications/UIWidgets/Guides/SchedulerPreserveChanges/index.html
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| <div id="scheduler"></div> |
220 changes: 220 additions & 0 deletions
220
applications/UIWidgets/Guides/SchedulerPreserveChanges/index.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,220 @@ | ||
| $(function () { | ||
| const appointments = [ | ||
| { | ||
| id: 1, | ||
| text: 'Team Stand-up', | ||
| startDate: new Date(2026, 4, 8, 9, 0), | ||
| endDate: new Date(2026, 4, 8, 9, 30), | ||
| description: 'Daily morning sync with the full team.' | ||
| }, | ||
| { | ||
| id: 2, | ||
| text: 'Design Review', | ||
| startDate: new Date(2026, 4, 8, 11, 0), | ||
| endDate: new Date(2026, 4, 8, 12, 0), | ||
| description: 'Review latest UI mockups and prototypes.' | ||
| }, | ||
| { | ||
| id: 3, | ||
| text: 'Sprint Planning', | ||
| startDate: new Date(2026, 4, 11, 14, 0), | ||
| endDate: new Date(2026, 4, 11, 16, 0), | ||
| description: 'Plan tasks for the upcoming sprint.' | ||
| }, | ||
| { | ||
| id: 4, | ||
| text: 'Client Demo', | ||
| startDate: new Date(2026, 4, 12, 10, 0), | ||
| endDate: new Date(2026, 4, 12, 11, 30), | ||
| description: 'Showcase new features to the client.' | ||
| }, | ||
| { | ||
| id: 5, | ||
| text: 'Retrospective', | ||
| startDate: new Date(2026, 4, 13, 15, 0), | ||
| endDate: new Date(2026, 4, 13, 16, 0), | ||
| description: 'Sprint retrospective — what went well / what to improve.' | ||
| } | ||
| ]; | ||
| const DRAFT_PREFIX = 'dx-scheduler-draft-'; | ||
|
|
||
| function getDraftKey(appointmentId) { | ||
| return DRAFT_PREFIX + (appointmentId != null ? appointmentId : 'new'); | ||
|
vladaskorohodova marked this conversation as resolved.
|
||
| } | ||
|
|
||
| function saveDraft(appointmentId, formData) { | ||
| const key = getDraftKey(appointmentId); | ||
| const serializable = { | ||
| text: formData.text, | ||
| description: formData.description, | ||
| startDate: formData.startDate instanceof Date | ||
| ? formData.startDate.toISOString() | ||
| : formData.startDate, | ||
| endDate: formData.endDate instanceof Date | ||
| ? formData.endDate.toISOString() | ||
| : formData.endDate, | ||
| allDay: formData.allDay || false | ||
| }; | ||
| localStorage.setItem(key, JSON.stringify(serializable)); | ||
| } | ||
|
|
||
| function loadDraft(appointmentId) { | ||
| const key = getDraftKey(appointmentId); | ||
| const raw = localStorage.getItem(key); | ||
| if (!raw) return null; | ||
| const data = JSON.parse(raw); | ||
| if (data.startDate) data.startDate = new Date(data.startDate); | ||
| if (data.endDate) data.endDate = new Date(data.endDate); | ||
| return data; | ||
|
Comment on lines
+45
to
+68
Comment on lines
+65
to
+68
|
||
| } | ||
|
|
||
| function clearDraft(appointmentId) { | ||
| localStorage.removeItem(getDraftKey(appointmentId)); | ||
| } | ||
| let isSaved = false; | ||
| let currentAppointmentId = null; | ||
| let popupHidingHandler = null; | ||
| let currentPopup = null; | ||
|
|
||
|
|
||
| function onCanceled(form, originalData) { | ||
| if (isSaved) return; | ||
|
|
||
| const formData = form.option('formData'); | ||
| const appointmentId = originalData && originalData.id != null | ||
| ? originalData.id | ||
| : null; | ||
|
|
||
| saveDraft(appointmentId, formData); | ||
|
|
||
| DevExpress.ui.notify({ | ||
| message: 'Draft saved. Your unsaved changes will be restored next time you open this appointment.', | ||
| type: 'warning', | ||
| displayTime: 4500, | ||
| position: { my: 'bottom center', at: 'bottom center', of: window } | ||
| }); | ||
| } | ||
| $('#scheduler').dxScheduler({ | ||
| dataSource: appointments, | ||
| currentDate: new Date(2026, 4, 8), | ||
| currentView: 'week', | ||
| views: ['day', 'week', 'month'], | ||
| startDayHour: 8, | ||
| endDayHour: 19, | ||
| height: 600, | ||
| editing: { | ||
| form: { | ||
| labelMode: 'floating', | ||
| items: [ | ||
| { | ||
| itemType: 'group', | ||
| name: 'mainGroup', | ||
| items: [ | ||
| 'subjectGroup', | ||
| 'dateGroup', | ||
| 'descriptionGroup', | ||
| 'repeatGroup', | ||
| 'resourcesGroup' | ||
| ] | ||
| }, | ||
| { | ||
| itemType: 'group', | ||
| name: 'recurrenceGroup' | ||
| } | ||
| ] | ||
| } | ||
| }, | ||
| onAppointmentFormOpening: function (e) { | ||
| const form = e.form; | ||
| const popup = e.popup; | ||
| const appointmentData = e.appointmentData || {}; | ||
|
|
||
| isSaved = false; | ||
| currentAppointmentId = appointmentData.id != null ? appointmentData.id : null; | ||
| const draft = loadDraft(currentAppointmentId); | ||
| if (draft) { | ||
| const mergedData = $.extend({}, form.option('formData'), { | ||
| text: draft.text, | ||
| description: draft.description, | ||
| startDate: draft.startDate, | ||
| endDate: draft.endDate, | ||
| allDay: draft.allDay | ||
| }); | ||
| form.option('formData', mergedData); | ||
| const items = form.option('items'); | ||
| const hasDiscardBtn = items.some(function (item) { | ||
| return item.name === 'discardChangesButton'; | ||
| }); | ||
|
Comment on lines
+144
to
+147
|
||
|
|
||
| if (!hasDiscardBtn) { | ||
| const originalData = $.extend({}, appointmentData); | ||
|
|
||
| items.push({ | ||
| itemType: 'button', | ||
| name: 'discardChangesButton', | ||
| horizontalAlignment: 'left', | ||
| cssClass: 'discard-btn-item', | ||
| buttonOptions: { | ||
| text: 'Discard Changes', | ||
| type: 'danger', | ||
| stylingMode: 'outlined', | ||
| icon: 'undo', | ||
| onClick: function () { | ||
| clearDraft(currentAppointmentId); | ||
|
|
||
| form.option('formData', $.extend({}, form.option('formData'), { | ||
| text: originalData.text, | ||
|
vladaskorohodova marked this conversation as resolved.
|
||
| description: originalData.description, | ||
| startDate: originalData.startDate, | ||
| endDate: originalData.endDate, | ||
| allDay: originalData.allDay || false | ||
| })); | ||
|
|
||
| form.option('items', form.option('items').filter(function (item) { | ||
| return item.name !== 'discardChangesButton'; | ||
| })); | ||
|
|
||
| DevExpress.ui.notify({ | ||
| message: 'Changes discarded. Form reset to the last saved state.', | ||
| type: 'success', | ||
| displayTime: 3000 | ||
| }); | ||
| } | ||
| } | ||
| }); | ||
|
|
||
| form.option('items', items); | ||
| } | ||
|
|
||
| DevExpress.ui.notify({ | ||
| message: 'Unsaved draft restored. Use "Discard Changes" to revert to the saved appointment.', | ||
| type: 'info', | ||
| displayTime: 4000, | ||
| position: { my: 'bottom center', at: 'bottom center', of: window } | ||
| }); | ||
| } | ||
| if (currentPopup && popupHidingHandler) { | ||
| currentPopup.off('hiding', popupHidingHandler); | ||
| } | ||
|
|
||
| currentPopup = popup; | ||
| popupHidingHandler = function () { | ||
| if (!isSaved) { | ||
| onCanceled(form, appointmentData); | ||
| } | ||
| }; | ||
|
|
||
| popup.on('hiding', popupHidingHandler); | ||
| }, | ||
|
|
||
| onAppointmentAdding: function () { | ||
| isSaved = true; | ||
| clearDraft(null); | ||
| }, | ||
|
|
||
| onAppointmentUpdating: function () { | ||
| isSaved = true; | ||
| clearDraft(currentAppointmentId); | ||
|
vladaskorohodova marked this conversation as resolved.
Outdated
vladaskorohodova marked this conversation as resolved.
Outdated
|
||
| } | ||
| }); | ||
| }); | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.