Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

resource sources should receive start/end params #246

Closed
arshaw opened this issue Dec 12, 2016 · 8 comments
Closed

resource sources should receive start/end params #246

arshaw opened this issue Dec 12, 2016 · 8 comments
Milestone

Comments

@arshaw
Copy link
Member

arshaw commented Dec 12, 2016

The resources function should now begin to receive a start, end, and timezone parameter just like events function.

The resources feed should probably also receive these params for the network request, but only if refetchResourcesOnNavigate is enabled.

@arshaw arshaw added the Model label Dec 12, 2016
@arshaw
Copy link
Member Author

arshaw commented Dec 12, 2016

Workaround for the resources function:

resources: function(callback) {
    setTimeout(function() { // necessary hack
        var view = $('#calendar').fullCalendar('getView'); // TODO: update to your selector
        /* use view.start and view.end, which are both moments */
        /* call callback, just like you normally would */
        callback([]);
    }, 0);
}

Workaround for resources as an json feed (relies on a resources function):

resources: function(callback) {
    setTimeout(function() { // necessary hack
        var view = $('#calendar').fullCalendar('getView'); // TODO: update to your selector
        $.ajax({
            url: 'your feed url',
            dataType: 'json',
            cache: false,
            data: {
                start: view.start.format(),
                end: view.end.format(),
                timezone: view.options.timezone
            }
        }).then(resources) {
            callback(resources);
        });
    }, 0);
}

@kpollardsprypoint
Copy link

Thank you @arshaw !

@gcheema
Copy link

gcheema commented Dec 12, 2016

+1

@CraigHoneyfieldIS
Copy link

CraigHoneyfieldIS commented Dec 19, 2016

I noticed when I try to get the start date as mentioned above for resources, the date returned by
view.start.format(); = the prior date that the user was viewing, it's not the new date that is clicked on to navigate to.

I'm using the j-query calendar as a navigator and setting the date via
$('#calendar').fullCalendar('gotoDate', d);
View the JSBIN here

Any suggestions?
EDIT

I figured this out. You should be using:
$('#calendar').fullCalendar('getDate');
to get the date. This seems to work better.

@Spartaseventy
Copy link

Spartaseventy commented Dec 30, 2016

I have the same problem of @CraigHoneyfieldIS.
I need to refetch resources (and events) on day change and view change, but i'm encountering various problem.
This is my script code

`$(document).ready(function(){
		var $calendar = $("#calendar");
		$calendar.fullCalendar({
			schedulerLicenseKey: "GPL-My-Project-Is-Open-Source",
			editable: true,
			allDaySlot: false,
			aspectRatio: 2,
			scrollTime: "00:00",
			minTime: "00:00:00",
			slotDuration: "00:15:00",
			slotLabelFormat: "H:mm",
			slotWidth: "10%",
			timeFormat: "H:mm",
			header: {
				left: "today prev,next",
				center: "title",
				right: "timelineDay,agendaWeek,month,listWeek"
			},
			defaultView: "timelineDay",
			refetchResourcesOnNavigate: true,
			resourceLabelText: "Siti",
 			resourceGroupField: "site",
			resourceAreaWidth: "25%",
			resources: function(callback) {
			    var view = $("#calendar").fullCalendar("getView");
			    $.ajax({
					url: "myurl",
					dataType: "json",
					cache: false,
					data: {
						start: view.start.format(),
						end: view.end.format(),
						timezone: view.options.timezone
					}
				}).then(function(resources) {
					callback(resources);
				})
			}
		});
	})`

but on load i have this error in console view.start is null
If i add a condition to check if value of start and end of view is null bypassing error i show the resources but when i change day or view the date returned by view.start or view.end or view.intervalStart or view.intervalEnd are the prior date that the user was viewing, it's not the new date that is clicked on to navigate to.
It's a bug or i make same mistakes?

I take this opportunity to wish you happy new year

Thanks

@arshaw
Copy link
Member Author

arshaw commented Jan 3, 2017

@CraigHoneyfieldIS thanks, I understand the issue. I'll make a real fix for this soon, but a good ol' setTimeout will actually solve the problem. JSBin proof: http://jsbin.com/hiwidavixo/1/edit?js,output.

I have updated my previously posted sample code to include the timeout hack.

@margusarm
Copy link

margusarm commented Jan 10, 2017

there's a little mistake I believe in the json feed example. it gave me errors. this works:

resources: function(callback){
					setTimeout(function(){
					var view = $('#calendar').fullCalendar('getView');
					$.ajax({
            url: 'your feed',
            dataType: 'json',
            cache: false,
            data: {
                start: view.start.format(),
                end: view.end.format(),
                timezone: view.options.timezone
				}	
			}).then(function(resources){callback(resources)});					
		},0);
	}

@arshaw arshaw added this to the 1.5.1 milestone Feb 12, 2017
@arshaw arshaw changed the title event sources should receive start/end params resource sources should receive start/end params Feb 14, 2017
@arshaw arshaw closed this as completed Feb 14, 2017
jzaburunov added a commit to jzaburunov/groupcal that referenced this issue Nov 6, 2019
We need it since we are using interval start and end on resource fetching ( see fullcalendar/fullcalendar-workspace#246)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants