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
12
13
|
use yii\db\ActiveQuery;
use yii\helpers\Html;
use yii\widgets\ActiveForm;
use yii\helpers\ArrayHelper;
|
69390831
Yarik
Namespaces
|
14
|
use artweb\artbox\components\artboxtree\ArtboxTreeHelper;
|
2f25da09
Yarik
first commit
|
15
16
|
use artweb\artbox\ecommerce\helpers\ProductHelper;
use kartik\select2\Select2;
|
2b315849
Alexey Boroda
-Product card (wi...
|
17
|
use yii\web\View;
|
2f25da09
Yarik
first commit
|
18
19
|
/**
|
2b315849
Alexey Boroda
-Product card (wi...
|
20
|
* @var yii\web\View $this
|
2f25da09
Yarik
first commit
|
21
|
* @var artweb\artbox\ecommerce\models\Product $model
|
2b315849
Alexey Boroda
-Product card (wi...
|
22
23
24
25
|
* @var ProductLang[] $modelLangs
* @var yii\widgets\ActiveForm $form
* @var ActiveQuery $groups
* @var ProductVideo[] $videos
|
2f25da09
Yarik
first commit
|
26
|
*/
|
2b315849
Alexey Boroda
-Product card (wi...
|
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
|
$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
|
42
43
44
45
46
47
|
?>
<div class="product-form">
<?php $form = ActiveForm::begin(
[
|
70753ad4
Alexey Boroda
-Product card (vi...
|
48
49
50
51
|
'options' => [
'enctype' => 'multipart/form-data',
'id' => 'dynamic-form',
],
|
2f25da09
Yarik
first commit
|
52
53
54
55
56
57
58
59
60
61
|
]
); ?>
<?= $form->field($model, 'is_top')
->checkbox([ 'label' => 'ТОП' ]) ?>
<?= $form->field($model, 'is_new')
->checkbox([ 'label' => 'Новинка' ]) ?>
<?= $form->field($model, 'is_discount')
->checkbox([ 'label' => 'Акционный' ]) ?>
|
2b315849
Alexey Boroda
-Product card (wi...
|
62
63
64
65
66
67
68
69
70
71
|
<?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...
|
72
|
'min' => 0,
|
2b315849
Alexey Boroda
-Product card (wi...
|
73
74
75
76
77
78
79
80
|
// 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...
|
81
82
|
'quantity',
'title',
|
2b315849
Alexey Boroda
-Product card (wi...
|
83
84
85
86
87
88
89
|
],
]
); ?>
<div class="panel panel-default">
<div class="panel-heading">
<h4>
|
70753ad4
Alexey Boroda
-Product card (vi...
|
90
|
<i class="glyphicon glyphicon-film"></i> Видео (Пример: <iframe src='https://www.youtube.com/embed/6mXhDfoJau4' frameborder='0' allowfullscreen></iframe>)
|
2b315849
Alexey Boroda
-Product card (wi...
|
91
92
93
94
95
96
97
|
<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...
|
98
|
<?php foreach ($videos as $i => $video): ?>
|
2b315849
Alexey Boroda
-Product card (wi...
|
99
100
|
<div class="item panel panel-default"><!-- widgetItem -->
<div class="panel-body">
|
70753ad4
Alexey Boroda
-Product card (vi...
|
101
102
103
104
105
106
|
<?php
// necessary for update action.
if (!$video->isNewRecord) {
echo Html::activeHiddenInput($video, "[{$i}]id");
}
?>
|
2b315849
Alexey Boroda
-Product card (wi...
|
107
|
<div class="row">
|
797936c7
Alexey Boroda
-Product video mo...
|
108
109
110
111
112
|
<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...
|
113
|
<?= $form->field($video, "[{$i}]url")
|
70753ad4
Alexey Boroda
-Product card (vi...
|
114
|
->textInput([ 'maxlength' => true ])->label('Iframe') ?>
|
2b315849
Alexey Boroda
-Product card (wi...
|
115
|
</div>
|
70753ad4
Alexey Boroda
-Product card (vi...
|
116
|
<div class="col-sm-1" style="margin-top: 30px">
|
2b315849
Alexey Boroda
-Product card (wi...
|
117
118
119
120
121
122
|
<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...
|
123
|
<?php endforeach; ?>
|
2b315849
Alexey Boroda
-Product card (wi...
|
124
125
126
127
128
|
</div>
</div>
</div><!-- .panel -->
<?php DynamicFormWidget::end(); ?>
|
2f25da09
Yarik
first commit
|
129
130
131
132
133
134
135
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
|
<?= $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...
|
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
|
<?= $form->field($model, 'size_image')
->widget(
\kartik\file\FileInput::className(),
[
'language' => 'ru',
'options' => [
'accept' => 'image/*',
'multiple' => false,
],
'pluginOptions' => [
'allowedFileExtensions' => [
'jpg',
'gif',
'png',
],
'initialPreview' => !empty( $model->getBehavior('size_image')->imageUrl ) ? ArtboxImageHelper::getImage(
$model->getBehavior('size_image')->imageUrl,
'list'
) : '',
'overwriteInitial' => true,
'showRemove' => false,
'showUpload' => false,
'previewFileType' => 'image',
],
]
); ?>
|
2f25da09
Yarik
first commit
|
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
|
<?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
|
242
|
'formView' => '@artweb/artbox/ecommerce/views/manage/_form_language',
|
2f25da09
Yarik
first commit
|
243
244
245
246
247
248
249
250
251
252
253
254
255
256
|
'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>
|