implement device and profile delete modals

This commit is contained in:
Jakob Ketterl 2021-03-03 21:51:33 +01:00
parent eab1c6ce80
commit d123232f28
5 changed files with 87 additions and 3 deletions

7
htdocs/lib/bootstrap.bundle.min.js vendored Normal file

File diff suppressed because one or more lines are too long

View File

@ -17,4 +17,5 @@ ${header}
</div>
${content}
</div>
${modal}
</body>

View File

@ -144,6 +144,7 @@ class CompiledAssetsController(GzipMixin, ModificationAwareController):
],
"settings.js": [
"lib/jquery-3.2.1.min.js",
"lib/bootstrap.bundle.min.js",
"lib/Header.js",
"lib/settings/MapInput.js",
"lib/settings/ImageUpload.js",

View File

@ -54,17 +54,24 @@ class SettingsFormController(AuthorizationMixin, WebpageController, metaclass=AB
def render_sections(self):
sections = "".join(section.render(self.getData()) for section in self.getSections())
buttons = self.render_buttons()
return """
<form class="settings-body" method="POST">
{sections}
<div class="buttons container">
<button type="submit" class="btn btn-primary">Apply and save</button>
{buttons}
</div>
</form>
""".format(
sections=sections
sections=sections,
buttons=buttons,
)
def render_buttons(self):
return """
<button type="submit" class="btn btn-primary">Apply and save</button>
"""
def indexAction(self):
self.serve_template("settings/general.html", **self.template_variables())
@ -72,6 +79,7 @@ class SettingsFormController(AuthorizationMixin, WebpageController, metaclass=AB
variables = super().template_variables()
variables["content"] = self.render_sections()
variables["title"] = self.getTitle()
variables["modal"] = self.buildModal()
return variables
def parseFormData(self):
@ -97,3 +105,6 @@ class SettingsFormController(AuthorizationMixin, WebpageController, metaclass=AB
def store(self):
Config.get().store()
def buildModal(self):
return ""

View File

@ -9,7 +9,7 @@ from urllib.parse import quote, unquote
from owrx.sdr import SdrService
from owrx.form import TextInput, DropdownInput, Option
from owrx.property import PropertyLayer, PropertyStack
from abc import ABCMeta
from abc import ABCMeta, abstractmethod
class SdrDeviceListController(AuthorizationMixin, WebpageController):
@ -114,6 +114,40 @@ class SdrFormController(SettingsFormController, metaclass=ABCMeta):
return None, None
return device_id, config["sdrs"][device_id]
def buildModal(self):
return """
<div class="modal" id="deleteModal" tabindex="-1" role="dialog">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<h5>Please confirm</h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">&times;</span>
</button>
</div>
<div class="modal-body">
<p>Do you really want to delete this {object_type}?</p>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-dismiss="modal">Cancel</button>
<a type="button" class="btn btn-danger" href="{confirm_url}">Delete</a>
</div>
</div>
</div>
</div>
""".format(
object_type=self.getModalObjectType(),
confirm_url=self.getModalConfirmUrl(),
)
@abstractmethod
def getModalObjectType(self):
pass
@abstractmethod
def getModalConfirmUrl(self):
pass
class SdrDeviceController(SdrFormController):
def getData(self):
@ -127,6 +161,14 @@ class SdrDeviceController(SdrFormController):
# TODO provide a generic interface that allows to switch the type
return []
def render_buttons(self):
return (
"""
<button type="button" class="btn btn-danger" data-toggle="modal" data-target="#deleteModal">Remove device...</button>
"""
+ super().render_buttons()
)
def getTitle(self):
return self.device["name"]
@ -142,6 +184,12 @@ class SdrDeviceController(SdrFormController):
return
return super().processFormData()
def getModalObjectType(self):
return "SDR device"
def getModalConfirmUrl(self):
return "{}settings/deletesdr/{}".format(self.get_document_root(), quote(self.device_id))
class NewSdrDeviceController(SettingsFormController):
def __init__(self, handler, request, options):
@ -218,3 +266,19 @@ class SdrProfileController(SdrFormController):
self.send_response("profile not found", code=404)
return
return super().processFormData()
def render_buttons(self):
return (
"""
<button type="button" class="btn btn-danger" data-toggle="modal" data-target="#deleteModal">Remove profile...</button>
"""
+ super().render_buttons()
)
def getModalObjectType(self):
return "profile"
def getModalConfirmUrl(self):
return "{}settings/{}/deleteprofile/{}".format(
self.get_document_root(), quote(self.device_id), quote(self.profile_id)
)