how to call ajax popup from CMENU with control statying in the current page

Hi All,

I am struck creating a JavaScript/AJAX popup within CMENU. I want to implement a popup saying under construction when a CMENU item is clicked. I looked into itemOptions & linkOptions in CMENU but i could not understand what to do with it.

Please suggest me a solution.

Have nice day. Thank you.

Regards,

Krupa Sagar.

This is something CMENU itself cannot accomplish.

I would simply use Fancybox Yii Extension or an equivalent one to show a popup on demand and use CMENU’s “url” property to trigger that popup. Assuming you would go with Fancybox, the sample code for the same could be as below: (ofcourse, install the fancybox extension before you begin).

Embed this on the view file where your CMenu resides:




  <a href="/site/comingsoon" style="display: none;" id="coming-soon-popup-trigger" title="Coming Soon">Invisible</a>

  <?php    

  $this->widget('application.extensions.fancybox.EFancyBox', array(

    'target'=>'a#coming-soon-popup-trigger',

    'config'=>array(

      //'modal'=>true,

      'centerOnScroll'=>true,

    ),

  )); ?>



Your CMENU needs to have the “url” property set to “$(‘a#coming-soon-popup-trigger’).click();” - example below:




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

        'items'=>array(

          array('label'=>'Coming Soon', 'url'=>"$('a#coming-soon-popup-trigger').click();"),

        ),

      );



In this example, the popup contents are fetched from "/site/comingsoon"; Controller code for the same could be:




class SiteController {

  public function actionComingsoon() {

    $this->renderPartial('comingsoon');

  }

}



And the corresponding view - protected/views/site/comingsoon.php could be a standard HTML file, containing the actual popup contents.

Hi Rajan,

Thank you for the suggestion. But i am going wrong somewhere.

I am getting the following error

[i]Forbidden

You don’t have permission to access /my - site - name /$("a on this server.[/i]

for your reference:

view file:




<a href="/site/comingsoon" style="display: none;" id="coming-soon-popup-trigger" title="Coming Soon">Invisible</a>

					  <?php    

					  $this->widget('application.extensions.fancybox.EFancyBox', array(

						'target'=>"a#coming-soon-popup-trigger",

						'config'=>array(

						  //'modal'=>true,

						  'centerOnScroll'=>true,

						),

					  ));

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

						'items'=>array(

						array('label'=>'coming soon', 'url'=>'$("a#coming-soon-popup-trigger").click();'),						

						),												

					)); ?>	 



Regards,

Krupa Sagar.

Hi,

Probably you might have to add a prefix "javascript:" to the "url" part.

Example:




<?php

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

    'items'=>array(

      array('label'=>'coming soon', 'url'=>'javascript:$("a#coming-soon-popup-trigger").click();'),			    		

 	),									    		

   )); ?>



Rajan,

Lots & lots of thank you. I am getting the pop up now. But not as desired,I will just make it to work or else help me.

Thank you.

Regards,

Krupa Sagar.

Rajan,

One more issue. Well in the pop up i am getting requested content is not available & try later in Chrome. But in Firefox i am getting a black page with [Object][Object] in it. :blink:

Regards,

Krupa Sagar.

Looks like a missing code in the Controller (SiteController in this case). I would suggest to first make the EFancyBox (or an equivalent popup module) work independently - typically by following the examples provided with the module, with a visible LINK on the page where CMenu will reside.

You could simply “click” on that link and make the Popup appear properly. Once that’s done, simply HIDE the link and trigger it using a CMenu item.

Hi Rajan,

can you help me removing or hiding the above CMenu from the view inside fancybox…

Thanks

If you meant: How to get rid of full site’s theme, including the main menu, header, footer… Then you should be using $this->renderPartial() instead of $this->render() on the Controller/Action that generates the popup content.