Commit 7ed9667aafaaae474637a198d2ae9e4585af70ee

Authored by Yarik
1 parent 66ff620a

Image delete functionality

controllers/BlogArticleController.php
... ... @@ -280,6 +280,14 @@
280 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 292 * Finds the BlogArticle model based on its primary key value.
285 293 * If the model is not found, a 404 HTTP exception will be thrown.
... ...
controllers/BlogCategoryController.php
... ... @@ -180,6 +180,14 @@
180 180  
181 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 193 * Finds the BlogCategory model based on its primary key value.
... ...
views/blog-article/_form.php
... ... @@ -6,6 +6,7 @@
6 6 use artweb\artbox\blog\models\BlogTag;
7 7 use kartik\select2\Select2;
8 8 use yii\helpers\Html;
  9 + use yii\helpers\Url;
9 10 use yii\web\View;
10 11 use yii\widgets\ActiveForm;
11 12 use artweb\artbox\language\widgets\LanguageForm;
... ... @@ -85,6 +86,8 @@
85 86 'options' => [
86 87 'accept' => 'image/*',
87 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 92 'pluginOptions' => [
90 93 'allowedFileExtensions' => [
... ... @@ -92,13 +95,15 @@
92 95 'gif',
93 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 99 $model->imageUrl,
97 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 107 'previewFileType' => 'image',
103 108 ],
104 109 ]
... ...
views/blog-category/_form.php
... ... @@ -4,6 +4,7 @@
4 4 use artweb\artbox\blog\models\BlogCategoryLang;
5 5 use kartik\select2\Select2;
6 6 use yii\helpers\Html;
  7 + use yii\helpers\Url;
7 8 use yii\web\View;
8 9 use yii\widgets\ActiveForm;
9 10 use artweb\artbox\language\widgets\LanguageForm;
... ... @@ -44,6 +45,8 @@
44 45 'options' => [
45 46 'accept' => 'image/*',
46 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 51 'pluginOptions' => [
49 52 'allowedFileExtensions' => [
... ... @@ -51,13 +54,15 @@
51 54 'gif',
52 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 58 $model->imageUrl,
56 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 66 'previewFileType' => 'image',
62 67 ],
63 68 ]
... ...