[EXTENSION] EUpdateDialog

Sorry for the late reply, my day job is taking most of the time :(

With version 2 you can use other widgets, you just need to preload the scripts for the widgets and disable them so they don’t get loaded then update dialog is opened. Read http://www.yiiframework.com/extension/eupdatedialog/#hh11 and http://www.yiiframework.com/extension/eupdatedialog/#hh14 and it should give you the idea how it works.

Thanks ifdattic I’m going to study and I talk to them. :unsure:

Thanks for your time.

If you still have questions just ask. I tried to write documentation as easy to understand as possible, but if some more information is needed just ask, will try to help.

PS: ideas for EUpdateDialog v3 are always welcome :D

Thanks for the extension - appreciate you sharing it.

I have two questions, and being a newbie, there is probably simple answers…

I am using the extension in a very standard controller. When the input (from the dialog box) does not validate against the rules in the model, the dialog box properly shows these errors with the css changing the offending fields. However, the timeout has already started, and the box goes away. I played around with changing the timeout, giving the user a chance to correct the input, but this is not really the answer. The call has the json ‘status’ as failure.

Is there a way to make the behaviour such that the box does not close with status failure but closes appropriately (with timeout) if success?

How do I change the width of the dialog. I tried this:


$this->widget('ext.EUpdateDialog.EUpdateDialog',array('dialogOptions'=>array('width'=>700)));

in my view, but no change in width. How should I do it?

Thanks

  1. Make sure you use the newest extension version (including assets and actions) because I think you’re using old actions as in new version ‘failure’ status is not used anymore (as far as I can remember).

  2. Make sure you don’t overwrite the width somewhere and again make sure you’re using the newest version of the extension. I tried the code you use and it worked the way it’s supposed to.

If you still have the problems let me know, I will try to think of something else.

Hi,

first of all thank you very much for great extension - it is very useful.

I couldn’t reach you through my thread so decided to write the question in other words in extension’s thread.

My question is simple: I would like two different update action forms to be reflected in dialog on the same page - one to update the category of goods and another to update good presented using CGridView.

Upon successful update of category I would like to reload some certain part of page (including CGridView), I achieved that with the following setting of your extension:


'options' => array(

	'callback' => 'js:function() {$("#content").load("'.CHtml::normalizeUrl(array('/productcategory/admin')).'");}'

)

However upon change of good information I would like to refresh the grid only and this is also achievable by:


'options' => array(

	'callback' => 'js:function() {if(typeof $.fn.yiiGridView != "undefined") { $.fn.yiiGridView.update("product-grid");}}'

)

But could you advise how can I combine both these functionalities on the same page?

I was thinking about creating two different dialogs on the page and depending on link clicked one of them should be opened and execute callback function as a result but is it possible to set the html "id" of each dialog?

May be you know some easier solution for this problem…

Thank you very much in advance!

Sorry I didn’t reply to your thread, didn’t get any emails about new comments.

Well as far as I can’t say without too much thinking (got a cold, not enough oxygen for thinking) you’re overwriting the callback method a little too much. Callback method works as a switch to call a method depending on the returned status. And probably the fasted way to get what you want will be making a few changes to the actions/extension, just return a different status for one of the actions and then do a different callback for that status, and that should be about it.

Brilliant!

Did it within half an hour after reading your answer ;)

Thank you a lot!!

I’m just glad you found a solution :)

Dear ifdattic,

it seems I need your help again ::)

I’m trying to use in EUpdateDialog create-update form that accept file upload.

However it seems that for some reason value of CHTML::activeFileField isn’t transferred to action procedure.

Here is my form:


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

	'id'=>'product-form',

	'enableAjaxValidation'=>false,

	'htmlOptions'=>array('enctype'=>'multipart/form-data'),

)); ?>


	.....................................


	<div class="row">

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

		<?php echo CHTML::activeFileField($model,'uploadedFile'); ?>

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

	</div>


	<div class="row buttons">

		<?php echo CHtml::submitButton($model->isNewRecord ? 'Create' : 'Save'); ?>

	</div>


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

Code of my action:


public function actionCreate()

	{

		$model=new Product;


		// Uncomment the following line if AJAX validation is needed

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


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

		{

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

			

			// \/ Process image \/

			$model->uploadedFile=CUploadedFile::getInstance($model,'uploadedFile');

			$image = Yii::app()->image->load($model->uploadedFile->tempName);

			$imageName = $model->genImageName();

			$image->resize(200, 200, IMAGE::AUTO)->quality(75)->sharpen(20);

			$image->save(CHtml::normalizeUrl(Yii::getPathOfAlias('webroot').'/images/products/large/'.$imageName), False);

			$image->resize(100, 100, IMAGE::AUTO)->quality(75)->sharpen(20);

			$image->save(CHtml::normalizeUrl(Yii::getPathOfAlias('webroot').'/images/products/small/'.$imageName), False);

			$model->largepic = CHtml::normalizeUrl(Yii::getPathOfAlias('webroot').'/images/products/large/'.$imageName);

			$model->smallpic = CHtml::normalizeUrl(Yii::getPathOfAlias('webroot').'/images/products/small/'.$imageName);

			// /\ Process image /\

			

			if($model->save())	{

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

				{

			        // Stop jQuery from re-initialization

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

			        echo CJSON::encode( array(

			          'status' => 'success',

			          'content' => 'ModelName successfully updated',

			        ));

			        exit;

			    }

			    else	{

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

			    }

			}

		}


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

		{

		  // Stop jQuery from re-initialization

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

		

		  echo CJSON::encode( array(

		    'status' => 'failure',

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

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

		  ));

		  exit;

		}

		else	{

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

				'model'=>$model,

			));

		}

	}

Using normal request to index.php/product/create?categoryid=3 I can successfully create new Product and all needed images are properly resized and saved.

However using JUI Dialog it doesn’t seem to work, I receive:


<p>image file not found (Z:\home\stroyka\www\protected\extensions\image\Image.php:78)</p><pre>#0 Z:\home\stroyka\www\protected\extensions\image\CImageComponent.php(41): Image->__construct(NULL, Array)

#1 Z:\home\stroyka\www\protected\controllers\ProductController.php(75): CImageComponent->load(NULL)

#2 Z:\home\stroyka\www\yii\framework\web\actions\CInlineAction.php(50): ProductController->actionCreate

And this happens because $model->uploadedFile is NULL.

Could you advise what I’m missing here? I saw some threads where EAjaxUpload is used together with CJuiDialog - is that the only option?

As usual thanks a lot in advance!

Hi,

You should probably look into uploading files through AJAX as I doubt a file is sended with a simple AJAX post. Sorry can’t help you with this.

Hi Guys,

I can’t seem to get this extension to work.

I have been able to follow the first article (without plugin) with no problems:

http://www.yiiframework.com/wiki/216/update-delete-model-with-cjuidialog-works-in-cgridview/

Then I revert to the original gii generate files, and try to use the extension, but I get all kinds of problems.

I am not sure of what parts of the original article are now part of the extension and which not, so I get all kind of clashes.

Can someone send me (or post) a zip file with a completed example: model, controller and views?

Hi,

The first version of the extension was kind of the article just made for everyones convenience as the extension. The second version was a big step forward and almost the complete rewrite, so usage is a lot different from the first version.

But theory is kind of the same, only usage and features changed, so I you read through the extension docs I’m sure you will be able to figure how to use :)

I’ve started several times from scratch with the extensions docs:

In views/admin.php I add:

&#036;this-&gt;widget( 'ext.EUpdateDialog.EUpdateDialog' );

In my controller:

 change function: loadModel()


    (also need to declare a &quot;private &#036;_model&quot; class variable, not in docs)


  add function setFlash().

this does NOTHING in the controller:

public function actions()


{


	die(&quot;bug&quot;); //NOTICE DIE here&#33; this NEVER gets executed&#33;&#33;&#33;&#33;


      return array(


	'view' =&gt; 'application.actions.CreateAction',


  );


}

If I modify actionUpdate,actionCreate, etc as in the article it kind of works (validations fails, delete does not delete anything, etc).

Any chance of getting any sample files for version 2

I just found the sample files from version 1.

Starting from scratch again and using those sample files, I have gotten:

  • Update works great!!!

  • Create works, but it inserts TWO records each time!

  • Both View and Delete throw and error: 500 (Internal Server Error)!!!!

Any help would be appreciated!

Thanks

Hey all, Good plugin… Small problem UpdateAction working ViewAction not.

When I click on the view button the dialog just opens with Loading…

HELP!

Here is my controller:




<?php


class PhasesPhasesController 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','expandedview'),

				'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','kmgoddard'),

			),

			array('deny',  // deny all users

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

			),

		);

	}


	/**

	 * Displays a particular model.

	 * @param integer $id the ID of the model to be displayed

	 */

	

	public function actionExpandedView($id)

	{


		$dataProvider=new CActiveDataProvider('CostcodesCostcodes', array(

			'criteria'=>array(

				'condition'=>'phase_id=:phaseId',

				'params'=>array(':phaseId'=>$id),

			),

			'pagination'=>array(

				'pageSize'=>5,

			),		

		));

		

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

			'model'=>$this->loadModel($id),

			'dataProvider'=>$dataProvider,			

		));	

		

		

/*		$this->render('view',array(

			'model'=>$this->loadModel($id),

			'model'=>$this->loadModel($id),

			'model'=>$this->loadModel($id),

			'model'=>$this->loadModel($id),

		));*/

	}


	/**

	 * Creates a new model.

	 * If creation is successful, the browser will be redirected to the 'view' page.

	 */

	/*public function actionCreate()

	{

		$model=new PhasesPhases;


		// Uncomment the following line if AJAX validation is needed

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


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

		{

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

			if($model->save())

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

		}


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

			'model'=>$model,

		));

	}*/


	/**

	 * Updates a particular model.

	 * If update is successful, the browser will be redirected to the 'view' page.

	 * @param integer $id the ID of the model to be updated

	 */




	/**

	 * Deletes a particular model.

	 * If deletion is successful, the browser will be redirected to the 'admin' page.

	 * @param integer $id the ID of the model to be deleted

	 */

	public function actionDelete($id)

	{

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

		{

			// we only allow deletion via POST request

			$this->loadModel($id)->delete();


			// if AJAX request (triggered by deletion via admin grid view), we should not redirect the browser

			if(!isset($_GET['ajax']))

				$this->redirect(isset($_POST['returnUrl']) ? $_POST['returnUrl'] : array('admin'));

		}

		else

			throw new CHttpException(400,'Invalid request. Please do not repeat this request again.');

	}


	/**

	 * Lists all models.

	 */

	public function actionIndex()

	{

		$dataProvider=new CActiveDataProvider('PhasesPhases');

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

			'dataProvider'=>$dataProvider,

		));

	}


	/**

	 * Manages all models.

	 */

	public function actionAdmin()

	{

		$model=new PhasesPhases('search');

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

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

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


		$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 = PhasesPhases::model()->findByPk( (int) $_GET['id'] );

		

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

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

	  }

	  return $this->_model;

	}

	

	

	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',

	  );

	}

	/**

	 * Performs the AJAX validation.

	 * @param CModel the model to be validated

	 */

	protected function performAjaxValidation($model)

	{

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

		{

			echo CActiveForm::validate($model);

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

		}

	}

}




Here is the Admin view aka CGridView


<?php

$this->breadcrumbs=array(

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

	'Manage',

);


$this->menu=array(

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

	array('label'=>'Create PhasesPhases', '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('phases-phases-grid', {

		data: $(this).serialize()

	});

	return false;

});

");

?>


<h1>Manage Phases Phases</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 -->

<p>

  <?php echo CHtml::link( 'Add new Phase', array( 'create' ), array( 

    'class' => 'updateDialogOpen' ) ); ?>

</p>

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

	'id'=>'phases-phases-grid',

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

	'filter'=>$model,

	'columns'=>array(

		'id',

		'description',

		'ordering',

		array(

			'class'=>'CButtonColumn',

			'buttons'=> array(

			'update'=>array('click'=>'updateDialogOpen',

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

			,),

		  ),

		  'view' => array(

          'click' => 'updateDialogOpen',

          'options' => array(

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

          ),

        ),

		  ),

		),

	),

)); ?>

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

Basically same problem as @komannder

  • Both View and Delete throw and error: 500 (Internal Server Error)!!!!

My solution was this:

Line 22 in ViewAction.php


  public $ajaxView = '_view';

Change to


  public $ajaxView = 'view';

This will resolve the 500 error on the view. Link for the admin view.

Actually you can change this in ‘actions’ method, this property allows to render different view for ajax method.

No I know but it wasn’t documented and it was the guy above me problem. The 500 errors where related to the wrong view.