[EXTENSION] EUpdateDialog

Hey ifdattic,

I am using your extension and I really like it. Now that I got update and create action working I am struggeling a bit with the actionDelete, would be great if you can assist me somehow with it.

I started editing the controller (setFlash, actions are defined) and this is the delete action:





public function actionDelete()

	{

		$model = $this->loadModel();

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

		{

			// Stop jQuery from re-initialization

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

	

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

			{

				$model->delete();

				echo CJSON::encode( array(

						'status' => 'success',

						'content' => 'Deleted succussfully',

				));

				exit;

			}

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

			{

				echo CJSON::encode( array(

						'status' => 'canceled',

						'content' => 'Deletion canceled',

				));

				exit;

			}

			else

			{

				echo CJSON::encode( array(

						'status' => 'failure',

						'content' => $this->renderPartial( 'delete', array(

								'model' => $model ), true, true ),

				));

				exit;

			}

		}

		else

		{

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

			{

				$model->delete();

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

			}

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

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

			else

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

		}

	}




then from what I’ve taken from the wiki page is that I need to edit my CGridView>CButtonColumn like this:







	        'class' => 'CButtonColumn',

    		  'template'=>'{view} {update} {delete} {add Note} {ToDo}',

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

    		  "/tool/dTool/delete",

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

		      'buttons' => array(

		        // Delete button

		        'delete' => array(

		          'imageUrl'=>Yii::app()->request->baseUrl.'/images/adjokerHome/icons/Delete.png',		        

		          'click' => "function( e ){

		            e.preventDefault();

		            $( '#update-dialog' ).children( ':eq(0)' ).empty(); // Stop auto POST

		            updateDialog( $( this ).attr( 'href' ) );

		            $( '#update-dialog' )

		              .dialog( { title: 'Delete confirmation' } )

		              .dialog( 'open' ); }",

		          'options' => array(

		            'data-update-dialog-title' => Yii::t( 'app', 'Delete confirmation' ),

		          ),

		        ),



and last adding a view, I called it "delete" and placed it into the views/controllerXYZ folder:





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

  'id' => 'location-delete-form',

  'enableAjaxValidation' => false,

  'focus' => '#confirmDelete',

)); ?>

 

<div class="buttons">

<?php

	echo CHtml::submitButton( 'Yes', array( 'name' => 'deleteConfirmed' ) );

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

?>

</div>

 

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




but for some reason either the dialog is showing up nor the model gets deleted.

Do you have any idea? Am I doing anything wrong?

Best Regards,

-Seb

Hi, I’m trying to use this extension.

But I have an error within the "loadModel()" method.

I’m using giix extension, so all the controller extends from GxControler


class CuotaDetalleController extends GxController {

...

}

When I invoque method Update of a model I get:


Propiedad "CuotaDetalleController"."_model" no se encuentra definida. 

Property "_model" is not defined …

If I comment that function … it works !

It’s ok ! ?

Best Regards

Hi, I have the same problem.

But the record is deleted in the database:

this is my delete action:




	public function actionDelete($id) {

		if (Yii::app()->getRequest()->getIsPostRequest()) {

			$model = $this->loadModel($id, 'CuotaDetalle'); //This is the heeder id.

			

			$this->loadModel($id, 'CuotaDetalle')->delete();

			

			Cuota::model()->findbyPk($model->fk_cuota_id)->actualizarImporte(); //Actualiza Totales

			

			if (!Yii::app()->getRequest()->getIsAjaxRequest())

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

		} else

			throw new CHttpException(400, Yii::t('app', 'Your request is invalid.'));

	}

I follow instructions in extension, not in the wiki…

Any help ?

Any real/complete sample?

Hi!

Love your extension!

I’ve read this thread thoroughly and it has helped me a lot, but now I’m stuck.

I’m trying to use your EJuiTimePicker extension together with EUpdateDialog and I’ve done as you propose in post #41.

Disable in controller:




    public function actions()

    {

      return array(

        'update' => array(

            'class' => 'application.actions.UpdateAction',

            'disableScripts' => array(

                'jquery-ui-timepicker-addon.js',

            ),

        ),

      );

    }



And preload in view:




$this->widget( 'ext.EUpdateDialog.EUpdateDialog',array('preload' => array( '/kalender/jquery-ui-timepicker-addon.js' )));



I get a picker but without the time part.

I’ve set ‘mode’ => ‘datetime’ and even ‘time’ and it works in the regular update view but not in the update dialog.

Got any hints?

cheers!

Kim

Sebako and xNicox from what I understand you should not use ‘status’ => ‘failure’. That is old code.

If you want to render then:




'status' => 'render'



In the wikipost for callback I’ve found

“Currently recognized statuses: ‘render’, ‘success’, ‘deleted’, ‘canceled’, ‘imagedeleted’.”

Hope it helps,

Kim

Hi!

I’m having this problem while using your extension. _form view, that i load in popup is made by CActiveForm widget and have 2 additional java scripts, so every time i get it from server i get that scripts too. I’m not sure that understood correctly how to prevent this problem. I’ve solved problem with one of this script when it was added to ‘disableScripts’ => array(‘jquery.yiiactiveform.js’) option. And then i use ‘preload’ option to load it once. But second script that contains options for CActiveForm doesn’t exist as file, YII creates it on the fly. After several calls to popup i have in firebug scripts tab many scripts named 1,2,3 etc and they all contain the same code, that describes CActiveForm options such as:

$(’#products-form’).yiiactiveform({‘validateOnSubmit’:true,‘validateOnChange’:false,‘validateOnType’:false,‘validationUrl’…

How can I prevent multiple script loading?

P.S. Sory, my English is horrible. If you do not understand something, I’ll try to explain to another way.

ifdattic,

I still face the same problem # 1. I have the latest extension and the error popup disappears immediately. Please help.

To update the position of the dialog after the content loaded, had to make this change:

(EUpdateDialog.js:38)


addContent : function( url ){

		// Make an AJAX call to get contents

		$.ajax({

			'url': url,

			'data': this.csrfToken,

			'type': 'post',

			'dataType': 'json',

			'success': function( data ){

				// Remove loading indicator

				updateDialog.removeLoader();

        

				// Add returned contents to UpdateDialog

				updateDialog.dialogContent.html( data.content );

				

                                // Float the div after the content is rendered

				$( "#update-dialog" ).dialog( "option", "position", "center");

			},

			'cache': false

		});

},

I tried to follow this tip (http://forum.jquery.com/topic/re-positioning-of-dialog-after-resize-event) but had no success.

Someone went through the same situation and have another solution?

Hello.

I had the need to include more widgets within tabs, to remedy the problem they created multiple items with the same id I implemented extension in the variable id. It 'a simple but functional.

EUpdateDialog.php


 

...

/**

     * @var string message category used for Yii::t method.

     */

    public $tCategory = 'app';

    public $idWidget = 'update-dialog'; // new code




 public function run() {

      // Create jQuery UI dialog

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

          'id' => $this->idWidget, // edit code

          'options' => $this->dialogOptions,

      ));

      ?>

      <div class="update-dialog-content"></div>

      <?php

      $this->endWidget();

      $this->options['id']=$this->idWidget; // new code

....



EUpdateDialog.js




  ...

  /**

   * @var string CSRF token name for CSRF validation.

   */

  csrfTokenName : null,

/**

  *@var id widget

  */

 id:'update-dialog', //new code

...




 init : function(){

    // Set dialog

    this.dialog = $( '#'+this.id ); // edit code

...



in view





 <?php

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

        'idWidget'=>"dialogMacchina$puntovendita->id", //new code

        'dialogOptions' => array(

            'zIndex' => 0,

        ),

    ));

  ?>



can be sent to the dialog the value of a textbox?

hi all,

i’m using the latest version of this extension but still not able to make the ‘CJuiDatePicker’ and ‘CAutoComplete’ run in eupdatedialog, i had follow the instruction given in post #41 with set the ‘disableScripts’ and ‘preload’, but still no clue.

may i have your success example for this scenario?

thanks and have a nice day!

hi all

i have the same problem like shinten80 . using cjuidatepicker. any solution?

thanks excuse me for my english

Hi,

I have models generated by Gii and are working. However in some scenario I need to create the model and save it (show all validation error on dialog) via CJuiDialog. I have read all posts here as well as in ext url and I cannot get it. How do I display forms for create update and delete? I believe concrete example with extension will do justice to such a good extension!

here is my trial code.


public function actionCreateDialog()

	{

		$model=new RoundTable;


		// Uncomment the following line if AJAX validation is needed

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


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

		{

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

			if($model->save())

            {

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

                {

                    echo CJSON::encode(array(

                            'status'=>'success',

                            'div'=>"<div id='saveconfirm'>Los datos han sido almacenados.</div>",

                            'option'=>CHtml::tag('option',array (

                                            'value'=>$model->id,

                                            'selected'=>true), CHtml::encode($model->id),true)

                            ));

                            exit;

                    }

                    else  

                        $this->redirect(array('view','id'=>$model->roundtable_id));

            }

		}

        

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

        {

          // Stop jQuery from re-initialization

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

          echo CJSON::encode( array(

            'status' => 'render',

            'content' => $this->renderPartial( 'createDialog', array(

            'model' => $model ), true, true ),

          ));

          exit;

        }

        else  

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

                'model'=>$model,

            ));

	}

Hi,I’ve been trying to make this work for me for 2 days but still cannot figure out where I am missing. Both the link and the CButtonColumn dont’work, instead only showing “Loading”. When I check it using firebug, the response already showing my form and got no errors. Please help… Thanks so much

  1. I have placed the extension in my protected/extensions/

  2. I have placed the actions folder in my protected/

  3. In my view :





<?php $this->widget( 'ext.EUpdateDialog.EUpdateDialog' ); ?>


<?php


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

	/*

         *

        */

array(

	'class'=>'CButtonColumn',

        'buttons' => array(

        'receiving'=>array(

		'label' => 'Receiving',

	        'url'=>'Yii::app()->createUrl("admin/producthistory/add",

                                            array(

						"pid" => $data->product_id,

					        "poid_1" => $data->product_option_id_1,

					        "povid_1" => $data->product_option_value_id_1,

					        "poid_2" => $data->product_option_id_2,

						"povid_2" => $data->product_option_value_id_2,

						"poid_3" => $data->product_option_id_3,

						"povid_3" => $data->product_option_value_id_3

		))',

		'imageUrl' => Yii::app()->baseUrl.'/images/receiving.png',

		'click' => 'updateDialogOpen',

		'options' => array(

			'data-update-dialog-title' => Yii::t( 'app', 'Receiving' ),

		)

	),

)

/***/

)))); 

?>


<?php

echo CHtml::link( 'Add', array( 'productHistory/add',

			'pid'=>1,'poid_1'=>1,'povid_1'=>1,'poid_2'=>1,'povid_2'=>1,'poid_3'=>1,'povid_3'=>1),

			array(

				'class' => 'update-dialog-open-link',

				'data-update-dialog-title' => Yii::t( 'app', 'New Product' )

));

?>




  1. In my ProductHistoryController :




class ProductHistoryController extends AdministratorController

{

	private $_model;


        public function actionAdd($pid, $poid_1, $povid_1, $poid_2, $povid_2, $poid_3, $povid_3)

	{

		$model = new ProductHistory('add');

                

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

		{

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

                        

                        if($model->save())

			{

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

                                {

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

                       	

                       	        echo CJSON::encode(array(

                                    'status'=>'success',

                                    'content'=>"Product History successfully created"

                       	        ));

                       	        exit;

                                }

		                else

		                {

            	             Yii::app()->user->setFlash('formsuccess', 'Product History has been successfully added.');

		                }

                        }

		}

		

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

		{

			// Stop jQuery from re-initialization

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

			

			echo CJSON::encode( array(

					'status' => 'render',

					'content' => $this->renderPartial('form', compact('model'), true, true ));

			exit;

		}

		else

			$this->render('form', compact('model'));

	}


        public function loadModel($id)

	{

		  if( $this->_model === null )

		  {

		    if( isset( $_GET['id'] ) )

		      $this->_model = ProductHistory::model()->findByPk( (int)$_GET['id'] );

		    if( $this->_model === null )

		      throw new CHttpException( 404, 'The requested page does not exist.' );

		  }

		  return $this->_model;

	}

	

	public function actions()

	{

		return array(

		  'add' => 'application.actions.CreateAction',

                  'view' => 'application.actions.ViewAction',

                  'update'=> 'application.actions.UpdateAction',

		);

	}




When I check in firebug, at the end of the response :


{"status":"render","content":null,"0":true,"1":true}

Finally got it working and now it works great :D

It would be great if you could take a look at my tweak here: http://www.yiiframework.com/extension/eupdatedialog/#c10692

This will allow you to set predefined dialog buttons. If you have a better way of setting them that doesn’t use the extension ‘dialogOptions’ (because for me, they have to change depending on what is clicked) I’d like to hear about it.

Thanks for such a great extension!

Hi,

I would definitely check out your tweak as soon as I will have some free time, which apparently isn’t so easy when you work on multiple projects at the same time :D

Glad you like the extension. Updates are coming :) Hopefully, soon too…

Hi, how did you do it. I have the same problem. Can you share pls ?

Took some time, but finally it works like it should have. :)

p.s.: For any newbies to save time, who wants to start use this extension sample files included.

Hello guys,

it works great for me, but there is a problem with delete :

delete is successful (model is deleted of DB) but delete confirmation dialog doesn’t close and CGridView in admin.php doesn’t update. i should refresh admin page to update CGridView. while there isn’t this problem for create,update, means after i create a user create dialog is closed and CGridView in admin.php is updated. please help me to pass of this problem. i use of EUpdateDialog-2.0.1, my code for UserController.php, admin.php and delete.php as follow :

  1. protected/controllers/UserController.php

<?php


class UserController extends Controller

{

	/**

	 * @var string the default layout for the views. Defaults to '//layouts/column2', meaning

	 * using two-column layout. See 'protected/views/layouts/column2.php'.

	 */

	public $layout='//layouts/column2';


	/**

	 * @return array action filters

	 */

	public function filters()

	{

		return array(

			'accessControl', // perform access control for CRUD operations

		);

	}


	/**

	 * Specifies the access control rules.

	 * This method is used by the 'accessControl' filter.

	 * @return array access control rules

	 */

	public function accessRules()

	{

		return array(

			array('allow',  // allow all users to perform 'index' and 'view' actions

				'actions'=>array('index','view'),

				'users'=>array('*'),

			),

			array('allow', // allow authenticated user to perform 'create' and 'update' actions

				'actions'=>array('create','update'),

				'users'=>array('@'),

			),

			array('allow', // allow admin user to perform 'admin' and 'delete' actions

				'actions'=>array('admin','delete'),

				'users'=>array('admin'),

			),

			array('deny',  // deny all users

				'users'=>array('*'),

			),

		);

	}




	/**

	 * Lists all models.

	 */

	public function actionIndex()

	{

		$dataProvider=new CActiveDataProvider('User');

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

			'dataProvider'=>$dataProvider,

		));

	}


	/**

	 * Manages all models.

	 */

	public function actionAdmin()

	{

		$model=new User('search');

		$model->unsetAttributes();  // clear any default values

		if(isset($_GET['User']))

			$model->attributes=$_GET['User'];


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

			'model'=>$model,

		));

	}


	/**

	 * Returns the data model based on the primary key given in the GET variable.

	 * If the data model is not found, an HTTP exception will be raised.

	 * @param integer the ID of the model to be loaded

	 */


	private $_model;

	public function loadModel()

	{

		if($this->_model===null)

		{

				if(isset($_GET['id']))

						$this->_model=User::model()->findbyPk($_GET['id']);

				if($this->_model===null)

						throw new CHttpException(404,'The requested page does not exist.');

		}

		return $this->_model;

	}

	

	/**

	 * Performs the AJAX validation.

	 * @param CModel the model to be validated

	 */

	protected function performAjaxValidation($model)

	{

		if(isset($_POST['ajax']) && $_POST['ajax']==='user-form')

		{

			echo CActiveForm::validate($model);

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

		}

	}

	

	public function setFlash( $key, $value, $defaultValue = null )

	{

	  Yii::app()->user->setFlash( $key, $value, $defaultValue );

	}

	

	public function actions()

	{

	  return array(

		'create' => 'application.actions.CreateAction',

		'view' => 'application.actions.ViewAction',

		'update' => 'application.actions.UpdateAction',		

		'delete' => 'application.actions.DeleteAction',

	  );

	}

}



  1. protected\views\user\admin.php

<?php

$this->breadcrumbs=array(

	'Users'=>array('index'),

	'Manage',

);


$this->menu=array(

	array('label'=>'List User', 'url'=>array('index')),

	array('label'=>'Create User', 'url'=>array('create')),

);


Yii::app()->clientScript->registerScript('search', "

$('.search-button').click(function(){

	$('.search-form').toggle();

	return false;

});

$('.search-form form').submit(function(){

	$.fn.yiiGridView.update('user-grid', {

		data: $(this).serialize()

	});

	return false;

});

");

?>


<h1>Manage Users</h1>


<p>

You may optionally enter a comparison operator (<b>&lt;</b>, <b>&lt;=</b>, <b>&gt;</b>, <b>&gt;=</b>, <b>&lt;&gt;</b>

or <b>=</b>) at the beginning of each of your search values to specify how the comparison should be done.

</p>


<?php echo CHtml::link('Advanced Search','#',array('class'=>'search-button')); ?>

<div class="search-form" style="display:none">

<?php $this->renderPartial('_search',array(

	'model'=>$model,

)); ?>

</div><!-- search-form -->


<?php


$this->widget( 'ext.EUpdateDialog.EUpdateDialog' );


echo CHtml::link( 'Create', array( 'create' ),

  array(

    'class' => 'update-dialog-open-link',

    'data-update-dialog-title' => Yii::t( 'app', 'Create a new user' ),

));


?>


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

	'id'=>'user-grid',

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

	'filter'=>$model,

	'columns'=>array(

		'id',

		'name',

		'email',

		'pass',

		'state',

		array(

			'class'=>'CButtonColumn',

			'buttons' => array(

            // Delete button

                'delete' => array(

                    'click' => 'updateDialogOpen',

                    'url' => 'Yii::app()->createUrl("/user/delete", array( "id" => $data->primaryKey ) )',

                    'options' => array(

                        'data-update-dialog-title' => Yii::t( 'app', 'Delete confirmation' ),

                    ),

                ),

            // Update button

            'update' => array(

                'click' => 'updateDialogOpen',

                    'options' => array(

                        'data-update-dialog-title' => Yii::t( 'app', 'Update user' ),

                    ),

            ),

            // View button

            'view' => array(

                'click' => 'updateDialogOpen',

                    'options' => array(

                        'data-update-dialog-title' => Yii::t( 'app', 'Preview user' ),

                    ),

                ),

            ),				

		),

	),

)); ?>



  1. protected\views\user\delete.php

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

  'id' => 'location-delete-form',

  'enableAjaxValidation' => false,

  'focus' => '#confirmDelete',

)); ?>

 

<div class="buttons">

  <?php 

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

    'id' => 'confirmDelete' ) );

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

  ?>

</div>

 

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

I attached a picture of delete confirmation dialog, 3901

delete action.PNG
Thanks guys.