2f25da09
Yarik
first commit
|
1
2
|
<?php
|
176ac41d
Alexey Boroda
-Blog article for...
|
3
|
use artweb\artbox\components\artboximage\ArtboxImageHelper;
|
2b315849
Alexey Boroda
-Product card (wi...
|
4
|
use artweb\artbox\ecommerce\models\ProductVideo;
|
8a7e6ecf
Yarik
Namespaces
|
5
|
use artweb\artbox\language\widgets\LanguageForm;
|
2f25da09
Yarik
first commit
|
6
7
8
|
use artweb\artbox\ecommerce\models\Brand;
use artweb\artbox\ecommerce\models\ProductLang;
use artweb\artbox\ecommerce\models\TaxGroup;
|
2b315849
Alexey Boroda
-Product card (wi...
|
9
|
use wbraganca\dynamicform\DynamicFormWidget;
|
2f25da09
Yarik
first commit
|
10
11
|
use yii\db\ActiveQuery;
use yii\helpers\Html;
|
2ffeed3d
Yarik
Image delete func...
|
12
|
use yii\helpers\Url;
|
2f25da09
Yarik
first commit
|
13
14
|
use yii\widgets\ActiveForm;
use yii\helpers\ArrayHelper;
|
69390831
Yarik
Namespaces
|
15
|
use artweb\artbox\components\artboxtree\ArtboxTreeHelper;
|
2f25da09
Yarik
first commit
|
16
17
|
use artweb\artbox\ecommerce\helpers\ProductHelper;
use kartik\select2\Select2;
|
2b315849
Alexey Boroda
-Product card (wi...
|
18
|
use yii\web\View;
|
2f25da09
Yarik
first commit
|
19
20
|
/**
|
2b315849
Alexey Boroda
-Product card (wi...
|
21
|
* @var yii\web\View $this
|
2f25da09
Yarik
first commit
|
22
|
* @var artweb\artbox\ecommerce\models\Product $model
|
2b315849
Alexey Boroda
-Product card (wi...
|
23
24
25
26
|
* @var ProductLang[] $modelLangs
* @var yii\widgets\ActiveForm $form
* @var ActiveQuery $groups
* @var ProductVideo[] $videos
|
2f25da09
Yarik
first commit
|
27
|
*/
|
2b315849
Alexey Boroda
-Product card (wi...
|
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
|
$js = '
$(".dynamicform_wrapper").on("beforeDelete", function(e, item) {
if (! confirm("Are you sure you want to delete this item?")) {
return false;
}
return true;
});
$(".dynamicform_wrapper").on("limitReached", function(e, item) {
alert("Limit reached");
});
';
$this->registerJs($js, View::POS_END);
|
2f25da09
Yarik
first commit
|
43
44
45
46
47
48
|
?>
<div class="product-form">
<?php $form = ActiveForm::begin(
[
|
70753ad4
Alexey Boroda
-Product card (vi...
|
49
50
51
52
|
'options' => [
'enctype' => 'multipart/form-data',
'id' => 'dynamic-form',
],
|
2f25da09
Yarik
first commit
|
53
54
55
56
57
|
]
); ?>
<?= $form->field($model, 'is_top')
->checkbox([ 'label' => 'ТОП' ]) ?>
|
8ceca3a7
Anastasia
main admin
|
58
59
|
<?= $form->field($model, 'is_top_main')
->checkbox([ 'label' => 'ТОП (главная)' ]) ?>
|
2f25da09
Yarik
first commit
|
60
61
|
<?= $form->field($model, 'is_new')
->checkbox([ 'label' => 'Новинка' ]) ?>
|
8ceca3a7
Anastasia
main admin
|
62
63
|
<?= $form->field($model, 'is_new_main')
->checkbox([ 'label' => 'Новинка(главная)' ]) ?>
|
2f25da09
Yarik
first commit
|
64
65
|
<?= $form->field($model, 'is_discount')
->checkbox([ 'label' => 'Акционный' ]) ?>
|
8ceca3a7
Anastasia
main admin
|
66
67
|
<?= $form->field($model, 'is_discount_main')
->checkbox([ 'label' => 'Акционный(главная)' ]) ?>
|
2f25da09
Yarik
first commit
|
68
|
|
2b315849
Alexey Boroda
-Product card (wi...
|
69
70
71
72
73
74
75
76
77
78
|
<?php DynamicFormWidget::begin(
[
'widgetContainer' => 'dynamicform_wrapper',
// required: only alphanumeric characters plus "_" [A-Za-z0-9_]
'widgetBody' => '.container-items',
// required: css class selector
'widgetItem' => '.item',
// required: css class
'limit' => 10,
// the maximum times, an element can be added (default 999)
|
70753ad4
Alexey Boroda
-Product card (vi...
|
79
|
'min' => 0,
|
2b315849
Alexey Boroda
-Product card (wi...
|
80
81
82
83
84
85
86
87
|
// 0 or 1 (default 1)
'insertButton' => '.add-item',
// css class
'deleteButton' => '.remove-item',
// css class
'model' => $videos[ 0 ],
'formId' => 'dynamic-form',
'formFields' => [
|
70753ad4
Alexey Boroda
-Product card (vi...
|
88
89
|
'quantity',
'title',
|
2b315849
Alexey Boroda
-Product card (wi...
|
90
91
92
93
94
95
96
|
],
]
); ?>
<div class="panel panel-default">
<div class="panel-heading">
<h4>
|
70753ad4
Alexey Boroda
-Product card (vi...
|
97
|
<i class="glyphicon glyphicon-film"></i> Видео (Пример: <iframe src='https://www.youtube.com/embed/6mXhDfoJau4' frameborder='0' allowfullscreen></iframe>)
|
2b315849
Alexey Boroda
-Product card (wi...
|
98
99
100
101
102
103
104
|
<button type="button" class="add-item btn btn-success btn-sm pull-right">
<i class="glyphicon glyphicon-plus"></i> Add
</button>
</h4>
</div>
<div class="panel-body">
<div class="container-items"><!-- widgetBody -->
|
70753ad4
Alexey Boroda
-Product card (vi...
|
105
|
<?php foreach ($videos as $i => $video): ?>
|
2b315849
Alexey Boroda
-Product card (wi...
|
106
107
|
<div class="item panel panel-default"><!-- widgetItem -->
<div class="panel-body">
|
70753ad4
Alexey Boroda
-Product card (vi...
|
108
109
110
111
112
113
|
<?php
// necessary for update action.
if (!$video->isNewRecord) {
echo Html::activeHiddenInput($video, "[{$i}]id");
}
?>
|
2b315849
Alexey Boroda
-Product card (wi...
|
114
|
<div class="row">
|
797936c7
Alexey Boroda
-Product video mo...
|
115
116
117
118
119
|
<div class="col-sm-4">
<?= $form->field($video, "[{$i}]title")
->textInput([ 'maxlength' => true ]) ?>
</div>
<div class="col-sm-7">
|
2b315849
Alexey Boroda
-Product card (wi...
|
120
|
<?= $form->field($video, "[{$i}]url")
|
70753ad4
Alexey Boroda
-Product card (vi...
|
121
|
->textInput([ 'maxlength' => true ])->label('Iframe') ?>
|
2b315849
Alexey Boroda
-Product card (wi...
|
122
|
</div>
|
70753ad4
Alexey Boroda
-Product card (vi...
|
123
|
<div class="col-sm-1" style="margin-top: 30px">
|
2b315849
Alexey Boroda
-Product card (wi...
|
124
125
126
127
128
129
|
<button type="button" class="remove-item btn btn-danger btn-xs">
<i class="glyphicon glyphicon-minus"></i></button>
</div>
</div><!-- .row -->
</div>
</div>
|
70753ad4
Alexey Boroda
-Product card (vi...
|
130
|
<?php endforeach; ?>
|
2b315849
Alexey Boroda
-Product card (wi...
|
131
132
133
134
135
|
</div>
</div>
</div><!-- .panel -->
<?php DynamicFormWidget::end(); ?>
|
2f25da09
Yarik
first commit
|
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
|
<?= $form->field($model, 'brand_id')
->dropDownList(
ArrayHelper::map(
Brand::find()
->with('lang')
->all(),
'id',
'lang.title'
),
[
'prompt' => Yii::t('product', 'Select brand'),
]
) ?>
<?= $form->field($model, 'categories')
->widget(
Select2::className(),
[
'data' => ArtboxTreeHelper::treeMap(ProductHelper::getCategories(), 'id', 'lang.title'),
'language' => 'ru',
'options' => [
'placeholder' => Yii::t('product', 'Select categories'),
'multiple' => true,
],
'pluginOptions' => [
'allowClear' => true,
],
]
) ?>
<?= $form->field($model, 'imagesUpload[]')
->widget(
\kartik\file\FileInput::className(),
[
'language' => 'ru',
'options' => [
'accept' => 'image/*',
'multiple' => true,
],
'pluginOptions' => [
'allowedFileExtensions' => [
'jpg',
'gif',
'png',
],
'initialPreview' => !empty( $model->imagesHTML ) ? $model->imagesHTML : [],
'initialPreviewConfig' => $model->imagesConfig,
'overwriteInitial' => false,
'showRemove' => false,
'showUpload' => false,
'uploadAsync' => !empty( $model->id ),
'previewFileType' => 'image',
],
]
); ?>
|
176ac41d
Alexey Boroda
-Blog article for...
|
192
193
194
195
196
197
198
199
|
<?= $form->field($model, 'size_image')
->widget(
\kartik\file\FileInput::className(),
[
'language' => 'ru',
'options' => [
'accept' => 'image/*',
'multiple' => false,
|
2ffeed3d
Yarik
Image delete func...
|
200
201
|
'deleteurl' => $model->isNewRecord?false:Url::to(['/ecommerce/manage/delete-size', 'id' => $model->id]),
'class' => $model->isNewRecord?'':'artbox-delete-file',
|
176ac41d
Alexey Boroda
-Blog article for...
|
202
203
204
205
206
207
208
|
],
'pluginOptions' => [
'allowedFileExtensions' => [
'jpg',
'gif',
'png',
],
|
2ffeed3d
Yarik
Image delete func...
|
209
|
'initialPreview' => !empty( $model->getBehavior('size_image')->getImageUrl(0, false)) ? ArtboxImageHelper::getImage(
|
176ac41d
Alexey Boroda
-Blog article for...
|
210
211
212
|
$model->getBehavior('size_image')->imageUrl,
'list'
) : '',
|
2ffeed3d
Yarik
Image delete func...
|
213
214
215
216
217
218
|
'initialPreviewShowDelete' => false,
'overwriteInitial' => true,
'showRemove' => true,
'showUpload' => false,
'showClose' => false,
'previewFileType' => 'image',
|
176ac41d
Alexey Boroda
-Blog article for...
|
219
220
221
222
|
],
]
); ?>
|
2f25da09
Yarik
first commit
|
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
|
<?php if (!empty( $groups )) {
foreach ($groups->with('lang')
->all() as $group) {
/**
* @var TaxGroup $group
*/
echo $form->field($model, 'options')
->checkboxList(
ArrayHelper::map(
$group->getOptions()
->with('lang')
->all(),
'id',
'lang.value'
),
[
'multiple' => true,
'unselect' => NULL,
]
)
->label($group->lang->title);
}
}
?>
<hr>
<?= LanguageForm::widget(
[
'modelLangs' => $modelLangs,
|
b7e90569
Yarik
Namespaces
|
253
|
'formView' => '@artweb/artbox/ecommerce/views/manage/_form_language',
|
2f25da09
Yarik
first commit
|
254
255
256
257
258
259
260
261
262
263
264
265
266
267
|
'form' => $form,
]
) ?>
<div class="form-group">
<?= Html::submitButton(
$model->isNewRecord ? Yii::t('product', 'Create') : Yii::t('product', 'Update'),
[ 'class' => $model->isNewRecord ? 'btn btn-success' : 'btn btn-primary' ]
) ?>
</div>
<?php ActiveForm::end(); ?>
</div>
|