diff --git a/htdocs/lib/settings/ImageUpload.js b/htdocs/lib/settings/ImageUpload.js index 1e02563..051267c 100644 --- a/htdocs/lib/settings/ImageUpload.js +++ b/htdocs/lib/settings/ImageUpload.js @@ -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; + }); }); } \ No newline at end of file diff --git a/owrx/controllers/assets.py b/owrx/controllers/assets.py index 07b2f6f..c0ee0c6 100644 --- a/owrx/controllers/assets.py +++ b/owrx/controllers/assets.py @@ -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 diff --git a/owrx/controllers/settings.py b/owrx/controllers/settings.py index b5531ba..f45d4da 100644 --- a/owrx/controllers/settings.py +++ b/owrx/controllers/settings.py @@ -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) diff --git a/owrx/form/gfx.py b/owrx/form/gfx.py index 95b4e6e..05a01f3 100644 --- a/owrx/form/gfx.py +++ b/owrx/form/gfx.py @@ -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):
{label}
- + + """.format( id=self.id, label=self.label, url=self.cachebuster(self.getUrl()), classes=" ".join(self.getImgClasses())