<dx:BootstrapScheduler ID="SchedulerCustomContextMenu" runat="server" GroupType="Resource" ActiveViewType="WorkWeek"
OnPopupMenuShowing="SchedulerCustomContextMenu_PopupMenuShowing"
OnCustomCallback="SchedulerCustomContextMenu_CustomCallback"
AppointmentDataSourceID="AppointmentDataSource" ResourceDataSourceID="efResourceDataSource">
<ClientSideEvents MenuItemClicked="OnMenuItemClicked" />
<OptionsResourceNavigator EnableIncreaseDecrease="false" />
<Views>
<DayView ResourcesPerPage="2" DayCount="2" />
<WorkWeekView ResourcesPerPage="1" />
<FullWeekView Enabled="true" ResourcesPerPage="1" />
<WeekView Enabled="false" />
<MonthView Enabled="false" />
<TimelineView ResourcesPerPage="2" />
</Views>
</dx:BootstrapScheduler>
protected void SchedulerCustomContextMenu_PopupMenuShowing(object sender, BootstrapSchedulerPopupMenuShowingEventArgs e) {
var menu = e.Menu;
var menuItems = menu.Items;
if(menu.MenuId.Equals(SchedulerMenuItemId.DefaultMenu)) {
CustomMenuHelper.ClearUnusedDefaultMenuItems(menu);
CustomMenuHelper.AddScheduleNewEventSubMenu(menu, "Schedule New Event", "NewEvent");
}
else if(menu.MenuId.Equals(SchedulerMenuItemId.AppointmentMenu)) {
menu.Items.Clear();
CustomMenuHelper.AddScheduleNewEventSubMenu(menu, "Change Event", "ChangeEvent");
var deleteItem = new BootstrapMenuItem("Delete", "CustomItem_Delete");
deleteItem.BeginGroup = true;
menuItems.Add(deleteItem);
}
}
protected void SchedulerCustomContextMenu_CustomCallback(object sender, CallbackEventArgsBase e) {
var scheduler = (BootstrapScheduler)sender;
string[] callbackParams = e.Parameter.Split(new char[] { '_' }, StringSplitOptions.RemoveEmptyEntries);
var command = callbackParams[0];
var label = (CustomLabel)Enum.Parse(typeof(CustomLabel), callbackParams[1]);
if(command == "ChangeEvent") {
Appointment apt = scheduler.SelectedAppointments[0];
CustomMenuHelper.UpdateAppointment(label, apt);
}
else if(command == "NewEvent")
CustomMenuHelper.CreateAppointment(label, scheduler);
}
function OnMenuItemClicked(s, e) {
var menuParameters = e.itemName.split("_");
if (menuParameters[0] === "CustomItem") {
e.handled = true;
if (menuParameters[1] === "Delete" && confirm("Delete this appointment?")) {
var selectedAppointment = s.GetAppointmentById(s.GetSelectedAppointmentIds()[0]);
s.DeleteAppointment(selectedAppointment);
}
if (menuParameters.length > 2)
s.PerformCallback(menuParameters[1] + "_" + menuParameters[2]);
}
}
using System.Collections.Generic;
using DevExpress.Web.Bootstrap;
using DevExpress.Web.ASPxScheduler.Internal;
using DevExpress.XtraScheduler;
public enum CustomLabel { Routine = 1, FollowUp = 2, Urgent = 3, LabTesting = 4, Service = 5 }
public enum CustomStatus { Confirmed = 1, AwaitingConfirmation = 2, Cancelled = 3 }
public static class CustomMenuHelper {
public static void AddScheduleNewEventSubMenu(BootstrapSchedulerPopupMenu menu, string caption, string subMenuName) {
var newWithTemplateItem = new BootstrapMenuItem(caption, "TemplateEvents");
newWithTemplateItem.BeginGroup = true;
menu.Items.Insert(0, newWithTemplateItem);
AddTemplatesSubMenuItems(newWithTemplateItem, subMenuName);
}
static void AddTemplatesSubMenuItems(BootstrapMenuItem parentMenuItem, string subMenuName) {
parentMenuItem.Items.Add(new BootstrapMenuItem("Routine", string.Format("CustomItem_{0}_Routine", subMenuName)));
parentMenuItem.Items.Add(new BootstrapMenuItem("Follow-Up", string.Format("CustomItem_{0}_FollowUp", subMenuName)));
parentMenuItem.Items.Add(new BootstrapMenuItem("Urgent", string.Format("CustomItem_{0}_Urgent", subMenuName)));
parentMenuItem.Items.Add(new BootstrapMenuItem("Lab Testing", string.Format("CustomItem_{0}_LabTesting", subMenuName)));
parentMenuItem.Items.Add(new BootstrapMenuItem("Service", string.Format("CustomItem_{0}_Service", subMenuName)));
}
public static void ClearUnusedDefaultMenuItems(BootstrapSchedulerPopupMenu menu) {
RemoveMenuItem(menu, "NewAppointment");
RemoveMenuItem(menu, "NewAllDayEvent");
RemoveMenuItem(menu, "NewRecurringAppointment");
RemoveMenuItem(menu, "NewRecurringEvent");
RemoveMenuItem(menu, "GotoToday");
RemoveMenuItem(menu, "GotoDate");
}
static void RemoveMenuItem(BootstrapSchedulerPopupMenu menu, string menuItemName) {
var item = menu.Items.FindByName(menuItemName);
if(item != null)
menu.Items.Remove(item);
}
public static void UpdateAppointment(CustomLabel label, Appointment apt) {
if(label.Equals(CustomLabel.Service)) {
apt.Subject = "Routine Maintenance";
apt.Description = string.Empty;
apt.StatusKey = (int)CustomStatus.Cancelled;
}
else if(label.Equals(CustomLabel.LabTesting)) {
apt.Subject = "Lab Testing";
apt.Description = string.Empty;
apt.StatusKey = (int)CustomStatus.Confirmed;
}
else {
apt.Subject = "Name";
apt.Description = "Contact info:";
apt.StatusKey = (int)CustomStatus.AwaitingConfirmation;
}
apt.LabelKey = (int)label;
}
public static void CreateAppointment(CustomLabel label, BootstrapScheduler scheduler) {
Appointment apt = scheduler.Storage.CreateAppointment(AppointmentType.Normal);
UpdateAppointment(label, apt);
apt.Start = scheduler.SelectedInterval.Start;
apt.End = scheduler.SelectedInterval.End;
apt.ResourceId = scheduler.SelectedResource.Id;
scheduler.Storage.Appointments.Add(apt);
}
}