refactor imageoptions to use updateOption()

This commit is contained in:
zadam 2022-11-20 20:11:27 +01:00
parent a3783b0113
commit b3c0b36ba6
2 changed files with 28 additions and 27 deletions

View file

@ -1,5 +1,3 @@
import server from "../../../services/server.js";
import toastService from "../../../services/toast.js";
import OptionsTab from "./options_tab.js";
const TPL = `
@ -41,47 +39,37 @@ export default class ImageOptions extends OptionsTab {
this.$imageJpegQuality = this.$widget.find("#image-jpeg-quality");
this.$imageMaxWidthHeight.on('change', () => {
const opts = { 'imageMaxWidthHeight': this.$imageMaxWidthHeight.val() };
server.put('options', opts).then(() => toastService.showMessage("Options change have been saved."));
return false;
this.updateOption('imageMaxWidthHeight', this.$imageMaxWidthHeight.val());
});
this.$imageJpegQuality.on('change', () => {
const opts = { 'imageJpegQuality': this.$imageJpegQuality.val() };
server.put('options', opts).then(() => toastService.showMessage("Options change have been saved."));
return false;
this.updateOption('imageJpegQuality', this.$imageJpegQuality.val());
});
this.$downloadImagesAutomatically = this.$widget.find("#download-images-automatically");
this.$downloadImagesAutomatically.on("change", () => {
const isChecked = this.$downloadImagesAutomatically.prop("checked");
const opts = { 'downloadImagesAutomatically': isChecked ? 'true' : 'false' };
server.put('options', opts).then(() => toastService.showMessage("Options change have been saved."));
this.updateOption('downloadImagesAutomatically', isChecked ? 'true' : 'false');
});
this.$enableImageCompression = this.$widget.find("#image-compresion-enabled");
this.$imageCompressionWrapper = this.$widget.find("#image-compression-enabled-wraper");
this.setImageCompression = (isChecked) => {
this.$enableImageCompression.on("change", () => {
const isChecked = this.$enableImageCompression.prop("checked");
this.updateOption('compressImages', isChecked ? 'true' : 'false');
this.setImageCompression(isChecked);
});
}
setImageCompression(isChecked) {
if (isChecked) {
this.$imageCompressionWrapper.removeClass("disabled-field");
} else {
this.$imageCompressionWrapper.addClass("disabled-field");
}
};
this.$enableImageCompression.on("change", () => {
const isChecked = this.$enableImageCompression.prop("checked");
const opts = { 'compressImages': isChecked ? 'true' : 'false' };
server.put('options', opts).then(() => toastService.showMessage("Options change have been saved."));
this.setImageCompression(isChecked);
});
}
optionsLoaded(options) {

View file

@ -1,5 +1,18 @@
import BasicWidget from "../../basic_widget.js";
import server from "../../../services/server.js";
import toastService from "../../../services/toast.js";
export default class OptionsTab extends BasicWidget {
async updateOption(name, value) {
const opts = { [name]: value };
server.put('options', opts).then(() => {
toastService.showPersistent({
id: "options-change-saved",
title: "Options status",
message: "Options change have been saved.",
icon: "slider",
closeAfter: 2000
})
});
}
}