ability to restore original image
This commit is contained in:
		| @@ -1,11 +1,13 @@ | ||||
| $.fn.imageUpload = function() { | ||||
|     $.each(this, function(){ | ||||
|         var $button = $(this).find('button'); | ||||
|         var $uploadButton = $(this).find('button.upload'); | ||||
|         var $restoreButton = $(this).find('button.restore'); | ||||
|         var $img = $(this).find('img'); | ||||
|         var originalUrl = $img.prop('src'); | ||||
|         var $input = $(this).find('input'); | ||||
|         var id = $input.prop('id'); | ||||
|         $button.click(function(){ | ||||
|             $button.prop('disabled', true); | ||||
|         $uploadButton.click(function(){ | ||||
|             $uploadButton.prop('disabled', true); | ||||
|             var input = document.createElement('input'); | ||||
|             input.type = 'file'; | ||||
|             input.accept = 'image/jpeg, image/png'; | ||||
| @@ -25,7 +27,7 @@ $.fn.imageUpload = function() { | ||||
|                         $input.val(data.uuid); | ||||
|                         $img.prop('src', "/imageupload?id=" + id + "&uuid=" + data.uuid); | ||||
|                     }).always(function(){ | ||||
|                         $button.prop('disabled', false); | ||||
|                         $uploadButton.prop('disabled', false); | ||||
|                     }); | ||||
|                 } | ||||
|             }; | ||||
| @@ -33,5 +35,11 @@ $.fn.imageUpload = function() { | ||||
|             input.click(); | ||||
|             return false; | ||||
|         }); | ||||
|  | ||||
|         $restoreButton.click(function(){ | ||||
|             $input.val('restore'); | ||||
|             $img.prop('src', originalUrl + "&mapped=false"); | ||||
|             return false; | ||||
|         }); | ||||
|     }); | ||||
| } | ||||
| @@ -94,8 +94,8 @@ class OwrxAssetsController(AssetsController): | ||||
|             "gfx/openwebrx-avatar.png": "receiver_avatar", | ||||
|             "gfx/openwebrx-top-photo.jpg": "receiver_top_photo", | ||||
|         } | ||||
|         config = CoreConfig() | ||||
|         if file in mappedFiles: | ||||
|         if file in mappedFiles and ("mapped" not in self.request.query or self.request.query["mapped"][0] != "false"): | ||||
|             config = CoreConfig() | ||||
|             user_file = config.get_data_directory() + "/" + mappedFiles[file] | ||||
|             if os.path.exists(user_file) and os.path.isfile(user_file): | ||||
|                 return user_file | ||||
|   | ||||
| @@ -26,6 +26,7 @@ from owrx.wsjt import Fst4Profile, Fst4wProfile | ||||
| import json | ||||
| import logging | ||||
| import shutil | ||||
| import os | ||||
|  | ||||
| logger = logging.getLogger(__name__) | ||||
|  | ||||
| @@ -370,11 +371,15 @@ class GeneralSettingsController(AuthorizationMixin, WebpageController): | ||||
|         return variables | ||||
|  | ||||
|     def handle_image(self, data, image_id): | ||||
|         if image_id in data and data[image_id]: | ||||
|         if image_id in data: | ||||
|             config = CoreConfig() | ||||
|             filename = "{}-{}".format(image_id, data[image_id]) | ||||
|             shutil.copy(config.get_temporary_directory() + "/" + filename, config.get_data_directory() + "/" + image_id) | ||||
|         del data[image_id] | ||||
|             data_file = config.get_data_directory() + "/" + image_id | ||||
|             if data[image_id] == "restore": | ||||
|                 os.unlink(data_file) | ||||
|             elif data[image_id]: | ||||
|                 filename = "{}-{}".format(image_id, data[image_id]) | ||||
|                 shutil.copy(config.get_temporary_directory() + "/" + filename, data_file) | ||||
|             del data[image_id] | ||||
|  | ||||
|     def processFormData(self): | ||||
|         data = parse_qs(self.get_body().decode("utf-8"), keep_blank_values=True) | ||||
|   | ||||
| @@ -3,7 +3,6 @@ from owrx.form import Input | ||||
| from datetime import datetime | ||||
|  | ||||
|  | ||||
| # TODO: ability to restore the original image | ||||
| class ImageInput(Input, metaclass=ABCMeta): | ||||
|     def render_input(self, value): | ||||
|         return """ | ||||
| @@ -12,7 +11,8 @@ class ImageInput(Input, metaclass=ABCMeta): | ||||
|                 <div class="image-container"> | ||||
|                     <img class="{classes}" src="{url}" alt="{label}"/> | ||||
|                 </div> | ||||
|                 <button class="btn btn-primary">Upload new image...</button> | ||||
|                 <button class="btn btn-primary upload">Upload new image...</button> | ||||
|                 <button class="btn btn-secondary restore">Restore original image</button> | ||||
|             </div> | ||||
|         """.format( | ||||
|             id=self.id, label=self.label, url=self.cachebuster(self.getUrl()), classes=" ".join(self.getImgClasses()) | ||||
|   | ||||
		Reference in New Issue
	
	Block a user
	 Jakob Ketterl
					Jakob Ketterl