Skip to content

Commit

Permalink
Add IP Restrict Rule to NSync js
Browse files Browse the repository at this point in the history
  • Loading branch information
tafid committed Nov 25, 2015
1 parent 58c165e commit da3804b
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 17 deletions.
29 changes: 13 additions & 16 deletions src/assets/NSyncPluginAssets/js/NSyncPlugin.js
Original file line number Diff line number Diff line change
@@ -1,20 +1,12 @@
/**
* 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;
}
});
}
;
if (typeof String.prototype.endsWith !== 'function') {
String.prototype.endsWith = function(suffix) {
return this.indexOf(suffix, this.length - suffix.length) !== -1;
};
}
(function ($, window, document, undefined) {
var pluginName = "NSync";

Expand Down Expand Up @@ -50,19 +42,22 @@ if (!String.prototype.endsWith) {
},
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)) {
if (that.isChildDomain(containerFields.eq(0).val())) {
containerFields.eq(1).attr('disabled', false);
} else {
containerFields.eq(1).attr('disabled', true);
}
});
});
},
isChildDomain: function (nsName) {
var mainDomain = $(this.element).find('.domain_name').eq(0).val();
return nsName.endsWith(mainDomain);
},

// Inline Processing
addInlineFormListener: function (event) {
Expand Down Expand Up @@ -148,7 +143,9 @@ if (!String.prototype.endsWith) {
var stateItem = state.shift();
var containerFields = $(element).find('input');
containerFields.eq(0).val(stateItem.name);
containerFields.eq(1).val(stateItem.ip);
if (that.isChildDomain(stateItem.name)) {
containerFields.eq(1).val(stateItem.ip);
}
});
},
getDynamicElementsCount: function () {
Expand Down
2 changes: 1 addition & 1 deletion src/widgets/views/ns.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
use yii\bootstrap\ActiveForm;
use yii\bootstrap\Html;
use yii\helpers\Url;

Yii::$app->assetManager->forceCopy = true;
NSyncPluginAsset::register($this);
?>

Expand Down

0 comments on commit da3804b

Please sign in to comment.