drag: function (args) {
// todo update duration
if (_dragStartEmployee != _resourcesData[args.groupIndex].id) {
console.log('change employee', args);
_dragStartEmployee = _resourcesData[args.groupIndex].id;
args.data.EndTime = moment(_dragStartTime).add(15, 'm').toDate();
args.endTime = moment(args.startTime).add(15, 'm').toDate();
}
},
drag: function (args) {
let dragElements = $('.e-appointment.e-lib.e-draggable.e-schedule-event-clone.e-drag-clone');
// trigger only when resource is changed if (_dragStartGroupIndex != _resourcesData[args.groupIndex].id) {
_dragStartGroupIndex = _resourcesData[args.groupIndex].id;
let serviceItem = availableServices.find(service => service.id === args.data.ServiceId);
if (serviceItem !== undefined ) {
_dragEndDuration = _getServiceEmployeeDuration(serviceItem, _dragStartGroupIndex);
}
if (_dragStartGroupIndex === args.data.EmployeeId) {
_dragEndDuration = args.data.Duration;
}
// calculate new height
let timeInSlot = _calendarSettings.timeScale.interval / _calendarSettings.timeScale.slot;
_dragHeight = _dragEndDuration / timeInSlot * 36;
// change background
if (dragElements !== undefined) {
let dragElem = dragElements[0];
dragElem.style.backgroundColor = _resourcesData[args.groupIndex].calendarColor;
}
} // change height
dragElements.height(_dragHeight + 'px');
},
_scheduleDatasource = new ej.data.DataManager({
url: contextPath + '/b/api/schedules/data',
crudUrl: contextPath + '/b/api/schedules/update',
adaptor: new ej.data.UrlAdaptor(),
crossDomain: true,
headers: [{ "X-Requested-With": "XMLHttpRequest" }]
});
eventSettings: {
dataSource: _scheduleDatasource,
query: new ej.data.Query().requiresCount()
},
resources: [{
field: 'EmployeeId',
title: 'Employee',
name: _resourcesGroupId,
allowMultiple: false,
dataSource: _resourcesData,
textField: 'name',
idField: 'id',
colorField: 'calendarColor'
}],
group: {
resources: [_resourcesGroupId],
enableCompactView: false
},
|
public JsonResult LoadData(Params param) // Here we get the Start and End Date and based on that can filter the data and return to Scheduler
{
var data = db.ScheduleEventDatas.Where(app => (app.StartTime >= param.StartDate && app.StartTime <= param.EndDate) || (app.RecurrenceRule != null && app.RecurrenceRule != "")).ToList(); // Here filtering the events based on the start and end date value.
return Json(data, JsonRequestBehavior.AllowGet);
}
public class Params
{
public DateTime StartDate { get; set; }
public DateTime EndDate { get; set; }
}
[HttpPost]
public JsonResult UpdateData(EditParams param)
{
if (param.action == "insert" || (param.action == "batch" && param.added != null)) // this block of code will execute while inserting the appointments
{
var value = (param.action == "insert") ? param.value : param.added[0];
int intMax = db.ScheduleEventDatas.ToList().Count > 0 ? db.ScheduleEventDatas.ToList().Max(p => p.Id) : 1;
DateTime startTime = Convert.ToDateTime(value.StartTime);
DateTime endTime = Convert.ToDateTime(value.EndTime);
ScheduleEventData appointment = new ScheduleEventData()
{
Id = intMax + 1,
StartTime = startTime,
EndTime = endTime,
Subject = value.Subject,
Location = value.Location,
Description = value.Description,
IsAllDay = value.IsAllDay,
StartTimezone = value.StartTimezone,
EndTimezone = value.EndTimezone,
RecurrenceRule = value.RecurrenceRule,
RecurrenceID = value.RecurrenceID,
RecurrenceException = value.RecurrenceException,
GroupID = value.GroupID
};
db.ScheduleEventDatas.InsertOnSubmit(appointment);
db.SubmitChanges();
}
if (param.action == "update" || (param.action == "batch" && param.changed != null)) // this block of code will execute while updating the appointment
{
var value = (param.action == "update") ? param.value : param.changed[0];
var filterData = db.ScheduleEventDatas.Where(c => c.Id == Convert.ToInt32(value.Id));
if (filterData.Count() > 0)
{
DateTime startTime = Convert.ToDateTime(value.StartTime);
DateTime endTime = Convert.ToDateTime(value.EndTime);
ScheduleEventData appointment = db.ScheduleEventDatas.Single(A => A.Id == Convert.ToInt32(value.Id));
appointment.StartTime = startTime;
appointment.EndTime = endTime;
appointment.StartTimezone = value.StartTimezone;
appointment.EndTimezone = value.EndTimezone;
appointment.Subject = value.Subject;
appointment.Location = value.Location;
appointment.Description = value.Description;
appointment.IsAllDay = value.IsAllDay;
appointment.RecurrenceRule = value.RecurrenceRule;
appointment.RecurrenceID = value.RecurrenceID;
appointment.RecurrenceException = value.RecurrenceException;
appointment.GroupID = value.GroupID;
}
db.SubmitChanges();
}
if (param.action == "remove" || (param.action == "batch" && param.deleted != null)) // this block of code will execute while removing the appointment
{
if (param.action == "remove")
{
int key = Convert.ToInt32(param.key);
ScheduleEventData appointment = db.ScheduleEventDatas.Where(c => c.Id == key).FirstOrDefault();
if (appointment != null) db.ScheduleEventDatas.DeleteOnSubmit(appointment);
}
else
{
foreach (var apps in param.deleted)
{
ScheduleEventData appointment = db.ScheduleEventDatas.Where(c => c.Id == apps.Id).FirstOrDefault();
if (apps != null) db.ScheduleEventDatas.DeleteOnSubmit(appointment);
}
}
db.SubmitChanges();
}
var data = db.ScheduleEventDatas.ToList();
return Json(data, JsonRequestBehavior.AllowGet);
} |
|
var dataManger = new ej.data.DataManager({
crudUrl: "http://localhost:54738/Home/UpdateData",
crossDomain: true,
adaptor: new ej.data.UrlAdaptor()
});
var scheduleObj = new ej.schedule.Schedule({
width: "100%",
height: "650px",
selectedDate: new Date(2017, 5, 7),
group: {
resources: ["Owners"]
},
resources: [
{
field: "GroupID",
title: "Assignee",
name: "Owners",
allowMultiple: false,
dataSource: [
{ text: "Alice", id: 1, color: "#1aaa55" },
{ text: "Smith", id: 2, color: "#7fa900" },
{ text: "Nancy", id: 3, color: "#357cd2" },
{ text: "Steve", id: 4, color: "#EA7A57" },
{ text: "John", id: 5, color: "#1aaa55" },
{ text: "Austin", id: 6, color: "#7fa900" }
],
textField: "text",
idField: "id",
colorField: "color"
}
],
eventSettings: { dataSource: dataManger }
});
scheduleObj.appendTo("#Schedule"); |
|
public JsonResult UpdateData(EditParams param)
{
if (param.action == "insert" || (param.action == "batch" && param.added != null)) // this block of code will execute while inserting the appointments
{
for (var i = 0; i < param.added.Count; i++)
{
var value = (param.action == "insert") ? param.value : param.added[i];
int intMax = db.ScheduleEventDatas.ToList().Count > 0 ? db.ScheduleEventDatas.ToList().Max(p => p.Id) : 1;
DateTime startTime = Convert.ToDateTime(value.StartTime);
DateTime endTime = Convert.ToDateTime(value.EndTime);
ScheduleEventData appointment = new ScheduleEventData()
{
Id = intMax + 1,
StartTime = startTime,
EndTime = endTime,
Subject = value.Subject,
Location = value.Location,
Description = value.Description,
IsAllDay = value.IsAllDay,
StartTimezone = value.StartTimezone,
EndTimezone = value.EndTimezone,
RecurrenceRule = value.RecurrenceRule,
RecurrenceID = value.RecurrenceID,
RecurrenceException = value.RecurrenceException
};
db.ScheduleEventDatas.InsertOnSubmit(appointment);
db.SubmitChanges();
}
}
if (param.action == "update" || (param.action == "batch" && param.changed != null)) // this block of code will execute while updating the appointment
{
var value = (param.action == "update") ? param.value : param.changed[0];
var filterData = db.ScheduleEventDatas.Where(c => c.Id == Convert.ToInt32(value.Id));
if (filterData.Count() > 0)
{
DateTime startTime = Convert.ToDateTime(value.StartTime);
DateTime endTime = Convert.ToDateTime(value.EndTime);
ScheduleEventData appointment = db.ScheduleEventDatas.Single(A => A.Id == Convert.ToInt32(value.Id));
appointment.StartTime = startTime;
appointment.EndTime = endTime;
appointment.StartTimezone = value.StartTimezone;
appointment.EndTimezone = value.EndTimezone;
appointment.Subject = value.Subject;
appointment.Location = value.Location;
appointment.Description = value.Description;
appointment.IsAllDay = value.IsAllDay;
appointment.RecurrenceRule = value.RecurrenceRule;
appointment.RecurrenceID = value.RecurrenceID;
appointment.RecurrenceException = value.RecurrenceException;
}
db.SubmitChanges();
}
if (param.action == "remove" || (param.action == "batch" && param.deleted != null)) // this block of code will execute while removing the appointment
{
if (param.action == "remove")
{
int key = Convert.ToInt32(param.key);
ScheduleEventData appointment = db.ScheduleEventDatas.Where(c => c.Id == key).FirstOrDefault();
if (appointment != null) db.ScheduleEventDatas.DeleteOnSubmit(appointment);
}
else
{
foreach (var apps in param.deleted)
{
ScheduleEventData appointment = db.ScheduleEventDatas.Where(c => c.Id == apps.Id).FirstOrDefault();
if (apps != null) db.ScheduleEventDatas.DeleteOnSubmit(appointment);
}
}
db.SubmitChanges();
}
var data = db.ScheduleEventDatas.ToList();
return Json(data, JsonRequestBehavior.AllowGet);
} |
|
btnELe.element.onclick = function () {
var schObj = document.querySelector('.e-schedule').ej2_instances[0];
var schData = [{
Id: 1,
Subject: 'Explosion of Betelgeuse Star',
Location: 'Space Centre USA',
IsAllDay: false,
StartTime: new Date(2019, 0, 6, 9, 30),
EndTime: new Date(2019, 0, 6, 11, 0)
}, {
Id: 2,
Subject: 'Thule Air Crash Report',
Location: 'Newyork City',
IsAllDay: false,
StartTime: new Date(2019, 0, 7, 12, 0),
EndTime: new Date(2019, 0, 7, 14, 0)
}, {
Id: 3,
Subject: 'Blue Moon Eclipse',
Location: 'Space Centre USA',
IsAllDay: false,
StartTime: new Date(2019, 0, 8, 9, 30),
EndTime: new Date(2019, 0, 8, 11, 0)
}, {
Id: 4,
Subject: 'Meteor Showers in 2018',
Location: 'Space Centre USA',
IsAllDay: false,
StartTime: new Date(2019, 0, 9, 13, 0),
EndTime: new Date(2019, 0, 9, 14, 30)
}, {
Id: 5,
Subject: 'Milky Way as Melting pot',
Location: 'Space Centre USA',
IsAllDay: false,
StartTime: new Date(2019, 0, 10, 12, 0),
EndTime: new Date(2019, 0, 10, 14, 0)
}, {
Id: 6,
Subject: 'Mysteries of Bermuda Triangle',
Location: 'Bermuda',
IsAllDay: false,
StartTime: new Date(2019, 0, 10, 9, 30),
EndTime: new Date(2019, 0, 10, 11, 0)
}, {
Id: 7,
Subject: 'Glaciers and Snowflakes',
Location: 'Himalayas',
IsAllDay: false,
StartTime: new Date(2019, 0, 11, 11, 0),
EndTime: new Date(2019, 0, 11, 12, 30)
}, {
Id: 8,
Subject: 'Life on Mars',
Location: 'Space Centre USA',
IsAllDay: false,
StartTime: new Date(2019, 0, 12, 9, 0),
EndTime: new Date(2019, 0, 12, 10, 0)
}, {
Id: 9,
Subject: 'Alien Civilization',
Location: 'Space Centre USA',
IsAllDay: false,
StartTime: new Date(2019, 0, 14, 11, 0),
EndTime: new Date(2019, 0, 14, 13, 0)
}, {
Id: 10,
Subject: 'Wildlife Galleries',
Location: 'Africa',
IsAllDay: false,
StartTime: new Date(2019, 0, 16, 11, 0),
EndTime: new Date(2019, 0, 16, 13, 0)
}];
schObj.addEvent(schData);
}; |