Showing the changes to assets/javascripts (1 of 1 file). Show all
Unified · Split
| @@ -1,127 +1,109 @@ | |||
| 1 | // TODO: This file was created by bulk-decaffeinate. | 1 | app.views.Settings = class Settings extends app.View { |
| 2 | // Sanity-check the conversion and remove this comment. | 2 | static SIDEBAR_HIDDEN_LAYOUT = "_sidebar-hidden"; |
| 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 | |||
| 18 | this.el = "._settings"; | ||
| 19 | |||
| 20 | this.elements = { | ||
| 21 | sidebar: "._sidebar", | ||
| 22 | saveBtn: 'button[type="submit"]', | ||
| 23 | backBtn: "button[data-back]", | ||
| 24 | }; | ||
| 25 | |||
| 26 | this.events = { | ||
| 27 | import: "onImport", | ||
| 28 | change: "onChange", | ||
| 29 | submit: "onSubmit", | ||
| 30 | click: "onClick", | ||
| 31 | }; | ||
| 32 | |||
| 33 | this.shortcuts = { enter: "onEnter" }; | ||
| 34 | } | ||
| 35 | 3 | ||
| 36 | init() { | 4 | static el = "._settings"; |
| 37 | this.addSubview((this.docPicker = new app.views.DocPicker())); | ||
| 38 | } | ||
| 39 | 5 | ||
| 40 | activate() { | 6 | static elements = { |
| 41 | if (super.activate(...arguments)) { | 7 | sidebar: "._sidebar", |
| 42 | this.render(); | 8 | saveBtn: 'button[type="submit"]', |
| 43 | document.body.classList.remove(SIDEBAR_HIDDEN_LAYOUT); | 9 | backBtn: "button[data-back]", |
| 44 | } | 10 | }; |
| 45 | } | ||
| 46 | 11 | ||
| 47 | deactivate() { | 12 | static events = { |
| 48 | if (super.deactivate(...arguments)) { | 13 | import: "onImport", |
| 49 | this.resetClass(); | 14 | change: "onChange", |
| 50 | this.docPicker.detach(); | 15 | submit: "onSubmit", |
| 51 | if (app.settings.hasLayout(SIDEBAR_HIDDEN_LAYOUT)) { | 16 | click: "onClick", |
| 52 | document.body.classList.add(SIDEBAR_HIDDEN_LAYOUT); | 17 | }; |
| 53 | } | 18 | |
| 19 | static shortcuts = { enter: "onEnter" }; | ||
| 20 | |||
| 21 | init() { | ||
| 22 | this.addSubview((this.docPicker = new app.views.DocPicker())); | ||
| 23 | } | ||
| 24 | |||
| 25 | activate() { | ||
| 26 | if (super.activate(...arguments)) { | ||
| 27 | this.render(); | ||
| 28 | document.body.classList.remove(Settings.SIDEBAR_HIDDEN_LAYOUT); | ||
| 29 | } | ||
| 30 | } | ||
| 31 | |||
| 32 | deactivate() { | ||
| 33 | if (super.deactivate(...arguments)) { | ||
| 34 | this.resetClass(); | ||
| 35 | this.docPicker.detach(); | ||
| 36 | if (app.settings.hasLayout(Settings.SIDEBAR_HIDDEN_LAYOUT)) { | ||
| 37 | document.body.classList.add(Settings.SIDEBAR_HIDDEN_LAYOUT); | ||
| 54 | } | 38 | } |
| 55 | } | 39 | } |
| 40 | } | ||
| 56 | 41 | ||
| 57 | render() { | 42 | render() { |
| 58 | this.docPicker.appendTo(this.sidebar); | 43 | this.docPicker.appendTo(this.sidebar); |
| 59 | this.refreshElements(); | 44 | this.refreshElements(); |
| 60 | this.addClass("_in"); | 45 | this.addClass("_in"); |
| 61 | } | 46 | } |
| 62 | 47 | ||
| 63 | save(options) { | 48 | save(options) { |
| 64 | if (options == null) { | 49 | if (options == null) { |
| 65 | options = {}; | 50 | options = {}; |
| 51 | } | ||
| 52 | if (!this.saving) { | ||
| 53 | let docs; | ||
| 54 | this.saving = true; | ||
| 55 | |||
| 56 | if (options.import) { | ||
| 57 | docs = app.settings.getDocs(); | ||
| 58 | } else { | ||
| 59 | docs = this.docPicker.getSelectedDocs(); | ||
| 60 | app.settings.setDocs(docs); | ||
| 66 | } | 61 | } |
| 67 | if (!this.saving) { | 62 | |
| 68 | let docs; | 63 | this.saveBtn.textContent = "Saving\u2026"; |
| 69 | this.saving = true; | 64 | const disabledDocs = new app.collections.Docs( |
| 70 | 65 | (() => { | |
| 71 | if (options.import) { | 66 | const result = []; |
| 72 | docs = app.settings.getDocs(); | 67 | for (var doc of app.docs.all()) { |
| 73 | } else { | 68 | if (docs.indexOf(doc.slug) === -1) { |
| 74 | docs = this.docPicker.getSelectedDocs(); | 69 | result.push(doc); |
| 75 | app.settings.setDocs(docs); | ||
| 76 | } | ||
| 77 | |||
| 78 | this.saveBtn.textContent = "Saving\u2026"; | ||
| 79 | const disabledDocs = new app.collections.Docs( | ||
| 80 | (() => { | ||
| 81 | const result = []; | ||
| 82 | for (var doc of Array.from(app.docs.all())) { | ||
| 83 | if (docs.indexOf(doc.slug) === -1) { | ||
| 84 | result.push(doc); | ||
| 85 | } | ||
| 86 | } | 70 | } |
| 87 | return result; | 71 | } |
| 88 | })(), | 72 | return result; |
| 89 | ); | 73 | })(), |
| 90 | disabledDocs.uninstall(function () { | 74 | ); |
| 91 | app.db.migrate(); | 75 | disabledDocs.uninstall(function () { |
| 92 | return app.reload(); | 76 | app.db.migrate(); |
| 93 | }); | 77 | return app.reload(); |
| 94 | } | 78 | }); |
| 95 | } | 79 | } |
| 80 | } | ||
| 96 | 81 | ||
| 97 | onChange() { | 82 | onChange() { |
| 98 | this.addClass("_dirty"); | 83 | this.addClass("_dirty"); |
| 99 | } | 84 | } |
| 100 | 85 | ||
| 101 | onEnter() { | 86 | onEnter() { |
| 102 | this.save(); | 87 | this.save(); |
| 103 | } | 88 | } |
| 104 | 89 | ||
| 105 | onSubmit(event) { | 90 | onSubmit(event) { |
| 106 | event.preventDefault(); | 91 | event.preventDefault(); |
| 107 | this.save(); | 92 | this.save(); |
| 108 | } | 93 | } |
| 109 | 94 | ||
| 110 | onImport() { | 95 | onImport() { |
| 111 | this.addClass("_dirty"); | 96 | this.addClass("_dirty"); |
| 112 | this.save({ import: true }); | 97 | this.save({ import: true }); |
| 113 | } | 98 | } |
| 114 | 99 | ||
| 115 | onClick(event) { | 100 | onClick(event) { |
| 116 | if (event.which !== 1) { | 101 | if (event.which !== 1) { |
| 117 | return; | 102 | return; |
| 118 | } | ||
| 119 | if (event.target === this.backBtn) { | ||
| 120 | $.stopEvent(event); | ||
| 121 | app.router.show("/"); | ||
| 122 | } | ||
| 123 | } | 103 | } |
| 124 | }; | 104 | if (event.target === this.backBtn) { |
| 125 | app.views.Settings.initClass(); | 105 | $.stopEvent(event); |
| 126 | return app.views.Settings; | 106 | app.router.show("/"); |
| 127 | })(); | 107 | } |
| 108 | } | ||
| 109 | }; | ||