tabs on admin pages. How to remember tab with session?

For Joomla! 3.x Coding related discussions, please use: http://groups.google.com/group/joomla-dev-general

Moderator: ooffick

Forum rules
Please use the mailing list here: http://groups.google.com/group/joomla-dev-general rather than this forum.
Locked
User avatar
carsten888
Joomla! Ace
Joomla! Ace
Posts: 1224
Joined: Sat Feb 11, 2006 8:32 am
Contact:

tabs on admin pages. How to remember tab with session?

Post by carsten888 » Mon Nov 17, 2014 8:47 am

I could not find any documentation about tabs on admin pages, so I copy-pasted code from the banners component.

Code: Select all

<?php echo JHtml::_('bootstrap.startTabSet', 'myTab', array('active' => 'details'); ?>

		<?php echo JHtml::_('bootstrap.addTab', 'myTab', 'details', JText::_('COM_BANNERS_BANNER_DETAILS', true)); ?>
		details
		<?php echo JHtml::_('bootstrap.endTab'); ?>

		<?php echo JHtml::_('bootstrap.addTab', 'myTab', 'otherparams', JText::_('COM_BANNERS_GROUP_LABEL_BANNER_DETAILS', true)); ?>
		otherparams
		<?php echo JHtml::_('bootstrap.endTab'); ?>

		<?php echo JHtml::_('bootstrap.addTab', 'myTab', 'publishing', JText::_('JGLOBAL_FIELDSET_PUBLISHING', true)); ?>
		publishing
		<?php echo JHtml::_('bootstrap.endTab'); ?>

		<?php echo JHtml::_('bootstrap.endTabSet'); ?>
That gives tabs.
To link to a specific tab, I guess I'll have to set the active tab with this:

Code: Select all

array('active' => 'details')
But how to do this with sessions?

Obviously one could read the session and set the corresponding tab in the above code, but how to make the tabs set the session so the user clicks on a tab, goes to another page and when comes back the same tab is open.

Used to work so well with panels in the past.
Last edited by carsten888 on Tue Nov 18, 2014 7:55 am, edited 1 time in total.
http://www.pages-and-items.com my extensions:
User-Private-Page, Redirect-on-Login, Admin-Help-Pages, Dynamic-Menu-Links, Admin-Menu-Manager, plugin load module in article, plugin pure css tooltip and more...

 
User avatar
carsten888
Joomla! Ace
Joomla! Ace
Posts: 1224
Joined: Sat Feb 11, 2006 8:32 am
Contact:

Re: tabs on admin pages. How to remember tab with session?

Post by carsten888 » Tue Nov 18, 2014 7:54 am

Solved!

I created this workaround.

With jquery add an extra click-event to the tabs:

Code: Select all

var JNC_jQuery = jQuery.noConflict();
JNC_jQuery(function($){
$('#myTabTabs a').click(function(e){
do_tab_session('myTab',this.href);
});
});
The click runs a javascript that does an ajax call:

Code: Select all

function do_tab_session(id, href){	
	pos_tabname = href.indexOf("#");
	href_length = href.length;
	tabname = href.substring(pos_tabname+1, href_length);
	var JNC_jQuery = jQuery.noConflict();	
	ajax_url = "index.php?option=com_helppages&task=cookie_save&format=raw&id="+id+"&active="+tabname;		
	JNC_jQuery.ajax({	  
		url: ajax_url	   
	});	
}
in the controller the ajax function sets the session:

Code: Select all

function cookie_save(){
	
		$app = JFactory::getApplication();		
		$id = JRequest::getVar('id', '');
		$active = JRequest::getVar('active', '');		
		$app->setUserState("com_helppages.tab_".$id, $active);
	}
I hope this helps someone AND this gets integrated in the bootstrap.startTabSet script.
http://www.pages-and-items.com my extensions:
User-Private-Page, Redirect-on-Login, Admin-Help-Pages, Dynamic-Menu-Links, Admin-Menu-Manager, plugin load module in article, plugin pure css tooltip and more...

 

Locked

Return to “Joomla! 3.x Coding”