Skip to content

Commit

Permalink
Hdomain/view: redone with tabs, other minor
Browse files Browse the repository at this point in the history
  • Loading branch information
SilverFire committed Nov 9, 2015
1 parent a78d79e commit 7beeaa5
Show file tree
Hide file tree
Showing 3 changed files with 102 additions and 74 deletions.
1 change: 1 addition & 0 deletions src/grid/HdomainGridView.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ static public function defaultColumns()
'delimiter' => '<br />',
'button' => [
'label' => Yii::t('app', '+{0, plural, one{# alias} other{# aliases}}', count($aliases)),
'class' => 'badge progress-bar-info',
'popoverOptions' => ['html' => true],
],
'formatter' => function ($value, $key) {
Expand Down
8 changes: 7 additions & 1 deletion src/models/Hdomain.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ class Hdomain extends \hipanel\base\Model
const STATE_DISABLED = 'disabled';
const STATE_TEMPORARY = 'temporary';

public function init() {
public function init()
{
$this->on(self::EVENT_AFTER_FIND, function ($event) {
$this->setAttributes([
'ip' => $this->getAttribute('vhost')['ip'],
Expand Down Expand Up @@ -161,6 +162,11 @@ public function getIsBlocked()
return $this->state === static::STATE_BLOCKED;
}

public function getDnsId()
{
return $this->dns_hdomain_id ?: $this->id;
}

public function scenarioCommands()
{
$result = [];
Expand Down
167 changes: 94 additions & 73 deletions src/views/hdomain/view.php
Original file line number Diff line number Diff line change
@@ -1,13 +1,20 @@
<?php

use hipanel\modules\dns\widgets\DnsZoneEditWidget;
use hipanel\modules\hosting\grid\HdomainGridView;
use hipanel\modules\hosting\models\Hdomain;
use hipanel\widgets\Box;
use hipanel\widgets\ModalButton;
use yii\helpers\Html;
use yii\web\JsExpression;
use yii\web\View;

$this->title = $model->domain;
/**
* @var $this View
* @var $model Hdomain
*/

$this->title = $model->domain;
$this->subtitle = Yii::t('app', 'Hosting domain detailed information') . ' #' . $model->id;
$this->breadcrumbs->setItems([
['label' => Yii::t('app', 'Domains'), 'url' => ['index']],
Expand Down Expand Up @@ -38,13 +45,16 @@
<ul class="nav">
<li>
<?php $url = 'http://' . $model->domain . '/' ?>
<?= Html::a('<i class="fa fa-globe"></i>' . Yii::t('app', 'Go to site ') . $url, $url, ['target' => '_blank']); ?>
<?= Html::a('<i class="fa fa-globe"></i>' . Yii::t('app', 'Go to site ') . $url, $url,
['target' => '_blank']); ?>
</li>
<li>
<?= Html::a('<i class="fa fa-pencil"></i>' . Yii::t('app', 'Advanced settings'), ['/hosting/vhost/advanced-config', 'id' => $model->id]); ?>
<?= Html::a('<i class="fa fa-pencil"></i>' . Yii::t('app', 'Advanced settings'),
['/hosting/vhost/advanced-config', 'id' => $model->id]); ?>
</li>
<li>
<?= Html::a('<i class="fa fa-adjust"></i>' . Yii::t('app', 'Proxy settings'), ['/hosting/vhost/manage-proxy', 'id' => $model->id]); ?>
<?= Html::a('<i class="fa fa-adjust"></i>' . Yii::t('app', 'Proxy settings'),
['/hosting/vhost/manage-proxy', 'id' => $model->id]); ?>
</li>
<?php if (Yii::$app->user->can('support') && Yii::$app->user->id != $model->client_id) { ?>
<li>
Expand Down Expand Up @@ -79,77 +89,88 @@
</div>

<div class="col-md-9">
<div class="row">
<div class="col-md-6">
<?php
$box = Box::begin(['renderBody' => false]);
$box->beginHeader();
echo $box->renderTitle(Yii::t('app', 'Domain information'));
$box->endHeader();
$box->beginBody();
echo HdomainGridView::detailView([
'boxed' => false,
'model' => $model,
'columns' => [
'client_id',
'seller_id',
'account',
'server',
'service',
'ip',
'state',
'dns_on',
[
'attribute' => 'aliases',
'label' => Yii::t('app', 'Aliases'),
'format' => 'raw',
'value' => function ($model) {
$html = [];
foreach ((array)$model->getAttribute('aliases') as $id => $alias) {
$aliasModel = Yii::createObject([
'class' => Hdomain::className(),
'id' => $id,
'domain' => $alias
]);
$item = Html::a($aliasModel->domain, ['view', 'id' => $aliasModel->id]) . ' ';
$item .= ModalButton::widget([
'model' => $aliasModel,
'scenario' => 'delete-alias',
'submit' => ModalButton::SUBMIT_AJAX,
'button' => [
'label' => '<i class="fa fa-trash-o"></i>',
],
'modal' => [
'header' => Html::tag('h4', Yii::t('app', 'Confirm alias deleting')),
'headerOptions' => ['class' => 'label-info'],
'footer' => [
'label' => Yii::t('app', 'Delete alias'),
'data-loading-text' => Yii::t('app', 'Deleting alias...'),
'class' => 'btn btn-danger',
]
],
'body' => Yii::t('app',
'Are you sure, that you want to delete alias {name}?',
['name' => $aliasModel->domain]
),
'ajaxOptions' => [
'success' => new JsExpression("
function (data) {
form.closest('.alias-item').remove();
}
")
<div class="nav-tabs-custom">
<ul class="nav nav-tabs">
<li class="active"><a href="#hdomain-details" data-toggle="tab"><?= Yii::t('app', 'Details') ?></a></li>
<li><a href="#hdomain-dns" data-toggle="tab"><?= Yii::t('app', 'DNS records') ?></a></li>
</ul>
<div class="tab-content">
<div class="tab-pane active" id="hdomain-details">
<?= HdomainGridView::detailView([
'boxed' => false,
'model' => $model,
'columns' => [
'client_id',
'seller_id',
'account',
'server',
'service',
'ip',
'state',
'dns_on',
[
'attribute' => 'aliases',
'label' => Yii::t('app', 'Aliases'),
'format' => 'raw',
'value' => function ($model) {
$html = [];
foreach ((array)$model->getAttribute('aliases') as $id => $alias) {
$aliasModel = Yii::createObject([
'class' => Hdomain::className(),
'id' => $id,
'domain' => $alias
]);
$item = Html::a($aliasModel->domain, ['view', 'id' => $aliasModel->id]) . ' ';
$item .= ModalButton::widget([
'model' => $aliasModel,
'scenario' => 'delete-alias',
'submit' => ModalButton::SUBMIT_AJAX,
'button' => [
'label' => '<i class="fa fa-trash-o"></i>',
],
'modal' => [
'header' => Html::tag('h4', Yii::t('app', 'Confirm alias deleting')),
'headerOptions' => ['class' => 'label-info'],
'footer' => [
'label' => Yii::t('app', 'Delete alias'),
'data-loading-text' => Yii::t('app', 'Deleting alias...'),
'class' => 'btn btn-danger',
]
]);
$html[] = Html::tag('div', $item, ['class' => 'alias-item']);
}
return implode("\n", $html);
],
'body' => Yii::t('app',
'Are you sure, that you want to delete alias {name}?',
['name' => $aliasModel->domain]
),
'ajaxOptions' => [
'success' => new JsExpression("
function (data) {
form.closest('.alias-item').remove();
}
")
]
]);
$html[] = Html::tag('div', $item, ['class' => 'alias-item']);
}
]
],
]);
$box->endBody();
$box->end();
?>
return implode("\n", $html);
}
]
],
]); ?>
</div>
<div class="tab-pane" id="hdomain-dns">
<?php echo DnsZoneEditWidget::widget([
'domainId' => $model->getDnsId(),
'clientScriptWrap' => function ($js) {
return new \yii\web\JsExpression("
$('a[data-toggle=tab]').filter(function () {
return $(this).attr('href') == '#hdomain-dns';
}).on('shown.bs.tab', function (e) {
$js
});
");
}
]); ?>
</div>
</div>
</div>
</div>
Expand Down

0 comments on commit 7beeaa5

Please sign in to comment.