in my admin view file, i have a CGridview with the following column:
...
array(
'filter'=>false,
'name'=>'IsPresentInLocation',
'header'=>'',
'type'=>'raw',
'value'=>'Master::getIsPresentInLocation($data->ID, '.Yii::app()->session["label_location_id"].');',
),
...
the "getIsPresentInLocation" function from the Master model returns the following ajaxButton :
...
$str = TbHtml::ajaxButton(
'Add '.Yii::app()->session["label_location_id"],
Yii::app()->createUrl('master/togglePresent', array("id"=>$id, "location_id"=>Yii::app()->session["label_location_id"])),
array(
"success"=>"function(data){
$.fn.yiiGridView.update('master-grid', {data: $(this).serialize()});
console.log(data);
}",
),
array(
'size'=>TbHtml::BUTTON_SIZE_MINI,
'color'=>TbHtml::LABEL_COLOR_WARNING,
)
);
return $str;
and the "togglePresent" function in the controller :
public function actionTogglePresent($id, $location_id){
$sql ="
SELECT DISTINCT mp.MasterID
FROM MapPlants mp
INNER JOIN Location l ON (l.ID = $location_id)
INNER JOIN LocationMap lm ON (lm.LocationID = l.ID)
WHERE (mp.MasterID = $id) AND (mp.LocationMapID = lm.ID)
";
$command =Yii::app()->db->createCommand($sql);
$res = $command->queryRow();
if ($res){
echo "present";
}
else {
$modelLocationMap = LocationMap::model()->find('LocationID = ?', array($location_id));
if ($modelLocationMap) {
$modelMapPlants = new MapPlants;
$modelMapPlants->LocationMapID = $modelLocationMap->ID;
$modelMapPlants->MasterID = $id;
$modelMapPlants->save();
echo "added plant to location";
}
else
echo "error adding plant";
}
Yii::app()->end();
}
this works when I click the buttons in the grid, but at some point it generates a whole lot of GET calls in the Firebug console and then the "success" function is not called, or, at least, the "console.log(data)" does not appear…
I tried wrapping the grid refresh in a "setTimeout" call as so:
setTimeout('$.fn.yiiGridView.update(\"master-grid\", {data: $(this).serialize()});', 2000);
but although that seems to help somewhat, it did not solve the problem…
someone have an idea of what might be happening here in this flow of events ?