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