blob: 0646b8afd01f5215334c630a864505c177988f22 (
plain)
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
|
backupApp.directive('advancedOptionsEditor', function() {
return {
restrict: 'E',
scope: {
ngModel: '=',
ngOptionList: '='
},
templateUrl: 'templates/advancedoptionseditor.html',
controller: function($scope, $timeout) {
$scope.NewItem = null;
var optionmap = null;
function rebuildOptionMap() {
optionmap = {};
for(var n in $scope.ngOptionList)
optionmap[$scope.ngOptionList[n].Name.toLowerCase()] = $scope.ngOptionList[n];
}
function coreName(name) {
if (name == null)
return '';
if (typeof(name) != typeof(''))
name = name.Name;
name = name || '';
if (name.indexOf('--') == 0)
name = name.substr(2);
if (name.indexOf('=') >= 0)
name = name.substr(0, name.indexOf('='));
return name;
}
$scope.getEntry = function(key) {
if (optionmap == null)
return null;
return optionmap[coreName(key)];
};
$scope.getDisplayName = function(name) {
var item = $scope.getEntry(name);
if (item == null)
return coreName(name);
return item.Name + ': ' + item.ShortDescription;
};
$scope.getInputType = function(item) {
var item = $scope.getEntry(item);
if (item == null)
return 'text';
if (item.Type == 'Enumeration')
return 'enum';
if (item.Type == 'Flags')
return 'flags';
else if (item.Type == 'Boolean')
return 'bool';
else if (item.Type == 'Password')
return 'password';
else if (item.Type == 'Integer')
return 'int';
else if (item.Type == 'Size')
return 'size';
else if (item.Type == 'Timespan')
return 'timespan';
else
return 'text';
};
$scope.getShortName = function(name) {
var item = $scope.getEntry(name);
if (item == null)
return coreName(name);
return item.Name;
};
$scope.getShortDescription = function(item) {
var item = $scope.getEntry(item);
if (item == null)
return null;
return item.ShortDescription;
};
$scope.getLongDescription = function(item) {
var item = $scope.getEntry(item);
if (item == null)
return null;
return item.LongDescription;
};
$scope.getEnumerations = function(item) {
var item = $scope.getEntry(item);
if (item == null)
return null;
return item.ValidValues;
};
$scope.deleteItem = function(item) {
for (var i = $scope.ngModel.length - 1; i >= 0; i--) {
if ($scope.ngModel[i] == item) {
$scope.ngModel.splice(i, 1);
return;
}
};
};
$scope.$watch('ngOptionList', rebuildOptionMap);
$scope.$watch('NewItem', function() {
if ($scope.NewItem != null) {
var opt = '--' + $scope.NewItem.Name;
var itm = $scope.getEntry(opt);
if (itm != null && itm.DefaultValue != null)
opt += '=' + itm.DefaultValue;
$scope.ngModel.push(opt);
$scope.NewItem = null;
}
});
}
};
});
|