settings.js 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. // TODO: This file was created by bulk-decaffeinate.
  2. // Sanity-check the conversion and remove this comment.
  3. /*
  4. * decaffeinate suggestions:
  5. * DS101: Remove unnecessary use of Array.from
  6. * DS102: Remove unnecessary code created because of implicit returns
  7. * DS205: Consider reworking code to avoid use of IIFEs
  8. * DS206: Consider reworking classes to avoid initClass
  9. * DS207: Consider shorter variations of null checks
  10. * Full docs: https://github.com/decaffeinate/decaffeinate/blob/main/docs/suggestions.md
  11. */
  12. (function () {
  13. let SIDEBAR_HIDDEN_LAYOUT = undefined;
  14. app.views.Settings = class Settings extends app.View {
  15. static initClass() {
  16. SIDEBAR_HIDDEN_LAYOUT = "_sidebar-hidden";
  17. this.el = "._settings";
  18. this.elements = {
  19. sidebar: "._sidebar",
  20. saveBtn: 'button[type="submit"]',
  21. backBtn: "button[data-back]",
  22. };
  23. this.events = {
  24. import: "onImport",
  25. change: "onChange",
  26. submit: "onSubmit",
  27. click: "onClick",
  28. };
  29. this.shortcuts = { enter: "onEnter" };
  30. }
  31. init() {
  32. this.addSubview((this.docPicker = new app.views.DocPicker()));
  33. }
  34. activate() {
  35. if (super.activate(...arguments)) {
  36. this.render();
  37. document.body.classList.remove(SIDEBAR_HIDDEN_LAYOUT);
  38. }
  39. }
  40. deactivate() {
  41. if (super.deactivate(...arguments)) {
  42. this.resetClass();
  43. this.docPicker.detach();
  44. if (app.settings.hasLayout(SIDEBAR_HIDDEN_LAYOUT)) {
  45. document.body.classList.add(SIDEBAR_HIDDEN_LAYOUT);
  46. }
  47. }
  48. }
  49. render() {
  50. this.docPicker.appendTo(this.sidebar);
  51. this.refreshElements();
  52. this.addClass("_in");
  53. }
  54. save(options) {
  55. if (options == null) {
  56. options = {};
  57. }
  58. if (!this.saving) {
  59. let docs;
  60. this.saving = true;
  61. if (options.import) {
  62. docs = app.settings.getDocs();
  63. } else {
  64. docs = this.docPicker.getSelectedDocs();
  65. app.settings.setDocs(docs);
  66. }
  67. this.saveBtn.textContent = "Saving\u2026";
  68. const disabledDocs = new app.collections.Docs(
  69. (() => {
  70. const result = [];
  71. for (var doc of Array.from(app.docs.all())) {
  72. if (docs.indexOf(doc.slug) === -1) {
  73. result.push(doc);
  74. }
  75. }
  76. return result;
  77. })(),
  78. );
  79. disabledDocs.uninstall(function () {
  80. app.db.migrate();
  81. return app.reload();
  82. });
  83. }
  84. }
  85. onChange() {
  86. this.addClass("_dirty");
  87. }
  88. onEnter() {
  89. this.save();
  90. }
  91. onSubmit(event) {
  92. event.preventDefault();
  93. this.save();
  94. }
  95. onImport() {
  96. this.addClass("_dirty");
  97. this.save({ import: true });
  98. }
  99. onClick(event) {
  100. if (event.which !== 1) {
  101. return;
  102. }
  103. if (event.target === this.backBtn) {
  104. $.stopEvent(event);
  105. app.router.show("/");
  106. }
  107. }
  108. };
  109. app.views.Settings.initClass();
  110. return app.views.Settings;
  111. })();