2014-11-26 13:39:59 +01:00
|
|
|
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);
|
2015-03-01 22:10:34 +01:00
|
|
|
} else if (scope.folders.hasOwnProperty(viewValue)) {
|
2014-11-26 13:39:59 +01:00
|
|
|
// the folder exists already
|
|
|
|
|
ctrl.$setValidity('uniqueFolder', false);
|
|
|
|
|
} else {
|
|
|
|
|
// the folder is unique
|
|
|
|
|
ctrl.$setValidity('uniqueFolder', true);
|
|
|
|
|
}
|
|
|
|
|
return viewValue;
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
};
|
2018-12-25 14:26:46 +01:00
|
|
|
});
|