filter.js 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. /**
  2. * Copyright (c) 2014, Arthur Schiwon <blizzz@owncloud.com>
  3. * This file is licensed under the Affero General Public License version 3 or later.
  4. * See the COPYING-README file.
  5. */
  6. /**
  7. * @brief this object takes care of the filter functionality on the user
  8. * management page
  9. * @param {UserList} userList the UserList object
  10. * @param {GroupList} groupList the GroupList object
  11. */
  12. function UserManagementFilter (userList, groupList) {
  13. this.userList = userList;
  14. this.groupList = groupList;
  15. this.oldFilter = '';
  16. this.init();
  17. }
  18. /**
  19. * @brief sets up when the filter action shall be triggered
  20. */
  21. UserManagementFilter.prototype.init = function () {
  22. OC.Plugins.register('OCA.Search', this);
  23. };
  24. /**
  25. * @brief the filter action needs to be done, here the accurate steps are being
  26. * taken care of
  27. */
  28. UserManagementFilter.prototype.run = _.debounce(function (filter) {
  29. if (filter === this.oldFilter) {
  30. return;
  31. }
  32. this.oldFilter = filter;
  33. this.userList.filter = filter;
  34. this.userList.empty();
  35. this.userList.update(GroupList.getCurrentGID());
  36. if (this.groupList.filterGroups) {
  37. // user counts are being updated nevertheless
  38. this.groupList.empty();
  39. }
  40. this.groupList.update();
  41. },
  42. 300
  43. );
  44. /**
  45. * @brief returns the filter String
  46. * @returns string
  47. */
  48. UserManagementFilter.prototype.getPattern = function () {
  49. var input = this.filterInput.val(),
  50. html = $('html'),
  51. isIE8or9 = html.hasClass('lte9');
  52. // FIXME - TODO - once support for IE8 and IE9 is dropped
  53. if (isIE8or9 && input == this.filterInput.attr('placeholder')) {
  54. input = '';
  55. }
  56. return input;
  57. };
  58. /**
  59. * @brief adds reset functionality to an HTML element
  60. * @param jQuery the jQuery representation of that element
  61. */
  62. UserManagementFilter.prototype.addResetButton = function (button) {
  63. var umf = this;
  64. button.click(function () {
  65. umf.filterInput.val('');
  66. umf.run();
  67. });
  68. };
  69. UserManagementFilter.prototype.attach = function (search) {
  70. search.setFilter('settings', this.run.bind(this));
  71. };