History

Sanity-check decaffeinate app.views.Settings

Simon Legner committed 2 years ago

Commit 1995d8a1 parent 329da391 file · +93 −111Browse files

Unified · Split

assets/javascripts/views/layout/settings.js+93−111
@@ -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";
353
36− init() {
37− this.addSubview((this.docPicker = new app.views.DocPicker()));
38− }
4+ static el = "._settings";
395
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+ };
4611
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);
5438 }
5539 }
40+ }
5641
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+ }
6247
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);
6661 }
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);
8670 }
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+ });
9579 }
80+ }
9681
97− onChange() {
98− this.addClass("_dirty");
99− }
82+ onChange() {
83+ this.addClass("_dirty");
84+ }
10085
101− onEnter() {
102− this.save();
103− }
86+ onEnter() {
87+ this.save();
88+ }
10489
105− onSubmit(event) {
106− event.preventDefault();
107− this.save();
108− }
90+ onSubmit(event) {
91+ event.preventDefault();
92+ this.save();
93+ }
10994
110− onImport() {
111− this.addClass("_dirty");
112− this.save({ import: true });
113− }
95+ onImport() {
96+ this.addClass("_dirty");
97+ this.save({ import: true });
98+ }
11499
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;
123103 }
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+};