selectAll.js 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  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. App.directive('selectAllList', function () {
  15. return {
  16. controller: [
  17. '$scope',
  18. function ($scope) {
  19. // Selecting or deselecting all should apply to all projects
  20. this.selectAll = () => $scope.$broadcast('select-all:select')
  21. this.deselectAll = () => $scope.$broadcast('select-all:deselect')
  22. this.clearSelectAllState = () => $scope.$broadcast('select-all:clear')
  23. },
  24. ],
  25. link(scope, element, attrs) {},
  26. }
  27. })
  28. App.directive('selectAll', function () {
  29. return {
  30. require: '^selectAllList',
  31. link(scope, element, attrs, selectAllListController) {
  32. scope.$on('select-all:clear', () => element.prop('checked', false))
  33. return element.change(function () {
  34. if (element.is(':checked')) {
  35. selectAllListController.selectAll()
  36. } else {
  37. selectAllListController.deselectAll()
  38. }
  39. return true
  40. })
  41. },
  42. }
  43. })
  44. App.directive('selectIndividual', function () {
  45. return {
  46. require: '^selectAllList',
  47. scope: {
  48. ngModel: '=',
  49. },
  50. link(scope, element, attrs, selectAllListController) {
  51. let ignoreChanges = false
  52. scope.$watch('ngModel', function (value) {
  53. if (value != null && !ignoreChanges) {
  54. return selectAllListController.clearSelectAllState()
  55. }
  56. })
  57. scope.$on('select-all:select', function () {
  58. if (element.prop('disabled')) {
  59. return
  60. }
  61. ignoreChanges = true
  62. scope.$apply(() => (scope.ngModel = true))
  63. return (ignoreChanges = false)
  64. })
  65. scope.$on('select-all:deselect', function () {
  66. if (element.prop('disabled')) {
  67. return
  68. }
  69. ignoreChanges = true
  70. scope.$apply(() => (scope.ngModel = false))
  71. return (ignoreChanges = false)
  72. })
  73. return scope.$on('select-all:row-clicked', function () {
  74. if (element.prop('disabled')) {
  75. return
  76. }
  77. ignoreChanges = true
  78. scope.$apply(function () {
  79. scope.ngModel = !scope.ngModel
  80. if (!scope.ngModel) {
  81. return selectAllListController.clearSelectAllState()
  82. }
  83. })
  84. return (ignoreChanges = false)
  85. })
  86. },
  87. }
  88. })
  89. export default App.directive('selectRow', function () {
  90. return {
  91. scope: true,
  92. link(scope, element, attrs) {
  93. return element.on('click', e =>
  94. scope.$broadcast('select-all:row-clicked')
  95. )
  96. },
  97. }
  98. })