From bd9cdc1cba937df8be64017267e2b8e8168d6f0f Mon Sep 17 00:00:00 2001 From: Jakob Ketterl Date: Sat, 28 Sep 2019 20:15:47 +0200 Subject: [PATCH] buttons and storage action --- htdocs/css/openwebrx.css | 16 ++++++++++++++ htdocs/index.html | 7 +++++- htdocs/openwebrx.js | 47 +++++++++++++++++++++++++++++++++++----- 3 files changed, 63 insertions(+), 7 deletions(-) diff --git a/htdocs/css/openwebrx.css b/htdocs/css/openwebrx.css index 2bae781..f91a592 100644 --- a/htdocs/css/openwebrx.css +++ b/htdocs/css/openwebrx.css @@ -977,6 +977,10 @@ img.openwebrx-mirror-img flex-direction: row; } +.openwebrx-dialog .form-field:first-child { + padding-top: 0; +} + .openwebrx-dialog label { display: inline-block; flex: 1 0 20px; @@ -995,6 +999,18 @@ img.openwebrx-mirror-img padding: 0 5px; } +.openwebrx-dialog .buttons { + text-align: right; + padding: 5px 5px 0; + border-top: 1px solid #666; +} + +.openwebrx-dialog .buttons .openwebrx-button { + font-size: 12pt; + min-width: 50px; + text-align: center; + padding: 5px 10px; +} #openwebrx-panel-digimodes[data-mode="ft8"] #openwebrx-digimode-content-container, #openwebrx-panel-digimodes[data-mode="wspr"] #openwebrx-digimode-content-container, diff --git a/htdocs/index.html b/htdocs/index.html index 4f5a4d2..11bb2b1 100644 --- a/htdocs/index.html +++ b/htdocs/index.html @@ -226,7 +226,7 @@
- +
@@ -242,6 +242,11 @@
+
+
Cancel
+
Ok
+
+ diff --git a/htdocs/openwebrx.js b/htdocs/openwebrx.js index d9943a9..0aca058 100644 --- a/htdocs/openwebrx.js +++ b/htdocs/openwebrx.js @@ -1337,7 +1337,7 @@ function on_ws_recv(evt) } function update_bookmarks(bookmarks) { - $container = $('#openwebrx-bookmarks-container'); + var $container = $('#openwebrx-bookmarks-container'); $container.empty(); bookmarks.forEach(function(b){ $bookmark = $('
' + b.name + '
'); @@ -1348,14 +1348,14 @@ function update_bookmarks(bookmarks) { } function position_bookmarks() { - range = get_visible_freq_range(); + var range = get_visible_freq_range(); $('#openwebrx-bookmarks-container .bookmark').each(function(){ $(this).css('left', scale_px_from_freq($(this).data('frequency'), range)); }); } function init_bookmarks() { - $container = $("#openwebrx-bookmarks-container") + var $container = $("#openwebrx-bookmarks-container") $container.click(function(e){ $container.find('.bookmark').removeClass('selected'); $bookmark = $(e.target); @@ -1366,7 +1366,7 @@ function init_bookmarks() { $bookmark.addClass('selected'); }); - $bookmarkButton = $('#openwebrx-panel-receiver .openwebrx-bookmark-button'); + var $bookmarkButton = $('#openwebrx-panel-receiver .openwebrx-bookmark-button'); if (typeof(Storage) !== 'undefined') { $bookmarkButton.show(); } else { @@ -1375,17 +1375,52 @@ function init_bookmarks() { $bookmarkButton.click(function(){ showBookmarkEditDialog(); }); + + var $dialog = $("#openwebrx-dialog-bookmark"); + $dialog.find('.openwebrx-button[data-action=cancel]').click(function(){ + $dialog.hide(); + }); + $dialog.find('.openwebrx-button[data-action=submit]').click(function(){ + storeNewBookmark(); + }); } function showBookmarkEditDialog() { - $dialog = $("#openwebrx-dialog-bookmark"); - $form = $dialog.find("form"); + var $dialog = $("#openwebrx-dialog-bookmark"); + var $form = $dialog.find("form"); $form.find("#name").val(""); $form.find("#frequency").val(center_freq + demodulators[0].offset_frequency); $form.find("#modulation").val(demodulators[0].subtype); $dialog.show(); } +function storeNewBookmark() { + var $dialog = $("#openwebrx-dialog-bookmark"); + var bookmark = {}; + var valid = true; + ['name', 'frequency', 'modulation'].forEach(function(key){ + var $input = $dialog.find('#' + key); + valid = valid && $input[0].checkValidity(); + bookmark[key] = $input.val(); + }); + if (!valid) { + $dialog.find("form :submit").click(); + return; + } + var bookmarks = getLocalBookmarks(); + bookmarks.push(bookmark); + setLocalBookmarks(bookmarks); + $dialog.hide(); +} + +function getLocalBookmarks(){ + return JSON.parse(window.localStorage.getItem("bookmarks")) || []; +} + +function setLocalBookmarks(bookmarks){ + window.localStorage.setItem("bookmarks", JSON.stringify(bookmarks)); +} + var dial_frequencies = []; function find_dial_frequencies() {