Completed
Push — master ( 7515d1...e4fd13 )
by Andrii
16:30
created

ServerSwitcher::initClientScript()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 10
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 10
rs 9.4285
cc 1
eloc 4
nc 1
nop 0
1
<?php
2
3
namespace hipanel\modules\server\widgets;
4
5
use Yii;
6
use yii\base\Widget;
7
use yii\helpers\Url;
8
9
class ServerSwitcher extends Widget
10
{
11
    public $model;
12
13
    public function run()
14
    {
15
        if (!Yii::$app->user->can('support')) {
16
            return null;
17
        }
18
19
        $this->initClientScript();
20
21
        return $this->render('ServerSwitcher', ['model' => $this->model]);
22
    }
23
24
    protected function initClientScript()
25
    {
26
        $url = Url::to(['@server/view', 'id' => '']);
27
        $this->view->registerJs("
28
            $('#server-name').on('select2:select', function (e) {
29
                var selectedId = this.value;
30
                window.location.href = '{$url}' + selectedId;
31
            });
32
        ");
33
    }
34
}
35