Skip to content

Commit

Permalink
Merge f9c3315 into cf008aa
Browse files Browse the repository at this point in the history
  • Loading branch information
tafid committed Apr 2, 2020
2 parents cf008aa + f9c3315 commit 41be353
Show file tree
Hide file tree
Showing 4 changed files with 94 additions and 7 deletions.
11 changes: 7 additions & 4 deletions src/grid/IpGridView.php
Expand Up @@ -10,12 +10,15 @@

namespace hipanel\modules\hosting\grid;

use hipanel\grid\BoxedGridView;
use hipanel\grid\MainColumn;
use hipanel\grid\XEditableColumn;
use hipanel\helpers\FontIcon;
use hipanel\helpers\Url;
use hipanel\modules\hosting\menus\IpActionsMenu;
use hipanel\modules\hosting\models\HdomainSearch;
use hipanel\modules\hosting\models\Ip;
use hipanel\modules\hosting\widgets\ip\ApplyPtrChange;
use hipanel\modules\hosting\widgets\ip\IpTag;
use hipanel\widgets\ArraySpoiler;
use hipanel\widgets\XEditable;
Expand All @@ -24,7 +27,7 @@
use yii\base\InvalidParamException;
use yii\helpers\Html;

class IpGridView extends \hipanel\grid\BoxedGridView
class IpGridView extends BoxedGridView
{
public $controllerUrl = '@ip';

Expand Down Expand Up @@ -144,8 +147,8 @@ public function columns()
'style' => 'width: 40%',
],
'format' => 'raw',
'value' => function ($model) {
if ($model->canSetPtr()) {
'value' => static function (Ip $model): string {
if (!$model->canSetPtr()) {
return XEditable::widget([
'model' => $model,
'attribute' => 'ptr',
Expand All @@ -155,7 +158,7 @@ public function columns()
]);
}

return null;
return ApplyPtrChange::widget(compact('model'));
},
],
]);
Expand Down
3 changes: 3 additions & 0 deletions src/messages/ru/hipanel:hosting.php
Expand Up @@ -302,4 +302,7 @@
'Are you sure you want to delete backuping?' => 'Вы уверены, что хотите удалить настройки бэкапов?',

'Scheduled time' => 'Запланированное время',

'In order to change you need to {apply}' => 'Для редактирования этого значения, вам нужно {apply}',
'apply for change of PTR records' => 'создать тикет на изменение PTR записи',
];
10 changes: 7 additions & 3 deletions src/models/Ip.php
Expand Up @@ -144,9 +144,13 @@ public function addLink(Link $link)
*
* @return bool
*/
public function canSetPtr()
public function canSetPtr(): bool
{
return !in_array('aux', (array) $this->tags, true)
&& (new IpValidator(['ranges' => ['!system', 'any']]))->validate($this->ip);
if (Yii::$app->user->can('ip.update')) {
return !in_array('aux', (array)$this->tags, true)
&& (new IpValidator(['ranges' => ['!system', 'any']]))->validate($this->ip);
}

return false;
}
}
77 changes: 77 additions & 0 deletions src/widgets/ip/ApplyPtrChange.php
@@ -0,0 +1,77 @@
<?php

namespace hipanel\modules\hosting\widgets\ip;

use Yii;
use yii\base\Widget;
use yii\helpers\Html;
use yii\web\View;
use hipanel\modules\hosting\models\Ip;

class ApplyPtrChange extends Widget
{
/** @var Ip */
public $model;

/** @var string */
public $attribute = 'ptr';

public function init(): void
{
$this->view->registerJs(
<<<'JS'
$('.apply-ptr-change').popover({html: true});
$(document).on('click', function (e) {
$('[data-toggle="popover"], [data-original-title]').each(function () {
if (!$(this).is(e.target) && $(this).has(e.target).length === 0 && $('.popover').has(e.target).length === 0) {
(($(this).popover('hide').data('bs.popover')||{}).inState||{}).click = false
}
});
});
JS
,
View::POS_READY
);
$this->view->registerCss(
<<<'CSS'
.apply-ptr-change {
border-bottom: 1px #72afd2 dashed;
font-style: italic;
}
.apply-ptr-change:hover {
text-decoration: none;
}
CSS
);
}

public function run(): string
{
return Html::tag(
'a',
$this->model->{$this->attribute} ?? Yii::t('hipanel', 'Empty'),
[
'class' => 'apply-ptr-change',
'href' => '#',
'data' => [
'container' => 'body',
'toggle' => 'popover',
'content' => Yii::t(
'hipanel:hosting',
'In order to change you need to {apply}',
[
'apply' => Html::a(
Yii::t('hipanel:hosting', 'apply for change of PTR records'),
['@ticket/create'],
['target' => '_blank']
),
]
),
'placement' => 'top',
],
]
);
}
}

0 comments on commit 41be353

Please sign in to comment.