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

Jump to content

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

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

#61 User is offline   sebako 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 54
  • Joined: 15-February 12

Posted 07 March 2012 - 11:19 AM

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
0

#62 User is offline   xNicox 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 84
  • Joined: 19-October 10

Posted 07 March 2012 - 01:35 PM

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
Lic. Nicolas Machado
0

#63 User is offline   xNicox 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 84
  • Joined: 19-October 10

Posted 08 March 2012 - 10:22 AM

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?

View Postsebako, on 07 March 2012 - 11:19 AM, said:

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

Lic. Nicolas Machado
0

#64 User is offline   jramer 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 4
  • Joined: 11-April 12

Posted 12 April 2012 - 10:10 AM

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
0

#65 User is offline   jramer 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 4
  • Joined: 11-April 12

Posted 12 April 2012 - 10:22 AM

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
0

#66 User is offline   PaulChyrilov 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 1
  • Joined: 18-April 12

Posted 18 April 2012 - 10:56 AM

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.
0

#67 User is offline   spandu007 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 1
  • Joined: 23-April 12

Posted 01 May 2012 - 12:23 PM

View Postifdattic, on 12 January 2012 - 03:40 PM, said:

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.

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

#68 User is offline   Thiago Luís 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 74
  • Joined: 12-November 10
  • Location:Brasília-DF, Brasil

Posted 06 June 2012 - 03:47 PM

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....er-resize-event) but had no success.
Someone went through the same situation and have another solution?
<?php while(!($succeed=try())); ?>
0

#69 User is offline   eddigei 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 43
  • Joined: 14-February 11

Posted 03 July 2012 - 03:33 AM

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,
        ),
    ));
  ?>

0

#70 User is offline   eddigei 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 43
  • Joined: 14-February 11

Posted 10 July 2012 - 06:12 AM

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

#71 User is offline   shinten80 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 2
  • Joined: 10-July 12

Posted 05 August 2012 - 10:44 PM

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!
0

#72 User is offline   bdo30002 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 4
  • Joined: 28-August 12

Posted 28 August 2012 - 02:08 PM

hi all

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

thanks excuse me for my english
0

#73 User is offline   Stefano Mtangoo 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 258
  • Joined: 02-January 12
  • Location:Dar es Salaam, Tanzania

Posted 25 September 2012 - 03:36 PM

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,
            ));
	}

And God said, Let there be science...and it was so!
Training Manager Written in Yii here
0

#74 User is offline   C.S.Putera 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 92
  • Joined: 18-May 11

Posted 07 October 2012 - 02:56 AM

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' )
));
?>



4. 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}

0

#75 User is offline   C.S.Putera 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 92
  • Joined: 18-May 11

Posted 07 October 2012 - 08:56 AM

Finally got it working and now it works great :D
0

#76 User is offline   Xgamer99 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 5
  • Joined: 09-October 12

Posted 15 November 2012 - 01:34 PM

It would be great if you could take a look at my tweak here: http://www.yiiframew...edialog/#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!
0

#77 User is offline   ifdattic 

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

Posted 15 November 2012 - 01:43 PM

View PostXgamer99, on 15 November 2012 - 01:34 PM, said:

It would be great if you could take a look at my tweak here: http://www.yiiframew...edialog/#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..
Andrius Marcinkevičius
(In English: Andrew M.)
Web Developer
http://ifdattic.com

Posted Image
0

#78 User is offline   muadib 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 2
  • Joined: 08-July 10
  • Location:Bratislava, Slovakia

Posted 23 November 2012 - 05:09 PM

View PostC.S.Putera, on 07 October 2012 - 08:56 AM, said:

Finally got it working and now it works great :D


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

#79 User is offline   muadib 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 2
  • Joined: 08-July 10
  • Location:Bratislava, Slovakia

Posted 24 November 2012 - 08:40 AM

View Postmuadib, on 23 November 2012 - 05:09 PM, said:

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.

Attached File(s)


0

#80 User is offline   sadi 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 2
  • Joined: 19-April 12

Posted 08 March 2013 - 07:29 AM

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',
	  );
	}
}


2. 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' ),
                    ),
                ),
            ),				
		),
	),
)); ?>


3. 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, Attached File  delete action.PNG (33.92K)
Number of downloads: 11 Thanks guys.
0

Share this topic:


  • (5 Pages)
  • +
  • « First
  • 2
  • 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