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: https://ej2.syncfusion.com/home/index.html#platform
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.
Conclusion
I hope you enjoyed learning about how to prevent CRUD operation on specific appointments.
You can refer to our JavaScript Schedule feature tour page to know about its other groundbreaking feature representations. You can also explore our JavaScript Schedule documentation to understand how to create and manipulate data.
For current customers, you can check out our components from the License and Downloads page. If you are new to Syncfusion, you can try our 30-day free trial to check out our other controls.
If you have any queries or require clarifications, please let us know in the comments section below. You can also contact us through our support forums, Direct-Trac, or feedback portal. We are always happy to assist you!