Completed
Push — master ( 823023...c43f27 )
by Dmitry
06:01 queued 02:13
created

src/widgets/views/SellForm.php (1 issue)

1
<?php
2
3
use hipanel\modules\client\widgets\combo\ClientCombo;
4
use hipanel\modules\finance\widgets\TariffCombo;
5
use hipanel\modules\server\forms\HubSellForm;
6
use hipanel\modules\server\models\Server;
7
use hipanel\modules\server\widgets\HubNameBadge;
8
use hipanel\modules\server\widgets\ServerNameBadge;
9
use hipanel\widgets\DateTimePicker;
10
use yii\bootstrap\ActiveForm;
11
use yii\helpers\Html;
12
use yii\web\View;
13
14
/**
15
 * @var View
16
 * @var Server|HubSellForm $model
17
 * @var Server[]|HubSellForm[] $models
18
 * @var DateTime $defaultDateTime
19
 * @var string $actionUrl
20
 * @var string $validationUrl
21
 */
22
23
?>
24
25
<div>
26
    <!-- Nav tabs -->
27
    <ul class="nav nav-tabs" role="tablist">
28
        <li role="presentation" class="active">
29
            <a href="#bulk" aria-controls="home" role="tab"
30
               data-toggle="tab"><?= Yii::t('hipanel', 'Set for all') ?></a>
31
        </li>
32
        <li role="presentation">
33
            <a href="#by-one" aria-controls="profile" role="tab"
34
               data-toggle="tab"><?= Yii::t('hipanel', 'Set by one') ?></a>
35
        </li>
36
    </ul>
37
38
    <!-- Tab panes -->
39
    <div class="row">
40
        <div class="tab-content">
41
            <div role="tabpanel" class="tab-pane active" id="bulk">
42
                <div class="col-md-12" style="margin-top: 15pt;">
43
                    <?php
44
                    $form = ActiveForm::begin([
45
                        'id' => 'bulk-sale',
46
                        'action' => $actionUrl,
47
                        'enableAjaxValidation' => true,
48
                        'validateOnBlur' => true,
49
                        'validationUrl' => $validationUrl,
50
                    ]) ?>
51
52
                    <?php foreach ($models as $model) : ?>
53
                        <?= Html::activeHiddenInput($model, "[$model->id]id") ?>
54
                        <?= Html::activeHiddenInput($model, "[$model->id]name") ?>
55
                    <?php endforeach; ?>
56
57
                    <div class="panel panel-default">
58
                        <div class="panel-heading"><?= Yii::t('hipanel:server', 'Affected items') ?></div>
59
                        <div class="panel-body">
60
                            <?= \hipanel\widgets\ArraySpoiler::widget([
61
                                'data' => $models,
62
                                'visibleCount' => count($models),
63
                                'formatter' => function ($model) {
64
                                    if ($this->context->isServer()) {
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $this seems to be never defined.
Loading history...
65
                                        return ServerNameBadge::widget(['model' => $model]);
66
                                    } else {
67
                                        return HubNameBadge::widget(['model' => $model]);
68
                                    }
69
                                },
70
                                'delimiter' => '&nbsp;',
71
                            ]); ?>
72
                        </div>
73
                    </div>
74
75
                    <?= $form->field($model, 'client_id')->widget(ClientCombo::class, [
76
                        'inputOptions' => [
77
                            'name' => 'client_id',
78
                        ],
79
                    ])->hint($this->context->isServer() ? Yii::t('hipanel:server', 'Clear this input to unsale the servers') : '') ?>
80
81
                    <?= $form->field($model, 'tariff_id')->widget(TariffCombo::class, [
82
                        'tariffType' => 'server',
83
                        'inputOptions' => [
84
                            'name' => 'tariff_id',
85
                        ],
86
                    ]) ?>
87
                    <?= $form->field($model, 'sale_time')->widget(DateTimePicker::class, [
88
                        'clientOptions' => [
89
                            'autoclose' => true,
90
                            'format' => 'yyyy-mm-dd hh:ii:ss',
91
                            'pickerPosition' => 'top-right',
92
                            'todayBtn' => true,
93
                        ],
94
                        'options' => [
95
                            'value' => Yii::$app->formatter->asDatetime($defaultDateTime, 'php:Y-m-d H:i:s'),
96
                            'name' => 'sale_time',
97
                        ],
98
                    ]) ?>
99
100
                    <?php if ($this->context->isServer()) : ?>
101
                        <?= $form->field($model, 'move_accounts')->checkbox(['name' => 'move_accounts']) ?>
102
                    <?php endif; ?>
103
104
                    <hr>
105
                    <?= Html::submitButton(Yii::t('hipanel:server', 'Sell'), [
106
                        'class' => 'btn btn-success', 'id' => 'save-button',
107
                    ]) ?>
108
                    <?php ActiveForm::end() ?>
109
                </div>
110
            </div>
111
112
            <div role="tabpanel" class="tab-pane" id="by-one">
113
                <div class="col-md-12" style="margin-top: 15px;">
114
                    <?php $form = ActiveForm::begin([
115
                        'id' => 'bulk-by-one-sale',
116
                        'action' => $actionUrl,
117
                        'enableAjaxValidation' => true,
118
                        'validateOnBlur' => true,
119
                        'validationUrl' => $validationUrl,
120
                    ]); ?>
121
122
                    <div class="row">
123
                        <div class="col-md-12">
124
                            <?= $form->field($model, 'client_id')->widget(ClientCombo::class, [
125
                                'options' => ['id' => 'bulk-by-one-sale-client'],
126
                                'inputOptions' => [
127
                                    'id' => 'bulk-by-one-sale-client',
128
                                    'name' => 'client_id',
129
                                ],
130
                                'formElementSelector' => '.form-group',
131
                            ])->hint($this->context->isServer() ? Yii::t('hipanel:server', 'Clear this input to unsale the servers') : '') ?>
132
                        </div>
133
134
                        <?php foreach ($models as $model) : ?>
135
                            <div class="col-md-3 text-right" style="line-height: 34px;">
136
                                <?= Html::activeHiddenInput($model, "[$model->id]id") ?>
137
                                <?php if ($this->context->isServer()) : ?>
138
                                    <?= ServerNameBadge::widget(['model' => $model]) ?>
139
                                <?php else : ?>
140
                                    <?= HubNameBadge::widget(['model' => $model]) ?>
141
                                <?php endif; ?>
142
                            </div>
143
                            <div class="col-md-9">
144
                                <div class="row">
145
                                    <div class="col-md-6">
146
                                        <?= $form->field($model, "[$model->id]tariff_id")
147
                                            ->widget(TariffCombo::class, [
148
                                                'tariffType' => $this->context->isServer() ? 'server' : '',
149
                                                'inputOptions' => ['ref' => 'tariff-combo'],
150
                                            ])
151
                                            ->label(false)
152
                                        ?>
153
                                    </div>
154
                                    <div class="col-md-6">
155
                                        <?= $form->field($model, "[$model->id]sale_time")->widget(DateTimePicker::class, [
156
                                            'clientOptions' => [
157
                                                'autoclose' => true,
158
                                                'format' => 'yyyy-mm-dd hh:ii:ss',
159
                                                'todayBtn' => true,
160
                                            ],
161
                                            'options' => [
162
                                                'value' => Yii::$app->formatter->asDatetime($defaultDateTime, 'php:Y-m-d H:i:s'),
163
                                                'ref' => 'sale-time-combo',
164
                                            ],
165
                                        ])->label(false) ?>
166
                                    </div>
167
                                </div>
168
                            </div>
169
                        <?php endforeach; ?>
170
171
                    </div>
172
173
                    <div class="col-md-12">
174
                        <?php if ($this->context->isServer()) : ?>
175
                            <?= $form->field($model, 'move_accounts')->checkbox(['name' => 'move_accounts']) ?>
176
                        <?php endif; ?>
177
178
                        <hr>
179
                        <?= Html::submitButton(Yii::t('hipanel:server', 'Sell'), [
180
                            'class' => 'btn btn-success', 'id' => 'save-button',
181
                        ]) ?>
182
                        <?php ActiveForm::end() ?>
183
                    </div>
184
185
                </div>
186
187
            </div>
188
        </div>
189
    </div>
190
</div>
191
192
<?= \hipanel\widgets\BulkAssignmentFieldsLinker::widget([
193
    'inputSelectors' => ['select[ref=tariff-combo]', 'input[ref=sale-time-combo]'],
194
]) ?>
195