Render A View Page In Cjuidialog Widget?

Hi…

Is it possible to render a view file inside the dialog pop up.? If so can someone give me an insight into how the controller part would look like ?

Controller :




public function actionNewstaff() {	


	$this -> layout = 'main';

        $this->render('newstaff');//,  array('model' => $model));


	}



View :







<?php


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

    'id'=>'mydialog',

    // additional javascript options for the dialog plugin

    'options'=>array(

        'title'=>'Dialog box 1',

        'autoOpen'=>false,

        'height'=>500,

        'width'=>800,

        'top'=>50,

        'left'=>50,

    ),

));


$this->renderPartial('view', array('model'=>$model));

$this->endWidget('zii.widgets.jui.CJuiDialog');





?>



I am not sure how to go about the model part in controller. Just include all the contents of the other controller? … Im just getting my way around yii… :(

Nothing ??

In your view you can render another view with passing what You need to your second view. Your controller can pass to your view (first one) more than one variable, and you can use this variables everywhere you want. If variable exist in first view you can pass it to another.

I dont really understand where is the problem here, so maybe I solve your problem maybe not, if not please describe it one more time :)

it is possible. did you get any error?

No… Let me explain more :

My controller :




//Admin Staff Management - New

public function actionNewstaff() {		

		

//$model = new Healthcareproviders;


$model = new StaffmanagementForm('add');


if(Yii::app()->request->isPostRequest) { 

 $model->attributes = Yii::app()->request->getPost('StaffmanagementForm');  

  if($model->validate()) {

    $mob_userId = AdminAPI::getInstance()->createstaff($model->attributes);

    Yii::app()->user->setFlash('message', 'New Staff has been Added successfully.');

    this->redirect(array('user/staffmanagement'), array('model' => $model));

  }

  else{

    $model->status = 1;

  }

 }

 $this -> layout = 'main';

 $this->render('newstaff', array('model' => $model));

}



View :




<div class="staff-add-holder">


 <!--staff-add-holder start-->

 <label>Service Provider*</label>


 <input type="text" value="" class="field" name="StaffmanagementForm[mob_organisationId]"  id="StaffmanagementForm_mob_organisationId" name="Service Provider" placeholder="Search and select service provider"/>


 <a title="Click to search and select service providers" class="search-btn" onClick='$("#mydialog").dialog("open"); return false;'>Search</a>


 <div class="success org">

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

 </div>


</div><!--staff-add-holder end-->




I have contents for the form, but how do i call another model for the contents that has to be filled inside the pop-up when clicking the button :




<a title="Click to search and select service providers" class="search-btn" onClick='$("#mydialog").dialog("open"); return false;'>Search</a>



This would open up a pop-up where i have to list contents from another table. This is already done as a page separately(different controller, model, view - )


//$model = new Healthcareproviders;

and it works fine. But how can i include the same details to the pop-up part in this controller.

. I am not sure whether im clear enough…:(

if i want to submit one form in cjuidialog, i will use iframe concept with cjuidialog. i will load new form via ajax inside iframe of cjuidialog

i added details here

http://www.bsourcecode.com/tag/yii-iframe

Otherwise i dont have idea.

I am still not sure if I get you correctly. But I will try :D

You want to display Healthcareproviders model in your dialog ?

If yes, you can try:

Controller:


//Admin Staff Management - New

public function actionNewstaff() {              

                

$model2 = new Healthcareproviders; // another model to pass to view


$model = new StaffmanagementForm('add');


if(Yii::app()->request->isPostRequest) { 

 $model->attributes = Yii::app()->request->getPost('StaffmanagementForm');  

  if($model->validate()) {

    $mob_userId = AdminAPI::getInstance()->createstaff($model->attributes);

    Yii::app()->user->setFlash('message', 'New Staff has been Added successfully.');

    this->redirect(array('user/staffmanagement'), array('model' => $model));

  }

  else{

    $model->status = 1;

  }

 }

 $this -> layout = 'main';

 $this->render('newstaff', array('model' => $model, 'model2'=>$model2));

}

And in your view:


<?php

...

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

    'id'=>'mydialog',

    // additional javascript options for the dialog plugin

    'options'=>array(

        'title'=>'Dialog box 1',

        'autoOpen'=>false,

        'height'=>500,

        'width'=>800,

        'top'=>50,

        'left'=>50,

    ),

));


$this->renderPartial('second_view', array('model2'=>$model2)); //please remember to define your view name

$this->endWidget('zii.widgets.jui.CJuiDialog');

...

?>

And in your second_view file you do all the magic. Dont forget do add this file

This is great…Got it working… Thanks a lot for the help…:)

Is it possible to make the pop-up stay ?

I mean i am using a Cgridview in the Cuidialog pop-up… The grid view has sorting and pagination. Although the sorting and pagination works, the pop-up closes as soon as i click on sorting/pagination. when i reopen the pop-up the values are sorted accordingly.

So can i do stop the click function to reload the page?

My view for the pop-up is :







<?php 

                $pageSize=Yii::app()->user->getState('pageSize',Yii::app()->params['defaultPageSize']);

                // we use header of button column for the drop down   


                $widget = $this->widget('zii.widgets.grid.CGridView', array(

                            'id' => 'healthcareproviders-grid',

                            'cssFile' => Yii::app()->baseUrl . '/css/gridview_staffmanagement.css',

                            'dataProvider' => $model2->healthcareprovidersList(),

                            'enablePagination' => true,

                            'ajaxUpdate' => true,

                            'emptyText' => 'No results found.',

                            'template' => '{items}',

                            'pager' => array(

                                'class' => 'LinkPager',

                                'cssFile' => false,

                                'header' => '',

                                'firstPageLabel' => '',

                                'prevPageLabel' => '<img  class="next-btn">',

                                'nextPageLabel' => '<img  class="previous-btn">',

                                'lastPageLabel' => '',

                            ),

                            'columns' => array(

                                array(

                                        'name' => 'id',

                                        'type' => 'raw',

                                        'htmlOptions' => array('class' => 'width40'),

                                        'headerHtmlOptions'=>array('class' => 'width50-12 list-heading-row'),

                                        'header' => 'S/N',

                                        'value' => '$this->grid->dataProvider->pagination->currentPage * $this->grid->dataProvider->pagination->pageSize + ($row+1)',

                                    ),

                                array(

                                    'name' => 'name',

                                    'type' => 'raw',

                                    'htmlOptions'=> array('class'=>'width200'),

                                    'headerHtmlOptions'=>array('class' => 'width200'),

                                    'header' => 'Name',

                                    'value' => '$data->name',

                                ), 

                                array(

                                    'name' => 'type',

                                    'type' => 'raw',

                                    'htmlOptions'=> array('class'=>'width150'),

                                    'headerHtmlOptions'=>array('class' => 'width150'),

                                    'header' => 'Service',

                                    'value' => '$data->type',

                                ), 

                                array(

                                    'name' => 'category',

                                    'type' => 'raw',

                                    'htmlOptions'=> array('class'=>'width150'),

                                    'headerHtmlOptions'=>array('class' => 'width150'),

                                    'header' => 'Category',

                                    'value' => '$data->category',


                                ),

                                array(

                                    'name' => 'sub_category',

                                    'type' => 'raw',

                                    'htmlOptions'=> array('class'=>'width150'),

                                    'headerHtmlOptions'=>array('class' => 'width150'),

                                    'header' => 'Sub Category',

                                    'value' => '$data->sub_category',


                                ),                             

                                array(

                                    'class' => 'CButtonColumn',

                                    'header' => '',

                                    'htmlOptions' => array('class' => 'width100'),

                                    'headerHtmlOptions'=>array('class' => 'width100'),

                                    // 'template' => '<a class="profile-edit-btn" href="/isml/source/portal/index.php/user/editweblink" title="Click to edit web link"></a><a class="delete-btn" href="#" title="Click to delete web link"></a>',

                                    // 'buttons' => array(),

                                    'template' => '{edit}',

                                    'buttons' => array(

                                        'edit' => array(

                                            'label'=>'',     // text label of the button

                                            'url'=>'Yii::app()->createUrl("user/healthcareprovider",  array("id"=>$data->mob_organisationId))',       // the PHP expression for generating the URL of the button

                                            'visible' => '$data->mob_organisationId',

                                            'options'=>array('class'=>'profile-edit-btn'), // HTML options for the button tag


                                        ),                                 

                                    ),

                                ),

                            ),));

               ?>






I am thinking this is possible , but i just dont know how to…