(context)
| 25582 | |
| 25583 | // helper methods |
| 25584 | function addSetValidityMethod(context) { |
| 25585 | var ctrl = context.ctrl, |
| 25586 | $element = context.$element, |
| 25587 | classCache = {}, |
| 25588 | set = context.set, |
| 25589 | unset = context.unset, |
| 25590 | parentForm = context.parentForm, |
| 25591 | $animate = context.$animate; |
| 25592 | |
| 25593 | classCache[INVALID_CLASS] = !(classCache[VALID_CLASS] = $element.hasClass(VALID_CLASS)); |
| 25594 | |
| 25595 | ctrl.$setValidity = setValidity; |
| 25596 | |
| 25597 | function setValidity(validationErrorKey, state, controller) { |
| 25598 | if (state === undefined) { |
| 25599 | createAndSet('$pending', validationErrorKey, controller); |
| 25600 | } else { |
| 25601 | unsetAndCleanup('$pending', validationErrorKey, controller); |
| 25602 | } |
| 25603 | if (!isBoolean(state)) { |
| 25604 | unset(ctrl.$error, validationErrorKey, controller); |
| 25605 | unset(ctrl.$$success, validationErrorKey, controller); |
| 25606 | } else { |
| 25607 | if (state) { |
| 25608 | unset(ctrl.$error, validationErrorKey, controller); |
| 25609 | set(ctrl.$$success, validationErrorKey, controller); |
| 25610 | } else { |
| 25611 | set(ctrl.$error, validationErrorKey, controller); |
| 25612 | unset(ctrl.$$success, validationErrorKey, controller); |
| 25613 | } |
| 25614 | } |
| 25615 | if (ctrl.$pending) { |
| 25616 | cachedToggleClass(PENDING_CLASS, true); |
| 25617 | ctrl.$valid = ctrl.$invalid = undefined; |
| 25618 | toggleValidationCss('', null); |
| 25619 | } else { |
| 25620 | cachedToggleClass(PENDING_CLASS, false); |
| 25621 | ctrl.$valid = isObjectEmpty(ctrl.$error); |
| 25622 | ctrl.$invalid = !ctrl.$valid; |
| 25623 | toggleValidationCss('', ctrl.$valid); |
| 25624 | } |
| 25625 | |
| 25626 | // re-read the state as the set/unset methods could have |
| 25627 | // combined state in ctrl.$error[validationError] (used for forms), |
| 25628 | // where setting/unsetting only increments/decrements the value, |
| 25629 | // and does not replace it. |
| 25630 | var combinedState; |
| 25631 | if (ctrl.$pending && ctrl.$pending[validationErrorKey]) { |
| 25632 | combinedState = undefined; |
| 25633 | } else if (ctrl.$error[validationErrorKey]) { |
| 25634 | combinedState = false; |
| 25635 | } else if (ctrl.$$success[validationErrorKey]) { |
| 25636 | combinedState = true; |
| 25637 | } else { |
| 25638 | combinedState = null; |
| 25639 | } |
| 25640 | |
| 25641 | toggleValidationCss(validationErrorKey, combinedState); |
no outgoing calls
no test coverage detected