re-wire profile add & delete
This commit is contained in:
parent
a14f247859
commit
a3cfde02c4
@ -177,6 +177,12 @@ class SdrFormController(SettingsFormController, metaclass=ABCMeta):
|
|||||||
|
|
||||||
|
|
||||||
class SdrFormControllerWithModal(SdrFormController, metaclass=ABCMeta):
|
class SdrFormControllerWithModal(SdrFormController, metaclass=ABCMeta):
|
||||||
|
def render_remove_button(self):
|
||||||
|
return ""
|
||||||
|
|
||||||
|
def render_buttons(self):
|
||||||
|
return self.render_remove_button() + super().render_buttons()
|
||||||
|
|
||||||
def buildModal(self):
|
def buildModal(self):
|
||||||
return """
|
return """
|
||||||
<div class="modal" id="deleteModal" tabindex="-1" role="dialog">
|
<div class="modal" id="deleteModal" tabindex="-1" role="dialog">
|
||||||
@ -224,13 +230,10 @@ class SdrDeviceController(SdrFormControllerWithModal):
|
|||||||
# TODO provide a generic interface that allows to switch the type
|
# TODO provide a generic interface that allows to switch the type
|
||||||
return []
|
return []
|
||||||
|
|
||||||
def render_buttons(self):
|
def render_remove_button(self):
|
||||||
return (
|
return """
|
||||||
"""
|
|
||||||
<button type="button" class="btn btn-danger" data-toggle="modal" data-target="#deleteModal">Remove device...</button>
|
<button type="button" class="btn btn-danger" data-toggle="modal" data-target="#deleteModal">Remove device...</button>
|
||||||
"""
|
"""
|
||||||
+ super().render_buttons()
|
|
||||||
)
|
|
||||||
|
|
||||||
def isDeviceActive(self) -> bool:
|
def isDeviceActive(self) -> bool:
|
||||||
return True
|
return True
|
||||||
@ -341,13 +344,10 @@ class SdrProfileController(SdrFormControllerWithModal):
|
|||||||
return
|
return
|
||||||
return super().processFormData()
|
return super().processFormData()
|
||||||
|
|
||||||
def render_buttons(self):
|
def render_remove_button(self):
|
||||||
return (
|
return """
|
||||||
"""
|
<button type="button" class="btn btn-danger" data-toggle="modal" data-target="#deleteModal">Remove profile...</button>
|
||||||
<button type="button" class="btn btn-danger" data-toggle="modal" data-target="#deleteModal">Remove profile...</button>
|
"""
|
||||||
"""
|
|
||||||
+ super().render_buttons()
|
|
||||||
)
|
|
||||||
|
|
||||||
def getModalObjectType(self):
|
def getModalObjectType(self):
|
||||||
return "profile"
|
return "profile"
|
||||||
@ -363,29 +363,28 @@ class SdrProfileController(SdrFormControllerWithModal):
|
|||||||
config = Config.get()
|
config = Config.get()
|
||||||
del self.device["profiles"][self.profile_id]
|
del self.device["profiles"][self.profile_id]
|
||||||
config.store()
|
config.store()
|
||||||
return self.send_redirect("{}settings/sdr".format(self.get_document_root()))
|
return self.send_redirect("{}settings/sdr/{}".format(self.get_document_root(), quote(self.device_id)))
|
||||||
|
|
||||||
|
|
||||||
class NewProfileController(SdrFormController):
|
class NewProfileController(SdrProfileController):
|
||||||
def __init__(self, handler, request, options):
|
def __init__(self, handler, request, options):
|
||||||
super().__init__(handler, request, options)
|
|
||||||
id_layer = PropertyLayer(id="")
|
id_layer = PropertyLayer(id="")
|
||||||
self.data_layer = PropertyLayer(name="")
|
self.data_layer = PropertyLayer(name="")
|
||||||
self.stack = PropertyStack()
|
self.stack = PropertyStack()
|
||||||
self.stack.addLayer(0, id_layer)
|
self.stack.addLayer(0, self.data_layer)
|
||||||
self.stack.addLayer(1, self.data_layer)
|
self.stack.addLayer(1, id_layer)
|
||||||
|
super().__init__(handler, request, options)
|
||||||
|
|
||||||
|
def _get_profile(self):
|
||||||
|
return "new", self.stack
|
||||||
|
|
||||||
def getSections(self):
|
def getSections(self):
|
||||||
return [
|
return [
|
||||||
Section(
|
Section(
|
||||||
"New profile settings",
|
"New profile settings",
|
||||||
TextInput("name", "Profile name"),
|
|
||||||
TextInput("id", "Profile ID"),
|
TextInput("id", "Profile ID"),
|
||||||
)
|
)
|
||||||
]
|
] + super().getSections()
|
||||||
|
|
||||||
def getTitle(self):
|
|
||||||
return "New profile"
|
|
||||||
|
|
||||||
def isNewProfileActive(self) -> bool:
|
def isNewProfileActive(self) -> bool:
|
||||||
return True
|
return True
|
||||||
@ -396,10 +395,11 @@ class NewProfileController(SdrFormController):
|
|||||||
self.device["profiles"][self.stack["id"]] = self.data_layer
|
self.device["profiles"][self.stack["id"]] = self.data_layer
|
||||||
super().store()
|
super().store()
|
||||||
|
|
||||||
def getData(self):
|
|
||||||
return self.stack
|
|
||||||
|
|
||||||
def getSuccessfulRedirect(self):
|
def getSuccessfulRedirect(self):
|
||||||
return "{}settings/sdr/{}/profile/{}".format(
|
return "{}settings/sdr/{}/profile/{}".format(
|
||||||
self.get_document_root(), quote(self.device_id), quote(self.stack["id"])
|
self.get_document_root(), quote(self.device_id), quote(self.stack["id"])
|
||||||
)
|
)
|
||||||
|
|
||||||
|
def render_remove_button(self):
|
||||||
|
# new profile doesn't have a remove button
|
||||||
|
return ""
|
||||||
|
Loading…
Reference in New Issue
Block a user