Blame view

backend/views/sitemap/update.php 6.84 KB
a42025b8   Yarik   Sitemap and slugb...
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
  <?php
      use common\models\SitemapDynamic;
      use common\models\SitemapStatic;
      use artbox\gentelella\widgets\XPanel;
      use yii\bootstrap\ActiveForm;
      use yii\bootstrap\Html;
      use yii\helpers\Url;
      use yii\web\View;
      
      /**
       * @var View             $this
       * @var SitemapStatic[]  $models
       * @var SitemapDynamic[] $entity_models
       */
      $this->params[ 'breadcrumbs' ][] = [
          'label' => \Yii::t('core', 'Sitemap'),
          'url'   => [ 'index' ],
      ];
      $this->title = \Yii::t('core', 'Update sitemap');
      $this->params[ 'breadcrumbs' ][] = $this->title;
      $form = ActiveForm::begin();
      $xPanel = XPanel::begin(
          [
              'title'         => \Yii::t('core', 'Static pages'),
              'toolbarLayout' => '{collapse}',
              'options'       => [
                  'class' => 'dynamic_fields',
              ],
          ]
      );
      foreach ($models as $index => $model) {
          echo Html::tag(
              'div',
              $form->field(
                  $model,
                  "[$index]url",
                  [
                      'options' => [
9af79e71   Yarik   Sitemap and slugb...
39
                          'class' => 'form-group col-xs-5 col-sm-6',
a42025b8   Yarik   Sitemap and slugb...
40
41
42
43
44
                      ],
                  ]
              )
                   ->textInput() . $form->field(
                  $model,
9af79e71   Yarik   Sitemap and slugb...
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
                  "[$index]frequency",
                  [
                      'options' => [
                          'class' => 'form-group col-xs-3 col-sm-3',
                      ],
                  ]
              )
                                        ->dropDownList(
                                            [
                                                'always'  => 'always',
                                                'hourly'  => 'hourly',
                                                'daily'   => 'daily',
                                                'weekly'  => 'weekly',
                                                'monthly' => 'monthly',
                                                'yearly'  => 'yearly',
                                                'never'   => 'never',
                                            ]
                                        ) . $form->field(
                  $model,
a42025b8   Yarik   Sitemap and slugb...
64
65
66
67
68
69
70
                  "[$index]priority",
                  [
                      'options' => [
                          'class' => 'form-group col-xs-3 col-sm-2',
                      ],
                  ]
              )
9af79e71   Yarik   Sitemap and slugb...
71
                                                 ->textInput() . Html::icon(
a42025b8   Yarik   Sitemap and slugb...
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
103
104
105
106
                  'minus',
                  [
                      'class'   => 'col-xs-1 field-group-remove',
                      'onclick' => 'sitemap_remove(this)',
                  ]
              ),
              [
                  'class' => 'row field-group',
              ]
          );
      }
      echo Html::button(
          \Yii::t('core', 'Add field'),
          [
              'class'   => 'btn btn-default',
              'onclick' => 'sitemap_add(this)',
              'data'    => [
                  'url' => Url::to([ 'create-static' ]),
              ],
          ]
      );
      $xPanel::end();
      $xPanel2 = XPanel::begin(
          [
              'title'         => \Yii::t('core', 'Dynamic pages'),
              'toolbarLayout' => '{collapse}',
          ]
      );
  ?>
      <div class="col-xs-9 col-sm-10"></div>
      <div class="col-xs-3 col-sm-2 text-center"><?php echo $entity_models[ 0 ]->getAttributeLabel('priority'); ?></div>
      <div class="clearfix"></div>
  <?php
      foreach ($entity_models as $index => $entity_model) {
          ?>
9af79e71   Yarik   Sitemap and slugb...
107
          <div class="form-group col-xs-6 col-sm-8">
a42025b8   Yarik   Sitemap and slugb...
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
              <?php
                  echo Html::tag(
                      'div',
                      Html::activeInput(
                          'text',
                          $entity_model,
                          "[$index]entity",
                          [
                              'class'    => 'form-control',
                              'readonly' => 1,
                          ]
                      ) . Html::tag(
                          'span',
                          Html::activeCheckbox(
                              $entity_model,
                              "[$index]status",
                              [
                                  'label' => false,
                              ]
                          ),
                          [
                              'class' => 'input-group-addon',
                          ]
                      ),
                      [
                          'class' => 'input-group',
                      ]
                  );
              ?>
          </div>
          <div class="form-group col-xs-3 col-sm-2">
              <?php
9af79e71   Yarik   Sitemap and slugb...
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
                  echo $form->field($entity_model, "[$index]frequency")
                            ->label(false)
                            ->dropDownList(
                                [
                                    'always'  => 'always',
                                    'hourly'  => 'hourly',
                                    'daily'   => 'daily',
                                    'weekly'  => 'weekly',
                                    'monthly' => 'monthly',
                                    'yearly'  => 'yearly',
                                    'never'   => 'never',
                                ]
                            );
              ?>
          </div>
          <div class="form-group col-xs-3 col-sm-2">
              <?php
a42025b8   Yarik   Sitemap and slugb...
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
206
207
208
209
210
211
212
213
214
215
                  echo $form->field($entity_model, "[$index]priority")
                            ->label(false)
                            ->input(
                                'number',
                                [
                                    'step' => 0.1,
                                    'min'  => 0,
                                    'max'  => 1,
                                ]
                            );
              ?>
          </div>
          <?php
      }
      $xPanel2::end();
      echo Html::submitButton(
          \Yii::t('core', 'Save'),
          [
              'class' => 'btn btn-success',
          ]
      );
      echo Html::submitButton(
          \Yii::t('core', 'Save and generate'),
          [
              'class' => 'btn btn-primary',
              'name'  => 'action',
              'value' => 'generate',
          ]
      );
      $form::end();
      $js = <<<JS
      function sitemap_add(e) {
          var url = $(e)
              .data('url');
          var form_id = $(e)
              .parents('form')
              .attr('id');
          var form = $('#' + form_id);
          var count = $('.field-group').length;
          $.get(
              url, {
                  'formId': form_id,
                  'count': count
              }, function(data) {
                  form.find('.field-group')
                      .last()
                      .after(data);
              }
          );
      }
      function sitemap_remove(e) {
          if($('.field-group').length > 1) {
              $(e)
                  .parents('.field-group')
                  .remove();
          }
      }
  JS;
      $this->registerJs($js, $this::POS_END);