Blame view

views/manage/_form.php 10.2 KB
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
58
59
60
61
62
          ]

      ); ?>

      

      <?= $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...
63
64
65
66
67
68
69
70
71
72
      <?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...
73
              'min'             => 0,

2b315849   Alexey Boroda   -Product card (wi...
74
75
76
77
78
79
80
81
              // 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...
82
83
                  'quantity',

                  'title',

2b315849   Alexey Boroda   -Product card (wi...
84
85
86
87
88
89
90
              ],

          ]

      ); ?>

      

      <div class="panel panel-default">

          <div class="panel-heading">

              <h4>

70753ad4   Alexey Boroda   -Product card (vi...
91
                  <i class="glyphicon glyphicon-film"></i> Видео (Пример: &ltiframe src='https://www.youtube.com/embed/6mXhDfoJau4' frameborder='0' allowfullscreen&gt&lt/iframe&gt)

2b315849   Alexey Boroda   -Product card (wi...
92
93
94
95
96
97
98
                  <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...
99
                  <?php foreach ($videos as $i => $video): ?>

2b315849   Alexey Boroda   -Product card (wi...
100
101
                      <div class="item panel panel-default"><!-- widgetItem -->

                          <div class="panel-body">

70753ad4   Alexey Boroda   -Product card (vi...
102
103
104
105
106
107
                              <?php

                                  // necessary for update action.

                                  if (!$video->isNewRecord) {

                                      echo Html::activeHiddenInput($video, "[{$i}]id");

                                  }

                              ?>

2b315849   Alexey Boroda   -Product card (wi...
108
                              <div class="row">

797936c7   Alexey Boroda   -Product video mo...
109
110
111
112
113
                                  <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...
114
                                      <?= $form->field($video, "[{$i}]url")

70753ad4   Alexey Boroda   -Product card (vi...
115
                                               ->textInput([ 'maxlength' => true ])->label('Iframe') ?>

2b315849   Alexey Boroda   -Product card (wi...
116
                                  </div>

70753ad4   Alexey Boroda   -Product card (vi...
117
                                  <div class="col-sm-1" style="margin-top: 30px">

2b315849   Alexey Boroda   -Product card (wi...
118
119
120
121
122
123
                                      <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...
124
                  <?php endforeach; ?>

2b315849   Alexey Boroda   -Product card (wi...
125
126
127
128
129
              </div>

          </div>

      </div><!-- .panel -->

      <?php DynamicFormWidget::end(); ?>

      

2f25da09   Yarik   first commit
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
185
      <?= $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...
186
187
188
189
190
191
192
193
      <?= $form->field($model, 'size_image')

               ->widget(

                   \kartik\file\FileInput::className(),

                   [

                       'language'      => 'ru',

                       'options'       => [

                           'accept'   => 'image/*',

                           'multiple' => false,

2ffeed3d   Yarik   Image delete func...
194
195
                           '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...
196
197
198
199
200
201
202
                       ],

                       'pluginOptions' => [

                           'allowedFileExtensions' => [

                               'jpg',

                               'gif',

                               'png',

                           ],

2ffeed3d   Yarik   Image delete func...
203
                           'initialPreview'        => !empty( $model->getBehavior('size_image')->getImageUrl(0, false)) ? ArtboxImageHelper::getImage(

176ac41d   Alexey Boroda   -Blog article for...
204
205
206
                               $model->getBehavior('size_image')->imageUrl,

                               'list'

                           ) : '',

2ffeed3d   Yarik   Image delete func...
207
208
209
210
211
212
                           'initialPreviewShowDelete' => false,

                           'overwriteInitial'         => true,

                           'showRemove'               => true,

                           'showUpload'               => false,

                           'showClose'                => false,

                           'previewFileType'          => 'image',

176ac41d   Alexey Boroda   -Blog article for...
213
214
215
216
                       ],

                   ]

               ); ?>

      

2f25da09   Yarik   first commit
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
242
243
244
245
246
      <?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
247
              'formView'   => '@artweb/artbox/ecommerce/views/manage/_form_language',

2f25da09   Yarik   first commit
248
249
250
251
252
253
254
255
256
257
258
259
260
261
              '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>