jQuery full calendar resource view restrict past slots












0















I'm using jQuery FullCalendar plugin for Room Booking. For this, I'm getting both Resources and Event list from server code as JSON array.



Here is my code:



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 });
});
}
});
}
});
}
}


Here, I wanted to restrict users to book the rooms if slot time is lesser than current time. How can I achieve this?



I'm using moment.js as well for date comparisons.










share|improve this question




















  • 1





    async: false is deprecated and you should not use it (it causes a poor user experience by locking the browser during the AJAX request), also eventually it will stop working at all as browsers remove the feature. In any case you don't need it - you're handling the response properly. You can remove that line.

    – ADyson
    Nov 21 '18 at 9:17













  • Anyway, normally you should create events with select not dayClick. Then you can use selectConstraint to set a date/time range where events are allowed to be entered.

    – ADyson
    Nov 21 '18 at 9:22













  • But if you don't want to move away from using dayClick, then when dayClick runs you can check the date variable to see whether it's before the current date or not (you can use the momentJS isBefore() function for that).

    – ADyson
    Nov 21 '18 at 9:24
















0















I'm using jQuery FullCalendar plugin for Room Booking. For this, I'm getting both Resources and Event list from server code as JSON array.



Here is my code:



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 });
});
}
});
}
});
}
}


Here, I wanted to restrict users to book the rooms if slot time is lesser than current time. How can I achieve this?



I'm using moment.js as well for date comparisons.










share|improve this question




















  • 1





    async: false is deprecated and you should not use it (it causes a poor user experience by locking the browser during the AJAX request), also eventually it will stop working at all as browsers remove the feature. In any case you don't need it - you're handling the response properly. You can remove that line.

    – ADyson
    Nov 21 '18 at 9:17













  • Anyway, normally you should create events with select not dayClick. Then you can use selectConstraint to set a date/time range where events are allowed to be entered.

    – ADyson
    Nov 21 '18 at 9:22













  • But if you don't want to move away from using dayClick, then when dayClick runs you can check the date variable to see whether it's before the current date or not (you can use the momentJS isBefore() function for that).

    – ADyson
    Nov 21 '18 at 9:24














0












0








0








I'm using jQuery FullCalendar plugin for Room Booking. For this, I'm getting both Resources and Event list from server code as JSON array.



Here is my code:



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 });
});
}
});
}
});
}
}


Here, I wanted to restrict users to book the rooms if slot time is lesser than current time. How can I achieve this?



I'm using moment.js as well for date comparisons.










share|improve this question
















I'm using jQuery FullCalendar plugin for Room Booking. For this, I'm getting both Resources and Event list from server code as JSON array.



Here is my code:



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 });
});
}
});
}
});
}
}


Here, I wanted to restrict users to book the rooms if slot time is lesser than current time. How can I achieve this?



I'm using moment.js as well for date comparisons.







jquery date events calendar fullcalendar






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 21 '18 at 6:22









WC2

1989




1989










asked Nov 21 '18 at 5:40









55SK5555SK55

609




609








  • 1





    async: false is deprecated and you should not use it (it causes a poor user experience by locking the browser during the AJAX request), also eventually it will stop working at all as browsers remove the feature. In any case you don't need it - you're handling the response properly. You can remove that line.

    – ADyson
    Nov 21 '18 at 9:17













  • Anyway, normally you should create events with select not dayClick. Then you can use selectConstraint to set a date/time range where events are allowed to be entered.

    – ADyson
    Nov 21 '18 at 9:22













  • But if you don't want to move away from using dayClick, then when dayClick runs you can check the date variable to see whether it's before the current date or not (you can use the momentJS isBefore() function for that).

    – ADyson
    Nov 21 '18 at 9:24














  • 1





    async: false is deprecated and you should not use it (it causes a poor user experience by locking the browser during the AJAX request), also eventually it will stop working at all as browsers remove the feature. In any case you don't need it - you're handling the response properly. You can remove that line.

    – ADyson
    Nov 21 '18 at 9:17













  • Anyway, normally you should create events with select not dayClick. Then you can use selectConstraint to set a date/time range where events are allowed to be entered.

    – ADyson
    Nov 21 '18 at 9:22













  • But if you don't want to move away from using dayClick, then when dayClick runs you can check the date variable to see whether it's before the current date or not (you can use the momentJS isBefore() function for that).

    – ADyson
    Nov 21 '18 at 9:24








1




1





async: false is deprecated and you should not use it (it causes a poor user experience by locking the browser during the AJAX request), also eventually it will stop working at all as browsers remove the feature. In any case you don't need it - you're handling the response properly. You can remove that line.

– ADyson
Nov 21 '18 at 9:17







async: false is deprecated and you should not use it (it causes a poor user experience by locking the browser during the AJAX request), also eventually it will stop working at all as browsers remove the feature. In any case you don't need it - you're handling the response properly. You can remove that line.

– ADyson
Nov 21 '18 at 9:17















Anyway, normally you should create events with select not dayClick. Then you can use selectConstraint to set a date/time range where events are allowed to be entered.

– ADyson
Nov 21 '18 at 9:22







Anyway, normally you should create events with select not dayClick. Then you can use selectConstraint to set a date/time range where events are allowed to be entered.

– ADyson
Nov 21 '18 at 9:22















But if you don't want to move away from using dayClick, then when dayClick runs you can check the date variable to see whether it's before the current date or not (you can use the momentJS isBefore() function for that).

– ADyson
Nov 21 '18 at 9:24





But if you don't want to move away from using dayClick, then when dayClick runs you can check the date variable to see whether it's before the current date or not (you can use the momentJS isBefore() function for that).

– ADyson
Nov 21 '18 at 9:24












0






active

oldest

votes











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53405856%2fjquery-full-calendar-resource-view-restrict-past-slots%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























0






active

oldest

votes








0






active

oldest

votes









active

oldest

votes






active

oldest

votes
















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53405856%2fjquery-full-calendar-resource-view-restrict-past-slots%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

mysqli_query(): Empty query in /home/lucindabrummitt/public_html/blog/wp-includes/wp-db.php on line 1924

How to change which sound is reproduced for terminal bell?

Can I use Tabulator js library in my java Spring + Thymeleaf project?