2019-08-29 21:08:53 +02:00
|
|
|
import mimeTypesService from "../../services/mime_types.js";
|
2020-02-05 22:08:45 +01:00
|
|
|
import options from "../../services/options.js";
|
2019-08-29 21:08:53 +02:00
|
|
|
|
2019-11-03 19:06:22 +01:00
|
|
|
const TPL = `
|
|
|
|
<h4>Available MIME types in the dropdown</h4>
|
|
|
|
|
|
|
|
<ul id="options-mime-types" style="max-height: 500px; overflow: auto; list-style-type: none;"></ul>`;
|
|
|
|
|
2019-08-29 21:08:53 +02:00
|
|
|
export default class CodeNotesOptions {
|
|
|
|
constructor() {
|
2019-11-03 19:06:22 +01:00
|
|
|
$("#options-code-notes").html(TPL);
|
|
|
|
|
2019-08-29 21:08:53 +02:00
|
|
|
this.$mimeTypes = $("#options-mime-types");
|
|
|
|
}
|
|
|
|
|
2020-02-05 22:08:45 +01:00
|
|
|
async optionsLoaded() {
|
2019-08-29 21:08:53 +02:00
|
|
|
this.$mimeTypes.empty();
|
|
|
|
|
|
|
|
let idCtr = 1;
|
|
|
|
|
|
|
|
for (const mimeType of await mimeTypesService.getMimeTypes()) {
|
|
|
|
const id = "code-mime-type-" + (idCtr++);
|
|
|
|
|
|
|
|
this.$mimeTypes.append($("<li>")
|
|
|
|
.append($('<input type="checkbox">')
|
|
|
|
.attr("id", id)
|
|
|
|
.attr("data-mime-type", mimeType.mime)
|
|
|
|
.prop("checked", mimeType.enabled))
|
2019-11-09 17:39:48 +01:00
|
|
|
.on('change', () => this.save())
|
2019-08-29 21:08:53 +02:00
|
|
|
.append(" ")
|
|
|
|
.append($('<label>')
|
|
|
|
.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")));
|
|
|
|
|
2020-02-05 22:08:45 +01:00
|
|
|
await options.save('codeNotesMimeTypes', JSON.stringify(enabledMimeTypes));
|
2019-08-29 21:08:53 +02:00
|
|
|
|
2020-02-05 22:08:45 +01:00
|
|
|
mimeTypesService.loadMimeTypes();
|
2019-08-29 21:08:53 +02:00
|
|
|
}
|
|
|
|
}
|