4253cbec
root
first commit
|
1
|
<?php
|
776dd7a1
Alexey Boroda
-Added status 'wa...
|
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
|
use common\modules\product\models\ProductVariant;
use common\modules\product\models\Stock;
use yii\helpers\Html;
use yii\web\View;
use yii\widgets\ActiveForm;
use yii\helpers\ArrayHelper;
use wbraganca\dynamicform\DynamicFormWidget;
/**
* @var View $this
* @var ProductVariant $model
* @var ActiveForm $form
* @var Stock $stocks
*/
$js = '
|
4253cbec
root
first commit
|
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
|
$(".dynamicform_wrapper").on("beforeInsert", function(e, item) {
console.log("beforeInsert");
});
$(".dynamicform_wrapper").on("afterInsert", function(e, item) {
console.log("afterInsert");
});
$(".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("afterDelete", function(e) {
console.log("Deleted item!");
});
$(".dynamicform_wrapper").on("limitReached", function(e, item) {
alert("Limit reached");
});
';
|
776dd7a1
Alexey Boroda
-Added status 'wa...
|
42
43
|
$this->registerJs($js, View::POS_LOAD);
|
4253cbec
root
first commit
|
44
45
|
?>
<div class="product-form">
|
776dd7a1
Alexey Boroda
-Added status 'wa...
|
46
47
|
<?php $form = ActiveForm::begin(
|
4253cbec
root
first commit
|
48
|
[
|
776dd7a1
Alexey Boroda
-Added status 'wa...
|
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
|
'id' => 'dynamic-form',
'options' => [ 'enctype' => 'multipart/form-data' ],
]
); ?>
<?= $form->field($model, 'name')
->textInput([ 'maxlength' => true ]) ?>
<?= $form->field($model, 'product_id')
->hiddenInput()
->label(false); ?>
<?= $form->field($model, 'sku')
->textarea(); ?>
<?= $form->field($model, 'status')
->dropDownList(
[
0 => 'В наличии / под заказ',
1 => 'снят с производства',
2 => 'в ожидании',
]
)->label('Статус') ?>
<?= $form->field($model, 'price')
->textarea(); ?>
<?= $form->field($model, 'price_old')
->textarea(); ?>
<?= $form->field($model, 'image')
->widget(
\kartik\file\FileInput::classname(),
[
'model' => $model,
'attribute' => 'image',
'options' => [
'accept' => 'image/*',
'multiple' => true,
],
'pluginOptions' => [
'allowedFileExtensions' => [
'jpg',
'gif',
'png',
],
'initialPreview' => $model->imageUrl ? \common\components\artboximage\ArtboxImageHelper::getImage(
$model->imageUrl,
'products'
) : '',
'overwriteInitial' => true,
'showRemove' => true,
'showUpload' => false,
],
]
); ?>
|
4253cbec
root
first commit
|
103
|
|
776dd7a1
Alexey Boroda
-Added status 'wa...
|
104
|
<?php DynamicFormWidget::begin(
|
4253cbec
root
first commit
|
105
|
[
|
776dd7a1
Alexey Boroda
-Added status 'wa...
|
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
|
'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)
'min' => 0,
// 0 or 1 (default 1)
'insertButton' => '.add-item',
// css class
'deleteButton' => '.remove-item',
// css class
'model' => $stocks[ 0 ],
'formId' => 'dynamic-form',
'formFields' => [
'quantity',
'name',
],
|
4253cbec
root
first commit
|
126
|
]
|
776dd7a1
Alexey Boroda
-Added status 'wa...
|
127
128
129
130
131
132
133
134
135
136
|
); ?>
<div class="panel panel-default">
<div class="panel-heading">
<h4>
<i class="glyphicon glyphicon-envelope"></i> Склады
<button type="button" class="add-item btn btn-success btn-sm pull-right">
<i class="glyphicon glyphicon-plus"></i> Add
</button>
</h4>
|
4253cbec
root
first commit
|
137
|
</div>
|
776dd7a1
Alexey Boroda
-Added status 'wa...
|
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
192
193
194
195
196
197
198
199
200
201
202
203
204
205
|
<div class="panel-body">
<div class="container-items"><!-- widgetBody -->
<?php foreach ($stocks as $i => $stock): ?>
<div class="item panel panel-default"><!-- widgetItem -->
<div class="panel-body">
<?php
// necessary for update action.
if (!$stock->isNewRecord) {
echo Html::activeHiddenInput($stock, "[{$i}]stock_id");
}
?>
<div class="row">
<div class="col-sm-5">
<?= $form->field($stock, "[{$i}]quantity")
->textInput([ 'maxlength' => true ]) ?>
</div>
<div class="col-sm-5">
<?= $form->field($stock, "[{$i}]name")
->textInput([ 'maxlength' => true ]) ?>
</div>
<div class="col-sm-2" style="margin-top: 30px">
<button type="button" class="remove-item btn btn-danger btn-xs">
<i class="glyphicon glyphicon-minus"></i></button>
</div>
</div><!-- .row -->
</div>
</div>
<?php endforeach; ?>
</div>
</div>
</div><!-- .panel -->
<?php DynamicFormWidget::end(); ?>
<?= $form->field($model, 'product_unit_id')
->dropDownList(
ArrayHelper::map(
\common\modules\product\models\ProductUnit::find()
->all(),
'product_unit_id',
'name'
),
[
'prompt' => Yii::t('product', 'Unit'),
]
)
->label(Yii::t('product', 'Unit')) ?>
<?php if (isset($groups)) : ?>
<?php foreach ($groups->all() as $group) : ?>
<?= $form->field($model, 'options')
->checkboxList(
ArrayHelper::map($group->options, 'tax_option_id', 'ValueRenderFlash'),
[
'multiple' => true,
'unselect' => null,
]
)
->label($group->name); ?>
<?php endforeach ?>
<?php endif ?>
<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>
|
4253cbec
root
first commit
|
206
207
208
|
<?php ActiveForm::end(); ?>
</div>
|