import libraryLoader from "../../services/library_loader.js"; import server from "../../services/server.js"; import optionsService from "../../services/options.js"; export default class SidebarOptions { constructor() { this.$sidebarMinWidth = $("#sidebar-min-width"); this.$sidebarWidthPercent = $("#sidebar-width-percent"); this.$showSidebarInNewTab = $("#show-sidebar-in-new-tab"); this.$widgetsConfiguration = $("#widgets-configuration"); this.$widgetsEnabled = $("#widgets-enabled"); this.$widgetsDisabled = $("#widgets-disabled"); this.$sidebarMinWidth.change(async () => { await server.put('options/sidebarMinWidth/' + this.$sidebarMinWidth.val()); this.resizeSidebar(); }); this.$sidebarWidthPercent.change(async () => { await server.put('options/sidebarWidthPercent/' + this.$sidebarWidthPercent.val()); this.resizeSidebar(); }); this.$showSidebarInNewTab.change(async () => { const flag = this.$showSidebarInNewTab.is(":checked") ? 'true' : 'false'; await server.put('options/showSidebarInNewTab/' + flag); optionsService.reloadOptions(); }); } async optionsLoaded(options) { this.$widgetsEnabled.empty(); this.$widgetsDisabled.empty(); this.$sidebarMinWidth.val(options.sidebarMinWidth); this.$sidebarWidthPercent.val(options.sidebarWidthPercent); if (parseInt(options.showSidebarInNewTab)) { this.$showSidebarInNewTab.attr("checked", "checked"); } else { this.$showSidebarInNewTab.removeAttr("checked"); } const widgets = [ {name: 'attributes', title: 'Attributes'}, {name: 'linkMap', title: 'Link map'}, {name: 'noteInfo', title: 'Note info'}, {name: 'noteRevisions', title: 'Note revisions'}, {name: 'whatLinksHere', title: 'What links here'}, {name: 'similarNotes', title: 'Similar notes'}, {name: 'editedNotes', title: 'Edited notes (only on day note)'}, {name: 'calendar', title: 'Calendar (only on day note)'} ].map(widget => { widget.option = this.parseJsonSafely(options[widget.name + 'Widget']) || { enabled: true, expanded: true, position: 1000 }; return widget; }); widgets.sort((a, b) => a.option.position - b.option.position); for (const {name, title, option} of widgets) { const $widgetTitle = $('