filters.js 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. 'use strict';
  2. /* Filters for EventMan(ager) lists of objects. */
  3. /* Filter for events that have (or not) information about a registered person. */
  4. eventManApp.filter('eventWithPersonData', ['$filter',
  5. function($filter) {
  6. return function(inputArray, mustBePresent) {
  7. if (mustBePresent === undefined) {
  8. mustBePresent = true;
  9. }
  10. inputArray = inputArray || [];
  11. var returnArray = [];
  12. for (var x=0; x < inputArray.length; x++) {
  13. var found = inputArray[x].person_data && inputArray[x].person_data.person_id;
  14. if ((found && mustBePresent) || (!found && !mustBePresent)) {
  15. returnArray.push(inputArray[x]);
  16. }
  17. }
  18. return returnArray;
  19. };
  20. }]
  21. );
  22. /* Filter for persons (not) registered for a given event. */
  23. eventManApp.filter('personRegistered', ['$filter',
  24. function($filter) {
  25. return function(inputArray, data) {
  26. if (data.present === undefined) {
  27. data.present = true;
  28. }
  29. inputArray = inputArray || [];
  30. var returnArray = [];
  31. var registeredIDs = [];
  32. if (!(data.event && data.event.persons && data.event.persons.length)) {
  33. return inputArray;
  34. }
  35. for (var x=0; x < data.event.persons.length; x++) {
  36. registeredIDs.push(data.event.persons[x].person_id);
  37. }
  38. for (var x=0; x < inputArray.length; x++) {
  39. var found = registeredIDs.indexOf(inputArray[x]._id) != -1;
  40. if ((found && data.present) || (!found && !data.present)) {
  41. returnArray.push(inputArray[x]);
  42. }
  43. }
  44. return returnArray;
  45. }
  46. }]
  47. );
  48. /* Filter that handles splitted words. */
  49. eventManApp.filter('splittedFilter', ['$filter',
  50. function($filter) {
  51. return function(inputArray, searchText) {
  52. var wordArray = searchText ? searchText.toLowerCase().split(/\s+/) : [];
  53. for (var x=0; x < wordArray.length; x++) {
  54. inputArray = $filter('filter')(inputArray, wordArray[x]);
  55. }
  56. return inputArray;
  57. };
  58. }]
  59. );