Skip to content

Commit 54e56ad

Browse files
docs(scheduler):added section in edit appointments for delete confirm… (#410)
* docs(scheduler):added section in edit appointments for delete confirmation dialog * chore(scheduler):added fixes as per comment
1 parent 0367315 commit 54e56ad

File tree

2 files changed

+142
-1
lines changed

2 files changed

+142
-1
lines changed

components/scheduler/edit-appointments.md

Lines changed: 142 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ This article contains the following sections:
1616

1717
* [Basics](#basics)
1818
* [User Experience](#user-experience)
19+
* [Delete Confirmation Dialog](#delete-confirmation-dialog)
1920
* [Example](#example)
2021

2122

@@ -33,7 +34,7 @@ Main events you need to implement so you can store the appointment information c
3334

3435
* `OnCreate` - fires when the user saves a new appointment, including an exception for a recurring appointment.
3536
* `OnUpdate` - fires when the user changes an existing appointment. Fires for the recurring appointment when an exception has been created for it.
36-
* `OnDelete` - fires when the user deletes and appointment (including a recurring appointment).
37+
* `OnDelete` - fires when the user deletes and appointment (including a recurring appointment). You can also enable a [delete confirmation dialog](#delete-confirmation-dialog).
3738

3839
There are two other events that you are not required to handle - you can use them to implement application logic:
3940

@@ -80,8 +81,148 @@ The UI for the scheduler provides the following options for interacting with the
8081
* An appointment that spans multiple days but is not marked as an all-day appointment shows up in the all-day slot for the days that it spans entirely. The first and last day would render in the day portions to denote the start and end time accurately.
8182

8283

84+
## Delete Confirmation Dialog
8385

86+
The delete confirmation dialog triggers before event deletion. You can enable it by setting the `ConfirmDelete` parameter of the Scheduler to `true`. The default texts of the dialog are exposed in the [localization]({%slug globalization-localization%}) messages of the component, and you can customize them.
8487

88+
>important This dialog displays only for **single** events, **not** for recurring. The built-in delete confirmation dialog for recurring events is **not** changed.
89+
90+
>caption Delete Confirmation dialog appearance
91+
92+
![](images/scheduler-delete-confirmation.gif)
93+
94+
>caption Enabling of the Delete Confirmation Dialog
95+
96+
````CSHTML
97+
@* Scheduler with enabled Delete Confirmation Dialog *@
98+
99+
<TelerikScheduler Data="@Appointments"
100+
OnDelete="@DeleteAppointment" AllowDelete="true"
101+
@bind-Date="@StartDate" Height="500px" @bind-View="@CurrView" ConfirmDelete="true">
102+
<SchedulerViews>
103+
<SchedulerDayView StartTime="@DayStart" />
104+
<SchedulerWeekView StartTime="@DayStart" />
105+
<SchedulerMultiDayView StartTime="@DayStart" NumberOfDays="10" />
106+
</SchedulerViews>
107+
</TelerikScheduler>
108+
109+
@code {
110+
public SchedulerView CurrView { get; set; } = SchedulerView.Week;
111+
public DateTime StartDate { get; set; } = new DateTime(2019, 12, 2);
112+
public DateTime DayStart { get; set; } = new DateTime(2000, 1, 1, 8, 0, 0);
113+
114+
List<SchedulerAppointment> Appointments { get; set; }
115+
116+
async Task DeleteAppointment(SchedulerDeleteEventArgs args)
117+
{
118+
SchedulerAppointment item = (SchedulerAppointment)args.Item;
119+
120+
await MyService.Delete(item);
121+
122+
await GetSchedulerData();
123+
}
124+
125+
public class SchedulerAppointment
126+
{
127+
public Guid Id { get; set; }
128+
public string Title { get; set; }
129+
public string Description { get; set; }
130+
public DateTime Start { get; set; }
131+
public DateTime End { get; set; }
132+
public bool IsAllDay { get; set; }
133+
public string RecurrenceRule { get; set; }
134+
public List<DateTime> RecurrenceExceptions { get; set; }
135+
public Guid? RecurrenceId { get; set; }
136+
137+
public SchedulerAppointment()
138+
{
139+
Id = Guid.NewGuid();
140+
}
141+
}
142+
143+
async Task GetSchedulerData()
144+
{
145+
Appointments = await MyService.Read();
146+
}
147+
148+
protected override async Task OnInitializedAsync()
149+
{
150+
await GetSchedulerData();
151+
}
152+
153+
public static class MyService
154+
{
155+
private static List<SchedulerAppointment> _data { get; set; } = new List<SchedulerAppointment>()
156+
{
157+
new SchedulerAppointment
158+
{
159+
Title = "Board meeting",
160+
Description = "Q4 is coming to a close, review the details.",
161+
Start = new DateTime(2019, 12, 5, 10, 00, 0),
162+
End = new DateTime(2019, 12, 5, 11, 30, 0)
163+
},
164+
165+
new SchedulerAppointment
166+
{
167+
Title = "Vet visit",
168+
Description = "The cat needs vaccinations and her teeth checked.",
169+
Start = new DateTime(2019, 12, 2, 11, 30, 0),
170+
End = new DateTime(2019, 12, 2, 12, 0, 0)
171+
},
172+
173+
new SchedulerAppointment
174+
{
175+
Title = "Planning meeting",
176+
Description = "Kick off the new project.",
177+
Start = new DateTime(2019, 12, 6, 9, 30, 0),
178+
End = new DateTime(2019, 12, 6, 12, 45, 0)
179+
},
180+
181+
new SchedulerAppointment
182+
{
183+
Title = "Trip to Hawaii",
184+
Description = "An unforgettable holiday!",
185+
IsAllDay = true,
186+
Start = new DateTime(2019, 11, 27),
187+
End = new DateTime(2019, 12, 05)
188+
},
189+
190+
new SchedulerAppointment
191+
{
192+
Title = "Morning run",
193+
Description = "Some time to clear the head and exercise.",
194+
Start = new DateTime(2019, 11, 27, 9, 0, 0),
195+
End = new DateTime(2019, 11, 27, 9, 30, 0),
196+
RecurrenceRule = "FREQ=WEEKLY;BYDAY=MO,TU,WE,TH,FR"
197+
}
198+
};
199+
200+
public static async Task<List<SchedulerAppointment>> Read()
201+
{
202+
return await Task.FromResult(_data);
203+
}
204+
205+
public static async Task Delete(SchedulerAppointment itemToDelete)
206+
{
207+
if (itemToDelete.RecurrenceId != null)
208+
{
209+
// a recurrence exception was deleted, you may want to update
210+
// the rest of the data source - find an item where theItem.Id == itemToDelete.RecurrenceId
211+
// and remove the current exception date from the list of its RecurrenceExceptions
212+
}
213+
214+
if (!string.IsNullOrEmpty(itemToDelete.RecurrenceRule) && itemToDelete.RecurrenceExceptions?.Count > 0)
215+
{
216+
// a recurring appointment was deleted that had exceptions, you may want to
217+
// delete or update any exceptions from the data source - look for
218+
// items where theItem.RecurrenceId == itemToDelete.Id
219+
}
220+
221+
_data.Remove(itemToDelete);
222+
}
223+
}
224+
}
225+
````
85226
## Example
86227

87228
The example below shows the signature of the event handlers so you can copy the proper arguments and start implementing your business logic and data storage operations. The example only updates the local collection of appointments used in the UI.
275 KB
Loading

0 commit comments

Comments
 (0)