diff --git a/src/assets/js/NSyncPluginAsset.js b/src/assets/js/NSyncPluginAsset.js index d723675a..b762b7b4 100644 --- a/src/assets/js/NSyncPluginAsset.js +++ b/src/assets/js/NSyncPluginAsset.js @@ -1,7 +1,19 @@ /** * Created by tofid on 23.11.15. */ - +if (!String.prototype.endsWith) { + Object.defineProperty(String.prototype, 'endsWith', { + value: function(searchString, position) { + var subjectString = this.toString(); + if (position === undefined || position > subjectString.length) { + position = subjectString.length; + } + position -= searchString.length; + var lastIndex = subjectString.indexOf(searchString, position); + return lastIndex !== -1 && lastIndex === position; + } + }); +} ; (function ($, window, document, undefined) { var pluginName = "NSync"; @@ -31,10 +43,26 @@ init: function (event) { this.addInlineFormListener(event); this.addDynamicFormListener(event); + this.fieldslistener(event); }, isStateChanged: function () { return this.getDynamicElementsCount() !== this.getInlineElementsCount(); }, + fieldslistener: function (event) { + var that = this; + var domain_name = $(this.element).find('.domain_name').eq(0).val(); + $(this.element).on('change keyup input click', function (event) { + var DWContainer = $(that.element).find(that.options.dynamicFormWidgetContainer); + DWContainer.find(that.options.dynamicFormWidgetItem).each(function (i, elem) { + var containerFields = $(elem).find('input'); + if (containerFields.eq(0).val().endsWith(domain_name)) { + containerFields.eq(1).attr('disabled', false); + } else { + containerFields.eq(1).attr('disabled', true); + } + }); + }); + }, // Inline Processing addInlineFormListener: function (event) { @@ -56,7 +84,7 @@ if (elem.ip !== '') { nsInlineField += '/' + elem.ip; } - nsInlineField += ', '; + nsInlineField += ','; }); $(this.element).find(this.options.inlineFieldSelector).val(nsInlineField.replace(/,\s*$/g, '')); diff --git a/src/controllers/DomainController.php b/src/controllers/DomainController.php index 4a756849..6529cba0 100644 --- a/src/controllers/DomainController.php +++ b/src/controllers/DomainController.php @@ -58,7 +58,7 @@ public function actions() ], 'view' => [ 'class' => 'hipanel\actions\ViewAction', - 'findOptions' => ['with_dns' => 1], + 'findOptions' => ['with_nsips' => 1], 'data' => function ($action) { return [ 'domainContactInfo' => Domain::perform('GetContactsInfo', ['id' => $action->getId()]), diff --git a/src/models/Domain.php b/src/models/Domain.php index 4ddc8128..aba9f76c 100644 --- a/src/models/Domain.php +++ b/src/models/Domain.php @@ -53,7 +53,7 @@ public function rules() [['foa_sent_to'], 'email'], [['url_fwval' ,'mailval', 'parkval', 'soa', 'dns', 'counters'], 'safe'], [['registrant', 'admin', 'tech', 'billing'], 'integer'], - [['block', 'epp_client_id', 'nameservers'], 'safe'], + [['block', 'epp_client_id', 'nameservers', 'nsips'], 'safe'], [['note'], 'safe', 'on' => ['set-note','default']], [['registrant','admin','tech','billing'], 'safe', 'on' => ['set-contacts']], diff --git a/src/models/Ns.php b/src/models/Ns.php index f81cd772..fba9f151 100644 --- a/src/models/Ns.php +++ b/src/models/Ns.php @@ -18,7 +18,7 @@ public function rules() [['name'], FqdnValueValidator::className()], [['ip'], 'ip'], [['ip'], function ($attribute, $params) { - if (StringHelper::endsWith($this->name, $this->domain_name)) { + 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'))); } }], diff --git a/src/views/domain/view.php b/src/views/domain/view.php index 201d654b..cd359365 100644 --- a/src/views/domain/view.php +++ b/src/views/domain/view.php @@ -156,7 +156,7 @@ ?> = NsWidget::widget([ 'model' => $model, - 'attribute' => 'nameservers', + 'attribute' => 'nsips', ]); ?> diff --git a/src/widgets/NsWidget.php b/src/widgets/NsWidget.php index a56f1ec3..64885023 100644 --- a/src/widgets/NsWidget.php +++ b/src/widgets/NsWidget.php @@ -44,9 +44,10 @@ private function createNsModels($string) $models = []; foreach (explode(',', $string) as $item) { if (strpos($item, '/')) { - $data = [ - 'name' => '', - 'ip' => '', + $ns_ip = explode('/', $item); + $data['Ns'] = [ + 'name' => $ns_ip[0], + 'ip' => $ns_ip[1], ]; } else { $data['Ns']['name'] = $item; diff --git a/src/widgets/views/ns.php b/src/widgets/views/ns.php index bb829b4e..59791121 100644 --- a/src/widgets/views/ns.php +++ b/src/widgets/views/ns.php @@ -1,5 +1,6 @@ assetManager->forceCopy = true; - NSyncPluginAsset::register($this); - ?> 'nss-pjax-container', 'enablePushState' => false, 'enableReplaceState' => true]) ?> @@ -42,7 +41,7 @@