<?php $this->widget('DTGridView', array('id' => 'masters-employee-rewards-grid', 'itemsCssClass' => 'table datatable', 'dataProvider' => MastersEmployeeHistoryRewards::model()->searchByEmployee($model->id), 'columns' => array(array('name' => 'id', 'header' => '#', 'htmlOptions' => array('style' => 'width:50px;')), array('name' => 'reward_type', 'header' => at('Type')), array('name' => 'name', 'header' => at('Name')), array('name' => 'instantion', 'header' => at('Instantion')), array('name' => 'certificate_date', 'header' => at('Cert Date')))));
/** * Returns the data model based on the primary key given in the GET variable. * If the data model is not found, an HTTP exception will be raised. * @param integer $id the ID of the model to be loaded * @return MastersEmployeeHistoryRewards the loaded model * @throws CHttpException */ public function loadModel($id) { $c = new CDbCriteria(); $c->compare('id', $id); $c->compare('employee_id', getUser()->id); $model = MastersEmployeeHistoryRewards::model()->find($c); if ($model === null) { throw new CHttpException(404, 'The requested page does not exist.'); } return $model; }
$template = '{view}'; if ($isform) { ?> <div class="row"> <a href="#reward_id#create#0" class="btn btn-primary"><?php echo at('Add Reward'); ?> </a> </div> <?php $template .= '{update}{delete}'; } ?> <?php $this->widget('DTGridView', array('id' => 'masters-employee-rewards-grid', 'itemsCssClass' => 'table datatable', 'dataProvider' => MastersEmployeeHistoryRewards::model()->searchByEmployee($model->id), 'columns' => array(array('name' => 'id', 'header' => '#', 'htmlOptions' => array('style' => 'width:50px;')), array('name' => 'reward_type', 'header' => at('Type')), array('name' => 'name', 'header' => at('Name')), array('name' => 'instantion', 'header' => at('Instantion')), array('name' => 'certificate_date', 'header' => at('Cert Date')), array('class' => 'CButtonColumn', 'htmlOptions' => array('style' => 'width: 80px'), 'template' => $template, 'buttons' => array('view' => array('url' => '"#reward_id#view#".$data->id'), 'update' => array('url' => '"#reward_id#update#".$data->id'), 'delete' => array('url' => 'createUrl("employee/rewards/delete", array("id"=>$data->id))')))))); ?> <!-- Modal --> <div class="modal fade" id="rewardsModal" tabindex="-1" role="dialog" aria-labelledby="rewardsModalLabel" aria-hidden="true"> <div class="modal-dialog"> <div class="modal-content"> <div class="modal-header"> <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button> <h4 class="modal-title" id="rewardsModalLabel">Reward</h4> </div> <div class="modal-body" id="rewardsModalBody"> <!-- tampilan dari ajax --> </div> </div> </div>
public function actionAjaxcreate($id) { $model = new MastersEmployeeHistoryRewards(); if ($id != '') { $model = MastersEmployeeHistoryRewards::model()->findByPk($id); } $model->employee_id = $_POST['employee_id']; $model->reward_type = $_POST['type']; $model->name = $_POST['name']; $model->certificate_no = $_POST['certificate_no']; $model->certificate_date = $_POST['certificate_date']; $model->instantion = $_POST['instantion']; if ($model->save()) { $_POST['success'] = 1; } else { $_POST['success'] = 0; } $_POST['id'] = $id; $_POST['error_employee_id'] = ''; $_POST['error_type'] = ''; $_POST['error_name'] = ''; $_POST['error_certificate_no'] = ''; $_POST['error_certificate_date'] = ''; $_POST['error_instantion'] = ''; if (isset($model->errors['employee_id'][0])) { $_POST['error_employee_id'] = $model->errors['employee_id'][0]; } if (isset($model->errors['reward_type'][0])) { $_POST['error_type'] = $model->errors['reward_type'][0]; } if (isset($model->errors['name'][0])) { $_POST['error_name'] = $model->errors['name'][0]; } if (isset($model->errors['certificate_no'][0])) { $_POST['error_certificate_no'] = $model->errors['certificate_no'][0]; } if (isset($model->errors['certificate_date'][0])) { $_POST['error_certificate_date'] = $model->errors['certificate_date'][0]; } if (isset($model->errors['instantion'][0])) { $_POST['error_instantion'] = $model->errors['instantion'][0]; } echo json_encode($_POST); }