public function actionCreate(Request $request) { if ($request->isXhr()) { $model = Unit::find($request->getAttribute('id')); return $this->renderAjax('image/ajax/modal', ['model' => $model]); } $this->uploadFiles($request->getUploadedFiles(), $request->getParams(), $request->getAttribute('id')); return $this->goBack(); }
public function actionDelete(Request $request) { if (!Oauth::isLogged()) { return $this->goBack(); } /* @var $model Unit */ $model = Unit::find($request->getAttribute('id')); if ($model->delete()) { Alert::add("Successful delete {$model->name}"); } return $this->goBack(); }
protected function parseSort(array $params, Query $query) { if (!isset($params['sort'])) { return $query->orderBy('id', 'desc'); } $column = strtolower($params['sort']); $direction = 'asc'; if (strpos($params['sort'], '-') === 0) { $direction = 'desc'; $column = ltrim($column, '-'); } if (!in_array($column, Unit::getColumns())) { return $query->orderBy('id', 'desc'); } return $query->orderBy($column, $direction); }
<?php use models\Unit; use app\core\View; /* @var $this View */ /* @var $model Unit */ $rarities = Unit::getRarities(); $isNewUnit = !$model->id; $route = $isNewUnit ? Main::$app->router->pathFor('unitCreate') : Main::$app->router->pathFor('unitUpdate', ['id' => $model->id]); ?> <div class="modal fade" id="modal-unit-<?php echo $isNewUnit ? '0' : $model->id; ?> " tabindex="-1" role="dialog" aria-labelledby="myModalLabel"> <div class="modal-dialog" role="document"> <form method="post" role="form" class="ws-validate" action="<?php echo $route; ?> "> <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="myModalLabel"> <?php echo $isNewUnit ? 'Create new unit' : 'Update ' . $model->name; ?> </h4> </div> <div class="modal-body"> <div class="form-group"> <label>Original name:</label>