Yii Framework Forum: [EXTENSION] EUpdateDialog - Yii Framework Forum

Jump to content

  • (5 Pages)
  • +
  • « First
  • 3
  • 4
  • 5
  • You cannot start a new topic
  • You cannot reply to this topic

[EXTENSION] EUpdateDialog Rate Topic: ***** 1 Votes

#81 User is offline   ric_ardo 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 70
  • Joined: 04-September 12

Posted 05 July 2013 - 10:28 PM

Hi Guys, really is fantastic this extension, and it is exactly what i need. But, unfortunatelly i am working a lot in it, but didn't work yet. If anybody could help me i will appreciate.

Dialog box appears, but didn't save or update on database. When i click on SAVE button, it just redirect to "create", but i was on "admin". It seems that it skip this part on controller:

if( $model->save() )
        {
          // If callback is set run additional processing
          if( $this->callback !== null &&
              method_exists( $controller, $this->callback ) )
            $controller->{$this->callback}( $model );
          
          // Accessing through AJAX, return success content
          if( $this->isAjaxRequest )
          {
            // Output JSON encoded content
            echo CJSON::encode( array(
              'status' => 'success',
              'content' => $this->messages['success'],
            ));
            
            // Stop script execution
            Yii::app()->end();
          }


I don't know if has some problem but i am using bootstrap.
Below my codes to help. Any help will be very appreciate. I am trying for a long time.

Controller:
<?php

class PedidoAmbienteController 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/column1';
        
        private $_model;

	/**
	 * @return array action filters
	 */
        
	public function filters()
	{
		return array(
			'accessControl', // perform access control for CRUD operations
			//'postOnly + delete', // we only allow deletion via POST request
		);
	}

	/**
	 * 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('pedidoAmbiente');
		$this->render('index',array(
			'dataProvider'=>$dataProvider,
		));
	}

	/**
	 * Manages all models.
	 */
	public function actionAdmin()
	{
		$model=new pedidoAmbiente('search');
		$model->unsetAttributes();  // clear any default values
		if(isset($_GET['pedidoAmbiente']))
			$model->attributes=$_GET['pedidoAmbiente'];

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

        public function loadModel()
        {
            if( $this->_model === null )
            {
                if( isset( $_GET['id'] ) ){
                    $this->_model = pedidoAmbiente::model()->findByPk( (int) $_GET['id'] );
                    //echo 'teste';
                    //exit();
                }
                if( $this->_model === null )
                    throw new CHttpException( 404, 'The requested page does not exist.' );
            }
            return $this->_model;
        }

	/**
	 * Performs the AJAX validation.
	 * @param pedidoAmbiente $model the model to be validated
	 */
	protected function performAjaxValidation($model)
	{
		if(isset($_POST['ajax']) && $_POST['ajax']==='pedido-ambiente-form')
		{
			echo CActiveForm::validate($model);
			Yii::app()->end();
		}
	}
        
        /**
         *
         * Parâmetro para utilização do setflash para permitir automaticamente mensagens de feedback.
         * @param type $key
         * @param type $value
         * @param type $defaultValue 
         */
        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',
            );
        }
        
}
?>


view/pedidoambiente/admin
<?php
/* @var $this PedidoAmbienteController */
/* @var $model pedidoAmbiente */

$this->breadcrumbs=array(
	'Pedido Ambientes'=>array('index'),
	'Manage',
);

$this->menu=array(
	array('label'=>'List pedidoAmbiente', 'url'=>array('index')),
	array('label'=>'Create pedidoAmbiente', '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('grid-view', {
                data: $(this).serialize()
        });
	return false;
});
");
?>

<h2>Visualizar / Adicionar Ambientes do Pedido </h2>



<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( 'Ambientes', array( 'create' ),
            array(
                'class' => 'update-dialog-open-link',
                'data-update-dialog-title' => Yii::t( 'app', 'Inserir Ambiente' ),
            ));
            
?>            

<?php $this->widget('zii.widgets.grid.CGridView', array(
        'id'=>'grid-view',
        'dataProvider'=>$model->search(),
        'filter'=>$model,
        'columns'=>array(
               'Pedido_idPedido',
		'ambiente_idambiente',
		'previsao_medicao',
		'realizado_medicao',
		'realizado_projeto',
		'aprovacao_arquiteto',
                array(
                        'class'=>'CButtonColumn',
                        'buttons' => array(
            // Delete button
                'delete' => array(
                    'click' => 'updateDialogOpen',
                    'url' => 'Yii::app()->createUrl("/pedidoAmbiente/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', 'Atualizar Ambiente' ),
                    ),
            ),
            // View button
            'view' => array(
                'click' => 'updateDialogOpen',
                    'options' => array(
                        'data-update-dialog-title' => Yii::t( 'app', 'Visulizar Ambiente' ),
                    ),
                ),
            ),                          
                ),
        ),
)); ?>

0

#82 User is offline   aubej 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 3
  • Joined: 13-January 13

Posted 24 August 2013 - 08:11 PM

Hi,

This is a great extension. I've got it working pretty much exactly the way I want it, but I am stuck on one last thing. I am using the extension to manage groups within my web app. The user clicks a link, the dialog opens, the user enters the info for the group, submits the form, the data is sent to the controller via an AJAX call, a JSON success status is returned and the dialog shows the success message, waits a second and then closes the dialog. I have the list of groups in a gridview which is updated with the latest group. This all works great.

The problem I am having is with the update of the group. I am using the update button from the gridview to launch the dialog, retrieve the model based on the group ID an populate the form. This works great. When I submit the form, I call the update action in the controller. The group is updated and the action returns the JSON success message. The problem I am seeing is that the dialog does not display the success message and it is not closed.

I am just learning JQuery so I am having difficulty tracing how the function is triggered when the success message is returned. I can see it in the EUpdateDialog.js file, but I am not sure how it gets triggered from the AJAX response.

On the update, the JSON response looks identical to the create response...

{"status":"success","content":"
Group successfully updated<\/div>"}


I'm stumped. Any help would be appreciated. Below is my code.



Admin Groups View
		<?php
		echo 'Admin Groups<br><br>';
		
		$this->widget('ext.EUpdateDialog.EUpdateDialog',
							array(
								'dialogOptions'=>array(
									//'id'=>'grpDlg',
									'width'=>'500',
									'height'=>'300',
									'modal' => true

								),
							)
						);

		echo CHtml::link( 'Create new group', array( 'create' ),
		  array(
		    'class' => 'update-dialog-open-link',
		    'data-update-dialog-title' => 'Add a new group',
		));
		?>

	<?php

	$this->widget('zii.widgets.grid.CGridView', array(
						'dataProvider'=>$groupListDataProvider,
						'id'=>'groupsGrid',
						'columns'=>array(
							array(
								'header'=>'Group Name',
								'type'=>'raw',
								'value'=>'$data->name',  
							),
							array(
								'header'=>'Description',
								'type'=>'raw',
								'value'=>'substr($data->desc,0,2)',  // works
							),
							
							array(
					           	'class'=>'CLinkColumn', //here is the link column
                        		'label'=>'Manage This Group\'s Members',
								'header'=>'Member Management',
                        		'urlExpression'=>'Yii::app()->createUrl("/group/AdmGroupMbrs", array("id"=>$data["id"]))',
                				'htmlOptions'=>array(
					                  				'width'=>'180px',
													'style' => 'text-align: center;'
													),
								),
							array(
								'class' => 'CButtonColumn',
								'deleteConfirmation'=>'Please confirm you want to delete this group',
								'template' => '{update} {delete}',
								'buttons'=>array(
											//delete button
											'delete' => array(
										 		'label'=>'Delete this group',
												'url'=>'Yii::app()->createUrl("/group/deleteGroup", array("id"=>$data->id))',
											),
											// Update button
											 'update' => array(
									         	'click' => 'updateDialogOpen',
									         	'options' => array(
									         		          'data-update-dialog-title' => Yii::t( 'app', 'Atualizar Ambiente' ),
															),
											),
										),
									)
								),
							));
	?>		



Form for the dialog

<?php
$form=$this->beginWidget('ExtActiveForm', array(
	'id'=>'addGroup_form',
	//'enableAjaxValidation'=>true,
	'enableClientValidation'=>false,
	'clientOptions'=>array(
		//'validateOnSubmit'=>true,
	),
));
?>

<p class="note">Fields with <span class="required">*</span> are required.</p>

<?php echo $form->errorSummary(array($group)); ?>

<div class="row">
	<?php echo $form->labelEx2($group,'name'); ?>
	<?php echo $form->textField($group,'name', array('size'=>'30', 'maxlength'=>'100')); ?>
	<?php //echo $form->hiddenField($group,'id',array('type'=>"hidden")); ?>
	<div class="inlineError">
		<?php //echo $form->error($group,'name'); ?>
	</div>
</div>

<div class="row">
	<?php echo $form->labelEx2($group,'desc'); ?>
	<?php echo $form->textArea($group,'desc',array('rows'=>4, 'cols'=>30)); ?>
	<div class="inlineError">
		<?php //echo $form->error($group,'desc'); ?>
	</div>
</div>

<div class="row buttons">
	&nbsp;
</div>

<div class="row buttons">

        <?php
        	$submitTarget = '';
        	$btnText = '';
        	if($mode == 'create'){
        		$submitTarget = 'group/create';
        		$btnText = 'Create Group';
        	}elseif ($mode == 'update'){
        		$submitTarget = 'group/update';
        		$btnText = 'Update Group';
        	}

        	echo CHtml::ajaxSubmitButton(
        					$btnText,
        					CHtml::normalizeUrl(array($submitTarget,'render'=>false, 'id'=>$group->id)),
						array('id'=>'closeGrpsDialog')
						);

        ?>

        <div class="row buttons">

</div>



	</div>

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




Controller code
	public function actions(){
		  return array(
		  	//needed for EUpdateDialog
		    'create' => 'extensions.EUpdateDialog.actions.CreateAction',
		  	'update'=> 'extensions.EUpdateDialog.actions.UpdateAction',
		  );
	}


	private $_model;
	public function loadModel(){
		if($this->_model === null ){
			if( isset( $_GET['id'] ) )
			$this->_model = Group::model()->findByPk( (int) $_GET['id'] );
			if( $this->_model === null )
			throw new CHttpException( 404, 'The requested page does not exist.' );
		}
		return $this->_model;
	}




	public function actionCreate(){

		$group=new Group;

		//form submitted, create the new group

        if(isset($_POST['Group'])){

			$group->attributes=$_POST['Group'];
			//set the club and owner
		    $group->club_id = Yii::app()->session['user_club_id'];
			$group->owner_id = Yii::app()->user->id;
			if($group->save()){
				if (Yii::app()->request->isAjaxRequest){
					Yii::app()->clientScript->scriptMap['jquery.js'] = false;

					echo CJSON::encode(array(
						'status'=>'success',
                        'content'=>"<div id='saveconfirm'>The new group was created.</div>",
						));
						exit;
				}

				  else{
					echo CJSON::encode(array(
		                'status'=>'render', 	//@todo..why status failure?
		               // 'content'=>$this->renderPartial('_addGroup', array('group'=>$group), true, true)
						'content'=>$this->renderPartial('_addGroup', array('group'=>$group))
		            ));
		            exit;
					//$this->redirect(array('view','id'=>$model->id));
                }

			}
        }




		//Display the add group form
        if (Yii::app()->request->isAjaxRequest){
        	Yii::app()->clientScript->scriptMap['jquery.js'] = false;
            echo CJSON::encode(array(
               // 'status'=>'failure', 	//@todo..why status failure?
               	'status'=>'render',
                'content'=>$this->renderPartial('_addGroup', array('group'=>$group, 'mode' => 'create'), true)
            ));
            exit;
        }else{
	            $this->render('_addGroup',array(
	                'group'=>$group, 'mode' => 'create'
	            ));
			}
	     }



	     public function actionUpdate(){

			$group = $this->loadModel();
	     	if( isset( $_POST['Group'] ) ){


	     		$group->attributes = $_POST['Group'];

	     		//set the club and owner
			   // $group->id = Yii::app()->session['user_club_id'];
	     		$group->club_id = Yii::app()->session['user_club_id'];
				$group->owner_id = Yii::app()->user->id;
	     		if( $group->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'=>"<div id='saveconfirm'>Group successfully updated</div>",
	     					//'content'=>"xxxx",
	     				));
	     				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' => 'render',
			      'content' => $this->renderPartial( '_addGroup', array(
			        'group' => $group,
	     			'mode' => 'update' ), true, true ),
	     		));
	     		exit;
	     	}
	     	/*
	     	 else
	     	 $this->render( 'update', array( 'model' => $model ) );
	     	 */
	     }


0

#83 User is offline   aubej 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 3
  • Joined: 13-January 13

Posted 27 August 2013 - 09:57 PM

Figured it out.

I was trying to handle the Ajax submit to the controller...I needed to let the extension handle it. :|

Simply needed to replace my button with:

<?php echo CHtml::submitButton( 'Submit'); ?>


Now, next question. Anyone know how to submit the form using the dialog button and not the CHtml::submitButton?

Jason
0

#84 User is offline   aubej 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 3
  • Joined: 13-January 13

Posted 28 August 2013 - 01:17 PM

Figured that one out also....

$this->widget('ext.EUpdateDialog.EUpdateDialog',
		array(
			'dialogOptions'=>array(
				'width'=>'500',
				'height'=>'300',
				'buttons' => array(
					'Submit'=>'js:function(){ updateDialog.submit(); }',
				),
			),
		)
	);

0

#85 User is offline   marianux 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 14
  • Joined: 03-September 13

Posted 01 October 2013 - 02:19 PM

Hi, i'd like to know if it's possible that inside dialog window there'd be dropdownlist dependant that work via AJAX.
I've been trying but no success:
example: country - State - City, when i select a country i see via FireBug that make the ajax and get all the states for this country but the problem is that dropdownlist States is not bind from these data.

Any idea?
0

#86 User is offline   marianux 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 14
  • Joined: 03-September 13

Posted 02 October 2013 - 05:25 AM

View Postmarianux, on 01 October 2013 - 02:19 PM, said:

Hi, i'd like to know if it's possible that inside dialog window there'd be dropdownlist dependant that work via AJAX.
I've been trying but no success:
example: country - State - City, when i select a country i see via FireBug that make the ajax and get all the states for this country but the problem is that dropdownlist States is not bind from these data.

Any idea?


Well i've fixed.
Problem was in View code, because code for EUpdateDialog widget was before code for gridview widget. I have changed it and set EUpdateDialog code to the final of View code and the it works right.
0

#87 User is offline   ifdattic 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 71
  • Joined: 08-March 11

Posted 02 October 2013 - 01:33 PM

View Postmarianux, on 02 October 2013 - 05:25 AM, said:

Well i've fixed.
Problem was in View code, because code for EUpdateDialog widget was before code for gridview widget. I have changed it and set EUpdateDialog code to the final of View code and the it works right.


Sorry could not reply earlier.
Great that you were able to fix it yourself.
Andrius Marcinkevičius
(In English: Andrew M.)
Web Developer
http://ifdattic.com

Posted Image
0

#88 User is offline   lgastmans 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 57
  • Joined: 26-October 11
  • Location:Pondicherry, India

Posted 13 August 2014 - 10:35 PM

Hi All,

I have the problem that the dialog box opens, but all it shows is "loading..."

I have seen that a few others have had the same problem.

Any ideas?
0

#89 User is offline   lgastmans 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 57
  • Joined: 26-October 11
  • Location:Pondicherry, India

Posted 14 August 2014 - 02:09 AM

View Postlgastmans, on 13 August 2014 - 10:35 PM, said:

Hi All,

I have the problem that the dialog box opens, but all it shows is "loading..."

I have seen that a few others have had the same problem.

Any ideas?


While trying to figure out the problem with Firebug, I noticed that if, in the controller actionUpdate, I change this:

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


to this:

  	echo json_encode(array("content"=>'fantastic'));


it works fine, implying that the call to render is not returning the expected json format...

I guess I am missing something simple... I would really appreciate some feedback on this.
0

#90 User is offline   lgastmans 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 57
  • Joined: 26-October 11
  • Location:Pondicherry, India

Posted 14 August 2014 - 02:48 AM

View Postlgastmans, on 14 August 2014 - 02:09 AM, said:

While trying to figure out the problem with Firebug, I noticed that if, in the controller actionUpdate, I change this:

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


to this:

  	echo json_encode(array("content"=>'fantastic'));


it works fine, implying that the call to render is not returning the expected json format...

I guess I am missing something simple... I would really appreciate some feedback on this.


sorry for all the posts, I guess I could have waited a bit while debugging. But I guess it could be added to the "Basic Extension Usage" that you have to also update the return value of the controller:
		$res = $this->renderPartial('_form', array('model'=>$model), true, false);
		echo json_encode(
			array("content" => $res)
		);

0

Share this topic:


  • (5 Pages)
  • +
  • « First
  • 3
  • 4
  • 5
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users