selectAll.js 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. /* eslint-disable
  2. max-len,
  3. no-return-assign,
  4. no-undef,
  5. */
  6. // TODO: This file was created by bulk-decaffeinate.
  7. // Fix any style issues and re-enable lint.
  8. /*
  9. * decaffeinate suggestions:
  10. * DS102: Remove unnecessary code created because of implicit returns
  11. * DS207: Consider shorter variations of null checks
  12. * Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md
  13. */
  14. define(['base'], function(App) {
  15. App.directive('selectAllList', () => ({
  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. App.directive('selectAll', () => ({
  28. require: '^selectAllList',
  29. link(scope, element, attrs, selectAllListController) {
  30. scope.$on('select-all:clear', () => element.prop('checked', false))
  31. return element.change(function() {
  32. if (element.is(':checked')) {
  33. selectAllListController.selectAll()
  34. } else {
  35. selectAllListController.deselectAll()
  36. }
  37. return true
  38. })
  39. }
  40. }))
  41. App.directive('selectIndividual', () => ({
  42. require: '^selectAllList',
  43. scope: {
  44. ngModel: '='
  45. },
  46. link(scope, element, attrs, selectAllListController) {
  47. let ignoreChanges = false
  48. scope.$watch('ngModel', function(value) {
  49. if (value != null && !ignoreChanges) {
  50. return selectAllListController.clearSelectAllState()
  51. }
  52. })
  53. scope.$on('select-all:select', function() {
  54. if (element.prop('disabled')) {
  55. return
  56. }
  57. ignoreChanges = true
  58. scope.$apply(() => (scope.ngModel = true))
  59. return (ignoreChanges = false)
  60. })
  61. scope.$on('select-all:deselect', function() {
  62. if (element.prop('disabled')) {
  63. return
  64. }
  65. ignoreChanges = true
  66. scope.$apply(() => (scope.ngModel = false))
  67. return (ignoreChanges = false)
  68. })
  69. return scope.$on('select-all:row-clicked', function() {
  70. if (element.prop('disabled')) {
  71. return
  72. }
  73. ignoreChanges = true
  74. scope.$apply(function() {
  75. scope.ngModel = !scope.ngModel
  76. if (!scope.ngModel) {
  77. return selectAllListController.clearSelectAllState()
  78. }
  79. })
  80. return (ignoreChanges = false)
  81. })
  82. }
  83. }))
  84. return App.directive('selectRow', () => ({
  85. scope: true,
  86. link(scope, element, attrs) {
  87. return element.on('click', e =>
  88. scope.$broadcast('select-all:row-clicked')
  89. )
  90. }
  91. }))
  92. })