Skip to content

Commit b7c0847

Browse files
committed
luci-base: jsdoc Slider -> RangeSlider and fixes for RangeSlider
The usecalc property suffers from recursive calculation; that is, its output becomes its input at the next save. It is not known in advance whether a stored value is one that was calculated or not. So this part was removed. The getCalculatedValue() function is retained should it be desirable to get this value. The 'optional' property was removed since it didn't do anything. The 'validate' property is now correctly bound. Signed-off-by: Paul Donald <[email protected]>
1 parent 4d5ac5b commit b7c0847

File tree

2 files changed

+44
-32
lines changed

2 files changed

+44
-32
lines changed

modules/luci-base/htdocs/luci-static/resources/form.js

Lines changed: 4 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -4209,38 +4209,19 @@ const CBIRangeSliderValue = CBIValue.extend(/** @lends LuCI.form.RangeSliderValu
42094209
* @default null
42104210
*/
42114211

4212-
/**
4213-
* Whether to use the calculated result of the chosen value instead of the
4214-
* chosen value: the result of the calculation returned by the
4215-
* <code>calculate</code> function on the chosen value
4216-
* is written to the configuration instead of the chosen value. The
4217-
* <code>calcunits</code> displayed units are not included.
4218-
*
4219-
* Note: Implementers of the <code>calculate</code> function shall be
4220-
* mindful that it may be possible to return a NaN value which is seldom a
4221-
* sensible input for the underlying daemon or system. Verification of any
4222-
* calculated value is an exercise left to the implementer.
4223-
*
4224-
* @name LuCI.form.RangeSliderValue.prototype#usecalc
4225-
* @type boolean
4226-
* @default false
4227-
*/
4228-
42294212
/** @private */
42304213
renderWidget(section_id, option_index, cfgvalue) {
42314214
const slider = new ui.RangeSlider((cfgvalue != null) ? cfgvalue : this.default, {
42324215
id: this.cbid(section_id),
42334216
name: this.cbid(section_id),
4234-
optional: this.optional,
42354217
min: this.min,
42364218
max: this.max,
42374219
step: this.step,
42384220
calculate: this.calculate,
42394221
calcunits: this.calcunits,
4240-
usecalc: this.usecalc,
42414222
disabled: this.readonly || this.disabled,
42424223
datatype: this.datatype,
4243-
validate: this.validate,
4224+
validate: L.bind(this.validate, this, section_id),
42444225
});
42454226

42464227
this.widget = slider;
@@ -4255,15 +4236,13 @@ const CBIRangeSliderValue = CBIValue.extend(/** @lends LuCI.form.RangeSliderValu
42554236
* The configuration section ID
42564237
*
42574238
* @returns {*}
4258-
* Returns the current input value.
4239+
* Returns the currently selected value if it does not match the default.
4240+
* If the currently selected value matches the default value, returns null.
42594241
*/
42604242
formvalue(section_id) {
42614243
const elem = this.getUIElement(section_id);
42624244
if (!elem) return null;
4263-
let val = (this.usecalc && (typeof this.calculate === 'function'))
4264-
? elem.getCalculatedValue()
4265-
: elem.getValue();
4266-
val = val?.toString();
4245+
const val = elem.getValue().toString();
42674246
return (val === this.default?.toString()) ? null : val;
42684247
}
42694248
});

modules/luci-base/htdocs/luci-static/resources/ui.js

Lines changed: 40 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2647,7 +2647,7 @@ const UIDynamicList = UIElement.extend(/** @lends LuCI.ui.DynamicList.prototype
26472647
/**
26482648
* Instantiate a range slider widget.
26492649
*
2650-
* @constructor Slider
2650+
* @constructor RangeSlider
26512651
* @memberof LuCI.ui
26522652
* @augments LuCI.ui.AbstractElement
26532653
*
@@ -2661,25 +2661,53 @@ const UIDynamicList = UIElement.extend(/** @lends LuCI.ui.DynamicList.prototype
26612661
* instantiating CBI forms.
26622662
*
26632663
* This class is automatically instantiated as part of `LuCI.ui`. To use it
2664-
* in views, use `'require ui'` and refer to `ui.Slider`. To import it in
2664+
* in views, use `'require ui'` and refer to `ui.RangeSlider`. To import it in
26652665
* external JavaScript, use `L.require("ui").then(...)` and access the
2666-
* `Slider` property of the class instance value.
2666+
* `RangeSlider` property of the class instance value.
26672667
*
26682668
* @param {string|string[]} [value=null]
2669-
* ...
2669+
* The initial value to set the slider handle position.
26702670
*
2671+
* @param {LuCI.ui.RangeSlider.InitOptions} [options]
2672+
* Object describing the widget specific options to initialize the range slider.
26712673
*/
26722674
const UIRangeSlider = UIElement.extend({
2675+
/**
2676+
* In addition to the [AbstractElement.InitOptions]{@link LuCI.ui.AbstractElement.InitOptions}
2677+
* the following properties are recognized:
2678+
*
2679+
* @typedef {LuCI.ui.AbstractElement.InitOptions} InitOptions
2680+
* @memberof LuCI.ui.RangeSlider
2681+
*
2682+
* @property {int} [min=1]
2683+
* Specifies the minimum value of the range.
2684+
*
2685+
* @property {int} [max=100]
2686+
* Specifies the maximum value of the range.
2687+
*
2688+
* @property {int} [step=1]
2689+
* Specifies the step value of the range slider handle.
2690+
*
2691+
* @param {function} [calculate=null]
2692+
* A function to invoke when the slider is adjusted by the user. The function
2693+
* performs a calculation on the selected value to produce a new value.
2694+
*
2695+
* @property {string} [calcunits=null]
2696+
* Specifies a suffix string to append to the calculated value output.
2697+
*
2698+
* @property {boolean} [disabled=false]
2699+
* Specifies whether the the widget is disabled.
2700+
*
2701+
*/
2702+
26732703
__init__(value, options) {
26742704
this.value = value;
26752705
this.options = Object.assign({
2676-
optional: true,
26772706
min: 0,
26782707
max: 100,
26792708
step: 1,
26802709
calculate: null,
26812710
calcunits: null,
2682-
usecalc: false,
26832711
disabled: false,
26842712
}, options);
26852713
},
@@ -2744,7 +2772,12 @@ const UIRangeSlider = UIElement.extend({
27442772
return this.sliderEl.value;
27452773
},
27462774

2747-
/** @private */
2775+
/**
2776+
* Return the value calculated by the `calculate` function.
2777+
*
2778+
* @instance
2779+
* @memberof LuCI.ui.RangeSlider
2780+
*/
27482781
getCalculatedValue() {
27492782
return this.calculatedvalue;
27502783
},

0 commit comments

Comments
 (0)