(context)
| 23968 | |
| 23969 | // helper methods |
| 23970 | function addSetValidityMethod(context) { |
| 23971 | var ctrl = context.ctrl, |
| 23972 | $element = context.$element, |
| 23973 | classCache = {}, |
| 23974 | set = context.set, |
| 23975 | unset = context.unset, |
| 23976 | parentForm = context.parentForm, |
| 23977 | $animate = context.$animate; |
| 23978 | |
| 23979 | classCache[INVALID_CLASS] = !(classCache[VALID_CLASS] = $element.hasClass(VALID_CLASS)); |
| 23980 | |
| 23981 | ctrl.$setValidity = setValidity; |
| 23982 | |
| 23983 | function setValidity(validationErrorKey, state, controller) { |
| 23984 | if (state === undefined) { |
| 23985 | createAndSet('$pending', validationErrorKey, controller); |
| 23986 | } else { |
| 23987 | unsetAndCleanup('$pending', validationErrorKey, controller); |
| 23988 | } |
| 23989 | if (!isBoolean(state)) { |
| 23990 | unset(ctrl.$error, validationErrorKey, controller); |
| 23991 | unset(ctrl.$$success, validationErrorKey, controller); |
| 23992 | } else { |
| 23993 | if (state) { |
| 23994 | unset(ctrl.$error, validationErrorKey, controller); |
| 23995 | set(ctrl.$$success, validationErrorKey, controller); |
| 23996 | } else { |
| 23997 | set(ctrl.$error, validationErrorKey, controller); |
| 23998 | unset(ctrl.$$success, validationErrorKey, controller); |
| 23999 | } |
| 24000 | } |
| 24001 | if (ctrl.$pending) { |
| 24002 | cachedToggleClass(PENDING_CLASS, true); |
| 24003 | ctrl.$valid = ctrl.$invalid = undefined; |
| 24004 | toggleValidationCss('', null); |
| 24005 | } else { |
| 24006 | cachedToggleClass(PENDING_CLASS, false); |
| 24007 | ctrl.$valid = isObjectEmpty(ctrl.$error); |
| 24008 | ctrl.$invalid = !ctrl.$valid; |
| 24009 | toggleValidationCss('', ctrl.$valid); |
| 24010 | } |
| 24011 | |
| 24012 | // re-read the state as the set/unset methods could have |
| 24013 | // combined state in ctrl.$error[validationError] (used for forms), |
| 24014 | // where setting/unsetting only increments/decrements the value, |
| 24015 | // and does not replace it. |
| 24016 | var combinedState; |
| 24017 | if (ctrl.$pending && ctrl.$pending[validationErrorKey]) { |
| 24018 | combinedState = undefined; |
| 24019 | } else if (ctrl.$error[validationErrorKey]) { |
| 24020 | combinedState = false; |
| 24021 | } else if (ctrl.$$success[validationErrorKey]) { |
| 24022 | combinedState = true; |
| 24023 | } else { |
| 24024 | combinedState = null; |
| 24025 | } |
| 24026 | |
| 24027 | toggleValidationCss(validationErrorKey, combinedState); |
no outgoing calls
no test coverage detected