This repository has been archived by the owner on Jun 28, 2024. It is now read-only.
forked from LanaDX/mvc-responsive-web-application
-
Notifications
You must be signed in to change notification settings - Fork 1
/
SchedulerHelper.cs
126 lines (109 loc) · 7.3 KB
/
SchedulerHelper.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
using DevExpress.Web;
using DevExpress.Web.ASPxScheduler;
using DevExpress.Web.Internal;
using DevExpress.Web.Mvc;
using DevExpress.XtraScheduler;
using MvcResponsiveWebApplication.Model;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web.UI.WebControls;
namespace MvcResponsiveWebApplication.Model {
public static class SchedulerHelper {
public static SchedulerSettings Settings {
get {
SchedulerSettings settings = new SchedulerSettings();
settings.Name = "scheduler";
settings.CallbackRouteValues = new { Controller = "Scheduler", Action = "SchedulerPartial" };
settings.EditAppointmentRouteValues = new { Controller = "Scheduler", Action = "SchedulerPartialEditAppointment" };
settings.ClientSideEvents.Init = "onSchedulerInit";
settings.ClientSideEvents.EndCallback = "onSchedulerEndCallback";
settings.ClientSideEvents.BeginCallback = "onSchedulerBeginCallback";
settings.Start = DateTime.Now;
settings.EnablePagingGestures = AutoBoolean.False;
settings.Width = Unit.Percentage(100);
settings.ControlStyle.CssClass = "scheduler";
// DXCOMMENT: Setting ViewType: a compact view (Day) for mobile devices, a large view (WorkWeek) for desktops
settings.ActiveViewType = RenderUtils.Browser.Platform.IsMobileUI ? SchedulerViewType.Day : SchedulerViewType.WorkWeek;
settings.OptionsView.VerticalScrollBarMode = ScrollBarMode.Auto;
settings.OptionsAdaptivity.Enabled = true;
settings.OptionsBehavior.RecurrentAppointmentEditAction = RecurrentAppointmentAction.Ask;
settings.OptionsBehavior.ShowViewVisibleInterval = true;
settings.OptionsBehavior.ShowViewNavigator = true;
settings.Storage.EnableReminders = true;
settings.Storage.Appointments.AutoRetrieveId = true;
// DXCOMMENT: Configure appointment mappings
settings.Storage.Appointments.Mappings.AppointmentId = "Id";
settings.Storage.Appointments.Mappings.Type = "EventType";
settings.Storage.Appointments.Mappings.Start = "StartDate";
settings.Storage.Appointments.Mappings.End = "EndDate";
settings.Storage.Appointments.Mappings.AllDay = "AllDay";
settings.Storage.Appointments.Mappings.Subject = "Subject";
settings.Storage.Appointments.Mappings.Location = "Location";
settings.Storage.Appointments.Mappings.Description = "Description";
settings.Storage.Appointments.Mappings.Status = "Status";
settings.Storage.Appointments.Mappings.Label = "LabelId";
settings.Storage.Appointments.Mappings.ResourceId = "ResourceId";
settings.Storage.Appointments.Mappings.RecurrenceInfo = "RecurrenceInfo";
// DXCOMMENT: Map labels by their ids
settings.Storage.Appointments.Labels.Clear();
foreach(SchedulerLabel label in SchedulerLabelsHelper.GetItems())
settings.Storage.Appointments.Labels.Add(label.Id, label.Name, label.Name, label.Color);
// DXCOMMENT: Configure resource mappings
settings.Storage.Resources.Mappings.ResourceId = "Id";
settings.Storage.Resources.Mappings.Caption = "Name";
settings.Views.AgendaView.DayCount = 30;
settings.Views.DayView.VisibleTime.Start = new TimeSpan(7, 0, 0);
settings.Views.DayView.VisibleTime.End = new TimeSpan(22, 0, 0);
settings.Views.WeekView.Enabled = false;
settings.Views.FullWeekView.Enabled = true;
settings.Views.MonthView.CompressWeekend = false;
settings.Views.TimelineView.Enabled = false;
// DXCOMMENT: Scroll to actual time
var currentTime = new TimeSpan(DateTime.Now.Hour - 1, 0, 0);
settings.Views.DayView.TopRowTime = currentTime;
settings.Views.WorkWeekView.TopRowTime = currentTime;
settings.Views.FullWeekView.TopRowTime = currentTime;
// DXCOMMENT: Configure DateNavigator for Scheduler
settings.DateNavigatorExtensionSettings.Name = "dateNavigator";
settings.DateNavigatorExtensionSettings.SchedulerName = "Scheduler";
settings.DateNavigatorExtensionSettings.Width = Unit.Percentage(100);
settings.DateNavigatorExtensionSettings.Properties.ShowTodayButton = true;
settings.DateNavigatorExtensionSettings.Properties.EnableChangeVisibleDateGestures = DevExpress.Utils.DefaultBoolean.True;
settings.DateNavigatorExtensionSettings.Properties.EnableLargePeriodNavigation = false;
settings.DateNavigatorExtensionSettings.Properties.AppointmentDatesHighlightMode = AppointmentDatesHighlightMode.Labels;
settings.DateNavigatorExtensionSettings.Properties.Style.CssClass = "date-navigator";
settings.DateNavigatorExtensionSettings.Properties.HeaderStyle.CssClass = "date-navigator-header";
settings.DateNavigatorExtensionSettings.ClientSideEvents.SelectionChanged = "onDateNavigatorSelectionChanged";
return settings;
}
}
public static SchedulerDataSource GetSchedulerDataSource(List<long> selectedResourceIds) {
return new SchedulerDataSource(selectedResourceIds);
}
public static void UpdateSchedulerDataSource() {
SchedulerDataSource schedulerDataSource = new SchedulerDataSource(null);
InsertAppointments(schedulerDataSource);
UpdateAppointments(schedulerDataSource);
RemoveAppointments(schedulerDataSource);
}
static void InsertAppointments(SchedulerDataSource schedulerDataSource) {
SchedulerAppointment[] appointmentsToInsert = SchedulerExtension.GetAppointmentsToInsert<SchedulerAppointment>("scheduler",
schedulerDataSource.Appointments, schedulerDataSource.Resources,
Settings.Storage.Appointments, Settings.Storage.Resources);
schedulerDataSource.InsertSchedulerAppointments(appointmentsToInsert.ToList());
}
static void UpdateAppointments(SchedulerDataSource schedulerDataSource) {
SchedulerAppointment[] appointmentsToUpdate = SchedulerExtension.GetAppointmentsToUpdate<SchedulerAppointment>("scheduler",
schedulerDataSource.Appointments, schedulerDataSource.Resources,
Settings.Storage.Appointments, Settings.Storage.Resources);
schedulerDataSource.UpdateSchedulerAppointments(appointmentsToUpdate.ToList());
}
static void RemoveAppointments(SchedulerDataSource schedulerDataSource) {
SchedulerAppointment[] appointmentsToRemove = SchedulerExtension.GetAppointmentsToRemove<SchedulerAppointment>("scheduler",
schedulerDataSource.Appointments, schedulerDataSource.Resources,
Settings.Storage.Appointments, Settings.Storage.Resources);
schedulerDataSource.RemoveSchedulerAppointments(appointmentsToRemove.ToList());
}
}
}