update.php
5.21 KB
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
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
107
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
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
<?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' => [
'class' => 'form-group col-xs-8 col-sm-9',
],
]
)
->textInput() . $form->field(
$model,
"[$index]priority",
[
'options' => [
'class' => 'form-group col-xs-3 col-sm-2',
],
]
)
->textInput() . Html::icon(
'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) {
?>
<div class="form-group col-xs-9 col-sm-10">
<?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
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);