Commit 2ffeed3da6a52e17bb1f4a9dc71362c9060fa2e4
1 parent
664d2171
Image delete functionality
Showing
9 changed files
with
210 additions
and
89 deletions
Show diff stats
controllers/BrandController.php
... | ... | @@ -40,6 +40,7 @@ |
40 | 40 | 'update', |
41 | 41 | 'view', |
42 | 42 | 'delete', |
43 | + 'delete-image', | |
43 | 44 | ], |
44 | 45 | 'allow' => true, |
45 | 46 | 'roles' => [ '@' ], |
... | ... | @@ -49,7 +50,8 @@ |
49 | 50 | 'verbs' => [ |
50 | 51 | 'class' => VerbFilter::className(), |
51 | 52 | 'actions' => [ |
52 | - 'logout' => [ 'post' ], | |
53 | + 'logout' => [ 'post' ], | |
54 | + 'delete-image' => [ 'post' ], | |
53 | 55 | ], |
54 | 56 | ], |
55 | 57 | ]; |
... | ... | @@ -57,6 +59,7 @@ |
57 | 59 | |
58 | 60 | /** |
59 | 61 | * Lists all Brand models. |
62 | + * | |
60 | 63 | * @return mixed |
61 | 64 | */ |
62 | 65 | public function actionIndex() |
... | ... | @@ -64,10 +67,13 @@ |
64 | 67 | $searchModel = new BrandSearch(); |
65 | 68 | $dataProvider = $searchModel->search(Yii::$app->request->queryParams); |
66 | 69 | |
67 | - return $this->render('index', [ | |
68 | - 'searchModel' => $searchModel, | |
69 | - 'dataProvider' => $dataProvider, | |
70 | - ]); | |
70 | + return $this->render( | |
71 | + 'index', | |
72 | + [ | |
73 | + 'searchModel' => $searchModel, | |
74 | + 'dataProvider' => $dataProvider, | |
75 | + ] | |
76 | + ); | |
71 | 77 | } |
72 | 78 | |
73 | 79 | /** |
... | ... | @@ -79,33 +85,42 @@ |
79 | 85 | */ |
80 | 86 | public function actionView($id) |
81 | 87 | { |
82 | - return $this->render('view', [ | |
83 | - 'model' => $this->findModel($id), | |
84 | - ]); | |
88 | + return $this->render( | |
89 | + 'view', | |
90 | + [ | |
91 | + 'model' => $this->findModel($id), | |
92 | + ] | |
93 | + ); | |
85 | 94 | } |
86 | 95 | |
87 | 96 | /** |
88 | 97 | * Creates a new Brand model. |
89 | 98 | * If creation is successful, the browser will be redirected to the 'view' page. |
99 | + * | |
90 | 100 | * @return mixed |
91 | 101 | */ |
92 | 102 | public function actionCreate() |
93 | 103 | { |
94 | 104 | $model = new Brand(); |
95 | 105 | $model->generateLangs(); |
96 | - if($model->load(Yii::$app->request->post())) { | |
106 | + if ($model->load(Yii::$app->request->post())) { | |
97 | 107 | $model->loadLangs(\Yii::$app->request); |
98 | - if($model->save() && $model->transactionStatus) { | |
99 | - return is_null(Yii::$app->request->post('create_and_new')) ? $this->redirect([ | |
100 | - 'view', | |
101 | - 'id' => $model->id, | |
102 | - ]) : $this->redirect(array_merge([ 'create' ], Yii::$app->request->queryParams)); | |
108 | + if ($model->save() && $model->transactionStatus) { | |
109 | + return is_null(Yii::$app->request->post('create_and_new')) ? $this->redirect( | |
110 | + [ | |
111 | + 'view', | |
112 | + 'id' => $model->id, | |
113 | + ] | |
114 | + ) : $this->redirect(array_merge([ 'create' ], Yii::$app->request->queryParams)); | |
103 | 115 | } |
104 | 116 | } |
105 | - return $this->render('create', [ | |
106 | - 'model' => $model, | |
107 | - 'modelLangs' => $model->modelLangs, | |
108 | - ]); | |
117 | + return $this->render( | |
118 | + 'create', | |
119 | + [ | |
120 | + 'model' => $model, | |
121 | + 'modelLangs' => $model->modelLangs, | |
122 | + ] | |
123 | + ); | |
109 | 124 | } |
110 | 125 | |
111 | 126 | /** |
... | ... | @@ -121,19 +136,24 @@ |
121 | 136 | $model = $this->findModel($id); |
122 | 137 | $model->generateLangs(); |
123 | 138 | |
124 | - if($model->load(Yii::$app->request->post())) { | |
139 | + if ($model->load(Yii::$app->request->post())) { | |
125 | 140 | $model->loadLangs(\Yii::$app->request); |
126 | - if($model->save() && $model->transactionStatus) { | |
127 | - return $this->redirect([ | |
128 | - 'view', | |
129 | - 'id' => $model->id, | |
130 | - ]); | |
141 | + if ($model->save() && $model->transactionStatus) { | |
142 | + return $this->redirect( | |
143 | + [ | |
144 | + 'view', | |
145 | + 'id' => $model->id, | |
146 | + ] | |
147 | + ); | |
131 | 148 | } |
132 | 149 | } |
133 | - return $this->render('update', [ | |
134 | - 'model' => $model, | |
135 | - 'modelLangs' => $model->modelLangs, | |
136 | - ]); | |
150 | + return $this->render( | |
151 | + 'update', | |
152 | + [ | |
153 | + 'model' => $model, | |
154 | + 'modelLangs' => $model->modelLangs, | |
155 | + ] | |
156 | + ); | |
137 | 157 | } |
138 | 158 | |
139 | 159 | /** |
... | ... | @@ -152,6 +172,14 @@ |
152 | 172 | return $this->redirect([ 'index' ]); |
153 | 173 | } |
154 | 174 | |
175 | + public function actionDeleteImage($id) | |
176 | + { | |
177 | + $model = $this->findModel($id); | |
178 | + $model->image = null; | |
179 | + $model->updateAttributes(['image']); | |
180 | + return true; | |
181 | + } | |
182 | + | |
155 | 183 | /** |
156 | 184 | * Finds the Brand model based on its primary key value. |
157 | 185 | * If the model is not found, a 404 HTTP exception will be thrown. |
... | ... | @@ -163,7 +191,11 @@ |
163 | 191 | */ |
164 | 192 | protected function findModel($id) |
165 | 193 | { |
166 | - if(( $model = Brand::find()->with('lang')->where(['id' => $id])->one() ) !== NULL) { | |
194 | + if (( $model = Brand::find() | |
195 | + ->with('lang') | |
196 | + ->where([ 'id' => $id ]) | |
197 | + ->one() ) !== null | |
198 | + ) { | |
167 | 199 | return $model; |
168 | 200 | } else { |
169 | 201 | throw new NotFoundHttpException('The requested page does not exist.'); | ... | ... |
controllers/CategoryController.php
... | ... | @@ -210,6 +210,22 @@ |
210 | 210 | |
211 | 211 | return $this->redirect([ 'index' ]); |
212 | 212 | } |
213 | + | |
214 | + public function actionDeleteImage($id) | |
215 | + { | |
216 | + $model = $this->findModel($id); | |
217 | + $model->image = null; | |
218 | + $model->updateAttributes(['image']); | |
219 | + return true; | |
220 | + } | |
221 | + | |
222 | + public function actionDeleteIcon($id) | |
223 | + { | |
224 | + $model = $this->findModel($id); | |
225 | + $model->icon = null; | |
226 | + $model->updateAttributes(['icon']); | |
227 | + return true; | |
228 | + } | |
213 | 229 | |
214 | 230 | /** |
215 | 231 | * Finds the Category model based on its primary key value. | ... | ... |
controllers/ManageController.php
... | ... | @@ -123,6 +123,7 @@ |
123 | 123 | [ |
124 | 124 | 'model' => $model, |
125 | 125 | 'modelLangs' => $model->modelLangs, |
126 | + 'videos' => !empty( $model->videos ) ? $model->videos : [ new ProductVideo() ], | |
126 | 127 | ] |
127 | 128 | ); |
128 | 129 | } |
... | ... | @@ -409,6 +410,14 @@ |
409 | 410 | ] |
410 | 411 | ); |
411 | 412 | } |
413 | + | |
414 | + public function actionDeleteSize($id) | |
415 | + { | |
416 | + $model = $this->findModel($id); | |
417 | + $model->size_image = null; | |
418 | + $model->updateAttributes(['size_image']); | |
419 | + return true; | |
420 | + } | |
412 | 421 | |
413 | 422 | /** |
414 | 423 | * Finds the Product model based on its primary key value. | ... | ... |
controllers/TaxOptionController.php
... | ... | @@ -156,6 +156,14 @@ |
156 | 156 | ] |
157 | 157 | ); |
158 | 158 | } |
159 | + | |
160 | + public function actionDeleteImage($id) | |
161 | + { | |
162 | + $model = $this->findModel($id); | |
163 | + $model->image = null; | |
164 | + $model->updateAttributes(['image']); | |
165 | + return true; | |
166 | + } | |
159 | 167 | |
160 | 168 | /** |
161 | 169 | * Finds the TaxOption model based on its primary key value. | ... | ... |
views/brand/_form.php
... | ... | @@ -5,6 +5,7 @@ |
5 | 5 | use artweb\artbox\ecommerce\models\Brand; |
6 | 6 | use artweb\artbox\ecommerce\models\BrandLang; |
7 | 7 | use yii\helpers\Html; |
8 | + use yii\helpers\Url; | |
8 | 9 | use yii\web\View; |
9 | 10 | use yii\widgets\ActiveForm; |
10 | 11 | |
... | ... | @@ -18,47 +19,77 @@ |
18 | 19 | |
19 | 20 | <div class="brand-form"> |
20 | 21 | |
21 | - <?php $form = ActiveForm::begin([ | |
22 | - 'enableClientValidation' => false, | |
23 | - 'options' => [ 'enctype' => 'multipart/form-data' ], | |
24 | - ]); ?> | |
22 | + <?php $form = ActiveForm::begin( | |
23 | + [ | |
24 | + 'enableClientValidation' => false, | |
25 | + 'options' => [ 'enctype' => 'multipart/form-data' ], | |
26 | + ] | |
27 | + ); ?> | |
25 | 28 | |
26 | 29 | <?= $form->field($model, 'image') |
27 | - ->widget(\kartik\file\FileInput::className(), [ | |
28 | - 'language' => 'ru', | |
29 | - 'options' => [ | |
30 | - 'accept' => 'image/*', | |
31 | - 'multiple' => false, | |
32 | - ], | |
33 | - 'pluginOptions' => [ | |
34 | - 'allowedFileExtensions' => [ | |
35 | - 'jpg', | |
36 | - 'gif', | |
37 | - 'png', | |
30 | + ->widget( | |
31 | + \kartik\file\FileInput::className(), | |
32 | + [ | |
33 | + 'language' => 'ru', | |
34 | + 'options' => [ | |
35 | + 'accept' => 'image/*', | |
36 | + 'multiple' => false, | |
37 | + 'deleteurl' => $model->isNewRecord?false:Url::to(['/ecommerce/brand/delete-image', 'id' => $model->id]), | |
38 | + 'class' => $model->isNewRecord?'':'artbox-delete-file', | |
38 | 39 | ], |
39 | - 'initialPreview' => !empty( $model->imageUrl ) ? ArtboxImageHelper::getImage($model->imageUrl, 'list') : '', | |
40 | - 'overwriteInitial' => true, | |
41 | - 'showRemove' => false, | |
42 | - 'showUpload' => false, | |
43 | - 'previewFileType' => 'image', | |
44 | - ], | |
45 | - ]); ?> | |
40 | + 'pluginOptions' => [ | |
41 | + 'allowedFileExtensions' => [ | |
42 | + 'jpg', | |
43 | + 'gif', | |
44 | + 'png', | |
45 | + ], | |
46 | + 'initialPreview' => !empty( $model->getImageUrl( | |
47 | + 0, | |
48 | + false | |
49 | + ) ) ? ArtboxImageHelper::getImage( | |
50 | + $model->imageUrl, | |
51 | + 'list', | |
52 | + [] | |
53 | + ) : '', | |
54 | + 'initialPreviewShowDelete' => false, | |
55 | + 'overwriteInitial' => true, | |
56 | + 'showRemove' => true, | |
57 | + 'showUpload' => false, | |
58 | + 'showClose' => false, | |
59 | + 'previewFileType' => 'image', | |
60 | + ], | |
61 | + ] | |
62 | + ); ?> | |
46 | 63 | |
47 | - <?= $form->field($model, 'in_menu')->dropDownList([\Yii::t('product', 'No'), \Yii::t('product', 'Yes')]); ?> | |
64 | + <?= $form->field($model, 'in_menu') | |
65 | + ->dropDownList( | |
66 | + [ | |
67 | + \Yii::t('product', 'No'), | |
68 | + \Yii::t('product', 'Yes'), | |
69 | + ] | |
70 | + ); ?> | |
48 | 71 | |
49 | - <?= LanguageForm::widget([ | |
50 | - 'modelLangs' => $modelLangs, | |
51 | - 'formView' => '@artweb/artbox/ecommerce/views/brand/_form_language', | |
52 | - 'form' => $form, | |
53 | - ]) ?> | |
72 | + <?= LanguageForm::widget( | |
73 | + [ | |
74 | + 'modelLangs' => $modelLangs, | |
75 | + 'formView' => '@artweb/artbox/ecommerce/views/brand/_form_language', | |
76 | + 'form' => $form, | |
77 | + ] | |
78 | + ) ?> | |
54 | 79 | |
55 | 80 | <div class="form-group"> |
56 | - <?= Html::submitButton($model->isNewRecord ? Yii::t('product', 'Create') : Yii::t('product', 'Update'), [ 'class' => $model->isNewRecord ? 'btn btn-success' : 'btn btn-primary' ]) ?> | |
57 | - <?php if($model->isNewRecord) : ?> | |
58 | - <?= Html::submitButton(Yii::t('product', 'Create and continue'), [ | |
59 | - 'name' => 'create_and_new', | |
60 | - 'class' => 'btn btn-primary', | |
61 | - ]) ?> | |
81 | + <?= Html::submitButton( | |
82 | + $model->isNewRecord ? Yii::t('product', 'Create') : Yii::t('product', 'Update'), | |
83 | + [ 'class' => $model->isNewRecord ? 'btn btn-success' : 'btn btn-primary' ] | |
84 | + ) ?> | |
85 | + <?php if ($model->isNewRecord) : ?> | |
86 | + <?= Html::submitButton( | |
87 | + Yii::t('product', 'Create and continue'), | |
88 | + [ | |
89 | + 'name' => 'create_and_new', | |
90 | + 'class' => 'btn btn-primary', | |
91 | + ] | |
92 | + ) ?> | |
62 | 93 | <?php endif ?> |
63 | 94 | </div> |
64 | 95 | ... | ... |
views/category/_form.php
... | ... | @@ -5,6 +5,7 @@ |
5 | 5 | use artweb\artbox\ecommerce\models\Category; |
6 | 6 | use artweb\artbox\ecommerce\models\CategoryLang; |
7 | 7 | use yii\helpers\Html; |
8 | + use yii\helpers\Url; | |
8 | 9 | use yii\web\View; |
9 | 10 | use yii\widgets\ActiveForm; |
10 | 11 | |
... | ... | @@ -55,6 +56,8 @@ |
55 | 56 | 'options' => [ |
56 | 57 | 'accept' => 'image/*', |
57 | 58 | 'multiple' => false, |
59 | + 'deleteurl' => $model->isNewRecord?false:Url::to(['/ecommerce/category/delete-image', 'id' => $model->id]), | |
60 | + 'class' => $model->isNewRecord?'':'artbox-delete-file', | |
58 | 61 | ], |
59 | 62 | 'pluginOptions' => [ |
60 | 63 | 'allowedFileExtensions' => [ |
... | ... | @@ -62,14 +65,16 @@ |
62 | 65 | 'gif', |
63 | 66 | 'png', |
64 | 67 | ], |
65 | - 'initialPreview' => !empty( $model->imageUrl ) ? ArtboxImageHelper::getImage( | |
68 | + 'initialPreview' => !empty( $model->getImageUrl(0, false) ) ? ArtboxImageHelper::getImage( | |
66 | 69 | $model->imageUrl, |
67 | 70 | 'list' |
68 | 71 | ) : '', |
69 | - 'overwriteInitial' => true, | |
70 | - 'showRemove' => false, | |
71 | - 'showUpload' => false, | |
72 | - 'previewFileType' => 'image', | |
72 | + 'initialPreviewShowDelete' => false, | |
73 | + 'overwriteInitial' => true, | |
74 | + 'showRemove' => true, | |
75 | + 'showUpload' => false, | |
76 | + 'showClose' => false, | |
77 | + 'previewFileType' => 'image', | |
73 | 78 | ], |
74 | 79 | ] |
75 | 80 | ); ?> |
... | ... | @@ -82,6 +87,8 @@ |
82 | 87 | 'options' => [ |
83 | 88 | 'accept' => 'image/*', |
84 | 89 | 'multiple' => false, |
90 | + 'deleteurl' => $model->isNewRecord?false:Url::to(['/ecommerce/category/delete-icon', 'id' => $model->id]), | |
91 | + 'class' => $model->isNewRecord?'':'artbox-delete-file', | |
85 | 92 | ], |
86 | 93 | 'pluginOptions' => [ |
87 | 94 | 'allowedFileExtensions' => [ |
... | ... | @@ -96,10 +103,12 @@ |
96 | 103 | $model->getImageUrl(1, false), |
97 | 104 | 'list' |
98 | 105 | ) : '', |
99 | - 'overwriteInitial' => true, | |
100 | - 'showRemove' => false, | |
101 | - 'showUpload' => false, | |
102 | - 'previewFileType' => 'image', | |
106 | + 'initialPreviewShowDelete' => false, | |
107 | + 'overwriteInitial' => true, | |
108 | + 'showRemove' => true, | |
109 | + 'showUpload' => false, | |
110 | + 'showClose' => false, | |
111 | + 'previewFileType' => 'image', | |
103 | 112 | ], |
104 | 113 | ] |
105 | 114 | ); ?> | ... | ... |
views/manage/_form.php
... | ... | @@ -9,6 +9,7 @@ |
9 | 9 | use wbraganca\dynamicform\DynamicFormWidget; |
10 | 10 | use yii\db\ActiveQuery; |
11 | 11 | use yii\helpers\Html; |
12 | + use yii\helpers\Url; | |
12 | 13 | use yii\widgets\ActiveForm; |
13 | 14 | use yii\helpers\ArrayHelper; |
14 | 15 | use artweb\artbox\components\artboxtree\ArtboxTreeHelper; |
... | ... | @@ -190,6 +191,8 @@ $(".dynamicform_wrapper").on("limitReached", function(e, item) { |
190 | 191 | 'options' => [ |
191 | 192 | 'accept' => 'image/*', |
192 | 193 | 'multiple' => false, |
194 | + 'deleteurl' => $model->isNewRecord?false:Url::to(['/ecommerce/manage/delete-size', 'id' => $model->id]), | |
195 | + 'class' => $model->isNewRecord?'':'artbox-delete-file', | |
193 | 196 | ], |
194 | 197 | 'pluginOptions' => [ |
195 | 198 | 'allowedFileExtensions' => [ |
... | ... | @@ -197,14 +200,16 @@ $(".dynamicform_wrapper").on("limitReached", function(e, item) { |
197 | 200 | 'gif', |
198 | 201 | 'png', |
199 | 202 | ], |
200 | - 'initialPreview' => !empty( $model->getBehavior('size_image')->imageUrl ) ? ArtboxImageHelper::getImage( | |
203 | + 'initialPreview' => !empty( $model->getBehavior('size_image')->getImageUrl(0, false)) ? ArtboxImageHelper::getImage( | |
201 | 204 | $model->getBehavior('size_image')->imageUrl, |
202 | 205 | 'list' |
203 | 206 | ) : '', |
204 | - 'overwriteInitial' => true, | |
205 | - 'showRemove' => false, | |
206 | - 'showUpload' => false, | |
207 | - 'previewFileType' => 'image', | |
207 | + 'initialPreviewShowDelete' => false, | |
208 | + 'overwriteInitial' => true, | |
209 | + 'showRemove' => true, | |
210 | + 'showUpload' => false, | |
211 | + 'showClose' => false, | |
212 | + 'previewFileType' => 'image', | |
208 | 213 | ], |
209 | 214 | ] |
210 | 215 | ); ?> | ... | ... |
views/manage/create.php
... | ... | @@ -2,13 +2,15 @@ |
2 | 2 | |
3 | 3 | use artweb\artbox\ecommerce\models\Product; |
4 | 4 | use artweb\artbox\ecommerce\models\ProductLang; |
5 | + use artweb\artbox\ecommerce\models\ProductVideo; | |
5 | 6 | use yii\helpers\Html; |
6 | 7 | use yii\web\View; |
7 | 8 | |
8 | 9 | /** |
9 | - * @var View $this | |
10 | - * @var Product $model | |
11 | - * @var ProductLang[] $modelLangs | |
10 | + * @var View $this | |
11 | + * @var Product $model | |
12 | + * @var ProductLang[] $modelLangs | |
13 | + * @var ProductVideo[] $videos | |
12 | 14 | */ |
13 | 15 | |
14 | 16 | $this->title = Yii::t('product', 'Create Product'); |
... | ... | @@ -22,9 +24,13 @@ |
22 | 24 | |
23 | 25 | <h1><?= Html::encode($this->title) ?></h1> |
24 | 26 | |
25 | - <?= $this->render('_form', [ | |
26 | - 'model' => $model, | |
27 | - 'modelLangs' => $modelLangs, | |
28 | - ]) ?> | |
27 | + <?= $this->render( | |
28 | + '_form', | |
29 | + [ | |
30 | + 'model' => $model, | |
31 | + 'modelLangs' => $modelLangs, | |
32 | + 'videos' => $videos, | |
33 | + ] | |
34 | + ) ?> | |
29 | 35 | |
30 | 36 | </div> | ... | ... |
views/tax-option/_form.php
... | ... | @@ -6,6 +6,7 @@ |
6 | 6 | use artweb\artbox\ecommerce\models\TaxOptionLang; |
7 | 7 | use yii\helpers\ArrayHelper; |
8 | 8 | use yii\helpers\Html; |
9 | + use yii\helpers\Url; | |
9 | 10 | use yii\widgets\ActiveForm; |
10 | 11 | use artweb\artbox\ecommerce\models\TaxOption; |
11 | 12 | |
... | ... | @@ -48,6 +49,8 @@ |
48 | 49 | 'options' => [ |
49 | 50 | 'accept' => 'image/*', |
50 | 51 | 'multiple' => false, |
52 | + 'deleteurl' => $model->isNewRecord?false:Url::to(['/ecommerce/tax-option/delete-image', 'id' => $model->id]), | |
53 | + 'class' => $model->isNewRecord?'':'artbox-delete-file', | |
51 | 54 | ], |
52 | 55 | 'pluginOptions' => [ |
53 | 56 | 'allowedFileExtensions' => [ |
... | ... | @@ -55,14 +58,16 @@ |
55 | 58 | 'gif', |
56 | 59 | 'png', |
57 | 60 | ], |
58 | - 'initialPreview' => !empty( $model->imageUrl ) ? ArtboxImageHelper::getImage( | |
61 | + 'initialPreview' => !empty( $model->getImageUrl(0, false) ) ? ArtboxImageHelper::getImage( | |
59 | 62 | $model->imageUrl, |
60 | 63 | 'list' |
61 | 64 | ) : '', |
62 | - 'overwriteInitial' => true, | |
63 | - 'showRemove' => false, | |
64 | - 'showUpload' => false, | |
65 | - 'previewFileType' => 'image', | |
65 | + 'initialPreviewShowDelete' => false, | |
66 | + 'overwriteInitial' => true, | |
67 | + 'showRemove' => true, | |
68 | + 'showUpload' => false, | |
69 | + 'showClose' => false, | |
70 | + 'previewFileType' => 'image', | |
66 | 71 | ], |
67 | 72 | ] |
68 | 73 | ) | ... | ... |