FullCalendar passing starting date - fullcalendar

Can someone help me understand how I can pass the start date into the calendar. I have created a Delivery Scheduler calendar and I display the delivery details in a table under the calends that is feed via the database. This requires me to refresh the page when a user select a calendar day to load the table information. I can figure out how to start the calendar on a starting date that is passed into the page.
Seems like this would be easy but I am doing something wrong.
$('#calendar').fullCalendar(Options);
$('#calendar').fullCalendar('gotoDate', '2012-10-21');

Sample based on documentation http://arshaw.com/fullcalendar/docs/current_date/gotoDate/
Remember that month is 0-based, so 10 means November.
$(document).ready(function () {
var calendar = $('#calendar').fullCalendar({
events:[
{ title:'All Day Event', start:new Date(2012, 10, 20)},
{ title:'Long Event', start:new Date(2012, 10, 21), end:new Date(2012, 10, 22)}
]
});
$('#calendar').fullCalendar('gotoDate', 2012, 10, 21);
});

Thank you Biesior for your helpful answer. I was able to use your suggested code to get the behavior I was looking for.
While using the approach above, I notice that Firebug's console shows two AJAX data requests being executed simultaneously, one for the view associated with the current date, and one for the view associated with the specified gotoDate.
There doesn't appear to be any additional delay from the user's perspective, and the calendar displays the requested view from the start. However, 'loading' callbacks will be called multiple times which might cause strange behavior in certain circumstances. There may also be other undesired results associated with the superfluous AJAX request for the current date.
I was able to avoid the unnecessary AJAX request by initializing the calendar without an event source, then moving to the desired date as shown by Biesior above, and then adding the event source. The sequence is shown below. I've removed some unrelated FullCalendar options and callbacks to keep it concise. There are some additional AJAX parameters, and some PHP, but the important thing to notice is when the event source is specified.
The original code results in two simultaneous AJAX requests:
$('#calendar').fullCalendar({
events: {
url:'/Services/GetEvents.php',
type: 'POST',
data: {
lat: <?=$venLatitude?>,
lon: <?=$venLongitude?>,
userID: <?=$userID?>,
distance: <?=$distance?>
}
}
})
$('#calendar').fullCalendar('gotoDate', <?=(int)substr($startDate,0,4)?>, <?=((int)substr($startDate,5,2))-1?>);
This adjustment results in only the desired AJAX request:
$('#calendar').fullCalendar();
$('#calendar').fullCalendar('gotoDate', <?=(int)substr($startDate,0,4)?>, <?=((int)substr($startDate,5,2))-1?>);
$('#calendar').fullCalendar('addEventSource', {
url:'/Services/GetEvents.php',
type: 'POST',
data: {
lat: <?=$venLatitude?>,
lon: <?=$venLongitude?>,
userID: <?=$userID?>,
distance: <?=$distance?>
}
});

Related

Events created via API are not listed in printing

I have created one google calendar with my gmail account and I want to display that calendar in my website.
All Events related to that calender's are inserted via google calendar API using .Net Library.
It shows all events in website.but when i click on print and all events are not display in print preview.
Is there any parameter missing while calling Insert Event API?
I was having this problem with events created in a Chrome Extension. I'll spare you the code for the token, but I think it's enough that the event is created without any problems, yet refuses to print.
Desired behaviour: create event that can be printed.
Specific Error: event is created, but can not be printed.
Code:
var copyInit = {
'method': 'POST',
'async': true,
'headers': {
'Authorization': 'Bearer ' + Items.access_token,
'Content-Type': 'application/json'
},
'contentType': 'json',
'body': dataJson
};
dataJson:
"{"start":{"date":"2019-04-22"},"end":{"date":"2019-04-22"},"summary":"test"}"
API Call:
var url = 'https://www.googleapis.com/calendar/v3/calendars/' + calId + '/events?key=AIzaSyDfX9-blah9KoxzvGu3IzA1zu0oDQ-cJfw';
fetch(url, copyInit)
After much head scratching it turns out that although the Google Calendar API allows you to create all day events using the same start date and end date for all day events (using YYYY-MM-DD), such events can not be printed, and when shared will have an end date previous to the start date...
The solution is to use the following day as the end date for all day events:
"{"start":{"date":"2019-04-22"},"end":{"date":"2019-04-23"},"summary":"works!"}"

cakephp and full calendar integration

i am new developer and i want to make an app in cakephp 3.7 thas uses jquery full calendar plugin for reservations.In my database is stored a specific date range (starting date and ending date fields).I want to use this date range in my calendar so that if a user clicks on a specific day on the callendar that is out of this date range, the app will display a messange informing the user that he cannot make a reservation for that day!
Any useful suggestions on who i will handle on this ??
Thank you!!
I have done it using the cakephp 3.6.
Generic steps that you would follow:
You will include your full calendar js and jquery in the 'full
calendar' template
Then initialise your fullcalendar. Now you should see the calendar.
Once done, from the fullcalendar make an ajax call to your controller to get the events. eg.
var fcSources = {
loadEvents: {
url: //your controller action,
type: "GET",
cache: true,
timezone: "Europe/London",
className: "events",
dataType: "json",
success: function (data) {
return data.events;
}
},
}
Later part can be done by simply checking the date value against current date.

how to call fullcalendar events() with a paremeter?

Is there a way to filter events based on a drop down?
I tried :
events: '/Controller/action?id='+id,
$("#drop").change(function () {
id = $('#drop').val();
$('#calendar').fullCalendar('refetchEvents');
But the controller does not see the new id.
Any suggestions on passing a paremter to the events() method?
You gave the result of '/Controller/action?id='+id to the calendar as the events feed when the calendar was initialised. e.g. you passed in /Controller/action?id=3, for example. That code has run and does not run again. fullCalendar stores that static string as the URL of the events feed. It doesn't pay any attention to the value of "id" later.
The simplest way to solve this is probably using a custom event feed, as per https://fullcalendar.io/docs/event_data/events_function/ :
//declare the calendar with a custom "events" functions
$("#calendar").calendar({
//..all your calendar options, and then the events:
events: function( start, end, timezone, callback ) {
$.ajax({
//whatever ajax parameters you need, but make sure:
url: /Controller/action,
data: { "id": $('#drop').val(), "start": start.format("YYYY-MM-DD"), "end": end.format("YYYY-MM-DD") }
});
}
});
$("#drop").change(function () {
$('#calendar').fullCalendar('refetchEvents');
});
That way, when "refetchEvents" is called, it runs the function that you passed as the "events" parameter, which can look up the value of the dropdown dynamically at that moment in time.
Note I've also added "start" and "end" parameters to your data, because your event source is supposed to filter the events returned by the dates actually being displayed on the calendar, otherwise you end up returning all events every time the view or date changes.

TinCan Js Completion and Time Spent

I am new to TinCan, I am building a course where I need to set the completion status to completed and also the time needs to be recorded. I am using an LMS and also scormcloud for testing.
Currently, the completed status is working but it's not capturing the time spent.
This is the code:
var tincan = new TinCan({url: location.href});
tincan.sendStatement(new TinCan.Statement({
verb: 'completed',
result: {
success: true
}
}));
To include duration in that statement you should use the result.duration property. This is an ISO 8601 duration representing the attempt duration (rather than session duration). I actually have a blog on duration due out in the next month or so that I hope you'll find helpful.
I'd also recommend using a full verb object and using result.completion instead of result.success for a completion statement.
So your final code will be:
var tincan = new TinCan({url: location.href});
tincan.sendStatement(new TinCan.Statement({
verb: {
id: "http://adlnet.gov/expapi/verbs/completed",
display:{
"en-US": "completed"
}
},
result: {
completion: true,
duration: "PT21.896S"
}
}));
Note also that it be may best not to rely on the activity definition from the query string, but I appreciate you may be keeping the code sample short for the sake of the question.

Meteor reactive publishes/subscribes

I am currently working on a chat app in meteor. When first entering the room you get 25 messages initially. Now as new messages come into the page, that value should go up accordingly.
Now I so far I have a tried a couple different things, all not giving the desired result.
I have tried setting up a session variable on the client side that reactively re-subscribes to a given publish as the message count goes up. The problem with this route is this gives an adverse effect as new messages come in where all of the messages on the page need to reload because of the subscribe.
I have recently tried using the reactive-publish package with little luck in that the package has some various adverse effects of it's own.
What might be the best way to tackle this kind of problem? I am hoping there is a solution where I can set up some kind of publish that just streams in messages based on a numerical value that I in the database for each user.
EDIT: To add context
I am thinking something along the lines of
Meteor.publish 'messages', (roomId) ->
dl = // Some value that I pull from the database, which gets updated as new messages come into a room
Messages.find({room: roomId, type: "user_message"}, {sort: {time: -1}, limit: dl, fields: {_id: 1, name: 1, message: 1, room: 1, time: 1, type: 1}})
A huge amount of flexibility in Pub/Sub flexibility is achievable by using the low-level publications API - so much so that I've just written a blog post about it. It should make it pretty clear how you update variables when new documents appear in a query set.
It seems like you want each user to have a unique subscription based on the time that they enter the chat room, i.e. Meteor.subscribe("messages", roomId, new Date), that includes up to 25 messages from before they entered the room. Here's one option:
Meteor.publish("messages", function (roomId, time) {
var lastRecent = _.last(Messages.find({
room: roomId, type: "user_message"
}, {sort: {time: -1}, limit: 25}).fetch());
var cutoffTime = lastRecent && lastRecent.time || time;
return Messages.find({
room: roomId, type: "user_message", time: {$gt: cutoffTime}
});
});
If you want to successively add e.g. 25 old messages at a time whenever a user scrolls to the top of the chat window, consider that you may not actually need to "subscribe" to those older messages. You may be able to set up a method call like Meteor.call("getNOlderMessages", {roomId: roomId, N: 25, priorTo: oldestShownTime}) to fetch them, insert them into a local collection on the client (e.g. OlderMessages = new Meteor.Collection(null);), and then do something like:
<template="messages">
{{#each olderMessages}} {{> message}} {{/each}}
{{#each messages}} {{> message}} {{/each}}
</template>

Resources