Example #1
0
    protected function initColumn()
    {
        $collection = new DaActiveRecordCollection($this->grid->dataProvider->getData());
        $idObject = $this->getObject()->id_object;
        foreach ($collection as $key => $obj) {
            if (!Yii::app()->authManager->checkObjectInstance(DaDbAuthManager::OPERATION_DELETE, Yii::app()->user->id, $idObject, $key, false)) {
                $collection->remove($key);
            } else {
                $this->_availableIdInstance[] = $key;
            }
        }
        if ($collection->getCount() == 0) {
            $this->visible = false;
            return;
        }
        $info = $this->grid->dataProvider->model->isInstancesAvailableForDelete($collection);
        foreach ($info as $id => $availableInfo) {
            if (!$availableInfo['result']) {
                $key = array_search($id, $this->_availableIdInstance);
                unset($this->_availableIdInstance[$key]);
                $this->_unavailableInfo[$id] = implode(', ', $availableInfo['info']);
            }
        }
        $js = 'function da_deleteRecord(idObject, idInstance) {
  ' . CHtml::ajax(array('type' => 'POST', 'dataType' => 'json', 'url' => Yii::app()->createUrl('backend/ygin/deleteRecord'), 'data' => 'js:{idObject:idObject, idInstance:idInstance}', 'success' => 'function(data){
  if (data.error !== undefined) {$.daSticker({text:data.error, type:"error", sticked:true}); $("#ygin_inst_" + data.idInstance + " .action-delete a").removeClass("process"); return;}
  $.daSticker({text:data.message, type:"success"});
  $("#ygin_inst_" + data.idInstance).remove();
  if ($(".b-instance-list tbody tr").length == 0) {$(".b-instance-list, .b-instance-list-count").remove();}
}')) . '
}';
        Yii::app()->clientScript->registerScript('admin.delete-record-ajax', $js, CClientScript::POS_HEAD);
    }
Example #2
0
 protected function initColumn()
 {
     $collection = new DaActiveRecordCollection($this->grid->dataProvider->getData());
     $idObject = $this->getObject()->id_object;
     foreach ($collection as $key => $obj) {
         if (!Yii::app()->authManager->checkObjectInstance(DaDbAuthManager::OPERATION_EDIT, Yii::app()->user->id, $idObject, $key, false)) {
             $collection->remove($key);
         } else {
             $this->_availableIdInstance[] = $key;
         }
     }
     if ($collection->getCount() == 0) {
         $this->visible = false;
     }
 }