1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Hosting Plugin for HiPanel |
4
|
|
|
* |
5
|
|
|
* @link https://github.com/hiqdev/hipanel-module-hosting |
6
|
|
|
* @package hipanel-module-hosting |
7
|
|
|
* @license BSD-3-Clause |
8
|
|
|
* @copyright Copyright (c) 2015-2016, HiQDev (http://hiqdev.com/) |
9
|
|
|
*/ |
10
|
|
|
|
11
|
|
|
namespace hipanel\modules\hosting\menus; |
12
|
|
|
|
13
|
|
|
use hipanel\widgets\AjaxModal; |
14
|
|
|
use Yii; |
15
|
|
|
use yii\helpers\Html; |
16
|
|
|
use yii\web\JsExpression; |
17
|
|
|
|
18
|
|
|
class IpActionsMenu extends \hiqdev\yii2\menus\Menu |
19
|
|
|
{ |
20
|
|
|
public $model; |
21
|
|
|
|
22
|
|
|
public function run($config = []) |
23
|
|
|
{ |
24
|
|
|
$script = $this->registerClientScript(); |
25
|
|
|
|
26
|
|
|
return $script . parent::run($config); |
27
|
|
|
} |
28
|
|
|
|
29
|
|
|
public function items() |
30
|
|
|
{ |
31
|
|
|
return [ |
32
|
|
|
'view' => [ |
33
|
|
|
'label' => Yii::t('hipanel', 'View'), |
34
|
|
|
'icon' => 'fa-info', |
35
|
|
|
'url' => ['@ip/view', 'id' => $this->model->id], |
36
|
|
|
], |
37
|
|
|
'expand' => [ |
38
|
|
|
'label' => Yii::t('hipanel:hosting', 'Expand'), |
39
|
|
|
'icon' => 'fa-th', |
40
|
|
|
'url' => ['@ip/expand', 'id' => $this->model->id], |
41
|
|
|
'linkOptions' => [ |
42
|
|
|
'class' => 'btn-expand-ip', |
43
|
|
|
'data-id' => $this->model->id, |
44
|
|
|
'data-pjax' => 0, |
45
|
|
|
], |
46
|
|
|
], |
47
|
|
|
'update' => [ |
48
|
|
|
'label' => Yii::t('hipanel', 'Update'), |
49
|
|
|
'icon' => 'fa-pencil', |
50
|
|
|
'url' => ['@ip/update', 'id' => $this->model->id], |
51
|
|
|
'visible' => Yii::$app->user->can('admin'), |
52
|
|
|
], |
53
|
|
|
// 'delete' => [ |
|
|
|
|
54
|
|
|
// 'label' => Yii::t('hipanel', 'Delete'), |
55
|
|
|
// 'icon' => 'fa-trash', |
56
|
|
|
// 'url' => ['@ip/delete', 'id' => $this->model->id], |
57
|
|
|
// 'linkOptions' => [ |
58
|
|
|
// 'data' => [ |
59
|
|
|
// 'confirm' => Yii::t('hipanel', 'Are you sure you want to delete this item?'), |
60
|
|
|
// 'method' => 'POST', |
61
|
|
|
// 'pjax' => '0', |
62
|
|
|
// ], |
63
|
|
|
// ], |
64
|
|
|
// ], |
65
|
|
|
]; |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
public function registerClientScript() |
69
|
|
|
{ |
70
|
|
|
$this->getView()->registerJs("$(document).on('click', '.btn-expand-ip', function (event) { |
71
|
|
|
$('#expand-ip').data('ip_id', $(this).data('id')).modal('show'); |
72
|
|
|
event.preventDefault(); |
73
|
|
|
});"); |
74
|
|
|
|
75
|
|
|
return AjaxModal::widget([ |
76
|
|
|
'id' => 'expand-ip', |
77
|
|
|
'header' => Html::tag('h4', Yii::t('hipanel:hosting', 'Expanded range'), ['class' => 'modal-title']), |
78
|
|
|
'scenario' => 'expand', |
79
|
|
|
'actionUrl' => ['expand'], |
80
|
|
|
'size' => AjaxModal::SIZE_LARGE, |
81
|
|
|
'toggleButton' => false, |
82
|
|
|
'clientEvents' => [ |
83
|
|
|
'show.bs.modal' => function ($widget) { |
84
|
|
|
return new JsExpression("function() { |
85
|
|
|
$.get('{$widget->actionUrl}', {'id': $('#{$widget->id}').data('ip_id')}).done(function (data) { |
86
|
|
|
$('#{$widget->id} .modal-body').html(data); |
87
|
|
|
});; |
88
|
|
|
}"); |
89
|
|
|
}, |
90
|
|
|
], |
91
|
|
|
]); |
92
|
|
|
} |
93
|
|
|
} |
94
|
|
|
|
Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.
The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.
This check looks for comments that seem to be mostly valid code and reports them.