diff --git a/htdocs/lib/BookmarkBar.js b/htdocs/lib/BookmarkBar.js index 653eb02..ecae43b 100644 --- a/htdocs/lib/BookmarkBar.js +++ b/htdocs/lib/BookmarkBar.js @@ -102,40 +102,26 @@ BookmarkBar.prototype.render = function(){ }; BookmarkBar.prototype.showEditDialog = function(bookmark) { - var $form = this.$dialog.find("form"); if (!bookmark) { bookmark = { name: "", frequency: center_freq + this.getDemodulator().get_offset_frequency(), - modulation: this.getDemodulator().get_modulation() + modulation: this.getDemodulator().get_secondary_demod() || this.getDemodulator().get_modulation() } } - ['name', 'frequency', 'modulation'].forEach(function(key){ - $form.find('#' + key).val(bookmark[key]); - }); - this.$dialog.data('id', bookmark.id); + this.$dialog.bookmarkDialog().setValues(bookmark); this.$dialog.show(); this.$dialog.find('#name').focus(); }; BookmarkBar.prototype.storeBookmark = function() { var me = this; - var bookmark = {}; - var valid = true; - ['name', 'frequency', 'modulation'].forEach(function(key){ - var $input = me.$dialog.find('#' + key); - valid = valid && $input[0].checkValidity(); - bookmark[key] = $input.val(); - }); - if (!valid) { - me.$dialog.find("form :submit").click(); - return; - } + var bookmark = this.$dialog.bookmarkDialog().getValues(); + if (!bookmark) return; bookmark.frequency = Number(bookmark.frequency); var bookmarks = me.localBookmarks.getBookmarks(); - bookmark.id = me.$dialog.data('id'); if (!bookmark.id) { if (bookmarks.length) { bookmark.id = 1 + Math.max.apply(Math, bookmarks.map(function(b){ return b.id || 0; })); diff --git a/htdocs/lib/BookmarkDialog.js b/htdocs/lib/BookmarkDialog.js index 6d2f113..4a0a184 100644 --- a/htdocs/lib/BookmarkDialog.js +++ b/htdocs/lib/BookmarkDialog.js @@ -7,6 +7,30 @@ $.fn.bookmarkDialog = function() { }).map(function(m) { return ''; }).join('')); + return this; + }, + setValues: function(bookmark) { + var $form = $el.find('form'); + ['name', 'frequency', 'modulation'].forEach(function(key){ + $form.find('#' + key).val(bookmark[key]); + }); + $el.data('id', bookmark.id || false); + return this; + }, + getValues: function() { + var bookmark = {}; + var valid = true; + ['name', 'frequency', 'modulation'].forEach(function(key){ + var $input = $el.find('#' + key); + valid = valid && $input[0].checkValidity(); + bookmark[key] = $input.val(); + }); + if (!valid) { + $el.find("form :submit").click(); + return; + } + bookmark.id = $el.data('id'); + return bookmark; } } } \ No newline at end of file