selectAll.js 2.6 KB

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