How To Avoid Duplicate Script Download In Ajax Tab

Hi,

I have a view with a dropdownlist that I load in a CjuiTabs tab with its own ajax command.

I need to load the dropdownlist’s script on the first render, but on subsequent renders (such as when the tab is clicked again after moving to another tab) I only need to renderPartial to avoid loading the script again.

The problem is: how do you determine which is the first render and which is a subsequent render, since all requests are ajax requests?

Any ideas?

Hi,

can you post the code?

The view hosts a normal CJuiTabs with two tabs. The first tab (Data-Fields) is displayed on default. The second tab (Levels) only loads when the user clicks on the tab - via a separate controller action. This action uses a normal render or renderPartial. The question is when to render and when to renderPartial. I only want to render on the first instance that the user clicks the tab. All other subsequent clicks on the tab must result in renderPartial.




$tabs = array();


$tabs['Data Fields'] = array(

	'id'=>'Data-Fields',

	'content'=>$this->renderPartial('//'.$extract.'/form1_t1_a',

		array(

			'form' => $form,

			'parent_model'	=> $parent_model,

			'child_model_tr1_1' => 	$child_model_tr1_1,

		),

	true),

);


$prms=array(

	'parentId' => $parentId

);


$tabs['Levels (required)'] = array(

	'id'=>'Levels',

	'ajax'=>$this->createUrl('trn1_mct/createmm2', $prms),

);


/* Options for ALL tabs */

if($showAllTabs == true)

{

	$options = array(

		'collapsible' => false,

		'beforeActivate'=>"js:function(event, ui){

			loadingGif_in();

		}",

		'activate'=>"js:function(event, ui){

			loadingGif_out();

		}",

	);

}

else

{

	$options = array(

		'collapsible' => false,

		'beforeActivate'=>"js:function(event, ui){

			loadingGif_in();

		}",

		'activate'=>"js:function(event, ui){

			loadingGif_out();

		}",

		/* Disable all tabs except the first tab */

		'create'=>"js:function(event, ui){

			$( '#icTab' ).tabs( 'disable' );

			$( '#icTab' ).tabs( 'enable', 0 );

		}",

	);

}


$this->widget('zii.widgets.jui.CJuiTabs', array(

	'id'		=> 'icTab',

	'tabs' 		=> $tabs,

	// additional javascript options for ALL tabs

	'options' 	=> $options,

));



Hi,you can pass a hidden paramater on first tab page when you click on second time get this parameter.

like e.g.


 if (isset($_REQUEST['type'])) {

            $this->renderPartial('/tab1/', $params, false, true);

            

        } else {

            $this->render('/tab1/', $params, false, true);

        }

Hi, I also thought about hidden parameters. So the first click on the tab will not include the parameter, while subsequent clicks will. But how do you include a non-existing parameter (the tab is not yet created) in this url? Maybe a js test to determine if the tab already has a view in it?




$prms=array( 

        'parentId' => $parentId 

); 

 

$tabs['Levels (required)'] = array( 

        'id'=>'Levels', 

        'ajax'=>$this->createUrl('trn1_mct/createmm2', $prms), 

);



Check this wiki