reviewPanelToggle.js 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. /* eslint-disable
  2. max-len,
  3. no-return-assign,
  4. */
  5. // TODO: This file was created by bulk-decaffeinate.
  6. // Fix any style issues and re-enable lint.
  7. /*
  8. * decaffeinate suggestions:
  9. * DS102: Remove unnecessary code created because of implicit returns
  10. * DS207: Consider shorter variations of null checks
  11. * Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md
  12. */
  13. import App from '../../../base'
  14. export default App.directive('reviewPanelToggle', () => ({
  15. restrict: 'E',
  16. scope: {
  17. onToggle: '&',
  18. ngModel: '=',
  19. valWhenUndefined: '=?',
  20. isDisabled: '=?',
  21. onDisabledClick: '&?',
  22. description: '@',
  23. },
  24. link(scope) {
  25. if (scope.disabled == null) {
  26. scope.disabled = false
  27. }
  28. scope.onChange = (...args) => scope.onToggle({ isOn: scope.localModel })
  29. scope.handleClick = function () {
  30. if (scope.disabled && scope.onDisabledClick != null) {
  31. return scope.onDisabledClick()
  32. }
  33. }
  34. scope.localModel = scope.ngModel
  35. return scope.$watch('ngModel', function (value) {
  36. if (scope.valWhenUndefined != null && value == null) {
  37. value = scope.valWhenUndefined
  38. }
  39. return (scope.localModel = value)
  40. })
  41. },
  42. template: `\
  43. <fieldset class="input-switch" ng-click="handleClick();">
  44. <legend class="sr-only">{{description}}</legend>
  45. <input id="input-switch-{{$id}}" ng-disabled="isDisabled" type="checkbox" class="input-switch-hidden-input" ng-model="localModel" ng-change="onChange()" />
  46. <label for="input-switch-{{$id}}" class="input-switch-btn"></label>
  47. </fieldset>\
  48. `,
  49. }))