mirror of https://github.com/freeCodeCamp/devdocs
parent
329da39c08
commit
1995d8a3bb
@ -1,127 +1,109 @@
|
|||||||
// TODO: This file was created by bulk-decaffeinate.
|
app.views.Settings = class Settings extends app.View {
|
||||||
// Sanity-check the conversion and remove this comment.
|
static SIDEBAR_HIDDEN_LAYOUT = "_sidebar-hidden";
|
||||||
/*
|
|
||||||
* decaffeinate suggestions:
|
|
||||||
* DS101: Remove unnecessary use of Array.from
|
|
||||||
* DS102: Remove unnecessary code created because of implicit returns
|
|
||||||
* DS205: Consider reworking code to avoid use of IIFEs
|
|
||||||
* DS206: Consider reworking classes to avoid initClass
|
|
||||||
* DS207: Consider shorter variations of null checks
|
|
||||||
* Full docs: https://github.com/decaffeinate/decaffeinate/blob/main/docs/suggestions.md
|
|
||||||
*/
|
|
||||||
(function () {
|
|
||||||
let SIDEBAR_HIDDEN_LAYOUT = undefined;
|
|
||||||
app.views.Settings = class Settings extends app.View {
|
|
||||||
static initClass() {
|
|
||||||
SIDEBAR_HIDDEN_LAYOUT = "_sidebar-hidden";
|
|
||||||
|
|
||||||
this.el = "._settings";
|
|
||||||
|
|
||||||
this.elements = {
|
|
||||||
sidebar: "._sidebar",
|
|
||||||
saveBtn: 'button[type="submit"]',
|
|
||||||
backBtn: "button[data-back]",
|
|
||||||
};
|
|
||||||
|
|
||||||
this.events = {
|
|
||||||
import: "onImport",
|
|
||||||
change: "onChange",
|
|
||||||
submit: "onSubmit",
|
|
||||||
click: "onClick",
|
|
||||||
};
|
|
||||||
|
|
||||||
this.shortcuts = { enter: "onEnter" };
|
|
||||||
}
|
|
||||||
|
|
||||||
init() {
|
static el = "._settings";
|
||||||
this.addSubview((this.docPicker = new app.views.DocPicker()));
|
|
||||||
}
|
|
||||||
|
|
||||||
activate() {
|
static elements = {
|
||||||
if (super.activate(...arguments)) {
|
sidebar: "._sidebar",
|
||||||
this.render();
|
saveBtn: 'button[type="submit"]',
|
||||||
document.body.classList.remove(SIDEBAR_HIDDEN_LAYOUT);
|
backBtn: "button[data-back]",
|
||||||
}
|
};
|
||||||
}
|
|
||||||
|
|
||||||
deactivate() {
|
static events = {
|
||||||
if (super.deactivate(...arguments)) {
|
import: "onImport",
|
||||||
this.resetClass();
|
change: "onChange",
|
||||||
this.docPicker.detach();
|
submit: "onSubmit",
|
||||||
if (app.settings.hasLayout(SIDEBAR_HIDDEN_LAYOUT)) {
|
click: "onClick",
|
||||||
document.body.classList.add(SIDEBAR_HIDDEN_LAYOUT);
|
};
|
||||||
}
|
|
||||||
|
static shortcuts = { enter: "onEnter" };
|
||||||
|
|
||||||
|
init() {
|
||||||
|
this.addSubview((this.docPicker = new app.views.DocPicker()));
|
||||||
|
}
|
||||||
|
|
||||||
|
activate() {
|
||||||
|
if (super.activate(...arguments)) {
|
||||||
|
this.render();
|
||||||
|
document.body.classList.remove(Settings.SIDEBAR_HIDDEN_LAYOUT);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
deactivate() {
|
||||||
|
if (super.deactivate(...arguments)) {
|
||||||
|
this.resetClass();
|
||||||
|
this.docPicker.detach();
|
||||||
|
if (app.settings.hasLayout(Settings.SIDEBAR_HIDDEN_LAYOUT)) {
|
||||||
|
document.body.classList.add(Settings.SIDEBAR_HIDDEN_LAYOUT);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
this.docPicker.appendTo(this.sidebar);
|
this.docPicker.appendTo(this.sidebar);
|
||||||
this.refreshElements();
|
this.refreshElements();
|
||||||
this.addClass("_in");
|
this.addClass("_in");
|
||||||
}
|
}
|
||||||
|
|
||||||
save(options) {
|
save(options) {
|
||||||
if (options == null) {
|
if (options == null) {
|
||||||
options = {};
|
options = {};
|
||||||
|
}
|
||||||
|
if (!this.saving) {
|
||||||
|
let docs;
|
||||||
|
this.saving = true;
|
||||||
|
|
||||||
|
if (options.import) {
|
||||||
|
docs = app.settings.getDocs();
|
||||||
|
} else {
|
||||||
|
docs = this.docPicker.getSelectedDocs();
|
||||||
|
app.settings.setDocs(docs);
|
||||||
}
|
}
|
||||||
if (!this.saving) {
|
|
||||||
let docs;
|
this.saveBtn.textContent = "Saving\u2026";
|
||||||
this.saving = true;
|
const disabledDocs = new app.collections.Docs(
|
||||||
|
(() => {
|
||||||
if (options.import) {
|
const result = [];
|
||||||
docs = app.settings.getDocs();
|
for (var doc of app.docs.all()) {
|
||||||
} else {
|
if (docs.indexOf(doc.slug) === -1) {
|
||||||
docs = this.docPicker.getSelectedDocs();
|
result.push(doc);
|
||||||
app.settings.setDocs(docs);
|
|
||||||
}
|
|
||||||
|
|
||||||
this.saveBtn.textContent = "Saving\u2026";
|
|
||||||
const disabledDocs = new app.collections.Docs(
|
|
||||||
(() => {
|
|
||||||
const result = [];
|
|
||||||
for (var doc of Array.from(app.docs.all())) {
|
|
||||||
if (docs.indexOf(doc.slug) === -1) {
|
|
||||||
result.push(doc);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return result;
|
}
|
||||||
})(),
|
return result;
|
||||||
);
|
})(),
|
||||||
disabledDocs.uninstall(function () {
|
);
|
||||||
app.db.migrate();
|
disabledDocs.uninstall(function () {
|
||||||
return app.reload();
|
app.db.migrate();
|
||||||
});
|
return app.reload();
|
||||||
}
|
});
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
onChange() {
|
onChange() {
|
||||||
this.addClass("_dirty");
|
this.addClass("_dirty");
|
||||||
}
|
}
|
||||||
|
|
||||||
onEnter() {
|
onEnter() {
|
||||||
this.save();
|
this.save();
|
||||||
}
|
}
|
||||||
|
|
||||||
onSubmit(event) {
|
onSubmit(event) {
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
this.save();
|
this.save();
|
||||||
}
|
}
|
||||||
|
|
||||||
onImport() {
|
onImport() {
|
||||||
this.addClass("_dirty");
|
this.addClass("_dirty");
|
||||||
this.save({ import: true });
|
this.save({ import: true });
|
||||||
}
|
}
|
||||||
|
|
||||||
onClick(event) {
|
onClick(event) {
|
||||||
if (event.which !== 1) {
|
if (event.which !== 1) {
|
||||||
return;
|
return;
|
||||||
}
|
|
||||||
if (event.target === this.backBtn) {
|
|
||||||
$.stopEvent(event);
|
|
||||||
app.router.show("/");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
};
|
if (event.target === this.backBtn) {
|
||||||
app.views.Settings.initClass();
|
$.stopEvent(event);
|
||||||
return app.views.Settings;
|
app.router.show("/");
|
||||||
})();
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
Loading…
Reference in new issue