How to prevent CRUD operation on specific appointments?
The Schedule control allows restricting the CRUD operations (Create, Read, Update, and Delete) on specific appointments based on certain conditions. The following steps shows the way to achieve it by setting specific modification rights for each appointments.
Here, the CRUD operations are prevented on appointments that are created by admin.
Step 1: Create an HTML page with the default schedule rendering code. Also, add and refer the required scripts and stylesheets to it by referring here.
Step 2: Define the dragStart, resizeStart, beforeAppointmentCreate, beforeAppointmentRemove and appointmentWindowOpen events of the scheduler as follows,
$(function () { $("#schedule").ejSchedule({ width: "100%", height: "525px", currentDate: new Date(2014, 4, 5), dragStart: "onDragandResizeStart", resizeStart: "onDragandResizeStart", beforeAppointmentCreate: "onBeforeAppointmentCreate", beforeAppointmentRemove: "onBeforeAppointmentRemove", appointmentWindowOpen: "onAppointmentWindowOpen", appointmentSettings: { dataSource: [ { isAdmin: true, Id: 100, Subject: "Bering Sea Gold", StartTime: new Date(2014, 4, 5, 10, 00), EndTime: new Date(2014, 4, 5, 12, 00), AllDay: false, Recurrence: false }, { isAdmin: false, Id: 101, Subject: "Bering Sea Gold", StartTime: new Date(2014, 4, 9, 09, 00), EndTime: new Date(2014, 4, 9, 10, 30), AllDay: false, Recurrence: false }, { isAdmin: true, Id: 102, Subject: "What Happened Next?", StartTime: new Date(2014, 4, 8, 01, 00), EndTime: new Date(2014, 4, 8, 03, 30), AllDay: false, Recurrence: false }, ] } }); });
Step 3: Now, define the following event handler functions to check for, whether the appointment is created by admin or not.
function onBeforeAppointmentCreate(args) { // Here add the privilege to appointment while saving new appointment args.appointment["isAdmin"] = false; } //This method to handle dragging and resizing of the appointments function onDragandResizeStart(args) { if (!ej.isNullOrUndefined(args.appointment) && args.appointment.isAdmin) { args.cancel = true; } } //This method to handle the appointment deletion function onBeforeAppointmentRemove(args) { if (!ej.isNullOrUndefined(args.appointment) && args.appointment[0].isAdmin) { args.cancel = true; } } //This method to handle the editing of appointments function onAppointmentWindowOpen(args) { if (!ej.isNullOrUndefined(args.appointment) && args.appointment.isAdmin) { args.cancel = true; } }
Sample Location: http://jsplayground.syncfusion.com/s2jpacjv
In the above sample, “isAdmin” field has been used to set the modification rights, based on which the CRUD operations are performed on the appointments. For example, if isAdmin field is set to false, only then the appointment operations such as drag and drop, resizing or editing of those appointment will be allowed for the users.
Step 4: Run the sample and perform CRUD operations on the schedule appointments based on isAdmin field value.