/
valid_unc_path.js
46 lines (44 loc) · 1.49 KB
/
valid_unc_path.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
ManageIQ.angular.app.directive('checkpath', ['miqService', function (miqService){
return {
require: 'ngModel',
link: function (scope, elem, attrs, ctrl) {
scope.$watch("repoModel.repo_path", function() {
if(ctrl.$modelValue != undefined && scope.afterGet) {
setValidity(scope, ctrl, ctrl.$modelValue, false);
}
});
ctrl.$parsers.push(function(value) {
setValidity(scope, ctrl, ctrl.$viewValue, true);
return value;
});
validPath = function(scope, path, bClearMsg) {
modified_path = path.replace(/\\/g, "/");
if(new RegExp("^//[^/].*/.+$").test(modified_path)) {
if(bClearMsg) $('#flash_msg_div').text("");
scope.path_type = "NAS";
return true;
}
else if(/^\[[^\]].+\].*$/.test(modified_path)) {
if(bClearMsg) $('#flash_msg_div').text("");
scope.path_type = "VMFS";
return true;
}
else {
if(scope.formId == "new") {
miqService.miqFlash("warn", __("Need a valid UNC path"));
} else {
miqService.miqFlash("error", __("Incorrect UNC path"));
}
return false;
}
};
var setValidity = function(scope, ctrl, value, bClearMsg) {
if(validPath(scope, value, bClearMsg)) {
ctrl.$setValidity("checkpath", true);
} else {
ctrl.$setValidity("checkpath", false);
}
};
}
}
}]);