forked from openshift/origin-web-console
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patheditCommand.js
74 lines (65 loc) · 2.01 KB
/
editCommand.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
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
"use strict";
angular.module('openshiftConsole')
.directive('editCommand', function($filter) {
return {
restrict: 'E',
scope: {
args: '=',
isRequired: '='
},
templateUrl: 'views/directives/_edit-command.html',
link: function(scope) {
scope.id = _.uniqueId('edit-command-');
scope.input = {};
var inputChanged, isMultiline = $filter('isMultiline');
scope.$watch('args', function() {
if (inputChanged) {
inputChanged = false;
return;
}
if (!_.isEmpty(scope.args)) {
// Convert the array of string to an array of objects internally to
// avoid problems dragging/dropping duplicate values, which
// ng-sortable doesn't handle well.
scope.input.args = _.map(scope.args, function(arg) {
return {
value: arg,
multiline: isMultiline(arg)
};
});
}
}, true);
scope.$watch('input.args', function(newValue, oldValue) {
if (newValue === oldValue) {
return;
}
inputChanged = true;
scope.args = _.map(scope.input.args, function(arg) {
return arg.value;
});
scope.form.command.$setDirty();
}, true);
scope.addArg = function() {
if (!scope.nextArg) {
return;
}
scope.input.args = scope.input.args || [];
scope.input.args.push({
value: scope.nextArg,
multiline: isMultiline(scope.nextArg)
});
scope.nextArg = '';
};
scope.removeArg = function(index) {
scope.input.args.splice(index, 1);
if (_.isEmpty(scope.input.args)) {
// Needs to be null rather than empty for validation.
scope.input.args = null;
}
};
scope.clear = function() {
scope.input.args = null;
};
}
};
});