mirror of
https://github.com/octoleo/syncthing.git
synced 2025-02-04 04:48:28 +00:00
22 lines
850 B
JavaScript
22 lines
850 B
JavaScript
angular.module('syncthing.core')
|
|
.directive('uniqueFolder', function () {
|
|
return {
|
|
require: 'ngModel',
|
|
link: function (scope, elm, attrs, ctrl) {
|
|
ctrl.$parsers.unshift(function (viewValue) {
|
|
if (scope.editingExisting) {
|
|
// we shouldn't validate
|
|
ctrl.$setValidity('uniqueFolder', true);
|
|
} else if (scope.folders.hasOwnProperty(viewValue)) {
|
|
// the folder exists already
|
|
ctrl.$setValidity('uniqueFolder', false);
|
|
} else {
|
|
// the folder is unique
|
|
ctrl.$setValidity('uniqueFolder', true);
|
|
}
|
|
return viewValue;
|
|
});
|
|
}
|
|
};
|
|
});
|