Skip to content

Commit

Permalink
Add Ns rules
Browse files Browse the repository at this point in the history
  • Loading branch information
tafid committed Nov 24, 2015
1 parent 5c7e551 commit 246ac1e
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 15 deletions.
4 changes: 4 additions & 0 deletions src/controllers/DomainController.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,10 @@ public function actions()
],
'validate-nss' => [
'class' => 'hipanel\actions\ValidateFormAction',
'model' => 'hipanel\modules\domain\models\Ns',
'scenario' => 'default',

'allowDynamicScenario' => false,
],
'set-note' => [
'class' => 'hipanel\actions\SmartUpdateAction',
Expand Down
13 changes: 10 additions & 3 deletions src/models/Ns.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
namespace hipanel\modules\domain\models;

use hipanel\base\Model;
use hipanel\modules\dns\validators\DomainPartValidator;
use hipanel\helpers\StringHelper;
use hipanel\modules\dns\validators\FqdnValueValidator;
use Yii;

class Ns extends Model
Expand All @@ -13,8 +14,14 @@ class Ns extends Model
public function rules()
{
return [
[['name', 'ip'], 'filter', 'filter' => 'trim'],
[['name'], DomainPartValidator::className()],
[['name', 'ip', 'domain_name'], 'filter', 'filter' => 'trim'],
[['name'], FqdnValueValidator::className()],
[['ip'], 'ip'],
[['ip'], function ($attribute, $params) {
if (StringHelper::endsWith($this->name, $this->domain_name)) {
$this->addError($attribute, Yii::t('app', Yii::t('app', 'To assign the IP, NS must be a child from main domain')));
}
}],
];
}

Expand Down
29 changes: 17 additions & 12 deletions src/widgets/views/ns.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
<?php

use hipanel\modules\domain\assets\NSyncPluginAsset;
use hipanel\widgets\Box;
use hipanel\widgets\Pjax;
use wbraganca\dynamicform\DynamicFormWidget;
use yii\bootstrap\ActiveForm;
Expand Down Expand Up @@ -31,6 +30,7 @@
<?php $form = ActiveForm::begin([
'id' => 'nss-form-pjax',
'action' => 'set-nss',
'enableAjaxValidation' => true,
'validationUrl' => Url::toRoute(['validate-nss', 'scenario' => 'default']),
'options' => [
'data-pjax' => true,
Expand All @@ -40,21 +40,28 @@
<?= Html::activeHiddenInput($model, "id") ?>
<?= Html::activeHiddenInput($model, "domain") ?>

<?php Box::begin(); ?>
<div class="row" style="margin-top: 15pt;">
<div class="col-md-10 inline-form-selector">
<?= Html::activeTextInput($model, 'nameservers', ['class' => 'form-control']) ?>
<?= Html::activeTextInput($model, 'nameservers', [
'class' => 'form-control',
'placeholder' => $model->getAttributeLabel('nameservers'),
'autocomplete' => 'off',
]) ?>
</div>
<div class="col-md-2 text-right">
<?= Html::submitButton(Yii::t('app', 'Save'), ['class' => 'btn btn-default', 'id' => 'nss-save-button', 'data-loading-text' => Yii::t('app', 'Saving') . '...']) ?>
<?= Html::submitButton(Yii::t('app', 'Save'), [
'class' => 'btn btn-default',
'id' => 'nss-save-button',
'data-loading-text' => Yii::t('app', 'Saving') . '...',
]) ?>
</div>
</div>
<?php Box::end(); ?>

<div class="row">
<div class="col-md-12">
<div class="panel panel-default">
<div class="panel-body">
<hr>
<div class="">
<div class="">
<?php DynamicFormWidget::begin([
'widgetContainer' => 'dynamicform_wrapper', // required: only alphanumeric characters plus "_" [A-Za-z0-9_]
'widgetBody' => '.container-items', // required: css class selector
Expand All @@ -72,16 +79,14 @@
]) ?>
<div class="container-items">
<?php foreach ($nsModels as $i => $nsModel): ?>
<?= Html::activeHiddenInput($nsModel, "[$i]domain_name") ?>
<div class="item">
<div class="row" style="margin-bottom: 5pt">
<div class="col-md-5">
<?= Html::activeTextInput($nsModel, "[$i]name", ['placeholder' => $nsModel->getAttributeLabel('name'), 'class' => 'form-control']) ?>
<?= $form->field($nsModel, "[$i]name")->textInput(['placeholder' => $nsModel->getAttributeLabel('name')])->label(false) ?>
</div>
<div class="col-md-5">
<?= Html::activeTextInput($nsModel, "[$i]ip", [
'placeholder' => $nsModel->getAttributeLabel('ip'),
'class' => 'form-control',
]) ?>
<?= $form->field($nsModel, "[$i]ip")->textInput(['placeholder' => $nsModel->getAttributeLabel('ip')])->label(false) ?>
</div>
<div class="col-md-2 text-right">
<div class="btn-group" role="group">
Expand Down

0 comments on commit 246ac1e

Please sign in to comment.