Blame view

common/widgets/views/education_field.php 4.74 KB
a8370482   Alexander Karnovsky   init project
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
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
  <?php
      use yii\helpers\Html;
  
  ?>
  <fieldset>
  
  <div class="skills-title">Образование</div>
  
      <div class="field_list">
  
      <?php $t = 0;
  
          $label = 0; // add this var
  
          for($i = 1; $i <= count($model); $i++):
              $row = $i;
  
              ?>
  
              <?= Html::beginTag('div', [
              'class' => 'form-group',
              'id'    => isset( $model[ $i ][ 'parent_key' ] ) ? $model[ $i ][ 'parent_key' ] : 0,
          ]) ?>
              <div class="input-blocks">
                  <input id="edu-name-<?= ++$label  ?>" type="text" placeholder="Название" class="form-control custom-input-2" value="<?= isset( $model[ $t ][ 'value' ] ) ? $model[ $t ][ 'value' ] : '' ?>" name="Fields[education][<?= $row ?>][0][name]"/>
                  <label for="edu-name-<?= $label ?>">Название ВУЗа</label>
               </div>
              <div class="input-blocks">
                  <input id="edu-to-<?= ++$label ?>" type="number" class="form-control form-control custom-input-2 custom-input-2-date" value="<?= isset( $model[ ++$t ][ 'value' ] ) ? $model[ $t ][ 'value' ] : '' ?>" name="Fields[education][<?= $row ?>][1][year_from]" min="1950" max="<?=date('Y')?>" />
                  <label for="edu-to-<?= $label ?>">год начала</label>
              </div>
              <div class="input-blocks">
                  <input id="edu-out-<?= ++$label ?>" type="number" class="form-control form-control custom-input-2 custom-input-2-date" value="<?= isset( $model[ ++$t ][ 'value' ] ) ? $model[ $t ][ 'value' ] : '' ?>" name="Fields[education][<?= $row ?>][2][year_to]" min="1950" />
                  <label for="edu-out-<?= $label ?>">год окончания</label>
              </div>
              <span data-id="<?= isset( $model[ $i ][ 'parent_key' ] ) ? $model[ $i ][ 'parent_key' ] : 0 ?>" title="удалить" class="glyphicon glyphicon-trash delete-field-item"></span>
              <?= Html::endTag('div') ?>
              <?php $i = ++$t; ?>
          <?php endfor; ?>
  
      </div>
      <p class="btn btn-success add_field_<?= $this->context->id ?>">добавить еще</p>
  </fieldset>
  
  <script>
      var start_i_<?=$this->context->id?> = <?=$i?>;
      var start_label_<?=$this->context->id?> = <?=$label?>; // add this var
      $ (document)
          .ready (
              function ()
              {
                  $ ('.add_field_<?=$this->context->id?>')
                      .click (
                          function ()
                          {
                              var block     = $ (this)
                                  .siblings('.field_list');
                              var block_id  = $ (this)
                                  .parent ('fieldset');
                              var sub_block = '<div class="form-group" >' +
                                              '<div class="input-blocks">'+
                                              '<input id="edu-name-' + ++start_label_<?=$this->context->id?> +'" type="text" placeholder="Название" class="form-control custom-input-2" value="" name="Fields[education][' + start_i_<?=$this->context->id?>++ + '][0][name]" />' +
                                              '<label for="edu-name-' + start_label_<?=$this->context->id?> +'">Название ВУЗа</label>'+
                                              '</div>'+
                                              '<div class="input-blocks">'+
                                              '<input id="edu-to-' + ++start_label_<?=$this->context->id?> +'" type="number" class="form-control custom-input-2 custom-input-2-date" value="" name="Fields[education][' + start_i_<?=$this->context->id?>++ + '][1][year_from]" min="1950" max="<?=date('Y')?>" />' +
                                              '<label for="edu-to-' + start_label_<?=$this->context->id?>  +'">год начала</label>'+
                                              '</div>'+
                                              '<div class="input-blocks">'+
                                              '<input id="edu-out-' + ++start_label_<?=$this->context->id?>  +'"" type="number" class="form-control custom-input-2 custom-input-2-date" value="" name="Fields[education][' + start_i_<?=$this->context->id?>++ + '][2][year_to]" min="1950" />' +
                                              '<label for="edu-out-' + start_label_<?=$this->context->id?> +'">год окончания</label>'+
                                              '</div>'+
                                              '<span title="удалить" class="glyphicon glyphicon-trash delete-field-item"></span>' +
                                              '<div>';
                              console.log (block);
                              block.append (sub_block);
                          }
                      );
              }
          );
  </script>