CListView with a button in each item view,

I am using a ClistView to display a list of companies. In each view items, I placed button to trigger a CJuiDialog.

In the dialog, we can enter a short message to send to the company in that specific view item.

The situation is a little bit like in the attached picture, but replace the "like" button with a send message button which will bring up an CJuiDialog.

My question is, how do I tell the dialog (CJuidialog) the company ID(or name) that I want to send message to?

I am stuck here. Please help!

Maybe my approach is not conventional, or even awkward, feel free to tell other solutions on your mind. Thank you!

  • Nick

Is it not simple?

As we have a itemView option in the CListView. We can set the item template there so see the desired results.

In each of the itemView, we can set a function as CallJuiDialog to call the JUIDialog.

Have a look at the topic http://www.yiiframework.com/forum/index.php?/topic/8297-pass-a-variable-into-juidialog/ regarding passing values to JUIDialog.

sounds simple to other people, and to me, but I just couldn’t do it.

Can you expand it a little bit? I can’t understand what you mean…

Thanks~

This is the part of application, I am working on. Hope this will help you, too.




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

	'id'=>'country-states-grid',

	'dataProvider'=>$states,

        'enablePagination'=>false,

	'columns'=>array(

		array(

                    'name'=>'name',

                    'type'=>'raw',

                    'value'=>'Chtml::link($data->name,array("viewstate","id"=>$data->id))'

                    ),

		array(

                    'name'=>'status',

                    'type'=>'raw',

                    'value'=>'Country::getstates($data->status)'

                ),            

array

(

    'class'=>'CButtonColumn',

    'template'=>'{update}{delete}',

    'buttons'=>array

    (

        'update' => array

        (

            'label'=>'Edit',

            'url'=>'Yii::app()->createUrl("/admin/country/updatestate",array("id"=>$data->id,"country_id"=>$data->country_id))',

            'click'=>"function(){

                UIDialog._update_url= $(this).attr('href');                

                UIDialog();             

                $('#uidialog').dialog('open'); return false;}"

        ),

        'delete' => array

        (

            'label'=>'Delete',

            'url'=>'Yii::app()->createUrl("/admin/country/deletestate",array("id"=>$data->id,"country_id"=>$data->country_id))',

        ),        

    ),

)

	),

)); 


?>




<?php

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

    'id'=>'uidialog',

    'options'=>array(

        'title'=>$model->name.' - States/Provinces',

        'autoOpen'=>false,

        'modal'=>true,

        'width'=>550,

        'height'=>470,

    ),

));?>

<div class="divdialog"></div>

 

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

 

<script type="text/javascript">

function UIDialog()

{

    // public property

    var _update_url;

 

    <?php echo CHtml::ajax(array(

        'url'=>'js:UIDialog._update_url',

        'data'=> "js:$(this).serialize()",

        'type'=>'post',

        'dataType'=>'json',

        'success'=>"function(data)

            {

                if (data.status == 'failure')

                {

                    $('#uidialog div.dialog').html(data.div);

                    // Here is the trick: on submit-> once again this function!

                    $('#uidialog div.dialog form').submit(UIDialog);

                }

                else

                {

                    $('#uidialog div.dialog').html(data.div);

                    $.fn.yiiGridView.update('country-states-grid');                     

                    $('#uidialog').dialog('close');


                   

                }

 

        } ",

    ))?>;

    return false;

 

}




 

</script>



In Controller




	public function actionUpdatestate($id)

	{

		$model=$this->loadState($id);


		// Uncomment the following line if AJAX validation is needed

		 $this->performAjaxValidation($model);


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

		{

			$model->attributes=$_POST['CountryStates'];

			if($model->save()){

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

                {

                    echo CJSON::encode(array(

                        'status'=>'success', 

                        'div'=>"Updated"

                        ));

                    exit;               

                }

                else{                                

                    $this->redirect(array('/admin/country/view','id'=>$model->country_id));

		}

                }

                }

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

        {

            Yii::app()->clientscript->scriptMap['jquery.js'] = false;

            echo CJSON::encode(array(

                'status'=>'failure', 

                'div'=>$this->renderPartial('_form', array('model'=>$model), true)));

            exit;               

        }

        else{               

		$this->render('update',array(

			'model'=>$model,

		));

        }

	}



I am glad you understand my problem. your code is very helpful to me!


js:$(this).serialize()

is used to generate a string from form input. The content of your CJuidialog is empty. Where is the form that $(this).serialize() is referring to?


$(this).serialize()

this is the value of the URL. When we click on the url, its value i.e. URL is passed to it.

If the contents are empty, then you need to check the controller part of your code.