diff --git a/htdocs/lib/settings/BookmarkTable.js b/htdocs/lib/settings/BookmarkTable.js
index 04372da..5594fc6 100644
--- a/htdocs/lib/settings/BookmarkTable.js
+++ b/htdocs/lib/settings/BookmarkTable.js
@@ -22,7 +22,7 @@ $.fn.bookmarktable = function() {
var $cell = $(e.target);
var html = $cell.html();
- var $row = $cell.parent('tr');
+ var $row = $cell.parents('tr');
var index = $row.find('td').index($cell);
var $input = inputs[index];
@@ -53,7 +53,20 @@ $.fn.bookmarktable = function() {
});
});
- $(this).find('.bookmark-add').on('click', function() {
+ $table.on('click', '.bookmark-delete', function(e) {
+ var $button = $(e.target);
+ $button.prop('disabled', true);
+ var $row = $button.parents('tr');
+ $.ajax(document.location.href + "/" + $row.data('id'), {
+ data: "{}",
+ contentType: 'application/json',
+ method: 'DELETE'
+ }).then(function(){
+ $row.remove();
+ });
+ });
+
+ $(this).on('click', '.bookmark-add', function() {
if ($table.find('tr[data-id="new"]').length) return;
var row = $('
');
diff --git a/owrx/bookmarks.py b/owrx/bookmarks.py
index 31ec647..d8a9a2b 100644
--- a/owrx/bookmarks.py
+++ b/owrx/bookmarks.py
@@ -99,3 +99,8 @@ class Bookmarks(object):
def addBookmark(self, bookmark: Bookmark):
self.bookmarks.append(bookmark)
+
+ def removeBookmark(self, bookmark: Bookmark):
+ if bookmark not in self.bookmarks:
+ return
+ self.bookmarks.remove(bookmark)
diff --git a/owrx/controllers/bookmarks.py b/owrx/controllers/bookmarks.py
index 8171ad7..4ece8dd 100644
--- a/owrx/controllers/bookmarks.py
+++ b/owrx/controllers/bookmarks.py
@@ -60,7 +60,7 @@ class BookmarksController(AuthorizationMixin, WebpageController):
{frequency} |
{modulation_name} |
- delete
+
|
""".format(
@@ -111,5 +111,16 @@ class BookmarksController(AuthorizationMixin, WebpageController):
except json.JSONDecodeError:
self.send_response("{}", content_type="application/json", code=400)
+ def delete(self):
+ bookmark_id = int(self.request.matches.group(1))
+ bookmark = self._findBookmark(bookmark_id)
+ if bookmark is None:
+ self.send_response("{}", content_type="application/json", code=404)
+ return
+ bookmarks = Bookmarks.getSharedInstance()
+ bookmarks.removeBookmark(bookmark)
+ bookmarks.store()
+ self.send_response("{}", content_type="application/json", code=200)
+
def indexAction(self):
self.serve_template("settings/bookmarks.html", **self.template_variables())
diff --git a/owrx/http.py b/owrx/http.py
index 008168b..90d4a72 100644
--- a/owrx/http.py
+++ b/owrx/http.py
@@ -35,6 +35,9 @@ class RequestHandler(BaseHTTPRequestHandler):
def do_POST(self):
self.router.route(self, self.get_request("POST"))
+ def do_DELETE(self):
+ self.router.route(self, self.get_request("DELETE"))
+
def get_request(self, method):
url = urlparse(self.path)
return Request(url, method, self.headers)
@@ -112,6 +115,7 @@ class Router(object):
StaticRoute("/settings/bookmarks", BookmarksController),
StaticRoute("/settings/bookmarks", BookmarksController, method="POST", options={"action": "new"}),
RegexRoute("/settings/bookmarks/(.+)", BookmarksController, method="POST", options={"action": "update"}),
+ RegexRoute("/settings/bookmarks/(.+)", BookmarksController, method="DELETE", options={"action": "delete"}),
StaticRoute("/login", SessionController, options={"action": "loginAction"}),
StaticRoute("/login", SessionController, method="POST", options={"action": "processLoginAction"}),
StaticRoute("/logout", SessionController, options={"action": "logoutAction"}),