Source

frontend/components/tags/tag_group_manager.js

  1. /* This file is part of Ezra Bible App.
  2. Copyright (C) 2019 - 2023 Ezra Bible App Development Team <contact@ezrabibleapp.net>
  3. Ezra Bible App 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 2 of the License, or
  6. (at your option) any later version.
  7. Ezra Bible App is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. GNU General Public License for more details.
  11. You should have received a copy of the GNU General Public License
  12. along with Ezra Bible App. See the file LICENSE.
  13. If not, see <http://www.gnu.org/licenses/>. */
  14. const ItemListManager = require("./item_list_manager.js");
  15. const eventController = require('../../controllers/event_controller.js');
  16. const { waitUntilIdle } = require("../../helpers/ezra_helper.js");
  17. /**
  18. * The tag group manager is a special ItemListManager for a list of tag groups.
  19. */
  20. class TagGroupManager extends ItemListManager {
  21. constructor(onClickHandler,
  22. onEditHandler,
  23. onDeleteHandler,
  24. selectable=false,
  25. editable=false,
  26. cssClass,
  27. virtualItems=[]) {
  28. let renameHintI18n = 'tags.rename-tag-group';
  29. let deleteHintI18n = 'tags.delete-tag-group';
  30. super(null,
  31. onClickHandler,
  32. onEditHandler,
  33. onDeleteHandler,
  34. selectable,
  35. editable,
  36. cssClass,
  37. renameHintI18n,
  38. deleteHintI18n,
  39. virtualItems);
  40. this._bookFilter = null;
  41. eventController.subscribe('on-tag-group-renamed', async (tagGroupId) => {
  42. await this.refreshItemList();
  43. await waitUntilIdle();
  44. this.highlightItem(tagGroupId);
  45. });
  46. eventController.subscribe('on-tag-group-members-changed', async () => {
  47. this.refreshItemList();
  48. });
  49. eventController.subscribe('on-tag-group-deleted', async (tagGroupId) => {
  50. this.removeItems([ tagGroupId ]);
  51. });
  52. }
  53. setBookFilter(bookFilter) {
  54. this._bookFilter = bookFilter;
  55. }
  56. async getDbItems() {
  57. var bibleBook = null;
  58. var bibleBookId = 0;
  59. if (this._bookFilter != null) {
  60. bibleBook = await ipcDb.getBibleBook(this._bookFilter);
  61. bibleBookId = bibleBook.id;
  62. }
  63. let dbItems = await ipcDb.getAllTagGroups(bibleBookId);
  64. return dbItems;
  65. }
  66. }
  67. module.exports = TagGroupManager;