multiple delete with cjuidialog

Hello yii team and other esteemed members,

i tried to find the above topic on a forum but i didnt got any solutions to it… i followed this link create new model which is created by Zaccaria. preety much good post which solved all of my problem but i am stuck at multiple delete…

can anybody please shade some light on it. below is my code

view => country/admin.php


<?php

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

    'id'=>'multipledelete',

    'options'=>array(

        'title'=>'Delete Multiple',

        'autoOpen'=>false,

        'modal'=>true,

        'width'=>'auto',

        'height'=>'auto',

		'resizable'=>true,


    ),

));?>

<div class="multipledelete1"></div>

 

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


<div class="gridborder">

	<div class="headblock">&nbsp; Manage Countries</div>

    <div class="restthing">


<?php $this->widget( 'ext.EUpdateDialog.EUpdateDialog', array(

  'height' => 'auto',

  'resizable' => true,

  'width' => 'auto', )); ?>


<?php echo CHtml::link( 'Add Country', array( 'country/create' ), array(

  'class' => 'update-dialog-create formlink' ) ); ?>

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

 

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

	'id'=>'country-grid',

	'dataProvider'=>$model->search(),

	'filter'=>$model,

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

	'selectableRows'=>'2',

	'columns'=>array(

	array(

      'class'=>'CCheckBoxColumn',

	  'id'=>'selectedItems',

	),

		'country_name',

	

		array(

			'class'=>'CButtonColumn',

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

			'deleteButtonUrl' => 'Yii::app()->createUrl( 

        "/country/delete", 

        array( "id" => $data->country_id ) )',

		'deleteConfirmation'=>false,

		'buttons' => array(

        'delete' => array(

          'click' => 'updateDialogDelete',

        ),

        'update' => array(

          'click' => 'updateDialogUpdate',

        ),

		

		),

			'header'=>CHtml::dropDownList('pageSize',

        $pageSize,

        array(20=>20,50=>50,100=>100),

        array(

       //

       // change 'user-grid' to the actual id of your grid!!

        'onchange'=>

        "$.fn.yiiGridView.update('country-grid',{ data:{pageSize: $(this).val() }})",

    )),

		),

	),

)); ?>

<?php echo CHtml::button('Delete', array('onclick' =>"{muldelete();  }",'class'=>'submitbutton')); ?>

	</div>

    <div class="clear">&nbsp;</div>

</div>

<script type="text/javascript">

// here is the magic

function muldelete()

{	

	var selectionIds = $.fn.yiiGridView.getSelection("country-grid");

    if (selectionIds.length!==0) {

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

    <?php echo CHtml::ajax(array(

            'url'=>array('country/deletemul'),

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

            'type'=>'post',

            'dataType'=>'json',

            'success'=>"function(data)

            {

				if (data.status == 'failure')

                {

                    $('#multipledelete div.multipledelete1').html(data.div);

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

                    $('#multipledelete div.multipledelete1 form').submit(muldelete);

                }

                else

                {

                    $('#multipledelete div.multipledelete1').html(data.div);

				      setTimeout(\"$('#multipledelete').dialog('close') \",500);

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

                }

 

            } ",

            ))?>;

		}

         else

           {

              alert("No Record Selected..");

           }		

    return false; 

 

}

 

</script>

controller =>CountryController.php

i am just trying to display view at the moment so no other code is written.




public function actionDeletemul()

	{

		$model = new Country;

		  

		

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

		  

		

	}



view=> country/deletemul.php




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

  'id' => 'country-grid',

  'enableAjaxValidation' => false,

  'focus' => '#confirmDelete',

)); ?>

 

<div class="buttons">

  <?php 

  echo CHtml::submitButton( 'Yes', array( 'name' => 'confirmDelete', 

    'id' => 'confirmDelete' ) );

  echo CHtml::submitButton( 'No', array( 'name' => 'denyDelete' ) ); 

  ?>

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



Please can anybody help me out… looking forward to hear from you all… :-[

Many thanks,

jay

my problem is it is not rendering deletemul view in cjuidialog… :-[

possible correction…

now i have made deletemul view to be visible in a cjuidialog with yes and no button but when i click any of the button nothing happens below is my code.




public function actionDeletemul()

	{

		$model = new Country;

		

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

		  {

			// Stop jQuery from re-initialization

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

		 

			if( isset( $_POST['action'] ) && $_POST['action'] == 'confirmDelete' )

			{

			

			  echo CJSON::encode( array(

				'status' => 'success',

				'div' => 'Deleted succussfully',

			  ));

			  exit;

			}

			else if( isset( $_POST['action'] ) )

			{

			  echo CJSON::encode( array(

				'status' => 'canceled',

				'div' => 'Deletion canceled',

			  ));

			  exit;

			}

			else

			{

			  echo CJSON::encode( array(

				'status' => 'failure',

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

			));

			  exit;

			}

		  }

		  else

		  {

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

			{

			 

			  $this->redirect( array( 'admin' ) );

			}

			else if( isset( $_POST['denyDelete'] ) )

			   $this->redirect( array( 'admin' ) );

			else

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

		  }

		  

		

	}



Come on guys???? any one????

As far as EUpdateDialog goes, it won’t delete multiple models. What you will need to is send selected ids, store them somehow in the form, if deletion is confirmed iterate through all ids and delete them separately.

PS: you are missing -&gt;delete() in your action. And you should use newest code for the extension.

HEllo andrew,

sorry for the late reply.

Somehow i am successful with a multiple delete option… i followed your suggestion and i am through it. but i have another problem if you can give me some suggestions.

i have a form on cjuidialog and i am following zaccaria post for create a new model form but i am not getting form value in the controller after i submit a form.

view code that is rendering in cjuidialog:




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

  'id' => 'contact-grid',

  'enableAjaxValidation' => false,

  'focus' => '#confirmDelete',

)); ?>

 

<div class="buttons">

<table width="100%" border="0" cellspacing="0" cellpadding="0">

  <tr>

    <td>Template:</td>

    <?php

	$smsmodel = new SmsTemplate;

	?>

    <td><?php echo CHtml::activeDropDownList($smsmodel,'sms_id',CHtml::listData(SmsTemplate::model()->findAll(),'sms_id','sms_title'),array('ajax' => array('type'=>'POST','url'=>CController::createUrl('contact/selecttext'), 'update'=>'#SmsTemplate_sms_text'),"prompt"=>"Select"));?></td>

  </tr>

  <tr>

    <td valign="top">Message:</td>

    <td><?php echo $form->textArea($smsmodel,'sms_text',array('rows'=>4, 'cols'=>40)); ?></td>

  </tr>

  <?php

  $seting = new Setting;

  $masktext = Setting::model()->findByPk("2");

  $maskarr = explode(",",$masktext->setvalue);

  ?>

  <tr>

    <td valign="top">Mask:</td>

    <td><?php echo $form->dropDownList($seting,'setvalue',$maskarr,array("prompt"=>"Select")); ?></td>

  </tr>

  <tr>

    <td>&nbsp;</td>

    <td><?php 

  echo CHtml::submitButton( 'Send', array( 'name' => 'confirmDelete', 

    'id' => 'confirmDelete','class'=>'submitbutton' ) );?>&nbsp;<?php  echo CHtml::submitButton( 'Cancel', array( 'name' => 'denyDelete','class'=>'submitbutton' ) );?></td>

  </tr>

  

</table>


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



Controller code




public function actionSendsms()

	{

		$model=new Contact;

 

        // Uncomment the following line if AJAX validation is needed

        // $this->performAjaxValidation($model);

 

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

        {

           

			

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

                { 

				

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

					if( isset( $_POST['confirmDelete'] ) && $_POST['confirmDelete'] == 'Send' )

					{

							

					  echo CJSON::encode( array(

						'status' => 'success',

						'content'=>"send click",

						'div' => 'Sms Sent succussfully',

					  ));

					  exit;

					}

					else

					{

						echo CJSON::encode(array(

							'status'=>'success', 

							'content'=>"$_POST[SmsTemplate][sms_text]"

							));

						exit;               

					}

                }

                else

					

                    $this->redirect(array('admin','model'=>$model));

            

        }

 

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

        {

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

            echo CJSON::encode(array(

                'status'=>'failure', 

                'content'=>$this->renderPartial('sendsms', array('model'=>$model),true, true)));

            exit;               

        }

        else

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

		

		

		

	}

	



function that does calling of cjuidialog




<script type="text/javascript">

// here is the magic

function sendselected()

{

    <?php echo CHtml::ajax(array(

            'url'=>array('contact/sendsms'),

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

            'type'=>'post',

            'dataType'=>'json',

            'success'=>"function(data)

            {

                if (data.status == 'failure')

                {

                    $('#delete-dialog div.delete-dialog-content').html(data.content);

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

                    $('#delete-dialog div.delete-dialog-content form').submit(sendselected);

                }

                else

                {

                    $('#delete-dialog div.delete-dialog-content').html(data.content);

                    setTimeout(\"$('#delete-dialog').dialog('close') \",400);

                }

 

            } ",

            ))?>;

    return false; 

 

}

 

</script>



Please please please pleae help me

i am successful with below

  1. created view and loaded data in form

  2. created cjuidialog and rendered sendsms view in a cjuidialog successfully (using CHTML:AJAX)

what i am not able to do is:

  1. in sendsms view i have whole form with fields and two submit button "send" and "cancel". when i press any of the button i am not getting form value to a controller actionSendsms().

can please somebody tells me what i am doing wrong.? any suggestions?

With quick look at code, as far as I can see it should work. Just I’m not sure you are calling your sendsms function, you should look into that. I would suggest to use Firebug and just debug it by looking at how your application behaves and what kind of data is send to the server.