How to switch to a particular week in a FullCalendar jQuery plugin - fullcalendar

I would like to switch to a particular week when a User selects any date.
On selection of the date the full calendar will display the agenda week in which the week resides.
Please suggest how to do it.
Thanks
Prabhanjan

This should work, but I haven't tested it yet. Let me know how it goes...
dayClick: function(date){
$("#calendar").fullCalendar('changeView', 'agendaWeek')
.fullCalendar('gotoDate', date);
}
And if your using select there is a problem when trying to use both so this should work. Again, it is untested so let me know...
select: function(start){
// you may have to parse the date first aka. var start = Date.parse(start);
$("#calendar").fullCalendar('changeView', 'agendaWeek')
.fullCalendar('gotoDate', start);
}

As of version 2.3.1, fullCalendar does not let you chain commands. In order to achieve what you want is to call it twice.
dayClick: function(date){
$("#calendar").fullCalendar('changeView', 'agendaWeek');
$("#calendar").fullCalendar('gotoDate', date);
}
or
dayClick: function(date){
var $calendar=$("#calendar");
$calendar.fullCalendar('changeView', 'agendaWeek');
$calendar.fullCalendar('gotoDate', date);
}

Related

Fullcalendar permit selectOverlap for one day

I'm using Fullcalendar and I need to allow event overlap for one day: the last still event day can overlap on the first new event day.
For resizing and drop I resolved in this way:
eventOverlap: function(stillEvent, movingEvent) {
var a = movingEvent.start.startOf('day');
var b = stillEvent.end.startOf('day');
if(a.unix() == b.unix()){
return true;
}
return false;
}
Now I need to do the same on selecting, according to documentation, I have to use selectOverlap option by define a function, but differently of eventOverlap, this function not have an argument that include the current selection period, then I don't know how to make the check.
Somebody can say me how to do so?
UPDATE 19/05/2017:
I opened an issue on github's project repository here

Fullcalendar: getting "Va.time is undefined" when trying to assign a moment to event.end

I'm using FullCalendar and it is working fine.
I allow users to drag events, but sometimes I need to force the event to start on a specific date. For example, some events MUST start on a Monday, so if a user drags it to a different weekday, I'll force the event move to the previous Monday.
So, on the eventDrop callback, I have something like:
jQuery('#calendar').fullCalendar({
...
...
eventDrop: function(event, delta, revertFunc) {
if (/*must force new event start date*/) {
var duration = event.end.diff(event.start, 'd');
event.start = moment('2015-07-01');
event.end = moment('2015-07-01').add(duration, 'd');
}
}
})
Some explaining:
I must calculate the original duration, because when I change the
start date, Fullcalendar assumes the end date is the same and changes
the event duration accordingly. So it forces me to assign a new end
date (is there another way to do this?)
assigning a new date to event.start works fine
assigning a new date to event.end always returns:
TypeError: Va.time is undefined
Am I missing something, or maybe overcomplicating things?
Is the error a bug?
Thanks in advance for helping me on this!
Just modify the existing moment like this:
eventDrop: function (event) {
event.start.day(1); //Move the startdate to day 1 (Monday, 0 = Sunday)
event.end.day(1); //Also move the enddate to Monday
}
jsFiddle
I'm not sure what causes the error. It looks like it has to be something to do with setting a new momentjs object in either the event.start or event.end.

Change IETF format to unix timestamp

Hi is there a way to change the time format for the following snipp in fullcalendar?
select: function(startDate, endDate) {
$.fancybox({
\'width\': \'40%\',
\'height\': \'40%\',
\'autoScale\': true,
\'transitionIn\': \'fade\',
\'transitionOut\': \'fade\',
\'type\': \'iframe\',
\'href\': \'test.php/?start=\'+startDate+\'&end=\'+endDate,
});
calendar.fullCalendar(\'unselect\');
}
I want Start & EndDate to be a unix Timestamp.
Thank You
It can be achieved by overriding the "start" and "end" parameter by sending separating Ajax Request inside the FullCalendar.
Take a look at this Similar Thread: add custom params to fullcalendar request

fullcalendar: Get the selected time in Week View

In the Week View, if I select a time period, how do I get the selected time, on the click of a button. Is there a function to call like, getTime or something?
I can get the selected day, by doing something like:
var start = $('#calendar').fullCalendar('getView').visStart;
however, not sure how to get the selected time.
I think the select callback works better than dayClick, because you can get the start date if a range of dates were selected.
select: function(startDate, endDate, allDay, jsEvent, view) {
// here startDate and endDate will give you the date-range selected
}
visStart property only keeps date object of the first visible day.
If you want get clicked date and time you may use dayClick event:
dayClick: function(date, allDay, jsEvent, view) {
//some code here
}
which has date as date object

Drupal hook to change date CCK field value

I need to send out a reminder email the DAY BEFORE a Calendar Event as well as the DAY AFTER. Unfortunately, I can't use Rules Scheduler, because the Tokens can't be manipulated with PHP. It doesn't work if I have
[node:field_event_date-datetime] -1 day
as the scheduled time.
What I've ended up doing is creating two "dummy" date fields for DAY BEFORE and DAY AFTER, and I'm trying to hook into the form, grabbing the event date, using some PHP like strtotime() to add/subtract a day, and make these the values that would go into the database.
I've tried linking to the #submit part of the form, but in phpMyAdmin, all values are NULL.
For this code i haven't even changed the date, I'm just trying to get values to appear in the database.
function mymodule_form_alter(&$form, &$form_state, $form_id) {
if ($form_id == "event_node_form") {
$form['#submit'][] = '_mymodule_after_build';
// Makes the fields invisible
$form["field_event_day_before"]["#access"] = FALSE;
$form["field_event_day_after"]["#access"] = FALSE;
}
}
function _mymodule_after_build($form, &$form_state) {
$eventcopy = array();
// copy the value part from the Event
$eventcopy = $form['field_event_date'][0]['#value'];
// without doing any PHP yet, simply copy the values. Doesn't show up in db.
$form['field_event_day_before'][0]['#value'] = $eventcopy;
dsm($form);
return $form;
}
I've read the tutorials about using Rules Scheduler with CCK and
I'm also following Schedule email to go out based on CCK date field - not working for me
Am I using the right hooks? How do I intercept the inputted date value properly?
I don't think you are approaching your problem the correct way. If you want to try to go down the path you are proposing then you would want to look at hook_nodeapi(). You can add some code for the 'insert' and/or 'save' (or maybe even 'presave') operations so you can update your $node->field_event_day_before'][0]['#value'] and $node->field_event_day_after'][0]['#value'] fields based on the event_date value.
However, you really don't want to add extra fields for date before and date after when you can just calculate those from the event_date.
What I think the better solution is to just implement hook_cron() and have that function handle querying for all events in your database whose event day is TODAY() +1. For all those results, send out an email. Do another query that looks for any event whose event_date is TODAY() - 1 and send out an email for those results. You'll want to make sure you only run this process once in every 24 hour period.
I want to share the answer, thanks to help from the community. If you run into this same problem, try this:
function mymodule_form_event_node_form_alter(&$form, &$form_state) {
// hide these dummy fields, will fill in programatically
$form["field_event_day_before"]["#access"] = FALSE;
$form["field_event_day_after"]["#access"] = FALSE;
}
function mymodule_nodeapi(&$node, $op, $a3 = NULL, $a4 = NULL){
switch ($op) {
//if the node is inserted in the database
case 'insert':
if($node->type == 'event') {
// Day before (+10 hours because I'm in Hawai`i, far from GMT)
$daybefore = strtotime('-1 day +10 hours', strtotime($node->field_event_date[0]['value']));
$daybefore = date('Y-m-j\TH:i:s', $daybefore);
$node->field_event_day_before[0]['value'] = $daybefore;
// Day after (+10 hours because I'm in Hawai`i)
$dayafter = strtotime('+1 day +10 hours', strtotime($node->field_event_date[0]['value']));
$dayafter = date('Y-m-j\TH:i:s', $dayafter);
$node->field_event_day_after[0]['value'] = $dayafter;
}
}
}
The rules scheduler can then take tokens from the day_before/day_after fields, and you can use their interface for scheduling.
You can do this by using the rules module, i did this in my one project, basically you have to create two rules, one for one day before, and another for one day after. Let me know if you want any clarification.
Thanks
K

Resources