diff --git a/htdocs/lib/settings/FrequencyInput.js b/htdocs/lib/settings/FrequencyInput.js new file mode 100644 index 0000000..482f658 --- /dev/null +++ b/htdocs/lib/settings/FrequencyInput.js @@ -0,0 +1,21 @@ +$.fn.frequencyInput = function() { + this.each(function(){ + var $group = $(this); + var currentExponent = 0; + $input = $group.find('input'); + + var setExponent = function() { + var newExponent = parseInt($exponent.val()); + var delta = currentExponent - newExponent; + $input.val(parseFloat($input.val()) * 10 ** delta); + currentExponent = newExponent; + }; + + $exponent = $group.find('select.frequency-exponent'); + $exponent.on('change', setExponent); + + // calculate initial exponent + $exponent.val(Math.floor(Math.log10($input.val()) / 3) * 3); + setExponent(); + }) +}; \ No newline at end of file diff --git a/htdocs/settings.js b/htdocs/settings.js index 3ac5e53..f3a2d44 100644 --- a/htdocs/settings.js +++ b/htdocs/settings.js @@ -7,4 +7,5 @@ $(function(){ $('#rf_gain').gainInput(); $('.optional-section').optionalSection(); $('#scheduler').schedulerInput(); + $('.frequency-input').frequencyInput(); }); \ No newline at end of file diff --git a/owrx/controllers/assets.py b/owrx/controllers/assets.py index 1613eec..d42ae23 100644 --- a/owrx/controllers/assets.py +++ b/owrx/controllers/assets.py @@ -153,6 +153,7 @@ class CompiledAssetsController(GzipMixin, ModificationAwareController): "lib/settings/GainInput.js", "lib/settings/OptionalSection.js", "lib/settings/SchedulerInput.js", + "lib/settings/FrequencyInput.js", "settings.js", ], } diff --git a/owrx/form/__init__.py b/owrx/form/__init__.py index 08d6408..f603738 100644 --- a/owrx/form/__init__.py +++ b/owrx/form/__init__.py @@ -319,3 +319,49 @@ class ModesInput(DropdownInput): def __init__(self, id, label): options = [Option(m.modulation, m.name) for m in Modes.getAvailableModes()] super().__init__(id, label, options) + + +class FrequencyInput(Input): + def __init__(self, id, label): + super().__init__(id, label) + + def defaultConverter(self): + return IntConverter() + + def input_properties(self, value): + props = super().input_properties(value) + props["type"] = "number" + props["step"] = "any" + return props + + def render_input(self, value): + append = """ +