1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
use hipanel\modules\client\widgets\combo\ClientCombo; |
4
|
|
|
use hipanel\modules\hosting\widgets\combo\HdomainCombo; |
5
|
|
|
use hipanel\modules\hosting\widgets\combo\SshAccountCombo; |
6
|
|
|
use hipanel\modules\hosting\widgets\combo\VhostCombo; |
7
|
|
|
use hipanel\modules\server\models\Server; |
8
|
|
|
use hipanel\modules\server\widgets\combo\PanelServerCombo; |
9
|
|
|
use yii\bootstrap\ActiveForm; |
10
|
|
|
use yii\helpers\Html; |
11
|
|
|
use yii\helpers\Url; |
12
|
|
|
use yii\web\JsExpression; |
13
|
|
|
|
14
|
|
|
/* @var $this yii\web\View */ |
15
|
|
|
/* @var $model hipanel\modules\hosting\models\Hdomain */ |
16
|
|
|
/* @var $type string */ |
17
|
|
|
|
18
|
|
|
$form = ActiveForm::begin([ |
19
|
|
|
'id' => 'dynamic-form', |
20
|
|
|
'enableClientValidation' => true, |
21
|
|
|
'validateOnBlur' => true, |
22
|
|
|
'enableAjaxValidation' => true, |
23
|
|
|
'validationUrl' => Url::toRoute(['validate-form', 'scenario' => $model->scenario]), |
24
|
|
|
]); ?> |
25
|
|
|
|
26
|
|
|
<div class="container-items"> |
27
|
|
|
<?php foreach ($models as $i => $model) : ?> |
28
|
|
|
<div class="row"> |
29
|
|
|
<div class="col-md-4"> |
30
|
|
|
<div class="box box-danger"> |
31
|
|
|
<div class="box-body"> |
32
|
|
|
<div class="form-instance"> |
33
|
|
|
<?php |
34
|
|
View Code Duplication |
if (Yii::$app->user->can('support')) { |
|
|
|
|
35
|
|
|
echo $form->field($model, "[$i]client")->widget(ClientCombo::class, [ |
36
|
|
|
'formElementSelector' => '.form-instance', |
37
|
|
|
]); |
38
|
|
|
} |
39
|
|
|
|
40
|
|
|
echo $form->field($model, "[$i]server")->widget(PanelServerCombo::class, [ |
41
|
|
|
'formElementSelector' => '.form-instance', |
42
|
|
|
'state' => Server::STATE_OK, |
43
|
|
|
]); |
44
|
|
|
echo $form->field($model, "[$i]account")->widget(SshAccountCombo::class, [ |
45
|
|
|
'formElementSelector' => '.form-instance', |
46
|
|
|
'inputOptions' => [ |
47
|
|
|
'data-attribute' => 'account', |
48
|
|
|
], |
49
|
|
|
]); |
50
|
|
|
echo $form->field($model, "[$i]vhost_id")->widget(VhostCombo::class, ['hasId' => true, 'formElementSelector' => '.form-instance']); |
51
|
|
|
|
52
|
|
|
echo $form->field($model, "[$i]alias_type")->radioList($model->getAliasTypeOptions(), ['class' => 'alias-type']); |
53
|
|
|
?> |
54
|
|
|
|
55
|
|
|
<div class="alias-subdomain"> |
56
|
|
|
<div class="row"> |
57
|
|
|
<div class="col-md-4"> |
58
|
|
|
<?= $form->field($model, "[$i]subdomain")->input('text', ['data-attribute' => 'subdomain'])->label(false) ?> |
59
|
|
|
</div> |
60
|
|
|
<div class="col-md-8"> |
61
|
|
|
<?= $form->field($model, "[$i]dns_hdomain_id")->widget(HdomainCombo::class, [ |
62
|
|
|
'formElementSelector' => '.form-instance', |
63
|
|
|
'inputOptions' => [ |
64
|
|
|
'data-attribute' => 'dns_hdomain_id', |
65
|
|
|
], |
66
|
|
|
'pluginOptions' => [ |
67
|
|
|
'onChange' => new JsExpression("function () { |
68
|
|
|
$(this).closest('.form-instance').find('input[data-attribute=\"sub-with-domain\"]').trigger('update'); |
69
|
|
|
} |
70
|
|
|
"), |
71
|
|
|
], |
72
|
|
|
])->label(false) ?> |
73
|
|
|
<?= $form->field($model, "[$i]domain")->hiddenInput([ |
74
|
|
|
'id' => $model->formName() . '-' . $i . '-domain-sub', |
75
|
|
|
'data-attribute' => 'sub-with-domain', |
76
|
|
|
])->label(false) ?> |
77
|
|
|
</div> |
78
|
|
|
</div> |
79
|
|
|
|
80
|
|
|
</div> |
81
|
|
|
<div class="alias-newdomain"> |
82
|
|
|
<?= $form->field($model, "[$i]domain")->input('text', [ |
83
|
|
|
'data-attribute' => 'domain', |
84
|
|
|
'disabled' => true, |
85
|
|
|
'class' => 'form-control collapse', |
86
|
|
|
])->label(false) ?> |
87
|
|
|
</div> |
88
|
|
|
<?= $form->field($model, "[$i]with_www")->checkbox() ?> |
89
|
|
|
</div> |
90
|
|
|
</div> |
91
|
|
|
</div> |
92
|
|
|
</div> |
93
|
|
|
</div> |
94
|
|
|
<?php endforeach ?> |
95
|
|
|
<div class="row"> |
96
|
|
|
<div class="col-md-4"> |
97
|
|
|
<?= Html::submitButton(Yii::t('hipanel', 'Save'), ['class' => 'btn btn-success']) ?> |
98
|
|
|
|
99
|
|
|
<?= Html::button(Yii::t('hipanel', 'Cancel'), [ |
100
|
|
|
'class' => 'btn btn-default', 'onclick' => 'history.go(-1)', |
101
|
|
|
]) ?> |
102
|
|
|
</div> |
103
|
|
|
</div> |
104
|
|
|
</div> |
105
|
|
|
<?php ActiveForm::end(); |
106
|
|
|
|
107
|
|
|
$this->registerJs(<<<'JS' |
108
|
|
|
function handleAliasType(currentValue) { |
109
|
|
|
var $form = $('#dynamic-form').find('.form-instance'); |
110
|
|
|
var $sub_inputs = $form.find('.alias-subdomain, input[data-attribute="subdomain"], input[data-attribute="sub-with-domain"]'); |
111
|
|
|
var $new_inputs = $form.find('.alias-newdomain, input[data-attribute="domain"]'); |
112
|
|
|
if (currentValue === 'subdomain') { |
113
|
|
|
$sub_inputs.prop('disabled', false).show(); |
114
|
|
|
$new_inputs.prop('disabled', true).hide(); |
115
|
|
|
} else if (currentValue === 'new') { |
116
|
|
|
$sub_inputs.prop('disabled', true).hide(); |
117
|
|
|
$new_inputs.prop('disabled', false).show(); |
118
|
|
|
} else { |
119
|
|
|
$sub_inputs.prop('disabled', true).hide(); |
120
|
|
|
$new_inputs.prop('disabled', true).hide(); |
121
|
|
|
} |
122
|
|
|
} |
123
|
|
|
|
124
|
|
|
var initialAliasType = $(":input[name*=alias_type]:checked").val(); |
125
|
|
|
handleAliasType(initialAliasType); |
126
|
|
|
|
127
|
|
|
$('#dynamic-form').on('change', '.alias-type', function (evt) { |
128
|
|
|
handleAliasType(evt.target.value); |
129
|
|
|
}); |
130
|
|
|
|
131
|
|
|
$('#dynamic-form').on('update', 'input[data-attribute="sub-with-domain"]', function (evt) { |
132
|
|
|
var $form = $(this).closest('.form-instance'); |
133
|
|
|
var subdomain = $form.find('input[data-attribute="subdomain"]').val(); |
134
|
|
|
var domain = $form.find(':input[data-attribute="dns_hdomain_id"]').select2('data'); |
135
|
|
|
var value = ''; |
136
|
|
|
|
137
|
|
|
if (domain && domain.length && domain[0].text) { |
138
|
|
|
value = (subdomain.length > 0 ? (subdomain + '.') : '') + domain[0].text; |
139
|
|
|
} |
140
|
|
|
$(this).val(value).trigger('change'); |
141
|
|
|
}); |
142
|
|
|
|
143
|
|
|
$('#dynamic-form').on('change', 'input[data-attribute="subdomain"]', function (evt) { |
144
|
|
|
var $form = $(this).closest('.form-instance'); |
145
|
|
|
$form.find('input[data-attribute="sub-with-domain"]').trigger('update'); |
146
|
|
|
}); |
147
|
|
|
JS |
148
|
|
|
); |
149
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.