Reputation: 71
I am trying to manipulate my buttons in CJuidialog. I want to have a submit button
inside my dialog. I have a checkbox "default" where if it is checked, check data from the database. I have a list of employees, where I input their data. Whenever the employee already have a schedule
it will display a popup that says. You already have a schedule. do you wish to continue? Then, in my cjuidialog. I have an "OK" button and "CANCEL". If the user clicks ok. It will submit the form and find the same employee and change its default "1" to "0".
So that the new form will be the default and the previous one will be just a regular schedule.
For example:
there is a fk_user = 1 , default = 1 , from= 07/07/13 , to = 07/10/13 , schedule = 5
data in the database. Then I create another form which is fk_user = 1 , default = 1, from = 10/10/13 , to = 12/12/13 , schedule = 6
,There is already a default for fk_user 1. It will display a popup where it says "You already have a schedule. do you wish to continue? ". If the user clicks "OK" the new data will be fk_user = 1 , default = 1, from = 10/10/13 , to = 12/12/13 , schedule = 6
and the previous will be fk_user = 1 , default = 0 , from= 07/07/13 , to = 07/10/13 , schedule = 5
the previous data becomes 0.
I have been trying this for the past days, and it is the only problem for my system to be completed. can anyone help me with these?
I dont know if I will still use the ajax submit button here, I had research over the net, but I cant find documentation about this.
I started with this.
public function actionCreate()
{
$model=new EmpSched;
// Uncomment the following line if AJAX validation is needed
// $this->performAjaxValidation($model);
if(isset($_POST['EmpSched']))
//$fk_user= $model->fk_user;
$model->attributes=$_POST['EmpSched'];
if($model->default==1){
$record = EmpSched::model()->findAllByAttributes(array('fk_user' => $model->fk_user,'default'=>array('1')));
var_dump($record);
if($record==false){
($model->save());
$this->redirect(array('view','id'=>$model->id_empsched));
}else{
$this->renderPartial('popup');
}
}else{
($model->save());
$this->redirect(array('view','id'=>$model->id_empsched));
}
}
$this->render('create',array(
'model'=>$model,
'emp'=> new CActiveDataProvider('schedule'),
));
}
popup.php
<?php $form=$this->beginWidget('bootstrap.widgets.TbActiveForm',array(
'id'=>'popup-form',
'enableAjaxValidation'=>true,
)); ?>
<?php
$this->beginWidget('zii.widgets.jui.CJuiDialog',array(
'id'=>'mydialog',
// additional javascript options for the dialog plugin
'options'=>array(
'title'=>'Michael',
'autoOpen'=>true,
'modal'=>true,
'width'=>300,
'height'=>300,
'buttons' => array(
'OK'=>'js:function(){
//$(this).dialog("close")
}',
'CANCEL'=>'js:function(){$(this).dialog("close")}'),
),
));
echo 'Another default schedule is already using. Do you want to set current schedule as default? ';
$this->endWidget('zii.widgets.jui.CJuiDialog');
?>
<?php $this->endWidget();?>
Upvotes: 0
Views: 1368
Reputation: 220
Why do you need to make this change before save?
I would do this on save and use the modal only for advertisement.
Like this:
public function actionCreate()
{
$model=new EmpSched;
// Uncomment the following line if AJAX validation is needed
// $this->performAjaxValidation($model);
if(isset($_POST['EmpSched']))
//$fk_user= $model->fk_user;
$model->attributes=$_POST['EmpSched'];
if($model->validate()){
if($model->default==1){
EmpSched::model()->updateAll(array('default'=>0),'fk_user=:fk_user',array(':fk_user' => $model->fk_user);
}
if($model->save(false)){
$this->redirect(array('view','id'=>$model->id_empsched));
}
}
}
$this->render('create',array(
'model'=>$model,
'emp'=> new CActiveDataProvider('schedule'),
));
}
Upvotes: 1