mirror of
				https://github.com/zadam/trilium.git
				synced 2025-10-31 18:36:30 +01:00 
			
		
		
		
	refactor imageoptions to use updateOption()
This commit is contained in:
		| @@ -1,5 +1,3 @@ | |||||||
| import server from "../../../services/server.js"; |  | ||||||
| import toastService from "../../../services/toast.js"; |  | ||||||
| import OptionsTab from "./options_tab.js"; | import OptionsTab from "./options_tab.js"; | ||||||
|  |  | ||||||
| const TPL = ` | const TPL = ` | ||||||
| @@ -33,7 +31,7 @@ const TPL = ` | |||||||
|  |  | ||||||
| export default class ImageOptions extends OptionsTab { | export default class ImageOptions extends OptionsTab { | ||||||
|     get tabTitle() { return "Images" } |     get tabTitle() { return "Images" } | ||||||
|      |  | ||||||
|     lazyRender() { |     lazyRender() { | ||||||
|         this.$widget = $(TPL); |         this.$widget = $(TPL); | ||||||
|  |  | ||||||
| @@ -41,49 +39,39 @@ export default class ImageOptions extends OptionsTab { | |||||||
|         this.$imageJpegQuality = this.$widget.find("#image-jpeg-quality"); |         this.$imageJpegQuality = this.$widget.find("#image-jpeg-quality"); | ||||||
|  |  | ||||||
|         this.$imageMaxWidthHeight.on('change', () => { |         this.$imageMaxWidthHeight.on('change', () => { | ||||||
|             const opts = { 'imageMaxWidthHeight': this.$imageMaxWidthHeight.val() }; |             this.updateOption('imageMaxWidthHeight', this.$imageMaxWidthHeight.val()); | ||||||
|             server.put('options', opts).then(() => toastService.showMessage("Options change have been saved.")); |  | ||||||
|  |  | ||||||
|             return false; |  | ||||||
|         }); |         }); | ||||||
|  |  | ||||||
|         this.$imageJpegQuality.on('change', () => { |         this.$imageJpegQuality.on('change', () => { | ||||||
|             const opts = { 'imageJpegQuality': this.$imageJpegQuality.val() }; |             this.updateOption('imageJpegQuality', this.$imageJpegQuality.val()); | ||||||
|             server.put('options', opts).then(() => toastService.showMessage("Options change have been saved.")); |  | ||||||
|  |  | ||||||
|             return false; |  | ||||||
|         }); |         }); | ||||||
|  |  | ||||||
|         this.$downloadImagesAutomatically = this.$widget.find("#download-images-automatically"); |         this.$downloadImagesAutomatically = this.$widget.find("#download-images-automatically"); | ||||||
|  |  | ||||||
|         this.$downloadImagesAutomatically.on("change", () => { |         this.$downloadImagesAutomatically.on("change", () => { | ||||||
|             const isChecked = this.$downloadImagesAutomatically.prop("checked"); |             const isChecked = this.$downloadImagesAutomatically.prop("checked"); | ||||||
|             const opts = { 'downloadImagesAutomatically': isChecked ? 'true' : 'false' }; |             this.updateOption('downloadImagesAutomatically', isChecked ? 'true' : 'false'); | ||||||
|  |  | ||||||
|             server.put('options', opts).then(() => toastService.showMessage("Options change have been saved.")); |  | ||||||
|         }); |         }); | ||||||
|  |  | ||||||
|         this.$enableImageCompression = this.$widget.find("#image-compresion-enabled"); |         this.$enableImageCompression = this.$widget.find("#image-compresion-enabled"); | ||||||
|         this.$imageCompressionWrapper = this.$widget.find("#image-compression-enabled-wraper"); |         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", () => { |         this.$enableImageCompression.on("change", () => { | ||||||
|             const isChecked = this.$enableImageCompression.prop("checked"); |             const isChecked = this.$enableImageCompression.prop("checked"); | ||||||
|             const opts = { 'compressImages': isChecked ? 'true' : 'false' }; |             this.updateOption('compressImages', isChecked ? 'true' : 'false'); | ||||||
|  |  | ||||||
|             server.put('options', opts).then(() => toastService.showMessage("Options change have been saved.")); |  | ||||||
|  |  | ||||||
|             this.setImageCompression(isChecked); |             this.setImageCompression(isChecked); | ||||||
|         }); |         }); | ||||||
|     } |     } | ||||||
|  |  | ||||||
|  |     setImageCompression(isChecked) { | ||||||
|  |         if (isChecked) { | ||||||
|  |             this.$imageCompressionWrapper.removeClass("disabled-field"); | ||||||
|  |         } else { | ||||||
|  |             this.$imageCompressionWrapper.addClass("disabled-field"); | ||||||
|  |         } | ||||||
|  |     } | ||||||
|  |  | ||||||
|     optionsLoaded(options) { |     optionsLoaded(options) { | ||||||
|         this.$imageMaxWidthHeight.val(options['imageMaxWidthHeight']); |         this.$imageMaxWidthHeight.val(options['imageMaxWidthHeight']); | ||||||
|         this.$imageJpegQuality.val(options['imageJpegQuality']); |         this.$imageJpegQuality.val(options['imageJpegQuality']); | ||||||
|   | |||||||
| @@ -1,5 +1,18 @@ | |||||||
| import BasicWidget from "../../basic_widget.js"; | import BasicWidget from "../../basic_widget.js"; | ||||||
|  | import server from "../../../services/server.js"; | ||||||
|  | import toastService from "../../../services/toast.js"; | ||||||
|  |  | ||||||
| export default class OptionsTab extends BasicWidget { | 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 | ||||||
|  |             }) | ||||||
|  |         }); | ||||||
|  |     } | ||||||
|  | } | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user