web/vtctld: Validate vindex owner.

This commit is contained in:
Anthony Yeh 2015-07-28 14:22:44 -07:00
Родитель a45da92687
Коммит 4572d8f2ef
2 изменённых файлов: 21 добавлений и 0 удалений

Просмотреть файл

@ -305,6 +305,7 @@ They are only used with the
<md-not-found>No tables found matching "{{vindex.Owner}}".</md-not-found>
<div ng-messages="vindexForm.vindexOwner.$error">
<div ng-message="vdefined">Undefined Table</div>
<div ng-message="vcontained">Table's class doesn't contain this vindex.</div>
</div>
</md-autocomplete>
<input ng-hide="true" name="vindexOwner" ng-model="vindex.Owner" vindex-owner>
@ -366,6 +367,7 @@ They are only used with the
<md-not-found>No tables found matching "{{newVindexOwner}}".</md-not-found>
<div ng-messages="vindexForm.vindexOwner.$error">
<div ng-message="vdefined">Undefined Table</div>
<div ng-message="vcontained">Table's class doesn't contain this vindex.</div>
</div>
</md-autocomplete>
<input ng-hide="true" name="vindexOwner" ng-model="newVindexOwner" vindex-owner>

Просмотреть файл

@ -362,6 +362,25 @@ app.directive('vindexOwner', function() {
return viewValue in scope.keyspace.Tables;
return true;
};
ctrl.$validators.vcontained = function(modelValue, viewValue) {
var form = scope.vindexForm;
var vindex = form.vindex.$modelValue;
if (viewValue && scope.keyspace.Tables[viewValue]) {
var classname = scope.keyspace.Tables[viewValue];
if (classname && scope.keyspace.Classes[classname]) {
var cls = scope.keyspace.Classes[classname];
if (cls.ColVindexes) {
for (var i = 0; i < cls.ColVindexes.length; i++) {
if (cls.ColVindexes[i].Name == vindex)
return true;
}
}
return false;
}
}
return true;
};
}
};
});