lib/amd/src/datafilter/selectors.js

  1. // This file is part of Moodle - http://moodle.org/
  2. //
  3. // Moodle is free software: you can redistribute it and/or modify
  4. // it under the terms of the GNU General Public License as published by
  5. // the Free Software Foundation, either version 3 of the License, or
  6. // (at your option) any later version.
  7. //
  8. // Moodle is distributed in the hope that it will be useful,
  9. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. // GNU General Public License for more details.
  12. //
  13. // You should have received a copy of the GNU General Public License
  14. // along with Moodle. If not, see <http://www.gnu.org/licenses/>.
  15. /**
  16. * Module containing the selectors for user filters.
  17. *
  18. * @module core/datafilter/selectors
  19. * @copyright 2020 Michael Hawkins <michaelh@moodle.com>
  20. * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  21. */
  22. const getFilterRegion = region => `[data-filterregion="${region}"]`;
  23. const getFilterAction = action => `[data-filteraction="${action}"]`;
  24. const getFilterField = field => `[data-filterfield="${field}"]`;
  25. export default {
  26. filter: {
  27. region: getFilterRegion('filter'),
  28. actions: {
  29. remove: getFilterAction('remove'),
  30. },
  31. fields: {
  32. join: getFilterField('join'),
  33. type: getFilterField('type'),
  34. },
  35. regions: {
  36. values: getFilterRegion('value'),
  37. },
  38. byName: name => `${getFilterRegion('filter')}[data-filter-type="${name}"]`,
  39. },
  40. filterset: {
  41. region: getFilterRegion('actions'),
  42. actions: {
  43. addRow: getFilterAction('add'),
  44. applyFilters: getFilterAction('apply'),
  45. resetFilters: getFilterAction('reset'),
  46. },
  47. regions: {
  48. filtermatch: getFilterRegion('filtermatch'),
  49. filterlist: getFilterRegion('filters'),
  50. datasource: getFilterRegion('filtertypedata'),
  51. },
  52. fields: {
  53. join: `${getFilterRegion('filtermatch')} ${getFilterField('join')}`,
  54. },
  55. },
  56. data: {
  57. fields: {
  58. byName: name => `[data-field-name="${name}"]`,
  59. all: `${getFilterRegion('filtertypedata')} [data-field-name]`,
  60. },
  61. typeList: getFilterRegion('filtertypelist'),
  62. typeListSelect: `select${getFilterRegion('filtertypelist')}`,
  63. },
  64. };