Commit 7ed9667aafaaae474637a198d2ae9e4585af70ee
1 parent
66ff620a
Image delete functionality
Showing
4 changed files
with
34 additions
and
8 deletions
Show diff stats
controllers/BlogArticleController.php
@@ -280,6 +280,14 @@ | @@ -280,6 +280,14 @@ | ||
280 | return $this->redirect([ 'index' ]); | 280 | return $this->redirect([ 'index' ]); |
281 | } | 281 | } |
282 | 282 | ||
283 | + public function actionDeleteImage($id) | ||
284 | + { | ||
285 | + $model = $this->findModel($id); | ||
286 | + $model->image = null; | ||
287 | + $model->updateAttributes(['image']); | ||
288 | + return true; | ||
289 | + } | ||
290 | + | ||
283 | /** | 291 | /** |
284 | * Finds the BlogArticle model based on its primary key value. | 292 | * Finds the BlogArticle model based on its primary key value. |
285 | * If the model is not found, a 404 HTTP exception will be thrown. | 293 | * If the model is not found, a 404 HTTP exception will be thrown. |
controllers/BlogCategoryController.php
@@ -180,6 +180,14 @@ | @@ -180,6 +180,14 @@ | ||
180 | 180 | ||
181 | return $this->redirect([ 'index' ]); | 181 | return $this->redirect([ 'index' ]); |
182 | } | 182 | } |
183 | + | ||
184 | + public function actionDeleteImage($id) | ||
185 | + { | ||
186 | + $model = $this->findModel($id); | ||
187 | + $model->image = null; | ||
188 | + $model->updateAttributes(['image']); | ||
189 | + return true; | ||
190 | + } | ||
183 | 191 | ||
184 | /** | 192 | /** |
185 | * Finds the BlogCategory model based on its primary key value. | 193 | * Finds the BlogCategory model based on its primary key value. |
views/blog-article/_form.php
@@ -6,6 +6,7 @@ | @@ -6,6 +6,7 @@ | ||
6 | use artweb\artbox\blog\models\BlogTag; | 6 | use artweb\artbox\blog\models\BlogTag; |
7 | use kartik\select2\Select2; | 7 | use kartik\select2\Select2; |
8 | use yii\helpers\Html; | 8 | use yii\helpers\Html; |
9 | + use yii\helpers\Url; | ||
9 | use yii\web\View; | 10 | use yii\web\View; |
10 | use yii\widgets\ActiveForm; | 11 | use yii\widgets\ActiveForm; |
11 | use artweb\artbox\language\widgets\LanguageForm; | 12 | use artweb\artbox\language\widgets\LanguageForm; |
@@ -85,6 +86,8 @@ | @@ -85,6 +86,8 @@ | ||
85 | 'options' => [ | 86 | 'options' => [ |
86 | 'accept' => 'image/*', | 87 | 'accept' => 'image/*', |
87 | 'multiple' => false, | 88 | 'multiple' => false, |
89 | + 'deleteurl' => $model->isNewRecord?false:Url::to(['/blog/blog-article/delete-image', 'id' => $model->id]), | ||
90 | + 'class' => $model->isNewRecord?'':'artbox-delete-file', | ||
88 | ], | 91 | ], |
89 | 'pluginOptions' => [ | 92 | 'pluginOptions' => [ |
90 | 'allowedFileExtensions' => [ | 93 | 'allowedFileExtensions' => [ |
@@ -92,13 +95,15 @@ | @@ -92,13 +95,15 @@ | ||
92 | 'gif', | 95 | 'gif', |
93 | 'png', | 96 | 'png', |
94 | ], | 97 | ], |
95 | - 'initialPreview' => !empty( $model->imageUrl ) ? \artweb\artbox\components\artboximage\ArtboxImageHelper::getImage( | 98 | + 'initialPreview' => !empty( $model->getImageUrl(0, false) ) ? \artweb\artbox\components\artboximage\ArtboxImageHelper::getImage( |
96 | $model->imageUrl, | 99 | $model->imageUrl, |
97 | 'list' | 100 | 'list' |
98 | ) : '', | 101 | ) : '', |
99 | - 'overwriteInitial' => true, | ||
100 | - 'showRemove' => false, | ||
101 | - 'showUpload' => false, | 102 | + 'initialPreviewShowDelete' => false, |
103 | + 'overwriteInitial' => true, | ||
104 | + 'showRemove' => true, | ||
105 | + 'showUpload' => false, | ||
106 | + 'showClose' => false, | ||
102 | 'previewFileType' => 'image', | 107 | 'previewFileType' => 'image', |
103 | ], | 108 | ], |
104 | ] | 109 | ] |
views/blog-category/_form.php
@@ -4,6 +4,7 @@ | @@ -4,6 +4,7 @@ | ||
4 | use artweb\artbox\blog\models\BlogCategoryLang; | 4 | use artweb\artbox\blog\models\BlogCategoryLang; |
5 | use kartik\select2\Select2; | 5 | use kartik\select2\Select2; |
6 | use yii\helpers\Html; | 6 | use yii\helpers\Html; |
7 | + use yii\helpers\Url; | ||
7 | use yii\web\View; | 8 | use yii\web\View; |
8 | use yii\widgets\ActiveForm; | 9 | use yii\widgets\ActiveForm; |
9 | use artweb\artbox\language\widgets\LanguageForm; | 10 | use artweb\artbox\language\widgets\LanguageForm; |
@@ -44,6 +45,8 @@ | @@ -44,6 +45,8 @@ | ||
44 | 'options' => [ | 45 | 'options' => [ |
45 | 'accept' => 'image/*', | 46 | 'accept' => 'image/*', |
46 | 'multiple' => false, | 47 | 'multiple' => false, |
48 | + 'deleteurl' => $model->isNewRecord?false:Url::to(['/blog/blog-category/delete-image', 'id' => $model->id]), | ||
49 | + 'class' => $model->isNewRecord?'':'artbox-delete-file', | ||
47 | ], | 50 | ], |
48 | 'pluginOptions' => [ | 51 | 'pluginOptions' => [ |
49 | 'allowedFileExtensions' => [ | 52 | 'allowedFileExtensions' => [ |
@@ -51,13 +54,15 @@ | @@ -51,13 +54,15 @@ | ||
51 | 'gif', | 54 | 'gif', |
52 | 'png', | 55 | 'png', |
53 | ], | 56 | ], |
54 | - 'initialPreview' => !empty( $model->imageUrl ) ? \artweb\artbox\components\artboximage\ArtboxImageHelper::getImage( | 57 | + 'initialPreview' => !empty( $model->getImageUrl(0, false) ) ? \artweb\artbox\components\artboximage\ArtboxImageHelper::getImage( |
55 | $model->imageUrl, | 58 | $model->imageUrl, |
56 | 'list' | 59 | 'list' |
57 | ) : '', | 60 | ) : '', |
58 | - 'overwriteInitial' => true, | ||
59 | - 'showRemove' => false, | ||
60 | - 'showUpload' => false, | 61 | + 'initialPreviewShowDelete' => false, |
62 | + 'overwriteInitial' => true, | ||
63 | + 'showRemove' => true, | ||
64 | + 'showUpload' => false, | ||
65 | + 'showClose' => false, | ||
61 | 'previewFileType' => 'image', | 66 | 'previewFileType' => 'image', |
62 | ], | 67 | ], |
63 | ] | 68 | ] |