我正在使用jQuery FullCalendar插件进行房间预订。为此,我将从服务器代码中获取“资源”和“事件”列表作为JSON数组。
这是我的代码:
function LoadBookings() {
var rooms = [];
var events = [];
var s = $("#hdnStudio").val();
var u = $("#hdnUnit").val();
var f = $("#hdnFloor").val();
var r = $("#hdnRoom").val();
if ($('#calendar').length > 0) {
$.ajax({
url: '/RoomBooking/Events',
data: { studio: s, unit: u, floor: f },
type: 'POST',
async: false,
dataType: 'json'
}).done(function (result) {
if (result != null) {
$.each(result.events, function (i, v) {
if (v.IsAllDayEvent) {
events.push({ id: v.Id, resourceId: v.RoomId, start: moment(v.StartDate).format("YYYY-MM-DD"), end: moment(v.EndDate).format("YYYY-MM-DD"), title: v.Title });
}
else {
events.push({ id: v.Id, resourceId: v.RoomId, start: moment(v.StartDate).format("YYYY-MM-DDTHH:mm:ss"), end: moment(v.EndDate).format("YYYY-MM-DDTHH:mm:ss"), title: v.Title });
}
});
$.each(result.rooms, function (i, v) {
rooms.push({ id: v.Id, title: v.Name, eventColor: v.EventColor });
});
$('#calendar').fullCalendar({
schedulerLicenseKey: "GPL-My-Project-Is-Open-Source",
editable: false, // enable draggable events
aspectRatio: 1.8,
resourceAreaWidth: '15%',
slotEventOverlap: false,
minTime: "09:30:00",
maxTime: "23:30:00",
scrollTime: '09:30', // undo default 6am scrollTime
header: {
left: 'today prev,next',
center: 'title',
right: 'timelineDay,agendaWeek,month,listWeek'
},
defaultView: 'timelineDay',
resourceLabelText: 'Rooms',
height: 500,
resources: rooms,
events: events,
dayClick: function (date, jsEvent, view, resourceObj) {
var url = "/RoomBooking/Create?roomId=" + resourceObj.id + "&sDate=" + date.format();
$("#room-booking-modal .modal-content").load(url, function () {
$("#room-booking-modal").modal({ show: true });
});
},
eventClick: function (calEvent, jsEvent, view) {
var url = "/RoomBooking/Edit?id=" + calEvent.id;
$("#room-booking-modal .modal-content").load(url, function () {
$("#room-booking-modal").modal({ show: true });
});
}
});
}
});
}
}
在这里,如果时段时间少于当前时间,我想限制用户预订房间。我该如何实现?
我也在使用moment.js进行日期比较。