diff --git a/controllers/BlogArticleController.php b/controllers/BlogArticleController.php index 1939f13..2fd9863 100755 --- a/controllers/BlogArticleController.php +++ b/controllers/BlogArticleController.php @@ -280,6 +280,14 @@ return $this->redirect([ 'index' ]); } + public function actionDeleteImage($id) + { + $model = $this->findModel($id); + $model->image = null; + $model->updateAttributes(['image']); + return true; + } + /** * Finds the BlogArticle model based on its primary key value. * If the model is not found, a 404 HTTP exception will be thrown. diff --git a/controllers/BlogCategoryController.php b/controllers/BlogCategoryController.php index 9629c7e..094912c 100755 --- a/controllers/BlogCategoryController.php +++ b/controllers/BlogCategoryController.php @@ -180,6 +180,14 @@ return $this->redirect([ 'index' ]); } + + public function actionDeleteImage($id) + { + $model = $this->findModel($id); + $model->image = null; + $model->updateAttributes(['image']); + return true; + } /** * Finds the BlogCategory model based on its primary key value. diff --git a/views/blog-article/_form.php b/views/blog-article/_form.php index 3b9e403..964c2f1 100755 --- a/views/blog-article/_form.php +++ b/views/blog-article/_form.php @@ -6,6 +6,7 @@ use artweb\artbox\blog\models\BlogTag; use kartik\select2\Select2; use yii\helpers\Html; + use yii\helpers\Url; use yii\web\View; use yii\widgets\ActiveForm; use artweb\artbox\language\widgets\LanguageForm; @@ -85,6 +86,8 @@ 'options' => [ 'accept' => 'image/*', 'multiple' => false, + 'deleteurl' => $model->isNewRecord?false:Url::to(['/blog/blog-article/delete-image', 'id' => $model->id]), + 'class' => $model->isNewRecord?'':'artbox-delete-file', ], 'pluginOptions' => [ 'allowedFileExtensions' => [ @@ -92,13 +95,15 @@ 'gif', 'png', ], - 'initialPreview' => !empty( $model->imageUrl ) ? \artweb\artbox\components\artboximage\ArtboxImageHelper::getImage( + 'initialPreview' => !empty( $model->getImageUrl(0, false) ) ? \artweb\artbox\components\artboximage\ArtboxImageHelper::getImage( $model->imageUrl, 'list' ) : '', - 'overwriteInitial' => true, - 'showRemove' => false, - 'showUpload' => false, + 'initialPreviewShowDelete' => false, + 'overwriteInitial' => true, + 'showRemove' => true, + 'showUpload' => false, + 'showClose' => false, 'previewFileType' => 'image', ], ] diff --git a/views/blog-category/_form.php b/views/blog-category/_form.php index ee05b0b..0511cd1 100755 --- a/views/blog-category/_form.php +++ b/views/blog-category/_form.php @@ -4,6 +4,7 @@ use artweb\artbox\blog\models\BlogCategoryLang; use kartik\select2\Select2; use yii\helpers\Html; + use yii\helpers\Url; use yii\web\View; use yii\widgets\ActiveForm; use artweb\artbox\language\widgets\LanguageForm; @@ -44,6 +45,8 @@ 'options' => [ 'accept' => 'image/*', 'multiple' => false, + 'deleteurl' => $model->isNewRecord?false:Url::to(['/blog/blog-category/delete-image', 'id' => $model->id]), + 'class' => $model->isNewRecord?'':'artbox-delete-file', ], 'pluginOptions' => [ 'allowedFileExtensions' => [ @@ -51,13 +54,15 @@ 'gif', 'png', ], - 'initialPreview' => !empty( $model->imageUrl ) ? \artweb\artbox\components\artboximage\ArtboxImageHelper::getImage( + 'initialPreview' => !empty( $model->getImageUrl(0, false) ) ? \artweb\artbox\components\artboximage\ArtboxImageHelper::getImage( $model->imageUrl, 'list' ) : '', - 'overwriteInitial' => true, - 'showRemove' => false, - 'showUpload' => false, + 'initialPreviewShowDelete' => false, + 'overwriteInitial' => true, + 'showRemove' => true, + 'showUpload' => false, + 'showClose' => false, 'previewFileType' => 'image', ], ] -- libgit2 0.21.4