Completed
Push — master ( cf008a...c4c41d )
by Dmitry
10:08
created

ApplyPtrChange::run()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 27

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 27
ccs 0
cts 25
cp 0
rs 9.488
c 0
b 0
f 0
cc 1
nc 1
nop 0
crap 2
1
<?php
2
3
namespace hipanel\modules\hosting\widgets\ip;
4
5
use Yii;
6
use yii\base\Widget;
7
use yii\helpers\Html;
8
use yii\web\View;
9
use hipanel\modules\hosting\models\Ip;
10
11
class ApplyPtrChange extends Widget
12
{
13
    /** @var Ip */
14
    public $model;
15
16
    /** @var string */
17
    public $attribute = 'ptr';
18
19
    public function init(): void
20
    {
21
        $this->view->registerJs(
22
            <<<'JS'
23
                $('.apply-ptr-change').popover({html: true});
24
                $(document).on('click', function (e) {
25
                    $('[data-toggle="popover"], [data-original-title]').each(function () {
26
                        if (!$(this).is(e.target) && $(this).has(e.target).length === 0 && $('.popover').has(e.target).length === 0) {
27
                            (($(this).popover('hide').data('bs.popover')||{}).inState||{}).click = false
28
                        }
29
                    });
30
                });
31
JS
32
            ,
33
            View::POS_READY
34
        );
35
        $this->view->registerCss(
36
            <<<'CSS'
37
            .apply-ptr-change {
38
                border-bottom: 1px #72afd2 dashed;
39
                font-style: italic;
40
            }
41
            
42
            .apply-ptr-change:hover {
43
                text-decoration: none;
44
            }
45
46
CSS
47
        );
48
    }
49
50
    public function run(): string
51
    {
52
        return Html::tag(
53
            'a',
54
            $this->model->{$this->attribute} ?? Yii::t('hipanel', 'Empty'),
55
            [
56
                'class' => 'apply-ptr-change',
57
                'href' => '#',
58
                'data' => [
59
                    'container' => 'body',
60
                    'toggle' => 'popover',
61
                    'content' => Yii::t(
62
                        'hipanel:hosting',
63
                        'In order to change you need to {apply}',
64
                        [
65
                            'apply' => Html::a(
66
                                Yii::t('hipanel:hosting', 'apply for change of PTR records'),
67
                                ['@ticket/create'],
68
                                ['target' => '_blank']
69
                            ),
70
                        ]
71
                    ),
72
                    'placement' => 'top',
73
                ],
74
            ]
75
        );
76
    }
77
}
78