-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathindex.js
150 lines (135 loc) · 4.25 KB
/
index.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
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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
(function() {
angular.module("ng-form-group", []);
}).call(this);
(function() {
var FormGroupController,
bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; };
FormGroupController = (function() {
function FormGroupController($scope) {
this.$scope = $scope;
this.update = bind(this.update, this);
this.status = null;
this.disabled = false;
this.inputs = [];
this.$scope.$watch(this.update);
}
FormGroupController.prototype.setParentForm = function(ctrl) {
return this.ngFormCtrl = ctrl;
};
FormGroupController.prototype.canValidate = function() {
var inputsReady;
inputsReady = this.inputs.every(function(i) {
return i.$dirty && !i.$pending;
});
if (this.ngFormCtrl) {
return this.ngFormCtrl.$submitted || inputsReady;
} else {
return inputsReady;
}
};
FormGroupController.prototype.update = function() {
if (this.disabled === false && this.canValidate()) {
return this.status = (this.inputs.every(function(i) {
return i.$valid;
})) ? "success" : "error";
} else {
return this.status = null;
}
};
FormGroupController.prototype.addInput = function(ctrl) {
return this.inputs.push(ctrl);
};
return FormGroupController;
})();
angular.module("ng-form-group").controller('FormGroupController', ['$scope', FormGroupController]).directive("formGroup", function() {
return {
restrict: "C",
require: ["formGroup", "?^form"],
controller: 'FormGroupController',
link: function(scope, el, attrs, ctrls) {
var ctrl, ngFormCtrl;
ctrl = ctrls[0], ngFormCtrl = ctrls[1];
if (ctrl.inputs.length === 0) {
ctrl.disabled = true;
return;
}
if (ngFormCtrl) {
ctrl.setParentForm(ngFormCtrl);
}
scope.$watch((function() {
return el.hasClass('form-group-without-feedback');
}), function(value) {
return ctrl.disabled = value;
});
return scope.$watch((function() {
return ctrl.status;
}), function(status) {
el.removeClass("has-error has-success");
if (status) {
return el.addClass("has-" + status);
}
});
}
};
}).directive("formControl", function() {
return {
restrict: "C",
require: ["?ngModel", "?^formGroup"],
link: function(scope, input, attrs, ctrls) {
var formGroupCtrl, ngModelCtrl;
ngModelCtrl = ctrls[0], formGroupCtrl = ctrls[1];
if (!formGroupCtrl || formGroupCtrl.disabled) {
return;
}
if (ngModelCtrl && formGroupCtrl) {
return formGroupCtrl.addInput(ngModelCtrl);
}
}
};
});
}).call(this);
(function() {
var toArray;
toArray = function(arrayish) {
return Array.prototype.slice.call(arrayish);
};
angular.module("ng-form-group").directive("hasFeedback", function() {
return {
restrict: "C",
compile: function(el, attrs) {
return toArray(el[0].querySelectorAll(".form-control")).forEach(function(input) {
return input.setAttribute("has-feedback-watcher", "");
});
}
};
}).directive("hasFeedbackWatcher", function() {
return {
require: "ngModel",
link: function(scope, input, attrs, ctrl) {
var feedbackIcon, unref;
feedbackIcon = function(isGood) {
var icon;
if (isGood == null) {
isGood = false;
}
icon = isGood ? "glyphicon-ok" : "glyphicon-remove";
return "<span class=\"glyphicon " + icon + " form-control-feedback\"></span>";
};
unref = scope.$watch(function() {
toArray(input[0].parentElement.querySelectorAll(".form-control-feedback")).forEach(function(span) {
return span.parentElement.removeChild(span);
});
if (!ctrl.$dirty) {
return;
}
if (ctrl.$valid) {
return input.after(feedbackIcon(true));
} else if (ctrl.$invalid) {
return input.after(feedbackIcon(false));
}
});
return scope.$on("$destroy", unref);
}
};
});
}).call(this);