Cannot close CJuiDialog from controller

Hello All,

I am having problem with closing CJuiDialog from pageStaticLinks/add controller. The code is to add a new entry to the database when a user clicks on button ‘Add New Link’. Ajax, json CJUIDialog are used to create the popup window and to interact with the actionAdd method. After save, it should close the popup, but it is not working.

Here is the step by step code files in my application.

_links.php view


 

<div class="row buttons prepend-top">

    <?php

      echo CHtml::button('Add New Link',

          array('class'=>'button center span-3', 'onclick' =>'{addLink();}'));

    ?>


    <script type="text/javascript">

      function addLink()

      {

          <?php

              echo CHtml::ajax(array(

                  // the controller/function to call

                  'url'=>CController::createUrl('pageStaticLinks/checkLink',

                      array("pageId"=>$this->page->id,)

                  ),


                  // Data to be passed to the ajax function

                  'data'=>array('url'=>'js:$(\'#StaticLink_static_link_url\').val()',

                                'linkOrder'=>'js:$(\'#PageStaticLink_link_order\').val()',

                                'asDialog'=>1,

                                'gridId'=>'linkGrid',

                               ),

                  'type'=>'post',

                  'dataType'=>'json',

                  'success'=>"function(data)

                  {

                      //open popup

                      if(data.popup == 1)

                      {

                        $('#cJuiFrame').attr('src',data.createUrl);

                        $('#cJuiDialog').dialog('open');

                        return false;

                      }


                      if (data.error=='FALSE')

                      {

                         //no error so refresh grid on this page

                         $.fn.yiiGridView.update('linkGrid');


                         //if no errors, open popup

                      }

                  } ",

              ))?>;

          return FALSE;

      }

    </script>

  </div>

  

 

<?php

 

  $this->beginWidget('zii.widgets.jui.CJuiDialog', array(

    'id'=>'cJuiDialog',

    'options'=>array(

        'title'=>'[Add | Edit] link for [all pages of type: $page_type | individual page: $page_title]',

        'autoOpen'=>FALSE,

        'modal'=>TRUE,

        'width'=>750,

        'height'=>260,

    ),

  ));

?>


<iframe id="cJuiFrame" width="100%" height="100%">

  <?php echo $this->renderPartial('_linkForm'); ?>

</iframe>


<?php $this->endWidget(); ?>

<div class="clear"></div>

_linkForm.php view




<?php 

  $model = $this->vh->addLinkModel;

?>

<div style="width:auto;height:auto; font-size: 75%;">


  <p>

    <em>Fields with <span class="required">*</span> are required.</em>

  </p>


  <?php 

    $form = $this->beginWidget('CActiveForm', array(

        'id' => 'pageLinkForm',

        'enableClientValidation' => TRUE,

        'enableAjaxValidation' => TRUE,

        'clientOptions' => array(

            'validateOnSubmit' => TRUE,

        ),

    ));

  ?>


  <div class="span-10 colborder append-bottom dialog-form-text">

    <div class="row">

      <?php echo $form->labelEx($model->staticLinks, 'static_link_title'); ?>

      <?php echo $form->textField($model->staticLinks, 'static_link_title', array('class' => 'static-link-title')); ?>

      <?php

        echo Yii::app()->tooltips->set(array('title' => 'Name of the url.  Must be unique.'));

      ?>

      <?php echo $form->error($model->staticLinks, 'static_link_title'); ?>

    </div>

    

    <div class="row">

      <?php echo $form->labelEx($model->staticLinks, 'static_link_url'); ?>

      <?php echo $form->textField($model->staticLinks, 'static_link_url', array('class' => 'static-link-url')); ?>

      <?php echo $form->error($model->staticLinks, 'static_link_url'); ?>

    </div>

  </div>


  <div class="span-5 last">

    <div class="row">

      <?php echo $form->labelEx($model, 'link_order'); ?>

      <?php echo $form->textField($model, 'link_order', array('class' => 'static-link-title')); ?>

      <?php echo $form->error($model, 'link_order'); ?>

    </div>

    <div class="row buttons prepend-top">

      <?php echo CHtml::submitButton('Save', array('class' => 'span-2 button center save'));

            echo CHtml::link('Cancel','#',array('class' => 'span-2 button center cancel'));   ?>

    </div>

  </div>

  <?php $this->endWidget(); ?>

</div>



pageStaticLinksController.php




/**

   * this has no view

   */

  public function actionCheckLink($pageId)

  {

    if (Yii::app()->request->isAjaxRequest)

    {

      // Get params from ajax call.

      $url = $_POST['url'];

      $linkOrder = $_POST['linkOrder'];

      $gridId = $_POST['gridId'];


      if (empty($url))

      {

        //No url has been entered so send the error back to the form

        echo CJSON::encode(array(

          'error' => 'TRUE',

          'status' => 'Please enter a url', //currently this is not in use, we need to set error labels text

        ));


        //exit

        Yii::app()->end();

      }

      else

      {

          $param = array('pageId' => $pageId, 'asDialog' => 1, 'gridId' => $gridId, 'urlToCheck' => $url, 'linkOrder' => $linkOrder);

          $createUrl = $this->createUrl('pageStaticLinks/add', $param);

          //open popup code with prefilled url and order fields.

          echo CJSON::encode(array(

            'createUrl' => $createUrl,

            'popup' => 1, //open popup

          ));

      }

    }

  }


  /**

   * Action to perform add on PageStaticLinks.

   *

   * @param integer $pageId Page id

   * @param integer $staticLinkId Optional.  If no static link id is provided, it will process as

   * a new static link.

   */

  public function actionAdd($pageId, $staticLinkId = NULL)

  {

    if (isset($_POST['PageStaticLink']))

    {

      $pslModel = new PageStaticLink();

      $pslModel->setAttributes($_POST['PageStaticLink']);

      $result = $pslModel->save;


        if ($result)

        {

          Yii::app()->user->setFlash('OK', 'Link has been Added successfully.');

          //**************Close the dialog, update the grid  ********* THE CODE BELOW IS NOT WORKING ********** ///

          echo CHtml::script("window.parent.$('#cJuiDialog').dialog('close');window.parent.$('#cJuiFrame').attr('src','');window.parent.$.fn.yiiGridView.update('{$_GET['gridId']}');");

          // echo CHtml::script("popUp('{$_GET['gridId']}');");

          Yii::app()->end();

        }

        else

        {

          Yii::app()->user->setFlash('ERR', 'Error saving url to page.');

        }

      }

    }


   // some code ..


    $this->render('_linkForm');

  }




found the problem…

deleting the following lines from _link.php view solves the issue




        'clientOptions' => array(

            'validateOnSubmit' => TRUE,

        ),