import mimeTypesService from "../../../services/mime_types.js";
import options from "../../../services/options.js";
import server from "../../../services/server.js";
import toastService from "../../../services/toast.js";
import utils from "../../../services/utils.js";
const TPL = `
Use vim keybindings in CodeNotes (no ex mode)
Enable Vim Keybindings
Wrap lines in CodeNotes
Enable Linewrap
Available MIME types in the dropdown
`;
export default class CodeNotesOptions {
constructor() {
$("#options-code-notes").html(TPL);
this.$vimKeymapEnabled = $("#vim-keymap-enabled");
this.$vimKeymapEnabled.on('change', () => {
const opts = { 'vimKeymapEnabled': this.$vimKeymapEnabled.is(":checked") ? "true" : "false" };
server.put('options', opts).then(() => toastService.showMessage("Options change have been saved."));
return false;
});
this.$linewrapEnabled = $("#linewrap-enabled");
this.$linewrapEnabled.on('change', () => {
const opts = { 'linewrapEnabled': this.$linewrapEnabled.is(":checked") ? "true" : "false" };
server.put('options', opts).then(() => toastService.showMessage("Options change have been saved."));
return false;
});
this.$mimeTypes = $("#options-mime-types");
}
async optionsLoaded(options) {
this.$mimeTypes.empty();
this.$vimKeymapEnabled.prop("checked", options['vimKeymapEnabled'] === 'true');
this.$linewrapEnabled.prop("checked", options['linewrapEnabled'] === 'true');
let idCtr = 1;
for (const mimeType of await mimeTypesService.getMimeTypes()) {
const id = "code-mime-type-" + (idCtr++);
this.$mimeTypes.append($("")
.append($(' ')
.attr("id", id)
.attr("data-mime-type", mimeType.mime)
.prop("checked", mimeType.enabled))
.on('change', () => this.save())
.append(" ")
.append($('')
.attr("for", id)
.text(mimeType.title))
);
}
}
async save() {
const enabledMimeTypes = [];
this.$mimeTypes.find("input:checked").each(
(i, el) => enabledMimeTypes.push($(el).attr("data-mime-type")));
await options.save('codeNotesMimeTypes', JSON.stringify(enabledMimeTypes));
mimeTypesService.loadMimeTypes();
}
}