diff --git a/action/adapter/File.php b/action/adapter/File.php index c4a1e20..2a3a7ea 100644 --- a/action/adapter/File.php +++ b/action/adapter/File.php @@ -24,6 +24,8 @@ class File extends Adapter public $model = null; public $dataAttribute = 'data'; public $nameAttribute = 'name'; + public $mimeTypeAttribute = 'mime_type'; + public $extensionAttribute = 'extension'; public $extensionIsRequired = true; protected function _run() { $attributes = $this->actionParams->get; @@ -41,27 +43,39 @@ protected function _run() { $dataAttribute = $this->dataAttribute; } - $selectedAttributes = array_merge([ + $extensionAttribute = $this->extensionAttribute; + $selectedAttributes = [ $this->nameAttribute, $dataAttribute, - 'mime_type', - ], array_keys($attributes)); + $extensionAttribute, + $this->mimeTypeAttribute, + ]; + + $selectedAttributes = array_filter($selectedAttributes); + $attributes = [ + $extensionAttribute => $attributes['extension'], + 'id' => $attributes['id'], + ]; $result = $class::find()->select($selectedAttributes)->andWhere($attributes)->one(); if (!$result) { throw new NotFoundHttpException('File by url "' . \yii::$app->request->getUrl() . '" not found'); } - if ($this->extensionIsRequired && strtolower($result->extension) !== $attributes['extension']) { + if ($this->extensionIsRequired && strtolower($result->$extensionAttribute) !== $attributes[$extensionAttribute]) { throw new NotFoundHttpException('File extension is wrong'); } $this->model = $result; $response = \Yii::$app->getResponse(); - if (strpos($result->mime_type, 'image/') === 0) { - $response->headers->set('Content-Type', $result->mime_type); + if ($this->mimeTypeAttribute) { + if (strpos($result->mime_type, 'image/') === 0) { + $response->headers->set('Content-Type', $result->mime_type); + } else { + $response->setDownloadHeaders($result->{$this->nameAttribute}, $result->mime_type); + } } else { - $response->setDownloadHeaders($result->{$this->nameAttribute}, $result->mime_type); + $response->headers->set('Content-Type', 'image/jpeg'); } $response = $this->getResponse([ diff --git a/widgets/EditDialog.php b/widgets/EditDialog.php index 7abf50b..f2d510f 100644 --- a/widgets/EditDialog.php +++ b/widgets/EditDialog.php @@ -10,6 +10,7 @@ use execut\yii\jui\Widget; +use function Leafo\ScssPhp\Tests\_dump; use yii\bootstrap\Modal; use yii\helpers\ArrayHelper; use yii\helpers\Html; diff --git a/widgets/GridView.php b/widgets/GridView.php index 4a1f75a..e532c36 100644 --- a/widgets/GridView.php +++ b/widgets/GridView.php @@ -58,7 +58,6 @@ protected function getUpdateUrl() { */ protected function registerWidget($name = null, $id = null) { - if ($name === null) { $name = $this->getDefaultJsWidgetName(); } @@ -147,10 +146,7 @@ public function getToolbarConfig(): array public function beginPjax() { parent::beginPjax(); if ($this->isAjaxCrud) { - $model = $this->formModel; - if (is_callable($model)) { - $model = $model(); - } + $model = $this->getFormModel(); if ($this->pjax) { $gridId = $this->id . '-pjax'; @@ -193,7 +189,13 @@ public function renderAlertBlock() { protected function renderAddButton() { $title = \yii::t('execut.actions', 'Add') . ' ' . $this->title; - return Html::a($title, Url::to($this->addButtonUrl), [ + $url = $this->addButtonUrl; + if (!is_array($url)) { + $url = [$url]; + } + + + return Html::a($title, Url::to($url), [ 'id' => $this->id . '-edit-add-button', 'type' => 'button', 'data-pjax' => 0, @@ -201,4 +203,16 @@ protected function renderAddButton() 'class' => 'btn btn-success' ]); } + + /** + * @return null + */ + protected function getFormModel() + { + $model = $this->formModel; + if (is_callable($model)) { + $model = $model(); + } + return $model; + } } \ No newline at end of file diff --git a/widgets/assets/EditDialog.js b/widgets/assets/EditDialog.js index 4da3f1b..94eb868 100644 --- a/widgets/assets/EditDialog.js +++ b/widgets/assets/EditDialog.js @@ -9,6 +9,11 @@ var t = this; t._initElements(); t._initEvents(); + // $.ajaxSetup({ + // cache: false, + // contentType: false, + // processData: false + // }); }, _initElements: function () { var t = this; @@ -78,7 +83,13 @@ var realAction = t._sourceAction; if (typeof attributes.id !== 'undefined') { - realAction += '?id=' + attributes.id; + if (realAction.search('\\?') !== 0) { + realAction += '&' + } else { + realAction += '?' + } + + realAction += 'id=' + attributes.id; } t.formEl.attr('action', realAction) diff --git a/widgets/assets/GridView.css b/widgets/assets/GridView.css index 602b19c..220f248 100644 --- a/widgets/assets/GridView.css +++ b/widgets/assets/GridView.css @@ -4,3 +4,7 @@ .kv-grid-table tr.link-row:hover td { color: #289939; } +.btn-group, +.summary { + padding: 10px; +} diff --git a/widgets/assets/GridView.less b/widgets/assets/GridView.less index 0553a9e..ce0e83a 100644 --- a/widgets/assets/GridView.less +++ b/widgets/assets/GridView.less @@ -5,4 +5,8 @@ color: #289939; } } -} \ No newline at end of file +} + +.btn-group, .summary { + padding: 10px; +}