jQuery FullCalendar click 'next' event notificatin - asp.net

How can i get notified when the user click on 'next' (arrow) ?
I'm using the calendar in month view and I want to load the next month data on demand.
Also, do smbdy has an example of consuming data from ASP.NET (AJAX call) ?

you can use the viewDisplay trigger (http://arshaw.com/fullcalendar/docs/display/viewDisplay/) but that gets called also when the calendar loads, or the user switches views.
it sounds like you'd want an events function instead:
http://arshaw.com/fullcalendar/docs/event_data/events_function/
for the asp.net thing, have you looked here?
http://weblogs.asp.net/gunnarpeipman/archive/2010/02/03/using-fullcalendar-jquery-component-with-asp-net-mvc.aspx

Your way of approaching is wrong. You may need to write an API which returns the list of calendar objects in JSON, and use the following options.
$('#calendar').fullCalendar({
events: '/myfeed.php'
});
Then, fullcalendar will automatically call /myfeed.php whenever it needs.
e.g. If a user clicks 'prev' or 'next' month button.
Here's the example URL fullcalendar will generate :
/myfeed.php?start=1262332800&end=1265011200&_=1263178646
For more information, please visit the following URL.
http://arshaw.com/fullcalendar/docs/event_data/events_json_feed/

Here the viewDisplay function is called when the user clicks next/prev. Also, you can see that is is getting the next lot of data via AJAX.
I hope this helps :)
$(document).ready(function () {
var calendar = $('#calendar').fullCalendar({
header: {
left: 'prev,next today',
center: 'title',
right: 'resourceMonth'
},
defaultView: 'resourceWeek',
eventSources: [ getCalData() ],
header: {
left: 'prev,next today',
center: 'title',
right: ''
},
viewDisplay: function (view) {
$('#calendar').fullCalendar('removeEvents');
$('#calendar').fullCalendar('addEventSource', getCalData());
$('#calendar').fullCalendar('rerenderEvents');
}
});
});
function getCalData() {
var source = [{}];
$.ajax({
async: false,
url: '/mysite/GetWeekData',
data: { myParam: $('#calendar').fullCalendar('getView').visStart },
success: function (data) {
$(data).each(function () {
source.push({
title: $(this).attr('title'),
start: $(this).attr('start'),
});
});
},
error: function () {
alert('could not get the data');
},
});
return source;
}

Related

fullcalendar event filter select almost working

Im trying to filter events in fullcalendar on select change which almost works.
This is my dropdown
<select id="dropdown">
<option value="All" data-feed="all-feed.php" selected>All</option>
<option value="This" data-feed="this-feed.php">This</option>
<option value="That" data-feed="that-feed.php">That</option>
</select>
This my script
$(document).ready(function(){
var feed = $('#dropdown').find(':selected').data('feed');
$('#calendar').fullCalendar({
locale: 'de',
editable: false,
firstDay: 1,
events: feed,
eventLimit: 3,
header: {
left: 'prev,next today',
center: 'title',
right: 'month,listWeek'
}
});
$('#dropdown').change(onSelectChangeFeed);
function onSelectChangeFeed() {
var feed = $(this).find(':selected').data('feed');
$('#calendar').fullCalendar('removeEvents');
$('#calendar').fullCalendar('addEventSource', feed);
};
});
This works untill I click the next or prev buttons. Then all events Ive filtered are added somehow in the "background": https://streamable.com/qnqwd
Ive also tried this function but then the events are added directly.
function onSelectChangeFeed() {
$('#calendar').fullCalendar('removeEventSource', feed);
$('#calendar').fullCalendar('refetchEvents');
var feed = $(this).find(':selected').data('feed');
$('#calendar').fullCalendar('addEventSource', feed);
$('#calendar').fullCalendar('refetchEvents');
};
Heres a fiddle https://jsfiddle.net/4j5s9yp2/5/
Your code doesn't quite work consistently, because you use "events" and "eventSources" interchangeably, and they are not the same concept. You also try to remove an eventSource with the wrong ID - as per the example in JSFiddle, by the time you call var feed = $(this).find(':selected').data('feed');, feed is set to the newly selected feed value. Therefore it cannot match it to an event source in the calendar to remove, because the event source currently defined is the old feed value.
This version resolves both issues:
var selectedFeed = $('#dropdown').find(':selected').data('feed');
$('#calendar').fullCalendar({
locale: 'de',
editable: false,
firstDay: 1,
displayEventTime: false,
eventSources: [ selectedFeed ], //event source, not "events" directly
eventLimit: 3,
header: {
left: 'prev,next today',
center: 'title',
right: 'month,listWeek'
},
loading: function(bool) {
if (bool) {
$(this).parent().find('#loading').fadeIn( "300");
}else {
$(this).parent().find('#loading').fadeOut( "300");
}
}
});
$('#dropdown').change(onSelectChangeFeed);
function onSelectChangeFeed() {
var feed = $(this).find(':selected').data('feed');
$('#calendar').fullCalendar('removeEventSource', selectedFeed); //remove _old_ feed value
$('#calendar').fullCalendar('addEventSource', feed);
selectedFeed = feed; //set currently selected feed to the new value
};
See https://jsfiddle.net/4j5s9yp2/6/ for a working example.

fullcalendar eventDragStop triggered after event returns to original position

I would like to delete events on a fullcalendar jquery plugin by dragging them to a trash can image and dropping them in. There are several posts that discuss this action but I can't seem to get mine to work.
The trash can image is defined in the cshtml below:
<div class="well well-sm" id="deleteEventsDiv" style="text-align:center">
<label id="delete_events_lbl" style="display:block; text-align:center; font-size:medium; font-weight:bold">Delete Events</label>
<img src="~/Images/cal-trash.png">
<div class="note">
<strong>Note:</strong> Drag and drop events here to delete them
</div>
</div>
I can drag the event to the trash can but it reverts back to its original position then the eventDragStop event is triggered. Since it is not over the trash can, the rest of the code is not run. This is my fullcalendar code:
$('#edit_calendar').fullCalendar({
header:
{
left: 'prev,next today',
center: 'title',
right: 'month,agendaWeek,agendaDay'
},
titleFormat: { month: 'MMMM' },
defaultView: 'month',
selectable: true,
selectHelper: true,
droppable: true,
drop: function (date, jsEvent, ui, resourceId) {
var memberName = $(this).data('event').title;
var memberID = $(this).attr('id').toString();
//Create Event - add to array
var newEvent = new Object();
newEvent = {
title: memberName,
id: memberID,
start: date.format(),
end: date.format(),
objectID: 0
};
eventsAdded.push(newEvent);
},
editable: true,
//The following constraints prevents the user from adding/updating/deleting events that are before the current date
//The end date is required. So, you can't add events over a year away from the current date
eventConstraint: {
start: moment().startOf('day'),
end: moment(moment().startOf('day'), 'MM-DD-YYY').add('days', 365)
},
selectConstraint: {
start: moment().startOf('day'),
end: moment(moment().startOf('day'), 'MM-DD-YYY').add('days', 365)
},
resizable: true,
dragRevertDuration: 0,
eventDragStop: function (event, jsEvent, ui, view) {
alert('event drag stopped...should be over trash can.');
// This condition makes it easier to test if the event is over the trash can using Jquery
if ($('div#deleteEventsDiv').is(':hover')) {
// Confirmation popup
$.SmartMessageBox({
title: "Delete Event?",
content: 'Are you sure you want to remove this event from the calender?',
buttons: '[No][Yes]'
}, function (ButtonPressed) {
if (ButtonPressed === "Yes") {
// You can change the URL and other details to your liking.
// On success a small box notification will fire
$.ajax({
url: '/events/' + event.id,
type: 'DELETE',
success: function (request) {
$.smallBox({
title: "Deleting Event",
content: "Event Deleted",
color: "#659265",
iconSmall: "fa fa-check fa-2x fadeInRight animated",
timeout: 4000
});
$('#edit_calendar').fullCalendar('removeEvents', event.id);
}
});
}
});
}
}
}); //end calendar initialization
How do I get the event from NOT returning to its original position when it is over the trash can?
i had same problem here. And i found a paleative solution.
I hope that it works for you too.
Open fullcalendar.js and edit:
dragRevertDuration: 500
to
dragRevertDuration: 0

How to send an ajax request to update event in FullCalender UI, when eventDrop is called?

I am trying to use this great UI "FullCalender" But what I want to do is send an ajax request to update the event data in the database when the user move the event around.
So If a user want to move an event to a different date in the calender then I need to be able to send the request to the database use ajax request.
How can I collect the new information so if the appointment was moved to a new date or a new time how can I obtain the new information so I can pass it along to the server?
More, what method do I use to send the same request if the user changes the time by expanding not by drag/drop event?
$(document).ready(function() {
$('#calendar').fullCalendar({
editable: true,
events: "json-events.php",
timeFormat: 'h:mm{ - h:mm}',
defaultView: 'agendaDay',
eventDrop: function(event, delta, minuteDelta, allDay, revertFunc) {
if (!confirm("Are you sure about this change?")) {
revertFunc();
}
// AJAX call goes here
$.ajax();
},
loading: function(bool) {
if (bool) $('#loading').show();
else $('#loading').hide();
}
});
});
Take a look at the parameters of the function: delta, minuteDelta and allDay. Those tell you how the event was modified in days, minutes and if it was moved to the allday slot. The event itself should hold an identifier so that you can identify it in your database.
I made me a helper function updateEventTimes which is simply called from eventDrop and eventResize with an extra boolean parameter.
The function looks roughly like this:
/*
* Sends a request to modify start/end date of an event to the server
*/
function updateEventTimes(drag, event, dayDelta, minuteDelta, allDay, revertFunc)
{
//console.log(event);
$.ajax({
url: "update.php",
type: "POST",
dataType: "json",
data: ({
id: event.id,
day: dayDelta,
min: minuteDelta,
allday: allDay,
drag: drag
}),
success: function(data, textStatus) {
if (!data)
{
revertFunc();
return;
}
calendar.fullCalendar('updateEvent', event);
},
error: function() {
revertFunc();
}
});
};
Since I found this topic now, I think information below will be helpful in future.
You could use JSON.stringify() method to generate JSON as send date.
But, small workaround need in this case: see Tip on serializing event in fullCalendar with JSON.stringify.
In short, you code should looks like:
/*
* Sends a request to modify start/end date of an event to the server
*/
function updateEventTimes(drag, event, dayDelta, minuteDelta, allDay, revertFunc)
{
delete event.source;
$.post(
"update.php",
event,
function(result) {
if (!result) revertFunc();
}
)
.fail(function() {
revertFunc();
});
};

click prev/next and load new data

I have fullcalendar working fine loading data using json from a flatfile(s).
I would like to load each months data from that months file on clicking prev/next.
Using ajax? events: function( start, end, callback ) addEventSource - removeEventSource? other?
Allow that jQuery is still a work in progress for me.
UPDATE:
I have set:
viewDisplay: function(view) { var next = view.title; alert(next); },
which gives me Month Year on clicking next/prev
How to parse this to json-events.php
I tried [split next] events: "json-events.php?month=month",
nope...
This is not using php, but you can change the AJAX call in getCalData() to do it.
EventSource will be filled with the next data.
I hope this helps a little bit.
$(document).ready(function () {
var calendar = $('#calendar').fullCalendar({
header: {
left: 'prev,next today',
center: 'title',
right: 'resourceMonth'
},
defaultView: 'resourceWeek',
eventSources: [ getCalData() ],
header: {
left: 'prev,next today',
center: 'title',
right: ''
},
viewDisplay: function (view) {
$('#calendar').fullCalendar('removeEvents');
$('#calendar').fullCalendar('addEventSource', getCalData());
$('#calendar').fullCalendar('rerenderEvents');
}
});
});
function getCalData() {
var source = [{}];
$.ajax({
async: false,
url: '/mysite/GetWeekData',
data: { myParam: $('#calendar').fullCalendar('getView').visStart },
success: function (data) {
$(data).each(function () {
source.push({
title: $(this).attr('title'),
start: $(this).attr('start'),
});
});
},
error: function () {
alert('could not get the data');
},
});
return source;
}
fullcalendar by default send 2 additional parameters when getting events, params[:start], params[:end]
u can use them to return queried events between these 2 values
you can just add View Render property to configuration Object of fullcalendar
viewRender: function(view, element) {
//console.debug("View Changed: ",view.start, view.end);
// events = loadevents();
jQuery(nativeelement).fullCalendar('removeEvents');
jQuery(nativeelement).fullCalendar('addEventSource', events);
}
now you can load month by month.
This syntax for angular2

Dynamic resize iframe in FullCalendar

I have Fullcalendar opening in iframe. I have a script from dyn-web.com on parent page that resizes Iframe and this works fine most of the time:
function setIframeHeight(id) {
var ifrm = document.getElementById(id);
var doc = ifrm.contentDocument ? ifrm.contentDocument : ifrm.contentWindow.document;
ifrm.style.visibility = 'hidden';
ifrm.style.height = "10px";
ifrm.style.height = getDocHeight( doc ) + 5+"px";
ifrm.style.visibility = 'visible';
}
When I open the calendar initially it resizes fine, but when I select another month that has a longer page render, it will not resize.
How can I invoke the resize on the parent window?
This is the start of my calendar but I cannot figure out the syntax to dynamically call resize. I have played with the height parameter, but it needs to be dynamic:
$('#calendar').fullCalendar({
month: <%=monthStart%>,
year: <%=yearStart%>,
eventSources:
[
{ url: <%=esource%>,
type: 'GET',
error: function() {
alert('there was an error while fetching events!');
}
},
You need to do something like this:
$('#calendar').fullCalendar({
month: <%=monthStart%>,
year: <%=yearStart%>,
eventSources:
[
{ url: <%=esource%>,
type: 'GET',
error: function() {
alert('there was an error while fetching events! ');
}
},
viewDisplay: function(view) {
parent.setIframeHeight(iframeId) ;
},
The viewDisplay handler is called every time the month/week/day view is changed. You can also use the windowResize handler to capture an event fired after the resize has actually taken place.

Resources