MCPcopy Create free account
hub / github.com/apache/cloudstack / FormController

Function FormController

tools/ngui/static/js/lib/angular.js:10865–10952  ·  view source on GitHub ↗
(element, attrs)

Source from the content-addressed store, hash-verified

10863//asks for $scope to fool the BC controller module
10864FormController.$inject = ['$element', '$attrs', '$scope'];
10865function FormController(element, attrs) {
10866 var form = this,
10867 parentForm = element.parent().controller('form') || nullFormCtrl,
10868 invalidCount = 0, // used to easily determine if we are valid
10869 errors = form.$error = {};
10870
10871 // init state
10872 form.$name = attrs.name;
10873 form.$dirty = false;
10874 form.$pristine = true;
10875 form.$valid = true;
10876 form.$invalid = false;
10877
10878 parentForm.$addControl(form);
10879
10880 // Setup initial state of the control
10881 element.addClass(PRISTINE_CLASS);
10882 toggleValidCss(true);
10883
10884 // convenience method for easy toggling of classes
10885 function toggleValidCss(isValid, validationErrorKey) {
10886 validationErrorKey = validationErrorKey ? '-' + snake_case(validationErrorKey, '-') : '';
10887 element.
10888 removeClass((isValid ? INVALID_CLASS : VALID_CLASS) + validationErrorKey).
10889 addClass((isValid ? VALID_CLASS : INVALID_CLASS) + validationErrorKey);
10890 }
10891
10892 form.$addControl = function(control) {
10893 if (control.$name && !form.hasOwnProperty(control.$name)) {
10894 form[control.$name] = control;
10895 }
10896 };
10897
10898 form.$removeControl = function(control) {
10899 if (control.$name && form[control.$name] === control) {
10900 delete form[control.$name];
10901 }
10902 forEach(errors, function(queue, validationToken) {
10903 form.$setValidity(validationToken, true, control);
10904 });
10905 };
10906
10907 form.$setValidity = function(validationToken, isValid, control) {
10908 var queue = errors[validationToken];
10909
10910 if (isValid) {
10911 if (queue) {
10912 arrayRemove(queue, control);
10913 if (!queue.length) {
10914 invalidCount--;
10915 if (!invalidCount) {
10916 toggleValidCss(isValid);
10917 form.$valid = true;
10918 form.$invalid = false;
10919 }
10920 errors[validationToken] = false;
10921 toggleValidCss(true, validationToken);
10922 parentForm.$setValidity(validationToken, true, form);

Callers

nothing calls this directly

Calls 5

toggleValidCssFunction · 0.85
forEachFunction · 0.85
arrayRemoveFunction · 0.85
includesFunction · 0.85
parentMethod · 0.80

Tested by

no test coverage detected