mirror of
				https://github.com/zadam/trilium.git
				synced 2025-11-03 21:19:01 +01:00 
			
		
		
		
	refactor imageoptions to use updateOption()
This commit is contained in:
		
							parent
							
								
									a3783b0113
								
							
						
					
					
						commit
						b3c0b36ba6
					
				@ -1,5 +1,3 @@
 | 
			
		||||
import server from "../../../services/server.js";
 | 
			
		||||
import toastService from "../../../services/toast.js";
 | 
			
		||||
import OptionsTab from "./options_tab.js";
 | 
			
		||||
 | 
			
		||||
const TPL = `
 | 
			
		||||
@ -33,7 +31,7 @@ const TPL = `
 | 
			
		||||
 | 
			
		||||
export default class ImageOptions extends OptionsTab {
 | 
			
		||||
    get tabTitle() { return "Images" }
 | 
			
		||||
    
 | 
			
		||||
 | 
			
		||||
    lazyRender() {
 | 
			
		||||
        this.$widget = $(TPL);
 | 
			
		||||
 | 
			
		||||
@ -41,49 +39,39 @@ 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) => {
 | 
			
		||||
            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.updateOption('compressImages', isChecked ? 'true' : 'false');
 | 
			
		||||
 | 
			
		||||
            this.setImageCompression(isChecked);
 | 
			
		||||
        });
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    setImageCompression(isChecked) {
 | 
			
		||||
        if (isChecked) {
 | 
			
		||||
            this.$imageCompressionWrapper.removeClass("disabled-field");
 | 
			
		||||
        } else {
 | 
			
		||||
            this.$imageCompressionWrapper.addClass("disabled-field");
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    optionsLoaded(options) {
 | 
			
		||||
        this.$imageMaxWidthHeight.val(options['imageMaxWidthHeight']);
 | 
			
		||||
        this.$imageJpegQuality.val(options['imageJpegQuality']);
 | 
			
		||||
 | 
			
		||||
@ -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
 | 
			
		||||
            })
 | 
			
		||||
        });
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user