import server from "../../../services/server.js"; import toastService from "../../../services/toast.js"; import OptionsTab from "./options_tab.js"; const TPL = `
`; export default class BackupOptions extends OptionsTab { get tabTitle() { return "Backup" } lazyRender() { this.$widget = $(TPL); this.$backupDatabaseButton = this.$widget.find("#backup-database-button"); this.$backupDatabaseButton.on('click', async () => { const {backupFile} = await server.post('database/backup-database'); toastService.showMessage("Database has been backed up to " + backupFile, 10000); }); this.$dailyBackupEnabled = this.$widget.find("#daily-backup-enabled"); this.$weeklyBackupEnabled = this.$widget.find("#weekly-backup-enabled"); this.$monthlyBackupEnabled = this.$widget.find("#monthly-backup-enabled"); this.$dailyBackupEnabled.on('change', () => { const opts = { 'dailyBackupEnabled': this.$dailyBackupEnabled.is(":checked") ? "true" : "false" }; server.put('options', opts).then(() => toastService.showMessage("Options change have been saved.")); return false; }); this.$weeklyBackupEnabled.on('change', () => { const opts = { 'weeklyBackupEnabled': this.$weeklyBackupEnabled.is(":checked") ? "true" : "false" }; server.put('options', opts).then(() => toastService.showMessage("Options change have been saved.")); return false; }); this.$monthlyBackupEnabled.on('change', () => { const opts = { 'monthlyBackupEnabled': this.$monthlyBackupEnabled.is(":checked") ? "true" : "false" }; server.put('options', opts).then(() => toastService.showMessage("Options change have been saved.")); return false; }); } optionsLoaded(options) { this.$dailyBackupEnabled.prop("checked", options['dailyBackupEnabled'] === 'true'); this.$weeklyBackupEnabled.prop("checked", options['weeklyBackupEnabled'] === 'true'); this.$monthlyBackupEnabled.prop("checked", options['monthlyBackupEnabled'] === 'true'); } }