- Home
- Forum
- ASP.NET MVC
- Appointments
Appointments
Thank you for using Syncfusion products.
We have analyzed all your above mentioned requirements and queries and have prepared a schedule sample to meet your requirement which can be downloaded from the following location.
http://www.syncfusion.com/downloads/support/forum/119916/ze/CustomSample1086044626
JSPlayground Link: http://jsplayground.syncfusion.com/2lvin20h
In the above sample, we have considered the current user name as “Person 2” and blocked the appointment CRUD operation for the user with the name “Person 1” appointments. Hence, the current user can’t be able to edit/alter the appointment with subject “Person 1”, making it readonly. Also, we have implemented the appointment creation by selecting the required time period using mouse in schedule control. Please refer the following code snippet to know details about this scenario.
<code>
--------------
--------------
recurrence: "Recurrence",
recurrenceRule: "RecurrenceRule"
},
appointmentClick: "readOnlyChange", //Bind the events to trace the appointment and make it as read only based on requirement
appointmentHover: "readOnlyChange",
appointmentWindowOpen: "readOnlyChange",
appointmentDeleted: "readOnlyChange",
resizeStop: "readOnlyChange",
dragStop: "readOnlyChange",
create: "onCreate" //Bind the event to apply the appointment creation by selecting cells
function onCreate(args) {
this._on(this.element, "mouseup", "td.e-workcells,td.e-monthcells,td.e-alldaycells", function (oEl) {
if ($(oEl.target).hasClass("e-workcells") || $(oEl.target).hasClass("e-monthcells") || $(oEl.target).hasClass("e-alldaycells")) {
var schObj = $("#Schedule").data("ejSchedule");
var tds = schObj.element.find('td.e-selectedCell');
var nt = tds.length - 1;
if (nt == 0) {
schObj._cellSelection(oEl.target);
}
else {
schObj._multipleCellAppointCreation(oEl.target);
}
if (!$(oEl.target).hasClass("e-workcells") ? (new Date(schObj.cur_EndTime) - new Date(schObj.cur_StartTime)) / 3600000 > 24 : (new Date(schObj.cur_EndTime) - new Date(schObj.cur_StartTime)) / 3600000 > 0.5) { //If you want to create appointment by click on cell remove this highlighted if block
var createObject = { Subject:"Person 2",StartTime: new Date(schObj.cur_StartTime), EndTime: new Date(schObj.cur_EndTime) };
schObj.saveAppointment(createObject); //Create object and save in schedule control
}
}
});
}
function readOnlyChange(args) {
if (args.originalEventType != "cellDoubleClick") {
var data = ej.DataManager(this._processed).executeLocal(new ej.Query().where("Id", "equal", args.appointment.Id))
for (var i = 0; i < data.length; i++) {
if (data[i].Subject == "Person 1") //Check the subject which has Person 1 to make it read-only
args.cancel = true;
}
}
}
</code>
Kindly try the above sample and let us know if you need further assistance on this.
Regards,
Sarath Kumar P K
Thanks for your update.
We are glad to hear that our previously provided sample meets your basic expectation. Also, we will wait to hear from you further.
Please let us know if you need any further assistance on this. As always, we will be happy to assist you.
Regards,
Sarath Kumar P K
Thanks for your update.
We have analyzed your scenario and prepared a schedule sample to validate the appointment before saving or updating to database, that can be downloaded from the following location.
http://www.syncfusion.com/downloads/support/forum/119916/ze/ScheduleSample-187162631
JSPlayground link: http://jsplayground.syncfusion.com/qkt2prii
In the above sample we have used the schedule event appointmentSaved, appointmentEdited, resizeStop and dragStop to validate the created/updated appointment. Using appValidate we checked the condition and updated in database. Please refer to the following code example to know more about the appointment validation.
<code>
$(function () {
$("#Schedule1").ejSchedule({
width: "100%",
height: "525px",
--------------
--------------
appointmentSaved: "appValidate",
appointmentEdited: "appValidate",
appointmentClick: "readOnlyChange",
appointmentHover: "readOnlyChange",
appointmentWindowOpen: "readOnlyChange",
appointmentDeleted: "readOnlyChange",
resizeStop: "readOnlyChange",
dragStop: "readOnlyChange", //Check for readOnly and validate the condition too.
create: "onCreate"
});
});
function appValidate(args) {
var schObj = $("#Schedule1").data("ejSchedule");
var appList = schObj._processed;
for (var i = 0; i < appList.length; i++) {
if ((args.type == "appointmentSaved" ? true : (appList[i][schObj.model.appointmentSettings["id"]]!=args.appointment.Id))&&(new Date(appList[i][schObj.model.appointmentSettings["endTime"]]) > new Date(args.appointment.StartTime))) { //Check the required condition for appointment create
if ((new Date(appList[i][schObj.model.appointmentSettings["startTime"]]) < new Date(args.appointment.EndTime))) {
if (new Date(new Date(appList[i][schObj.model.appointmentSettings["startTime"]]).setHours(0, 0, 0, 0)).getTime() === new Date(new Date(args.appointment.StartTime).setHours(0, 0, 0, 0)).getTime()) { }
args.cancel = true; //Return false if condition satisfies (Overlap)
}
}
}
}
</code>
Kindly try the above sample and let us know if you need further assistance on this.
Regards,
Sarath Kumar P K
- 5 Replies
- 2 Participants
-
JA jarrod
- Aug 13, 2015 12:31 PM UTC
- Aug 26, 2015 10:28 AM UTC