CJuiDialog not closing in Ajax success - yii

Im trying to close CJuiDialog in Ajax success but its not closing, only iframe contents gets cleared popup not closing,
CJuiDialog Coding:
<?php
$this->beginWidget('zii.Widgets.jui.CJuiDialog',array(
'id'=>'Document-Edit',
'options'=>array(
'title'=>'Manage Documents',
'autoOpen'=>false,
'modal'=>true,
'width'=>800,
'height'=>600,
// 'close'=>'js:function(e,o){location.reload();}' ,
),
));
?>
<iframe id="cru-frame-doc" width="100%" height="100%" frameBorder="0" scrolling="no" >
<?php $this->renderPartial('ManageDocuments_Update', array('model'=>$model)); ?>
</iframe>
<?php $this->endWidget();?>
CGridView Code:
<?php $this->widget('zii.widgets.grid.CGridView', array(
'id'=>'document-grid',
'dataProvider'=>$model->search(),
'columns'=>array(
array(
'class' => 'CButtonColumn',
'template' => '{DocumentEdit}',
'buttons' => array(
'DocumentEdit' => array(
'imageUrl'=>Yii::app()->request->baseUrl.'/images/update.png',
'url'=>'$this->grid->controller->createUrl("DocumentEdit", array("id"=>$data->crm_document_id,"asDialog"=>1))',
'click'=>'function(){
$("#cru-frame-doc").attr("src",$(this).attr("href")); $("#Document-Edit").dialog("open"); return false;}',
),
),),
'crm_document_id',
'name',
'doc_type',
'delivery_method',
'content_subject',
'content_body',
'is_active',
),
)); ?>
Ajax Submit Button Code:
<?php
echo CHtml::ajaxSubmitButton( 'Save',
'js:document.location.href='.'"'.Yii::app()->createUrl("baseContact/SaveManageDocuments_Update",array("id" => $model->crm_document_id)).'"',
array(
'type'=>'POST',
"dataType" => "json",
'success' => 'function(data){
if(data.result=="success"){
window.parent.$("#Document-Edit").dialog("close");
window.parent.$("#cru-frame-doc").attr("src","");
}
}',
));
?>
Can anyone point out where im making error...

Use the below code in SaveManageDocuments_Update Controller action to close the dialog,
echo CHtml::script("window.parent.$('#Document-Edit').dialog('close');window.parent.$('#cru-frame-doc').attr('src',''); window.parent.$.fn.yiiGridView.update('document-grid');");
Yii::app()->end();

Related

How do I set customized placeholder in 'booster.widgets.TbActiveForm'?

I use like this..
<div class="row">
<?php echo $form->textFieldGroup(
$User,'email_address',
array(
'wrapperHtmlOptions' => array(
'class'=> 'col-sm-5',
),
)
);
?>
</div>
But there is default placeholder 'Email Address'. How I want to set there my own placeholder ?
you can add html options as below:
<?php echo $form->textFieldGroup(
$User,'email_address',
array(
'wrapperHtmlOptions' => array(
'class'=> 'col-sm-5',
),
'widgetOptions' => array(
'htmlOptions' => array(
'placeholder' => 'my placeholder'
)
)
)
);
?>
for more detail have a look at Booster active form

Onsubmit call function in yii

I want to call function when submit form in yii. In my form I enabled validateOnSubmit.
when in call function form Onsubmit mean it will call function in twice.
My Coding,
<?php
$form = $this->beginWidget('CActiveForm', array(
'id' => 'question-form',
// Please note: When you enable ajax validation, make sure the corresponding
// controller action is handling ajax validation correctly.
// There is a call to performAjaxValidation() commented in generated controller code.
// See class documentation of CActiveForm for details on this.
'enableAjaxValidation' => true,
'enableClientValidation' => false,
'clientOptions' => array(
'validateOnSubmit' => true,
'validateOnChange' => false,
),
'htmlOptions' => array('onsubmit' => 'return checkmultiple()',),
));
?>
<div class="form-group">
<?php echo $form->labelEx($model, 'question_title'); ?>
<?php echo $form->textField($model, 'question_title', array('size' => 50, 'maxlength' => 250, 'class' => 'form-control')); ?>
<?php echo $form->error($model, 'question_title'); ?>
</div>
<?php if ($tileAssigned == Yii::app()->const->FLAG_ZERO) { ?>
<div class="form-group">
<?php echo $form->labelEx($model, 'type', array('label' => 'Is Multiple Choice')); ?>
<?php echo $form->radioButtonList($model, 'type', $yesnoList, array('separator' => '', 'onchange' => 'questionTypeChange(this.value);', 'class' => '')); ?>
<?php echo $form->error($model, 'type'); ?>
</div>
I am calling function checkmultiple mean it will call twice.
function checkmultiple()
{
}

How to know form submit sucessfully in yii

i want to submit button disable when form submitted sucessfully, because user click submit button so many times when page loading so its saved the same records so many times.so i want to decided to when form submit sucessfully mean disable that submit button.i am also using aftervalidate function but it can't correct form submit successfull.
My Coding:
<?php
$form = $this->beginWidget('CActiveForm', array(
'id' => 'question-form',
// Please note: When you enable ajax validation, make sure the corresponding
// controller action is handling ajax validation correctly.
// There is a call to performAjaxValidation() commented in generated controller code.
// See class documentation of CActiveForm for details on this.
'enableAjaxValidation' => true,
'enableClientValidation' => false,
'clientOptions' => array(
'validateOnSubmit' => true,
'validateOnChange' => false,
'afterValidate' => 'js:buttondisable',
),
));
?>
<div class="form-group">
<?php echo $form->labelEx($model, 'question_title'); ?>
<?php echo $form->textField($model, 'question_title', array('size' => 50, 'maxlength' => 250, 'class' => 'form-control')); ?>
<?php echo $form->error($model, 'question_title'); ?>
</div>
<?php if ($tileAssigned == Yii::app()->const->FLAG_ZERO) { ?>
<div class="form-group">
<?php echo $form->labelEx($model, 'type', array('label' => 'Is Multiple Choice')); ?>
<?php echo $form->radioButtonList($model, 'type', $yesnoList, array('separator' => '', 'onchange' => 'questionTypeChange(this.value);', 'class' => '')); ?>
<?php echo $form->error($model, 'type'); ?>
</div>
But After validation function calling when validation done in every time,but i want to form submit sucessfully at this time disable button.

yii CListView relation sorting

Currently when i click on sort by in CListView generated table, it adds MODEL_NAME_2 to the url
?page=1&sort=MODEL_NAME_2.cat.desc
is there a way to remove it? or maybe rename it to something else? Or is this just how Yii works?
here is my actionIndex() in my controller
public function actionIndex()
{
$dataProvider=new CActiveDataProvider('MODEL_NAME_1', array(
'id'=> '',
'criteria' => array(
'with' => 'MODEL_NAME_2',
'together'=>true, //specifies whether the query should be run using a join
),
'sort'=>array(
'defaultOrder'=>'MODEL_NAME_2.cat ASC',
'attributes'=>array(
'MODEL_NAME_2.cat'=>array(
'asc'=>'MODEL_NAME_2.cat',
'desc'=>'MODEL_NAME_2.cat DESC',
),
'*',
)
),
'pagination'=>array(
'pageVar'=>'page'
)
));
$this->render('index',array(
'dataProvider'=>$dataProvider,
));
}
in my view
$this->widget('zii.widgets.CListView', array(
'dataProvider'=>$dataProvider,
'itemView'=>'_view', // refers to the partial view named '_view'
'enableHistory'=> true,
'sortableAttributes' => array('MODEL_NAME_2.cat'=>'Make'),
'pagerCssClass' => 'pagination',
'loadingCssClass' => '', //remove loading icon
'template'=>'
<div class="row">
<div class="col-md-12">
<div class="pull-left">{summary}</div>
<div class="pull-right">{sorter}</div>
</div>
</div>
<div class="row">
<div class="col-md-12">{items}</div>
</div>',
));
ideally i would like my url to look like this
mysite.com/bla/page/2/sort/cat/desc
basically using alot of / and no ? or &
In ListView definition change:
'sortableAttributes' => array('make'=>'Make'),
In your dataProvider
'sort'=>array(
'defaultOrder'=>'MODEL_NAME_2.cat ASC',
'attributes'=>array(
'make'=>array(
'asc'=>'MODEL_NAME_2.cat',
'desc'=>'MODEL_NAME_2.cat DESC',
),
'*',
)
),

YiiBooster modal Dataprovider Undefined

I am trying to load the index view from another model view in a modal window using yiibooster but the dataprovider of this model looks like it is undefined:
<?php $this->beginWidget(
'bootstrap.widgets.TbModal',
array('id' => 'documentacion')
); ?>
<div class="modal-header">
<a class="close" data-dismiss="modal">×</a>
<h4>Documentación</h4>
</div>
<?php
$doc = new ZfDocumentacionInmueble;
$this->renderPartial('//ZfDocumentacionInmueble/index', array('model'=>$doc));
?>
<div class="modal-footer">
<?php $this->widget(
'bootstrap.widgets.TbButton',
array(
'label' => 'Cerrar',
'url' => '#',
'htmlOptions' => array('data-dismiss' => 'modal'),
)
); ?>
</div>
<?php $this->endWidget(); ?>
ERROR: Undefined variable: dataProvider
thanks!
ERROR:
C:\APP\htdocs\yii\yiitest\protected\views\zfDocumentacionInmueble\index.php(6)
1 <?php
2 /* #var $this ZfDocumentacionInmuebleController */
3 /* #var $dataProvider CActiveDataProvider */
4
5 $this->widget('zii.widgets.CListView', array(
6 'dataProvider'=>$dataProvider,
7 'itemView'=>'_view',
8 )); ?>
CONTROLLER CODE:
public function actionIndex()
{
$dataProvider=new CActiveDataProvider('ZfDocumentacionInmueble');
$this->render('index',array(
'dataProvider'=>$dataProvider,
));
}
If the "real url" works, then the ZfDocumentacionInmueble::actionIndex()-function is creating a $dataProvider and passing it to the view.
In your renderPartial call, you do not pass on a $dataProvider. If you have created it in your controller action, be sure to pass it along (or otherwise you might have to copy the code from the other controller):
$this->renderPartial('//ZfDocumentacionInmueble/index', array('model'=>$doc, 'dataProvider' => $dataProvider));