Blame view

backend/views/project/product-create.php 3.32 KB
cc658b4c   Yarik   Big commit
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
  <?php
      
      use common\models\ProductToProject;
      use common\models\Project;
      use common\modules\product\models\Product;
      use yii\helpers\Html;
      use yii\web\View;
      use yii\widgets\ActiveForm;
      
      /**
       * @var View             $this
       * @var Project          $project
       * @var Product[]        $products
       * @var ProductToProject $model
       * @var array            $variants
       */
96410438   Yarik   Project admin com...
17
18
19
20
21
      if($model->isNewRecord) {
          $this->title = \Yii::t('app', 'Create product to project');
      } else {
          $this->title = \Yii::t('app', 'Update product to project');
      }
cc658b4c   Yarik   Big commit
22
      $this->params[ 'breadcrumbs' ][] = [
96410438   Yarik   Project admin com...
23
24
25
26
27
28
29
          'label' => \Yii::t('app', 'Project'),
          'url'   => [
              'index',
          ],
      ];
      $this->params[ 'breadcrumbs' ][] = [
          'label' => \Yii::t('app', 'Products to project' . ': ' . $project->lang->title),
cc658b4c   Yarik   Big commit
30
31
32
33
34
35
36
          'url'   => [
              'product',
              'id' => $project->project_id,
          ],
      ];
      $this->params[ 'breadcrumbs' ][] = $this->title;
  ?>
96410438   Yarik   Project admin com...
37
38
39
40
41
42
43
44
45
46
47
48
49
      <div class="articles-create">
          <h1><?= Html::encode($this->title) ?></h1>
          <?php
              $form = ActiveForm::begin();
              echo $form->field($model, 'product_id')
                        ->dropDownList($products, [ 'prompt' => \Yii::t('app', 'Выберите коллекцию') ]);
          ?>
          <div class="<?php echo( !empty( $variants ) ? '' : 'hidden' ); ?> product_variant_container">
              <?php
                  echo $form->field($model, 'product_variant_id')
                            ->dropDownList($variants, [ 'prompt' => \Yii::t('app', 'Выберите товар') ]);
              ?>
          </div>
cc658b4c   Yarik   Big commit
50
          <?php
96410438   Yarik   Project admin com...
51
52
              echo Html::submitInput(( $model->isNewRecord ? \Yii::t('app', 'Добавить') : \Yii::t('app', 'Обновить') ), [ 'class' => 'btn btn-success' ]);
              $form::end();
cc658b4c   Yarik   Big commit
53
54
          ?>
      </div>
93c267f7   Yarik   Multilanguage big...
55
  <?php
96410438   Yarik   Project admin com...
56
      $this->registerJs("
93c267f7   Yarik   Multilanguage big...
57
            $(document).on(
cc658b4c   Yarik   Big commit
58
59
60
61
62
                  'change', '#producttoproject-product_id', function(e)
                  {
                      var value = parseInt($(this).val());
                      var dropDown = $('#producttoproject-product_variant_id');
                      var container = $(dropDown).parents('.product_variant_container');
93c267f7   Yarik   Multilanguage big...
63
                      $(dropDown).find('option[value!=\"\"]').remove();
cc658b4c   Yarik   Big commit
64
65
66
67
68
69
70
71
72
73
74
                      $(container).addClass('hidden');
                      if(value)
                      {
                          $.get(
                              '/admin/project/get-variants?product_id=' + value, function(data)
                              {
                                  if(data.length > 0)
                                  {
                                      $.each(
                                          data, function(key, value)
                                          {
96410438   Yarik   Project admin com...
75
                                         
cc658b4c   Yarik   Big commit
76
                                              $(dropDown)
96410438   Yarik   Project admin com...
77
                                              .append('<option value=\"' + value.product_variant_id + '\">' + value.lang.name + '</option>');
cc658b4c   Yarik   Big commit
78
79
                                          }
                                      );
cc658b4c   Yarik   Big commit
80
81
82
83
84
85
86
                                      $(container).removeClass('hidden');
                                  }
                              }
                          );
                      }
                  }
              );
93c267f7   Yarik   Multilanguage big...
87
88
  ");
  ?>