Change defaults on calendar object

Posted by jsniemi79 on 26-Sep-2014 07:35

I'd like to change the default for the types of records displayed as well as display only my tasks and events by default.  Is there a way to change these onload of the tab since they aren't in the calendar configuration?

All Replies

Posted by Godfrey Sorita on 26-Sep-2014 09:47

Hi Jason,

I have verified that the filter options are not available in the configuration of the calendar component. You can post this as an enhancement request to the ideas section of Rollbase.

I will check for a workaround solution to this limitation and let you know how it goes.


Regards,
Godfrey

Posted by jsniemi79 on 26-Sep-2014 09:51

I thought that might be the case. I'm hoping I can write something in the on load section of that tab to change the value in the interim.  If you find something, please advice.

Thanks,

Jason

Posted by Godfrey Sorita on 09-Oct-2014 13:46

Adding a code to the onload section of the calendar page does not actually solve the problem because the calendar component takes a few seconds to load completely. A part of the code could run prior to the loading of the calendar component.

Even so, I was able to find a workaround using undocumented functions from the JS libraries used by Rollbase. Please paste the code below your calendar:

<script type="text/javascript">
function setCalendarFilters() {
	/* 
	Description: Use to set 'Show' filter
	Possible values for objectFilter variable:
	 1. -1 => All Tasks & Events
	 2. -10 => All Tasks
	 3. -20 => All Events
	 4. <Object Definition ID> => Specific Object(e.g 110006390) 
	*/
	var objectFilter = '110006358';
	$("#rbe_objectsFilter").val(objectFilter);
	
	/* 
	Description: Use to set 'Assigned To' filer
	Possible values for assignedToFilter variable:
	 1. Me => Only Me
	 2. ALL_USERS => Any Users
	 3. R<Role ID> => Specific role(e.g R90)
	 4. G<Group ID> => Specific group(e.g G110007529)
	*/
	var assignedToFilter = 'R90';
	$("#rbe_assignedToFilter").val(assignedToFilter);
	
	rbf_refreshData();
}

rbf_addOnLoadMethod(setCalendarFilters);
</script>

Note: You will have to manually change the value objectFilter and assignedToFilter variables depending on the filter you need. 

Please remember that undocumented functions can change between major version releases. Its usage is not recommended but so far this is the only workaround solution I can provide.

Posted by jsniemi79 on 09-Oct-2014 19:10

I added this code as a script component on the home page below my calendar.  It appears to correctly change the values in the combo boxes, but the calendar refresh finished first and had data based on the default values.  Am I missing something in how I have this set up?

Posted by Godfrey Sorita on 13-Oct-2014 10:01

The workaround was setup correctly because the result you had is the expected behavior. The code updates the default filter and then reloads the calendar using the new filter values.

Posted by jsniemi79 on 13-Oct-2014 10:07

This isn't reloading with the new filters.  It still shows the old data based on any users.

My initial login shows the combo boxes are correctly defaulted to the values I set in the script component. However, the date showing in tasks on the calendar below is not for my user.

Now if I click on my browser refresh, the combo boxes are still defaulted correctly and the tasks are updated to remove those that aren't mine. 

This is what I want to happen upon initial login.

Make sense?

Posted by Godfrey Sorita on 13-Oct-2014 11:54

Please replace the content of the script component with the code below:

<script type="text/javascript">
function setCalendarFilters() {
	/* 
	Description: Use to set 'Show' filter
	Possible values for objectFilter variable:
	 1. -1 => All Tasks & Events
	 2. -10 => All Tasks
	 3. -20 => All Events
	 4. <Object Definition ID> => Specific Object(e.g 110006390) 
	*/
	var objectFilter = '110006358';
	$("#rbe_objectsFilter").val(objectFilter);
	
	/* 
	Description: Use to set 'Assigned To' filer
	Possible values for assignedToFilter variable:
	 1. Me => Only Me
	 2. ALL_USERS => Any Users
	 3. R<Role ID> => Specific role(e.g R90)
	 4. G<Group ID> => Specific group(e.g G110007529)
	*/
	var assignedToFilter = 'Me';
	$("#rbe_assignedToFilter").val(assignedToFilter);
}


rbf_addOnLoadMethod(setCalendarFilters);
rbf_addOnLoadMethod(rbf_refreshData);
</script>

Let me know if it works.

Posted by jsniemi79 on 13-Oct-2014 12:33

Unfortunately it is still not working.  Same result.

Posted by wytkat28 on 15-Oct-2014 12:55

I'm experiencing the same situation, but the page loads with the correct filters set and applied for about 2.5 seconds, then it pulls in all tasks and events for all users (defaults). I have tried adding the code to both the page onload and as a script component, but it didn't make a difference.

Posted by jsniemi79 on 15-Oct-2014 12:58

Mine does the same thing.  It appears to happen at login that way for me. If I refresh the page after login, it correctly displays.  

Posted by Godfrey Sorita on 15-Oct-2014 14:57

Adding a 1-second delay on the code might do the trick. Please try the code below and adjust the 'delayInMilliseconds' as needed:

<style>body { display: none; }</style>
<script type="text/javascript">
function setCalendarFilters() {
	/* 
	Description: Use to set 'Show' filter
	Possible values for objectFilter variable:
	 1. -1 => All Tasks & Events
	 2. -10 => All Tasks
	 3. -20 => All Events
	 4. <Object Definition ID> => Specific Object(e.g 110006390) 
	*/
	var objectFilter = '-20';
	$("#rbe_objectsFilter").val(objectFilter);
	
	/* 
	Description: Use to set 'Assigned To' filer
	Possible values for assignedToFilter variable:
	 1. Me => Only Me
	 2. ALL_USERS => Any Users
	 3. R<Role ID> => Specific role(e.g R90)
	 4. G<Group ID> => Specific group(e.g G110007529)
	*/
	var assignedToFilter = 'Me';
	$("#rbe_assignedToFilter").val(assignedToFilter);
}

function delayedRefresh() {
	delayInMilliseconds = 1000;
	setTimeout(function() {
		rbf_refreshData();
		$('body').show();	
	}, delayInMilliseconds);
}

rbf_addOnLoadMethod(setCalendarFilters);
rbf_addOnLoadMethod(delayedRefresh);
</script>

Posted by wytkat28 on 15-Oct-2014 16:39

It seems that a 3500 millisecond delay has been working pretty consistently so far without being too intrusive. 4000 milliseconds was a bit annoying, but it does refresh the whole page.  Can $('body').show(); be replaced with whatever designates the calendar component?

Posted by jsniemi79 on 15-Oct-2014 16:59

That did it for me.  Thank you very much for your help.

Posted by Godfrey Sorita on 15-Oct-2014 17:13

This version hides the section of the calendar component instead of the whole body. Since the code used to hide the calendar component is JavaScript, there might be a short execution delay. 

<script type="text/javascript">
calendarSectionName = 'Calendar';

function setCalendarFilters() {
	/* 
	Description: Use to set 'Show' filter
	Possible values for objectFilter variable:
	 1. -1 => All Tasks & Events
	 2. -10 => All Tasks
	 3. -20 => All Events
	 4. <Object Definition ID> => Specific Object(e.g 110006390) 
	*/
	var objectFilter = '-20';
	$("#rbe_objectsFilter").val(objectFilter);
	
	/* 
	Description: Use to set 'Assigned To' filer
	Possible values for assignedToFilter variable:
	 1. Me => Only Me
	 2. ALL_USERS => Any Users
	 3. R<Role ID> => Specific role(e.g R90)
	 4. G<Group ID> => Specific group(e.g G110007529)
	*/
	var assignedToFilter = 'Me';
	$("#rbe_assignedToFilter").val(assignedToFilter);
}

function delayedRefresh() {
	delayInMilliseconds = 1000;
	setTimeout(function() {
		rbf_refreshData();
		$("div[name='"+calendarSectionName+"']").show();	
	}, delayInMilliseconds);
}

$("div[name='"+calendarSectionName+"']").hide();
rbf_addOnLoadMethod(setCalendarFilters);
rbf_addOnLoadMethod(delayedRefresh);
</script>

Please change the value of 'calendarSectionName' with the section name of calendar component.

This thread is closed