Skip to content

Commit

Permalink
improved host with smart actions
Browse files Browse the repository at this point in the history
  • Loading branch information
hiqsol committed Jul 30, 2015
1 parent e4c10b9 commit e6a32f1
Show file tree
Hide file tree
Showing 7 changed files with 52 additions and 24 deletions.
26 changes: 21 additions & 5 deletions controllers/HostController.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@

namespace hipanel\modules\domain\controllers;

use hipanel\base\Model;
use hipanel\modules\domain\models\Host;
use hiqdev\hiart\Collection;
use Yii;
use yii\base\ErrorException;
Expand All @@ -19,7 +17,25 @@
class HostController extends \hipanel\base\CrudController
{

public function actionCreate()
public function actions()
{
return [
'create' => [
'class' => 'hipanel\actions\SmartCreateAction',
'success' => Yii::t('app', 'Name server created'),
],
'update' => [
'class' => 'hipanel\actions\SmartUpdateAction',
'success' => Yii::t('app', 'Name server updated'),
],
'delete' => [
'class' => 'hipanel\actions\SmartDeleteAction',
'success' => Yii::t('app', 'Name server deleted'),
],
];
}

public function actionCreateOld()
{
$model = static::newModel(['scenario' => 'create']);
if (Yii::$app->request->isPost) {
Expand All @@ -34,7 +50,7 @@ public function actionCreate()
return $this->render('create', ['models' => [$model]]);
}

public function actionUpdate($id = null)
public function actionUpdateOld($id = null)
{

$condition = Yii::$app->request->get('selection') ?: $id;
Expand Down Expand Up @@ -75,7 +91,7 @@ public function actionValidateForm($scenario)
}
}

public function actionDelete()
public function actionDeleteOld()
{
$condition = Yii::$app->request->post('selection');
if (!empty($condition)) {
Expand Down
7 changes: 7 additions & 0 deletions grid/HostGridView.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,13 @@ static public function defaultColumns()
'class' => 'hipanel\grid\MainColumn',
'filterAttribute' => 'host_like',
],
'bold_host' => [
'format' => 'html',
'attribute' => 'host',
'value' => function ($model) {
return Html::tag('b', $model->host);
}
],
'domain' => [
'format' => 'html',
'filterAttribute' => 'domain_like',
Expand Down
3 changes: 1 addition & 2 deletions models/Host.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,12 @@ public function rules () {
return [
[['host'], 'safe'],
[['id'], 'safe'],
[['id'], 'integer', 'on' => 'delete'],
[['seller_id','client_id','domain_id'], 'safe'],
[['seller','client'], 'safe'],
[['domain','host'], 'safe'],
[['ip'], 'safe'],
[['ips'], 'safe'],
// [['ips'], 'safe', 'on' => 'update'],
[['host', 'ips'], 'required', 'on' => 'create'],
[['host'], DomainValidator::className()],

Expand All @@ -36,7 +36,6 @@ public function rules () {
} else {
return $value;
}

}, 'on' => ['create', 'update']],

[['ips'], 'each', 'rule' => [IpValidator::className()], 'on' => ['create', 'update']],
Expand Down
18 changes: 12 additions & 6 deletions views/host/_form.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

use yii\bootstrap\ActiveForm;
use yii\helpers\Html;
use wbraganca\dynamicform\DynamicFormWidget;
Expand Down Expand Up @@ -27,7 +28,8 @@
'formFields' => [
'host'
],
]); ?>
]) ?>

<div class="container-items"><!-- widgetContainer -->
<?php foreach ($models as $i => $model): ?>

Expand All @@ -42,13 +44,13 @@
<div class="row input-row margin-bottom">
<div class="col-sm-5">
<?php if ($model->isNewRecord) : ?>
<?= $form->field($model, "[{$i}]host")->textInput(['placeholder' => Yii::t('app', 'Name server')])->label(false); ?>
<?= $form->field($model, "[{$i}]host")->textInput(['placeholder' => Yii::t('app', 'Name server')])->label(false) ?>
<?php else : ?>
<p class="form-control-static text-center"><?= $model->host; ?></p>
<?php endif; ?>
</div>
<div class="col-sm-5">
<?= $form->field($model, "[{$i}]ips")->textInput(['placeholder' => Yii::t('app', 'IP addresses')])->label(false)->hint('Up to 13 items, IPv4 or IPv6, comma or space delimited'); ?>
<?= $form->field($model, "[{$i}]ips")->textInput(['placeholder' => Yii::t('app', 'IP addresses')])->label(false)->hint('Up to 13 items, IPv4 or IPv6, comma or space delimited') ?>
</div>
<div class="col-sm-2">
<?php if ($model->isNewRecord) : ?>
Expand All @@ -60,7 +62,11 @@
</div>
<?php endforeach; ?>
</div>
<?php DynamicFormWidget::end(); ?>
<?= Html::submitButton(Yii::t('app', 'Save'), ['class' => 'btn btn-default']); ?>
<?php ActiveForm::end(); ?>

<?php DynamicFormWidget::end() ?>

<?= Html::submitButton(Yii::t('app', 'Save'), ['class' => 'btn btn-default']) ?>
&nbsp;
<?= Html::button(Yii::t('app', 'Cancel'), ['class' => 'btn btn-default', 'onclick' => 'history.go(-1)']) ?>
<?php ActiveForm::end() ?>

10 changes: 7 additions & 3 deletions views/host/create.php
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
<?php

use hipanel\widgets\Box;

$this->title = Yii::t('app', 'Create Name Server');
$this->params['breadcrumbs'][] = ['label' => Yii::t('app', 'Name Server'), 'url' => ['index']];
$this->params['breadcrumbs'][] = $this->title;

?>

<?php \hipanel\widgets\Box::begin() ?>
<?= $this->render('_form', ['models' => $models]); ?>
<?php \hipanel\widgets\Box::end() ?>
<?php Box::begin() ?>
<?= $this->render('_form', ['models' => $models]) ?>
<?php Box::end() ?>
8 changes: 3 additions & 5 deletions views/host/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,10 @@

$this->title = Yii::t('app', 'Name Servers');
$this->subtitle = Yii::t('app', Yii::$app->request->queryParams ? 'filtered list' : 'full list');
$this->breadcrumbs->setItems([
$this->title
]);
$this->breadcrumbs[] = $this->title;

?>
<?= Html::beginForm('', '') ?>
<?= Html::beginForm() ?>

<?php $box = ActionBox::begin(['bulk' => true, 'options' => ['class' => 'box-info']]) ?>
<?php $box->beginActions() ?>
Expand All @@ -21,7 +19,7 @@
<?php $box->beginBulkActions() ?>
<?= Html::submitButton(Yii::t('app', 'Change IP'), ['id' => 'change-ip-button', 'class' => 'btn btn-primary', 'formmethod' => 'GET', 'formaction' => Url::to('update')]) ?>
&nbsp;
<?= Html::submitButton(Yii::t('app', 'Delete'), ['id' => 'change-ip-button', 'class' => 'btn btn-danger', 'formmethod' => 'POST', 'formaction' => Url::to('delete')]) ?>
<?= Html::submitButton(Yii::t('app', 'Delete'), ['id' => 'delete-button', 'class' => 'btn btn-danger', 'formmethod' => 'POST', 'formaction' => Url::to('delete')]) ?>
<?php $box->endBulkActions() ?>
<?php $box::end() ?>

Expand Down
4 changes: 1 addition & 3 deletions views/host/view.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,9 @@
'model' => $model,
'columns' => [
'seller_id','client_id',
'domain',
['attribute' => 'host'],'ips',
'domain', 'bold_host', 'ips',
],
]) ?>
</div>
</div>
</div>
<? Pjax::end() ?>

0 comments on commit e6a32f1

Please sign in to comment.