Yii Framework Forum: Ajax Update - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

Ajax Update Rate Topic: -----

#1 User is offline   vena 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 8
  • Joined: 21-February 13

Posted 26 May 2013 - 03:03 PM

para master yii aku tanya nih
disini saya menggunakan ajax untuk update jumlah diviewnya seperti ini
<?php
$this->breadcrumbs=array(
	'Daftarusulans',
);

$this->menu=array(
	//array('label'=>'Update Kondisitanah','url'=>array('create')),
	//array('label'=>'Manage Pengusulan','url'=>array('admin')),
);
?>

<?php $box = $this->beginWidget('bootstrap.widgets.TbBox', array(
		'title' => 'Validasi Barang Pengusulan',
		'headerIcon' => 'icon-th-list',
		'htmlOptions'=>array('class'=>'inline'),
		// when displaying a table, if we include bootstra-widget-table class
		// the table will be 0-padding to the box
	));?>
<?php 
$this->widget('bootstrap.widgets.TbGridView', array(
'type'=>'striped bordered condensed',
'dataProvider'=>$dataProvider,
		'enablePagination' => true,
'columns'=>array(
array(
'name'=>'NIK',
'value'=>'$data["nik"]',
),
array(
'name'=>'Waktu Pengusulan',
'value'=>'$data["tanggal"]',
),
array(
'name'=>'Barang Usulan',
'value'=>'$data["namabarang"]',
),
array(
'name'=>'Jumlah',
'value'=>'$data["jumlah"]',
),
array(
'name'=>'Unit Pengusul',
'value'=>'$data["namaunit"]',
),
array(
		'name'=>'Terima',
		'type'=>'raw',
		'value'=>'CHtml::label(Validasi,"",array("onClick"=>"tes(\'$data[idpengusulan]\',$row,\'$data[namabarang]\',\'$data[jumlah]\',\'$data[nomorunit]\',\'$data[idkategori]\',\'$data[validate2]\')","id"=>"label_$row"));'
),
array(
		'name'=>'Tolak',
		'type'=>'raw',
		'value'=>'CHtml::link(Tolak, Yii::app()->controller->createUrl("pengusulan/tolakunit",array("id"=>$data[idpengusulan])))',
),
),
));?>
<?php $this->endWidget(); ?>
<?php
$url1 = CController::createUrl('pengusulan/ajaxvalidasidua');
$js = <<< JSCRIPT
 
function tes(idpengusulan,row,namabarang,jumlah,nomorunit,idkategori,validate2){
 
$('#editData').dialog('open');
var label = $('#label_'+row+'').text();
$('#editJumlah').val(jumlah);
$('#idpengusulanNya').val(idpengusulan);
$('#validate2Nya').val(validate2);
$('#namabarangNya').val(namabarang);
$('#idkategoriNya').val(idkategori);
$('#nomorunitNya').val(nomorunit);
$('#row').val(row);
 
}
 
function update(){
var jumlah  = $('#editJumlah').val();
var idpengusulan = $('#idpengusulanNya').val();
var namabarang = $('#namabarangNya').val();
var validate2 = $('#validate2Nya').val();
var idkategori = $('#idkategoriNya').val();
var nomorunit = $('#nomorunitNya').val();
var row = $('#row').val();
$('#editData').dialog('close');
$.post("${url1}", { idpengusulan:idpengusulan,namabarang:namabarang,jumlah:jumlah,validate2:validate2,idkategori:idkategori,nomorunit:nomorunit},
        function(data){
           $('#label_'+row+'').text(data.jumlah);
           alert('Jumlah yang disetujui menjadi '+data.jumlah+' ');
        }, "json");
 
}
 
JSCRIPT;
Yii::app()->clientScript->registerScript('disable_keluar', $js, CClientScript::POS_BEGIN);
?>
<?php
// ----- Dialog EditData ----------------------
$this->beginWidget('zii.widgets.jui.CJuiDialog', array(
        'id' => 'editData',
        'options' => array(
                'title' => 'Update Jumlah',
                'autoOpen' => false,
                'minWidth' => 600,
                'minHeight' => 100,
                'resizable' => false,
                'modal' => true,
                'show' => 'blind',
                'hide'=>'explode',
        ),
        )
);
?>

<?php
echo CHtml::label('Jumlah', 'jumlah').':';
echo CHtml::textField('editJumlah', '');
echo CHtml::hiddenField('idpengusulanNya','');
echo CHtml::hiddenField('namabarangNya','');
echo CHtml::hiddenField('validate2Nya','');
echo CHtml::hiddenField('idkategoriNya','');
echo CHtml::hiddenField('nomorunitNya','');
echo CHtml::hiddenField('row','');
echo '&nbsp;';
echo CHtml::button('Simpan', array("onClick"=>"update()"));
?>

 
<?php
$this->endWidget('zii.widgets.jui.CJuiDialog');
// ----- End dialog Edit Data ----------------------
?>



nah pada saat update juga melakukan insert ketabel lain controllernya seperti ini
public function actionAjaxValidasiDua(){
		$model2=new Barangusulanvalidate;
		$idpengusulan = $_POST['idpengusulan'];
		$namabarang= $_POST['namabarang'];
		$validate2= $_POST['validate2'];
		$jumlah = $_POST['jumlah'];
		$idkategori= $_POST['idkategori'];
		$nomorunit = $_POST['nomorunit'];
		$model = Pengusulan::model()->findByPk($idpengusulan);
		$model->jumlah = $jumlah;
		$model->validate2 = '1';
		$model2->namabarang=$namabarang;
		$model2->idkategori=$idkategori;
		$model2->nomorunit=$nomorunit;
		$model2->jumlah=$jumlah;
		$model2->status='0';
		if($model2->save()){
		if($model->update()){
			$data['jumlah']=$model->jumlah;
			$data['validate2']=$model->validate2;
			
		}
		else{
			$model = Pengusulan::model()->findByPk($idpengusulan);
			$data['jumlah']=$model->jumlah;
			$data['validate2']=$model->validate2;
			
		}
		}
		echo json_encode($data);
		$this->refresh();
		Yii::app()->end();
		
	}

kenapa action save() untuk model2 gak bisa jalan ya??
0

#2 User is offline   softark 

  • Keep It Simple
  • Yii
  • Group: Moderators
  • Posts: 2,999
  • Joined: 16-February 11
  • Location:Japan

Posted 26 May 2013 - 05:57 PM

/* Moved from "General Discussion for Yii 1.1.x" to "Indonesian" */
/* Please use English other than in "Indonesian" forum */

0

#3 User is offline   Nur Rochim 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 42
  • Joined: 04-February 13
  • Location:Indonesia

Posted 26 May 2013 - 10:41 PM

View Postsoftark, on 26 May 2013 - 05:57 PM, said:

/* Moved from "General Discussion for Yii 1.1.x" to "Indonesian" */
/* Please use English other than in "Indonesian" forum */



Hi softark, please your translate in Indonesian language.
Sorry bad english language... ;D
0

#4 User is offline   softark 

  • Keep It Simple
  • Yii
  • Group: Moderators
  • Posts: 2,999
  • Joined: 16-February 11
  • Location:Japan

Posted 26 May 2013 - 11:09 PM

Ah, sorry.
Well, I don't speak Indonesian, so I have to use "google translation" ...

/* Pindah dari "General Discussion for Yii 1.1.x" untuk "Indonesia" */
/* Silakan menggunakan bahasa Inggris selain di forum "Indonesia" */

The 2nd line may be a bad translation ... What I'm saying is:
Please use English in "General Discussion for Yii 1.1.x".
0

Share this topic:


Page 1 of 1
  • 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