From 8ea4d11e9cf2950308ec4e6f0130bb5bb445688d Mon Sep 17 00:00:00 2001 From: Jakob Ketterl Date: Sat, 13 Feb 2021 23:53:16 +0100 Subject: [PATCH] make the bookmarks table editable --- htdocs/css/admin.css | 6 ++++ htdocs/lib/settings/BookmarkTable.js | 41 ++++++++++++++++++++++++++++ htdocs/settings.js | 1 + owrx/controllers/assets.py | 1 + owrx/controllers/bookmarks.py | 25 +++++++++++++++-- 5 files changed, 71 insertions(+), 3 deletions(-) create mode 100644 htdocs/lib/settings/BookmarkTable.js diff --git a/htdocs/css/admin.css b/htdocs/css/admin.css index 3890b80..ec59bd2 100644 --- a/htdocs/css/admin.css +++ b/htdocs/css/admin.css @@ -57,4 +57,10 @@ h1 { table.bookmarks .frequency { text-align: right; +} + +table.bookmarks input, table.bookmarks select { + width: initial; + text-align: inherit; + display: initial; } \ No newline at end of file diff --git a/htdocs/lib/settings/BookmarkTable.js b/htdocs/lib/settings/BookmarkTable.js new file mode 100644 index 0000000..a9e28f8 --- /dev/null +++ b/htdocs/lib/settings/BookmarkTable.js @@ -0,0 +1,41 @@ +$.fn.bookmarktable = function() { + $.each(this, function(){ + var $table = $(this); + + var inputs = $table.find('tr.inputs td').map(function(){ + var candidates = $(this).find('input, select') + return candidates.length ? candidates.first() : false; + }).toArray(); + $table.find('tr.inputs').remove(); + + $table.on('dblclick', 'td', function(e) { + var $cell = $(e.target); + var html = $cell.html(); + + var index = $cell.parent('tr').find('td').index($cell); + + var $input = inputs[index]; + if (!$input) return; + + $input.val($cell.data('value') || html); + $cell.html($input); + $input.focus(); + + var submit = function() { + var $option = $input.find('option:selected') + if ($option.length) { + $cell.html($option.html()); + } else { + $cell.html($input.val()); + } + }; + + $input.on('blur', submit).on('change', submit).on('keyup', function(e){ + if (e.keyCode == 13) return submit(); + if (e.keyCode == 27) { + $cell.html(html); + } + }); + }); + }); +}; diff --git a/htdocs/settings.js b/htdocs/settings.js index e30de75..aa2db73 100644 --- a/htdocs/settings.js +++ b/htdocs/settings.js @@ -23,4 +23,5 @@ $(function(){ $(".sdrdevice").sdrdevice(); $(".imageupload").imageUpload(); + $("table.bookmarks").bookmarktable(); }); \ No newline at end of file diff --git a/owrx/controllers/assets.py b/owrx/controllers/assets.py index 6362e79..daeaddd 100644 --- a/owrx/controllers/assets.py +++ b/owrx/controllers/assets.py @@ -148,6 +148,7 @@ class CompiledAssetsController(GzipMixin, ModificationAwareController): "lib/settings/Input.js", "lib/settings/SdrDevice.js", "lib/settings/ImageUpload.js", + "lib/settings/BookmarkTable.js", "settings.js", ], } diff --git a/owrx/controllers/bookmarks.py b/owrx/controllers/bookmarks.py index acb284a..7c7d39d 100644 --- a/owrx/controllers/bookmarks.py +++ b/owrx/controllers/bookmarks.py @@ -1,6 +1,7 @@ from owrx.controllers.template import WebpageController from owrx.controllers.admin import AuthorizationMixin from owrx.bookmarks import Bookmark, Bookmarks +from owrx.modes import Modes class BookmarksController(AuthorizationMixin, WebpageController): @@ -16,6 +17,15 @@ class BookmarksController(AuthorizationMixin, WebpageController): def render_table(self): bookmarks = Bookmarks.getSharedInstance() + + def render_mode(m): + return """ + + """.format( + mode=m.modulation, + name=m.name, + ) + return """ @@ -25,17 +35,25 @@ class BookmarksController(AuthorizationMixin, WebpageController): {bookmarks} + + + + + +
Actions
""".format( - bookmarks="".join(self.render_bookmark(idx, b) for idx, b in enumerate(bookmarks.getBookmarks())) + bookmarks="".join(self.render_bookmark(idx, b) for idx, b in enumerate(bookmarks.getBookmarks())), + options="".join(render_mode(m) for m in Modes.getAvailableModes()), ) def render_bookmark(self, idx: int, bookmark: Bookmark): + mode = Modes.findByModulation(bookmark.getModulation()) return """ {name} {frequency} - {modulation} + {modulation_name}
delete
@@ -45,7 +63,8 @@ class BookmarksController(AuthorizationMixin, WebpageController): id=id(bookmark), name=bookmark.getName(), frequency=bookmark.getFrequency(), - modulation=bookmark.getModulation(), + modulation=bookmark.getModulation() if mode is None else mode.modulation, + modulation_name=bookmark.getModulation() if mode is None else mode.name, ) def indexAction(self):