code stringlengths 28 313k | docstring stringlengths 25 85.3k | func_name stringlengths 1 74 | language stringclasses 1
value | repo stringlengths 5 60 | path stringlengths 4 172 | url stringlengths 44 218 | license stringclasses 7
values |
|---|---|---|---|---|---|---|---|
isValid(section_id) {
const elem = this.getUIElement(section_id);
return elem ? elem.isValid() : true;
} | Test whether the input value is currently valid.
@param {string} section_id
The configuration section ID
@returns {boolean}
Returns `true` if the input value currently is valid, otherwise it
returns `false`. | isValid | javascript | openwrt/luci | modules/luci-base/htdocs/luci-static/resources/form.js | https://github.com/openwrt/luci/blob/master/modules/luci-base/htdocs/luci-static/resources/form.js | Apache-2.0 |
getValidationError(section_id) {
const elem = this.getUIElement(section_id);
return elem ? elem.getValidationError() : '';
} | Returns the current validation error for this input.
@param {string} section_id
The configuration section ID
@returns {string}
The validation error at this time | getValidationError | javascript | openwrt/luci | modules/luci-base/htdocs/luci-static/resources/form.js | https://github.com/openwrt/luci/blob/master/modules/luci-base/htdocs/luci-static/resources/form.js | Apache-2.0 |
isActive(section_id) {
const field = this.map.findElement('data-field', this.cbid(section_id));
return (field != null && !field.classList.contains('hidden'));
} | Test whether the option element is currently active.
An element is active when it is not hidden due to unsatisfied dependency
constraints.
@param {string} section_id
The configuration section ID
@returns {boolean}
Returns `true` if the option element currently is active, otherwise it
returns `false`. | isActive | javascript | openwrt/luci | modules/luci-base/htdocs/luci-static/resources/form.js | https://github.com/openwrt/luci/blob/master/modules/luci-base/htdocs/luci-static/resources/form.js | Apache-2.0 |
parse(section_id) {
const active = this.isActive(section_id);
if (active && !this.isValid(section_id)) {
const title = this.stripTags(this.title).trim();
const error = this.getValidationError(section_id);
return Promise.reject(new TypeError(
`${_('Option "%s" contains an invalid input value.').format... | Parse the option element input.
The function is invoked when the `parse()` method has been invoked on
the parent form and triggers input value reading and validation.
@param {string} section_id
The configuration section ID
@returns {Promise<void>}
Returns a promise resolving once the input value has been read and
va... | parse | javascript | openwrt/luci | modules/luci-base/htdocs/luci-static/resources/form.js | https://github.com/openwrt/luci/blob/master/modules/luci-base/htdocs/luci-static/resources/form.js | Apache-2.0 |
write(section_id, formvalue) {
return this.map.data.set(
this.uciconfig ?? this.section.uciconfig ?? this.map.config,
this.ucisection ?? section_id,
this.ucioption ?? this.option,
formvalue);
} | Write the current input value into the configuration.
This function is invoked upon saving the parent form when the option
element is valid and when its input value has been changed compared to
the initial value returned by
[cfgvalue()]{@link LuCI.form.AbstractValue#cfgvalue}.
The default implementation simply sets t... | write | javascript | openwrt/luci | modules/luci-base/htdocs/luci-static/resources/form.js | https://github.com/openwrt/luci/blob/master/modules/luci-base/htdocs/luci-static/resources/form.js | Apache-2.0 |
remove(section_id) {
const this_cfg = this.uciconfig ?? this.section.uciconfig ?? this.map.config;
const this_sid = this.ucisection ?? section_id;
const this_opt = this.ucioption ?? this.option;
for (let i = 0; i < this.section.children.length; i++) {
const sibling = this.section.children[i];
if (siblin... | Remove the corresponding value from the configuration.
This function is invoked upon saving the parent form when the option
element has been hidden due to unsatisfied dependencies or when the
user cleared the input value and the option is marked optional.
The default implementation simply removes the associated optio... | remove | javascript | openwrt/luci | modules/luci-base/htdocs/luci-static/resources/form.js | https://github.com/openwrt/luci/blob/master/modules/luci-base/htdocs/luci-static/resources/form.js | Apache-2.0 |
tab() {
throw 'Tabs are not supported by TableSection';
} | The `TableSection` implementation does not support option tabbing, so
its implementation of `tab()` will always throw an exception when
invoked.
@override
@throws Throws an exception when invoked. | tab | javascript | openwrt/luci | modules/luci-base/htdocs/luci-static/resources/form.js | https://github.com/openwrt/luci/blob/master/modules/luci-base/htdocs/luci-static/resources/form.js | Apache-2.0 |
cfgsections() {
return [ this.section ];
} | The `NamedSection` class overrides the generic `cfgsections()`
implementation to return a one-element array containing the mapped
section ID as sole element. User code should not normally change this.
@returns {string[]}
Returns a one-element array containing the mapped section ID. | cfgsections | javascript | openwrt/luci | modules/luci-base/htdocs/luci-static/resources/form.js | https://github.com/openwrt/luci/blob/master/modules/luci-base/htdocs/luci-static/resources/form.js | Apache-2.0 |
formvalue(section_id) {
const elem = this.getUIElement(section_id);
const checked = elem ? elem.isChecked() : false;
return checked ? this.enabled : this.disabled;
} | Query the checked state of the underlying checkbox widget and return
either the `enabled` or the `disabled` property value, depending on
the checked state.
@override | formvalue | javascript | openwrt/luci | modules/luci-base/htdocs/luci-static/resources/form.js | https://github.com/openwrt/luci/blob/master/modules/luci-base/htdocs/luci-static/resources/form.js | Apache-2.0 |
textvalue(section_id) {
let cval = this.cfgvalue(section_id);
if (cval == null)
cval = this.default;
return (cval == this.enabled) ? _('Yes') : _('No');
} | Query the checked state of the underlying checkbox widget and return
either a localized `Yes` or `No` string, depending on the checked state.
@override | textvalue | javascript | openwrt/luci | modules/luci-base/htdocs/luci-static/resources/form.js | https://github.com/openwrt/luci/blob/master/modules/luci-base/htdocs/luci-static/resources/form.js | Apache-2.0 |
function handleRpcReply(expect, rc) {
if (typeof(rc) == 'number' && rc != 0) {
var e = new Error(rpc.getStatusText(rc)); e.name = rpcErrors[rc] || 'Error';
throw e;
}
if (expect) {
var type = Object.prototype.toString;
for (var key in expect) {
if (rc != null && key != '')
rc = rc[key];
if (rc =... | @typedef {Object} FileExecResult
@memberof LuCI.fs
@property {number} code - The exit code of the invoked command
@property {string} [stdout] - The stdout produced by the command, if any
@property {string} [stderr] - The stderr produced by the command, if any | handleRpcReply | javascript | openwrt/luci | modules/luci-base/htdocs/luci-static/resources/fs.js | https://github.com/openwrt/luci/blob/master/modules/luci-base/htdocs/luci-static/resources/fs.js | Apache-2.0 |
extend(properties) {
const props = {
__id__: { value: classIndex },
__base__: { value: this.prototype },
__name__: { value: properties.__name__ ?? `anonymous${classIndex++}` }
};
const ClassConstructor = function() {
if (!(this instanceof ClassConstructor))
throw new TypeError('Constructo... | Extends this base class with the properties described in
`properties` and returns a new subclassed Class instance
@memberof LuCI.baseclass
@param {Object<string, *>} properties
An object describing the properties to add to the new
subclass.
@returns {LuCI.baseclass}
Returns a new LuCI.baseclass subclassed from this ... | extend | javascript | openwrt/luci | modules/luci-base/htdocs/luci-static/resources/luci.js | https://github.com/openwrt/luci/blob/master/modules/luci-base/htdocs/luci-static/resources/luci.js | Apache-2.0 |
singleton(properties, ...new_args) {
return Class.extend(properties).instantiate(new_args);
} | Extends this base class with the properties described in
`properties`, instantiates the resulting subclass using
the additional optional arguments passed to this function
and returns the resulting subclassed Class instance.
This function serves as a convenience shortcut for
{@link LuCI.baseclass.extend Class.extend()}... | singleton | javascript | openwrt/luci | modules/luci-base/htdocs/luci-static/resources/luci.js | https://github.com/openwrt/luci/blob/master/modules/luci-base/htdocs/luci-static/resources/luci.js | Apache-2.0 |
instantiate(args) {
return new (Function.prototype.bind.call(this, null, ...args))();
} | Calls the class constructor using `new` with the given argument
array being passed as variadic parameters to the constructor.
@memberof LuCI.baseclass
@param {Array<*>} params
An array of arbitrary values which will be passed as arguments
to the constructor function.
@returns {LuCI.baseclass}
Returns a new LuCI.base... | instantiate | javascript | openwrt/luci | modules/luci-base/htdocs/luci-static/resources/luci.js | https://github.com/openwrt/luci/blob/master/modules/luci-base/htdocs/luci-static/resources/luci.js | Apache-2.0 |
isSubclass(classValue) {
return (typeof(classValue) == 'function' && classValue.prototype instanceof this);
} | Checks whether the given class value is a subclass of this class.
@memberof LuCI.baseclass
@param {LuCI.baseclass} classValue
The class object to test.
@returns {boolean}
Returns `true` when the given `classValue` is a subclass of this
class or `false` if the given value is not a valid class or not
a subclass of thi... | isSubclass | javascript | openwrt/luci | modules/luci-base/htdocs/luci-static/resources/luci.js | https://github.com/openwrt/luci/blob/master/modules/luci-base/htdocs/luci-static/resources/luci.js | Apache-2.0 |
varargs(args, offset, ...extra_args) {
return extra_args.concat(Array.prototype.slice.call(args, offset));
} | Extract all values from the given argument array beginning from
`offset` and prepend any further given optional parameters to
the beginning of the resulting array copy.
@memberof LuCI.baseclass
@instance
@param {Array<*>} args
The array to extract the values from.
@param {number} offset
The offset from which to extr... | varargs | javascript | openwrt/luci | modules/luci-base/htdocs/luci-static/resources/luci.js | https://github.com/openwrt/luci/blob/master/modules/luci-base/htdocs/luci-static/resources/luci.js | Apache-2.0 |
super(key, ...callArgs) {
if (key == null)
return null;
const slotIdx = `${this.__id__}.${key}`;
const symStack = superContext[slotIdx];
let protoCtx = null;
for (protoCtx = Object.getPrototypeOf(symStack ? symStack[0] : Object.getPrototypeOf(this));
protoCtx != null && !protoCtx.hasOwn... | Walks up the parent class chain and looks for a class member
called `key` in any of the parent classes this class inherits
from. Returns the member value of the superclass or calls the
member as function and returns its return value when the
optional `callArgs` array is given.
This function has two signatures and is s... | super | javascript | openwrt/luci | modules/luci-base/htdocs/luci-static/resources/luci.js | https://github.com/openwrt/luci/blob/master/modules/luci-base/htdocs/luci-static/resources/luci.js | Apache-2.0 |
toString() {
let s = `[${this.constructor.displayName}]`, f = true;
for (const k in this) {
if (this.hasOwnProperty(k)) {
s += `${f ? ' {\n' : ''} ${k}: ${typeof(this[k])}\n`;
f = false;
}
}
return s + (f ? '' : '}');
} | Returns a string representation of this class.
@returns {string}
Returns a string representation of this class containing the
constructor functions `displayName` and describing the class
members and their respective types. | toString | javascript | openwrt/luci | modules/luci-base/htdocs/luci-static/resources/luci.js | https://github.com/openwrt/luci/blob/master/modules/luci-base/htdocs/luci-static/resources/luci.js | Apache-2.0 |
has(name) {
return this.headers.hasOwnProperty(String(name).toLowerCase());
} | Checks whether the given header name is present.
Note: Header-Names are case-insensitive.
@instance
@memberof LuCI.headers
@param {string} name
The header name to check
@returns {boolean}
Returns `true` if the header name is present, `false` otherwise | has | javascript | openwrt/luci | modules/luci-base/htdocs/luci-static/resources/luci.js | https://github.com/openwrt/luci/blob/master/modules/luci-base/htdocs/luci-static/resources/luci.js | Apache-2.0 |
get(name) {
const key = String(name).toLowerCase();
return this.headers.hasOwnProperty(key) ? this.headers[key] : null;
} | Returns the value of the given header name.
Note: Header-Names are case-insensitive.
@instance
@memberof LuCI.headers
@param {string} name
The header name to read
@returns {string|null}
The value of the given header name or `null` if the header isn't present. | get | javascript | openwrt/luci | modules/luci-base/htdocs/luci-static/resources/luci.js | https://github.com/openwrt/luci/blob/master/modules/luci-base/htdocs/luci-static/resources/luci.js | Apache-2.0 |
__init__(xhr, url, duration, headers, content) {
/**
* Describes whether the response is successful (status codes `200..299`) or not
* @instance
* @memberof LuCI.response
* @name ok
* @type {boolean}
*/
this.ok = (xhr.status >= 200 && xhr.status <= 299);
/**
* The numeric HTTP stat... | @class response
@memberof LuCI
@hideconstructor
@classdesc
The `Response` class is an internal utility class representing HTTP responses. | __init__ | javascript | openwrt/luci | modules/luci-base/htdocs/luci-static/resources/luci.js | https://github.com/openwrt/luci/blob/master/modules/luci-base/htdocs/luci-static/resources/luci.js | Apache-2.0 |
clone(content) {
const copy = new Response(this.xhr, this.url, this.duration, this.headers, content);
copy.ok = this.ok;
copy.status = this.status;
copy.statusText = this.statusText;
return copy;
} | Clones the given response object, optionally overriding the content
of the cloned instance.
@instance
@memberof LuCI.response
@param {*} [content]
Override the content of the cloned response. Object values will be
treated as JSON response data, all other types will be converted
using `String()` and treated as response... | clone | javascript | openwrt/luci | modules/luci-base/htdocs/luci-static/resources/luci.js | https://github.com/openwrt/luci/blob/master/modules/luci-base/htdocs/luci-static/resources/luci.js | Apache-2.0 |
json() {
if (this.responseJSON == null)
this.responseJSON = JSON.parse(this.responseText);
return this.responseJSON;
} | Access the response content as JSON data.
@instance
@memberof LuCI.response
@throws {SyntaxError}
Throws `SyntaxError` if the content isn't valid JSON.
@returns {*}
The parsed JSON data. | json | javascript | openwrt/luci | modules/luci-base/htdocs/luci-static/resources/luci.js | https://github.com/openwrt/luci/blob/master/modules/luci-base/htdocs/luci-static/resources/luci.js | Apache-2.0 |
text() {
if (this.responseText == null && this.responseJSON != null)
this.responseText = JSON.stringify(this.responseJSON);
return this.responseText;
} | Access the response content as string.
@instance
@memberof LuCI.response
@returns {string}
The response content. | text | javascript | openwrt/luci | modules/luci-base/htdocs/luci-static/resources/luci.js | https://github.com/openwrt/luci/blob/master/modules/luci-base/htdocs/luci-static/resources/luci.js | Apache-2.0 |
blob() {
return this.responseBlob;
} | Access the response content as blob.
@instance
@memberof LuCI.response
@returns {Blob}
The response content as blob. | blob | javascript | openwrt/luci | modules/luci-base/htdocs/luci-static/resources/luci.js | https://github.com/openwrt/luci/blob/master/modules/luci-base/htdocs/luci-static/resources/luci.js | Apache-2.0 |
expandURL(url) {
if (!/^(?:[^/]+:)?\/\//.test(url))
url = `${location.protocol}//${location.host}${url}`;
return url;
} | Turn the given relative URL into an absolute URL if necessary.
@instance
@memberof LuCI.request
@param {string} url
The URL to convert.
@returns {string}
The absolute URL derived from the given one, or the original URL
if it already was absolute. | expandURL | javascript | openwrt/luci | modules/luci-base/htdocs/luci-static/resources/luci.js | https://github.com/openwrt/luci/blob/master/modules/luci-base/htdocs/luci-static/resources/luci.js | Apache-2.0 |
request(target, options) {
return Promise.resolve(target).then(url => {
const state = { xhr: new XMLHttpRequest(), url: this.expandURL(url), start: Date.now() };
const opt = Object.assign({}, options, state);
let content = null;
let contenttype = null;
const callback = this.handleReadyStateChange... | Initiate an HTTP request to the given target.
@instance
@memberof LuCI.request
@param {string} target
The URL to request.
@param {LuCI.request.RequestOptions} [options]
Additional options to configure the request.
@returns {Promise<LuCI.response>}
The resulting HTTP response. | request | javascript | openwrt/luci | modules/luci-base/htdocs/luci-static/resources/luci.js | https://github.com/openwrt/luci/blob/master/modules/luci-base/htdocs/luci-static/resources/luci.js | Apache-2.0 |
get(url, options) {
return this.request(url, Object.assign({ method: 'GET' }, options));
} | Initiate an HTTP GET request to the given target.
@instance
@memberof LuCI.request
@param {string} url
The URL to request.
@param {LuCI.request.RequestOptions} [options]
Additional options to configure the request.
@returns {Promise<LuCI.response>}
The resulting HTTP response. | get | javascript | openwrt/luci | modules/luci-base/htdocs/luci-static/resources/luci.js | https://github.com/openwrt/luci/blob/master/modules/luci-base/htdocs/luci-static/resources/luci.js | Apache-2.0 |
post(url, data, options) {
return this.request(url, Object.assign({ method: 'POST', content: data }, options));
} | Initiate an HTTP POST request to the given target.
@instance
@memberof LuCI.request
@param {string} url
The URL to request.
@param {*} [data]
The request data to send, see {@link LuCI.request.RequestOptions} for details.
@param {LuCI.request.RequestOptions} [options]
Additional options to configure the request.
@re... | post | javascript | openwrt/luci | modules/luci-base/htdocs/luci-static/resources/luci.js | https://github.com/openwrt/luci/blob/master/modules/luci-base/htdocs/luci-static/resources/luci.js | Apache-2.0 |
addInterceptor(interceptorFn) {
if (typeof(interceptorFn) == 'function')
this.interceptors.push(interceptorFn);
return interceptorFn;
} | Register an HTTP response interceptor function. Interceptor
functions are useful to perform default actions on incoming HTTP
responses, such as checking for expired authentication or for
implementing request retries before returning a failure.
@instance
@memberof LuCI.request
@param {LuCI.request.interceptorFn} interc... | addInterceptor | javascript | openwrt/luci | modules/luci-base/htdocs/luci-static/resources/luci.js | https://github.com/openwrt/luci/blob/master/modules/luci-base/htdocs/luci-static/resources/luci.js | Apache-2.0 |
removeInterceptor(interceptorFn) {
const oldlen = this.interceptors.length;
let i = oldlen;
while (i--)
if (this.interceptors[i] === interceptorFn)
this.interceptors.splice(i, 1);
return (this.interceptors.length < oldlen);
} | Remove an HTTP response interceptor function. The passed function
value must be the very same value that was used to register the
function.
@instance
@memberof LuCI.request
@param {LuCI.request.interceptorFn} interceptorFn
The interceptor function to remove.
@returns {boolean}
Returns `true` if any function has been ... | removeInterceptor | javascript | openwrt/luci | modules/luci-base/htdocs/luci-static/resources/luci.js | https://github.com/openwrt/luci/blob/master/modules/luci-base/htdocs/luci-static/resources/luci.js | Apache-2.0 |
add(interval, url, options, callback) {
if (isNaN(interval) || interval <= 0)
throw new TypeError('Invalid poll interval');
const ival = interval >>> 0, opts = Object.assign({}, options, { timeout: ival * 1000 - 5 });
const fn = () => Request.request(url, opts).then(res => {
if (!Poll.active())
... | Register a repeating HTTP request with an optional callback
to invoke whenever a response for the request is received.
@instance
@memberof LuCI.request.poll
@param {number} interval
The poll interval in seconds.
@param {string} url
The URL to request on each poll.
@param {LuCI.request.RequestOptions} [options]
Addit... | add | javascript | openwrt/luci | modules/luci-base/htdocs/luci-static/resources/luci.js | https://github.com/openwrt/luci/blob/master/modules/luci-base/htdocs/luci-static/resources/luci.js | Apache-2.0 |
add(fn, interval) {
if (interval == null || interval <= 0)
interval = env.pollinterval || null;
if (isNaN(interval) || typeof(fn) != 'function')
throw new TypeError('Invalid argument to LuCI.poll.add()');
for (let i = 0; i < this.queue.length; i++)
if (this.queue[i].fn === fn)
return false;
... | Add a new operation to the polling loop. If the polling loop is not
already started at this point, it will be implicitly started.
@instance
@memberof LuCI.poll
@param {function} fn
The function to invoke on each poll interval.
@param {number} interval
The poll interval in seconds.
@throws {TypeError}
Throws `TypeErr... | add | javascript | openwrt/luci | modules/luci-base/htdocs/luci-static/resources/luci.js | https://github.com/openwrt/luci/blob/master/modules/luci-base/htdocs/luci-static/resources/luci.js | Apache-2.0 |
remove(fn) {
if (typeof(fn) != 'function')
throw new TypeError('Invalid argument to LuCI.poll.remove()');
const len = this.queue.length;
for (let i = len; i > 0; i--)
if (this.queue[i-1].fn === fn)
this.queue.splice(i-1, 1);
if (!this.queue.length && this.stop())
this.tick = 0;
retur... | Remove an operation from the polling loop. If no further operations
are registered, the polling loop is implicitly stopped.
@instance
@memberof LuCI.poll
@param {function} fn
The function to remove.
@throws {TypeError}
Throws `TypeError` when the given argument isn't a function.
@returns {boolean}
Returns `true` if ... | remove | javascript | openwrt/luci | modules/luci-base/htdocs/luci-static/resources/luci.js | https://github.com/openwrt/luci/blob/master/modules/luci-base/htdocs/luci-static/resources/luci.js | Apache-2.0 |
start() {
if (this.active())
return false;
this.tick = 0;
if (this.queue.length) {
this.timer = window.setInterval(this.step, 1000);
this.step();
document.dispatchEvent(new CustomEvent('poll-start'));
}
return true;
} | (Re)start the polling loop. Dispatches a custom `poll-start` event
to the `document` object upon successful start.
@instance
@memberof LuCI.poll
@returns {boolean}
Returns `true` if polling has been started (or if no functions
where registered) or `false` when the polling loop already runs. | start | javascript | openwrt/luci | modules/luci-base/htdocs/luci-static/resources/luci.js | https://github.com/openwrt/luci/blob/master/modules/luci-base/htdocs/luci-static/resources/luci.js | Apache-2.0 |
stop() {
if (!this.active())
return false;
document.dispatchEvent(new CustomEvent('poll-stop'));
window.clearInterval(this.timer);
delete this.timer;
delete this.tick;
return true;
} | Stop the polling loop. Dispatches a custom `poll-stop` event
to the `document` object upon successful stop.
@instance
@memberof LuCI.poll
@returns {boolean}
Returns `true` if polling has been stopped or `false` if it didn't
run to begin with. | stop | javascript | openwrt/luci | modules/luci-base/htdocs/luci-static/resources/luci.js | https://github.com/openwrt/luci/blob/master/modules/luci-base/htdocs/luci-static/resources/luci.js | Apache-2.0 |
active() {
return (this.timer != null);
} | Test whether the polling loop is running.
@instance
@memberof LuCI.poll
@returns {boolean} - Returns `true` if polling is active, else `false`. | active | javascript | openwrt/luci | modules/luci-base/htdocs/luci-static/resources/luci.js | https://github.com/openwrt/luci/blob/master/modules/luci-base/htdocs/luci-static/resources/luci.js | Apache-2.0 |
elem(e) {
return (e != null && typeof(e) == 'object' && 'nodeType' in e);
} | Tests whether the given argument is a valid DOM `Node`.
@instance
@memberof LuCI.dom
@param {*} e
The value to test.
@returns {boolean}
Returns `true` if the value is a DOM `Node`, else `false`. | elem | javascript | openwrt/luci | modules/luci-base/htdocs/luci-static/resources/luci.js | https://github.com/openwrt/luci/blob/master/modules/luci-base/htdocs/luci-static/resources/luci.js | Apache-2.0 |
parse(s) {
try {
return domParser.parseFromString(s, 'text/html').body.firstChild;
}
catch(e) {
return null;
}
} | Parses a given string as HTML and returns the first child node.
@instance
@memberof LuCI.dom
@param {string} s
A string containing an HTML fragment to parse. Note that only
the first result of the resulting structure is returned, so an
input value of `<div>foo</div> <div>bar</div>` will only return
the first `div` ele... | parse | javascript | openwrt/luci | modules/luci-base/htdocs/luci-static/resources/luci.js | https://github.com/openwrt/luci/blob/master/modules/luci-base/htdocs/luci-static/resources/luci.js | Apache-2.0 |
matches(node, selector) {
const m = this.elem(node) ? (node.matches ?? node.msMatchesSelector) : null;
return m ? m.call(node, selector) : false;
} | Tests whether a given `Node` matches the given query selector.
This function is a convenience wrapper around the standard
`Node.matches("selector")` function with the added benefit that
the `node` argument may be a non-`Node` value, in which case
this function simply returns `false`.
@instance
@memberof LuCI.dom
@par... | matches | javascript | openwrt/luci | modules/luci-base/htdocs/luci-static/resources/luci.js | https://github.com/openwrt/luci/blob/master/modules/luci-base/htdocs/luci-static/resources/luci.js | Apache-2.0 |
parent(node, selector) {
if (this.elem(node) && node.closest)
return node.closest(selector);
while (this.elem(node))
if (this.matches(node, selector))
return node;
else
node = node.parentNode;
return null;
} | Returns the closest parent node that matches the given query
selector expression.
This function is a convenience wrapper around the standard
`Node.closest("selector")` function with the added benefit that
the `node` argument may be a non-`Node` value, in which case
this function simply returns `null`.
@instance
@memb... | parent | javascript | openwrt/luci | modules/luci-base/htdocs/luci-static/resources/luci.js | https://github.com/openwrt/luci/blob/master/modules/luci-base/htdocs/luci-static/resources/luci.js | Apache-2.0 |
append(node, children) {
if (!this.elem(node))
return null;
if (Array.isArray(children)) {
for (let i = 0; i < children.length; i++)
if (this.elem(children[i]))
node.appendChild(children[i]);
else if (children !== null && children !== undefined)
node.appendChild(document.createTextN... | Appends the given children data to the given node.
@instance
@memberof LuCI.dom
@param {*} node
The `Node` argument to append the children to.
@param {*} [children]
The children to append to the given node.
When `children` is an array, then each item of the array
will be either appended as child element or text node... | append | javascript | openwrt/luci | modules/luci-base/htdocs/luci-static/resources/luci.js | https://github.com/openwrt/luci/blob/master/modules/luci-base/htdocs/luci-static/resources/luci.js | Apache-2.0 |
content(node, children) {
if (!this.elem(node))
return null;
const dataNodes = node.querySelectorAll('[data-idref]');
for (let i = 0; i < dataNodes.length; i++)
delete this.registry[dataNodes[i].getAttribute('data-idref')];
while (node.firstChild)
node.removeChild(node.firstChild);
return... | Replaces the content of the given node with the given children.
This function first removes any children of the given DOM
`Node` and then adds the given children following the
rules outlined below.
@instance
@memberof LuCI.dom
@param {*} node
The `Node` argument to replace the children of.
@param {*} [children]
The ... | content | javascript | openwrt/luci | modules/luci-base/htdocs/luci-static/resources/luci.js | https://github.com/openwrt/luci/blob/master/modules/luci-base/htdocs/luci-static/resources/luci.js | Apache-2.0 |
attr(node, key, val) {
if (!this.elem(node))
return null;
let attr = null;
if (typeof(key) === 'object' && key !== null)
attr = key;
else if (typeof(key) === 'string')
attr = {}, attr[key] = val;
for (key in attr) {
if (!attr.hasOwnProperty(key) || attr[key] == null)
continue;
... | Sets attributes or registers event listeners on element nodes.
@instance
@memberof LuCI.dom
@param {*} node
The `Node` argument to set the attributes or add the event
listeners for. When the given `node` value is not a valid
DOM `Node`, the function returns and does nothing.
@param {string|Object<string, *>} key
Spec... | attr | javascript | openwrt/luci | modules/luci-base/htdocs/luci-static/resources/luci.js | https://github.com/openwrt/luci/blob/master/modules/luci-base/htdocs/luci-static/resources/luci.js | Apache-2.0 |
create() {
const html = arguments[0];
let attr = arguments[1];
let data = arguments[2];
let elem;
if (!(attr instanceof Object) || Array.isArray(attr))
data = attr, attr = null;
if (Array.isArray(html)) {
elem = document.createDocumentFragment();
for (let i = 0; i < html.length; i++)
... | Creates a new DOM `Node` from the given `html`, `attr` and
`data` parameters.
This function has multiple signatures, it can be either invoked
in the form `create(html[, attr[, data]])` or in the form
`create(html[, data])`. The used variant is determined from the
type of the second argument.
@instance
@memberof LuCI.... | create | javascript | openwrt/luci | modules/luci-base/htdocs/luci-static/resources/luci.js | https://github.com/openwrt/luci/blob/master/modules/luci-base/htdocs/luci-static/resources/luci.js | Apache-2.0 |
data(node, key, val) {
if (!node?.getAttribute)
return null;
let id = node.getAttribute('data-idref');
/* clear all data */
if (arguments.length > 1 && key == null) {
if (id != null) {
node.removeAttribute('data-idref');
val = this.registry[id]
delete this.registry[id];
return ... | Attaches or detaches arbitrary data to and from a DOM `Node`.
This function is useful to attach non-string values or runtime
data that is not serializable to DOM nodes. To decouple data
from the DOM, values are not added directly to nodes, but
inserted into a registry instead which is then referenced by a
string key s... | data | javascript | openwrt/luci | modules/luci-base/htdocs/luci-static/resources/luci.js | https://github.com/openwrt/luci/blob/master/modules/luci-base/htdocs/luci-static/resources/luci.js | Apache-2.0 |
bindClassInstance(node, inst) {
if (!(inst instanceof Class))
LuCI.prototype.error('TypeError', 'Argument must be a class instance');
return this.data(node, '_class', inst);
} | Binds the given class instance ot the specified DOM `Node`.
This function uses the `dom.data()` facility to attach the
passed instance of a Class to a node. This is needed for
complex widget elements or similar where the corresponding
class instance responsible for the element must be retrieved
from DOM nodes obtained... | bindClassInstance | javascript | openwrt/luci | modules/luci-base/htdocs/luci-static/resources/luci.js | https://github.com/openwrt/luci/blob/master/modules/luci-base/htdocs/luci-static/resources/luci.js | Apache-2.0 |
findClassInstance(node) {
let inst = null;
do {
inst = this.data(node, '_class');
node = node.parentNode;
}
while (!(inst instanceof Class) && node != null);
return inst;
} | Finds a bound class instance on the given node itself or the
first bound instance on its closest parent node.
@instance
@memberof LuCI.dom
@param {Node} node
The DOM `Node` instance to start from.
@returns {Class|null}
Returns the founds class instance if any or `null` if no bound
class could be found on the node its... | findClassInstance | javascript | openwrt/luci | modules/luci-base/htdocs/luci-static/resources/luci.js | https://github.com/openwrt/luci/blob/master/modules/luci-base/htdocs/luci-static/resources/luci.js | Apache-2.0 |
callClassMethod(node, method, ...args) {
const inst = this.findClassInstance(node);
if (typeof(inst?.[method]) != 'function')
return null;
return inst[method].call(inst, ...args);
} | Finds a bound class instance on the given node itself or the
first bound instance on its closest parent node and invokes
the specified method name on the found class instance.
@instance
@memberof LuCI.dom
@param {Node} node
The DOM `Node` instance to start from.
@param {string} method
The name of the method to invoke... | callClassMethod | javascript | openwrt/luci | modules/luci-base/htdocs/luci-static/resources/luci.js | https://github.com/openwrt/luci/blob/master/modules/luci-base/htdocs/luci-static/resources/luci.js | Apache-2.0 |
isEmpty(node, ignoreFn) {
for (let child = node?.firstElementChild; child != null; child = child.nextElementSibling)
if (!child.classList.contains('hidden') && !ignoreFn?.(child))
return false;
return true;
} | Tests whether a given DOM `Node` instance is empty or appears
empty.
Any element child nodes which have the CSS class `hidden` set
or for which the optionally passed `ignoreFn` callback function
returns `false` are ignored.
@instance
@memberof LuCI.dom
@param {Node} node
The DOM `Node` instance to test.
@param {LuCI... | isEmpty | javascript | openwrt/luci | modules/luci-base/htdocs/luci-static/resources/luci.js | https://github.com/openwrt/luci/blob/master/modules/luci-base/htdocs/luci-static/resources/luci.js | Apache-2.0 |
getID() {
return env.sessionid ?? '00000000000000000000000000000000';
} | Retrieve the current session ID.
@returns {string}
Returns the current session ID. | getID | javascript | openwrt/luci | modules/luci-base/htdocs/luci-static/resources/luci.js | https://github.com/openwrt/luci/blob/master/modules/luci-base/htdocs/luci-static/resources/luci.js | Apache-2.0 |
getToken() {
return env.token ?? null;
} | Retrieve the current session token.
@returns {string|null}
Returns the current session token or `null` if not logged in. | getToken | javascript | openwrt/luci | modules/luci-base/htdocs/luci-static/resources/luci.js | https://github.com/openwrt/luci/blob/master/modules/luci-base/htdocs/luci-static/resources/luci.js | Apache-2.0 |
setLocalData(key, value) {
if (key == null)
return false;
try {
const sid = this.getID();
const item = 'luci-session-store';
let data = JSON.parse(window.sessionStorage.getItem(item));
if (!LuCI.prototype.isObject(data) || !data.hasOwnProperty(sid)) {
data = {};
data[sid] = {};
... | Set data in the local session storage.
@param {string} key
The key to set in the session data store.
@param {*} value
The value to store. It will be internally converted to JSON before
being put in the session store.
@returns {boolean}
Returns `true` if the data could be stored or `false` on error. | setLocalData | javascript | openwrt/luci | modules/luci-base/htdocs/luci-static/resources/luci.js | https://github.com/openwrt/luci/blob/master/modules/luci-base/htdocs/luci-static/resources/luci.js | Apache-2.0 |
handleSave(ev) {
const tasks = [];
document.getElementById('maincontent')
.querySelectorAll('.cbi-map').forEach(map => {
tasks.push(DOM.callClassMethod(map, 'save'));
});
return Promise.all(tasks);
} | The handleSave function is invoked when the user clicks
the `Save` button in the page action footer.
The default implementation should be sufficient for most
views using {@link form#Map form.Map()} based forms - it
will iterate all forms present in the view and invoke
the {@link form#Map#save Map.save()} method on eac... | handleSave | javascript | openwrt/luci | modules/luci-base/htdocs/luci-static/resources/luci.js | https://github.com/openwrt/luci/blob/master/modules/luci-base/htdocs/luci-static/resources/luci.js | Apache-2.0 |
handleSaveApply(ev, mode) {
return this.handleSave(ev).then(() => {
classes.ui.changes.apply(mode == '0');
});
} | The handleSaveApply function is invoked when the user clicks
the `Save & Apply` button in the page action footer.
The default implementation should be sufficient for most
views using {@link form#Map form.Map()} based forms - it
will first invoke
{@link LuCI.view.handleSave view.handleSave()} and then
call {@link ui#ch... | handleSaveApply | javascript | openwrt/luci | modules/luci-base/htdocs/luci-static/resources/luci.js | https://github.com/openwrt/luci/blob/master/modules/luci-base/htdocs/luci-static/resources/luci.js | Apache-2.0 |
handleReset(ev) {
const tasks = [];
document.getElementById('maincontent')
.querySelectorAll('.cbi-map').forEach(map => {
tasks.push(DOM.callClassMethod(map, 'reset'));
});
return Promise.all(tasks);
} | The handleReset function is invoked when the user clicks
the `Reset` button in the page action footer.
The default implementation should be sufficient for most
views using {@link form#Map form.Map()} based forms - it
will iterate all forms present in the view and invoke
the {@link form#Map#save Map.reset()} method on ... | handleReset | javascript | openwrt/luci | modules/luci-base/htdocs/luci-static/resources/luci.js | https://github.com/openwrt/luci/blob/master/modules/luci-base/htdocs/luci-static/resources/luci.js | Apache-2.0 |
addFooter() {
const footer = E([]);
const vp = document.getElementById('view');
let hasmap = false;
let readonly = true;
vp.querySelectorAll('.cbi-map').forEach(map => {
const m = DOM.findClassInstance(map);
if (m) {
hasmap = true;
if (!m.readonly)
readonly = false;
}
});... | Renders a standard page action footer if any of the
`handleSave()`, `handleSaveApply()` or `handleReset()`
functions are defined.
The default implementation should be sufficient for most
views - it will render a standard page footer with action
buttons labeled `Save`, `Save & Apply` and `Reset`
triggering the `handleS... | addFooter | javascript | openwrt/luci | modules/luci-base/htdocs/luci-static/resources/luci.js | https://github.com/openwrt/luci/blob/master/modules/luci-base/htdocs/luci-static/resources/luci.js | Apache-2.0 |
raise(type, fmt, ...args) {
let e = null;
const msg = fmt ? String.prototype.format.call(fmt, ...args) : null;
const stack = [];
if (type instanceof Error) {
e = type;
if (msg)
e.message = `${msg}: ${e.message}`;
}
else {
try { throw new Error('stacktrace') }
catch (e2) { stack.... | Captures the current stack trace and throws an error of the
specified type as a new exception. Also logs the exception as
error to the debug console if it is available.
@instance
@memberof LuCI
@param {Error|string} [type=Error]
Either a string specifying the type of the error to throw or an
existing `Error` instance... | raise | javascript | openwrt/luci | modules/luci-base/htdocs/luci-static/resources/luci.js | https://github.com/openwrt/luci/blob/master/modules/luci-base/htdocs/luci-static/resources/luci.js | Apache-2.0 |
error(type, fmt /*, ...*/) {
try {
LuCI.prototype.raise.apply(LuCI.prototype,
Array.prototype.slice.call(arguments));
}
catch (e) {
if (!e.reported) {
if (classes.ui)
classes.ui.addNotification(e.name || _('Runtime error'),
E('pre', {}, e.message), 'danger');
else
DOM.... | A wrapper around {@link LuCI#raise raise()} which also renders
the error either as modal overlay when `ui.js` is already loaded
or directly into the view body.
@instance
@memberof LuCI
@param {Error|string} [type=Error]
Either a string specifying the type of the error to throw or an
existing `Error` instance to copy.... | error | javascript | openwrt/luci | modules/luci-base/htdocs/luci-static/resources/luci.js | https://github.com/openwrt/luci/blob/master/modules/luci-base/htdocs/luci-static/resources/luci.js | Apache-2.0 |
bind(fn, self, ...args) {
return Function.prototype.bind.call(fn, self, ...args);
} | Return a bound function using the given `self` as `this` context
and any further arguments as parameters to the bound function.
@instance
@memberof LuCI
@param {function} fn
The function to bind.
@param {*} self
The value to bind as `this` context to the specified function.
@param {...*} [args]
Zero or more variabl... | bind | javascript | openwrt/luci | modules/luci-base/htdocs/luci-static/resources/luci.js | https://github.com/openwrt/luci/blob/master/modules/luci-base/htdocs/luci-static/resources/luci.js | Apache-2.0 |
require(name, from = []) {
const L = this;
let url = null;
/* Class already loaded */
if (classes[name] != null) {
/* Circular dependency */
if (from.indexOf(name) != -1)
LuCI.prototype.raise('DependencyError',
'Circular dependency: class "%s" depends on "%s"',
name, from.join('" w... | Load an additional LuCI JavaScript class and its dependencies,
instantiate it and return the resulting class instance. Each
class is only loaded once. Subsequent attempts to load the same
class will return the already instantiated class.
@instance
@memberof LuCI
@param {string} name
The name of the class to load in d... | require | javascript | openwrt/luci | modules/luci-base/htdocs/luci-static/resources/luci.js | https://github.com/openwrt/luci/blob/master/modules/luci-base/htdocs/luci-static/resources/luci.js | Apache-2.0 |
hasSystemFeature() {
const ft = sysFeatures[arguments[0]];
if (arguments.length == 2)
return this.isObject(ft) ? ft[arguments[1]] : null;
return (ft != null && ft != false);
} | Test whether a particular system feature is available, such as
hostapd SAE support or an installed firewall. The features are
queried once at the beginning of the LuCI session and cached in
`SessionStorage` throughout the lifetime of the associated tab or
browser window.
@instance
@memberof LuCI
@param {string} featu... | hasSystemFeature | javascript | openwrt/luci | modules/luci-base/htdocs/luci-static/resources/luci.js | https://github.com/openwrt/luci/blob/master/modules/luci-base/htdocs/luci-static/resources/luci.js | Apache-2.0 |
fspath() /* ... */{
let path = env.documentroot;
for (let i = 0; i < arguments.length; i++)
path += `/${arguments[i]}`;
const p = path.replace(/\/+$/, '').replace(/\/+/g, '/').split(/\//), res = [];
for (let i = 0; i < p.length; i++)
if (p[i] == '..')
res.pop();
else if (p[i] != '.')
... | Construct an absolute filesystem path relative to the server
document root.
@instance
@memberof LuCI
@param {...string} [parts]
An array of parts to join into a path.
@return {string}
Return the joined path. | fspath | javascript | openwrt/luci | modules/luci-base/htdocs/luci-static/resources/luci.js | https://github.com/openwrt/luci/blob/master/modules/luci-base/htdocs/luci-static/resources/luci.js | Apache-2.0 |
location() {
return this.path(env.scriptname, env.requestpath);
} | Return the complete URL path to the current view.
@instance
@memberof LuCI
@return {string}
Returns the URL path to the current view. | location | javascript | openwrt/luci | modules/luci-base/htdocs/luci-static/resources/luci.js | https://github.com/openwrt/luci/blob/master/modules/luci-base/htdocs/luci-static/resources/luci.js | Apache-2.0 |
isObject(val) {
return (val != null && typeof(val) == 'object');
} | Tests whether the passed argument is a JavaScript object.
This function is meant to be an object counterpart to the
standard `Array.isArray()` function.
@instance
@memberof LuCI
@param {*} [val]
The value to test
@return {boolean}
Returns `true` if the given value is of type object and
not `null`, else returns `fals... | isObject | javascript | openwrt/luci | modules/luci-base/htdocs/luci-static/resources/luci.js | https://github.com/openwrt/luci/blob/master/modules/luci-base/htdocs/luci-static/resources/luci.js | Apache-2.0 |
isArguments(val) {
return (Object.prototype.toString.call(val) == '[object Arguments]');
} | Tests whether the passed argument is a function arguments object.
@instance
@memberof LuCI
@param {*} [val]
The value to test
@return {boolean}
Returns `true` if the given value is a function arguments object,
else returns `false`. | isArguments | javascript | openwrt/luci | modules/luci-base/htdocs/luci-static/resources/luci.js | https://github.com/openwrt/luci/blob/master/modules/luci-base/htdocs/luci-static/resources/luci.js | Apache-2.0 |
sortedKeys(obj, key, sortmode) {
if (obj == null || typeof(obj) != 'object')
return [];
return Object.keys(obj).map(e => {
let v = (key != null) ? obj[e][key] : e;
switch (sortmode) {
case 'addr':
v = (v != null) ? v.replace(/(?:^|[.:])([0-9a-fA-F]{1,4})/g,
(m0, m1) => (`000${m1.toLow... | Return an array of sorted object keys, optionally sorted by
a different key or a different sorting mode.
@instance
@memberof LuCI
@param {object} obj
The object to extract the keys from. If the given value is
not an object, the function will return an empty array.
@param {string|null} [key]
Specifies the key to orde... | sortedKeys | javascript | openwrt/luci | modules/luci-base/htdocs/luci-static/resources/luci.js | https://github.com/openwrt/luci/blob/master/modules/luci-base/htdocs/luci-static/resources/luci.js | Apache-2.0 |
sortedArray(val) {
return this.toArray(val).sort(naturalCompare);
} | Converts the given value to an array using toArray() if needed,
performs a numerical sort using naturalCompare() and returns the
result. If the input already is an array, no copy is being made
and the sorting is performed in-place.
@see toArray
@see naturalCompare
@param {*} val
The input value to sort (and convert t... | sortedArray | javascript | openwrt/luci | modules/luci-base/htdocs/luci-static/resources/luci.js | https://github.com/openwrt/luci/blob/master/modules/luci-base/htdocs/luci-static/resources/luci.js | Apache-2.0 |
toArray(val) {
if (val == null)
return [];
else if (Array.isArray(val))
return val;
else if (typeof(val) == 'object')
return [ val ];
const s = String(val).trim();
if (s == '')
return [];
return s.split(/\s+/);
} | Converts the given value to an array. If the given value is of
type array, it is returned as-is, values of type object are
returned as one-element array containing the object, empty
strings and `null` values are returned as empty array, all other
values are converted using `String()`, trimmed, split on white
space and ... | toArray | javascript | openwrt/luci | modules/luci-base/htdocs/luci-static/resources/luci.js | https://github.com/openwrt/luci/blob/master/modules/luci-base/htdocs/luci-static/resources/luci.js | Apache-2.0 |
resolveDefault(value, defvalue) {
return Promise.resolve(value).catch(() => defvalue);
} | Returns a promise resolving with either the given value or with
the given default in case the input value is a rejecting promise.
@instance
@memberof LuCI
@param {*} value
The value to resolve the promise with.
@param {*} defvalue
The default value to resolve the promise with in case the given
input value is a rejec... | resolveDefault | javascript | openwrt/luci | modules/luci-base/htdocs/luci-static/resources/luci.js | https://github.com/openwrt/luci/blob/master/modules/luci-base/htdocs/luci-static/resources/luci.js | Apache-2.0 |
get(url, args, cb) {
return this.poll(null, url, args, cb, false);
} | Issues a GET request to the given url and invokes the specified
callback function. The function is a wrapper around
{@link LuCI.request#request Request.request()}.
@deprecated
@instance
@memberof LuCI
@param {string} url
The URL to request.
@param {Object<string, string>} [args]
Additional query string arguments to ... | get | javascript | openwrt/luci | modules/luci-base/htdocs/luci-static/resources/luci.js | https://github.com/openwrt/luci/blob/master/modules/luci-base/htdocs/luci-static/resources/luci.js | Apache-2.0 |
post(url, args, cb) {
return this.poll(null, url, args, cb, true);
} | Issues a POST request to the given url and invokes the specified
callback function. The function is a wrapper around
{@link LuCI.request#request Request.request()}. The request is
sent using `application/x-www-form-urlencoded` encoding and will
contain a field `token` with the current value of `LuCI.env.token`
by defau... | post | javascript | openwrt/luci | modules/luci-base/htdocs/luci-static/resources/luci.js | https://github.com/openwrt/luci/blob/master/modules/luci-base/htdocs/luci-static/resources/luci.js | Apache-2.0 |
poll(interval, url, args, cb, post) {
if (interval !== null && interval <= 0)
interval = env.pollinterval;
const data = Object.assign(post ? { token: env.token } : {}, args);
const method = post ? 'POST' : 'GET';
if (!/^(?:\/|\S+:\/\/)/.test(url))
url = this.url(url);
if (interval !== null)
... | Register a polling HTTP request that invokes the specified
callback function. The function is a wrapper around
{@link LuCI.request.poll#add Request.poll.add()}.
@deprecated
@instance
@memberof LuCI
@param {number} interval
The poll interval to use. If set to a value less than or equal
to `0`, it will default to the g... | poll | javascript | openwrt/luci | modules/luci-base/htdocs/luci-static/resources/luci.js | https://github.com/openwrt/luci/blob/master/modules/luci-base/htdocs/luci-static/resources/luci.js | Apache-2.0 |
hasViewPermission() {
if (!this.isObject(env.nodespec) || !env.nodespec.satisfied)
return null;
return !env.nodespec.readonly;
} | Check whether a view has sufficient permissions.
@return {boolean|null}
Returns `null` if the current session has no permission at all to
load resources required by the view. Returns `false` if readonly
permissions are granted or `true` if at least one required ACL
group is granted with write permissions. | hasViewPermission | javascript | openwrt/luci | modules/luci-base/htdocs/luci-static/resources/luci.js | https://github.com/openwrt/luci/blob/master/modules/luci-base/htdocs/luci-static/resources/luci.js | Apache-2.0 |
get(url, data, callback, timeout) {
this.active = true;
LuCI.prototype.get(url, data, this._response.bind(this, callback), timeout);
} | This function is a legacy wrapper around
{@link LuCI#get LuCI.get()}.
@instance
@deprecated
@memberof LuCI.xhr
@param {string} url
The URL to request
@param {Object} [data]
Additional query string data
@param {LuCI.requestCallbackFn} [callback]
Callback function to invoke on completion
@param {number} [timeout]
Re... | get | javascript | openwrt/luci | modules/luci-base/htdocs/luci-static/resources/luci.js | https://github.com/openwrt/luci/blob/master/modules/luci-base/htdocs/luci-static/resources/luci.js | Apache-2.0 |
post(url, data, callback, timeout) {
this.active = true;
LuCI.prototype.post(url, data, this._response.bind(this, callback), timeout);
} | This function is a legacy wrapper around
{@link LuCI#post LuCI.post()}.
@instance
@deprecated
@memberof LuCI.xhr
@param {string} url
The URL to request
@param {Object} [data]
Additional data to append to the request body.
@param {LuCI.requestCallbackFn} [callback]
Callback function to invoke on completion
@param {... | post | javascript | openwrt/luci | modules/luci-base/htdocs/luci-static/resources/luci.js | https://github.com/openwrt/luci/blob/master/modules/luci-base/htdocs/luci-static/resources/luci.js | Apache-2.0 |
list(...args) {
const msg = {
jsonrpc: '2.0',
id: rpcRequestID++,
method: 'list',
params: args.length ? args : undefined
};
return new Promise(L.bind(function(resolve, reject) {
/* store request info */
const req = { resolve, reject };
/* call rpc */
this.call(msg, this.parseCallR... | Lists available remote ubus objects or the method signatures of
specific objects.
This function has two signatures and is sensitive to the number of
arguments passed to it:
- `list()` -
Returns an array containing the names of all remote `ubus` objects
- `list("objname", ...)`
Returns method signatures for eac... | list | javascript | openwrt/luci | modules/luci-base/htdocs/luci-static/resources/rpc.js | https://github.com/openwrt/luci/blob/master/modules/luci-base/htdocs/luci-static/resources/rpc.js | Apache-2.0 |
declare(options) {
return Function.prototype.bind.call(function(rpc, options, ...args) {
return new Promise((resolve, reject) => {
/* build parameter object */
let p_off = 0;
const params = { };
if (Array.isArray(options.params))
for (p_off = 0; p_off < options.params.length; p_off++)
pa... | Describes a remote RPC call procedure and returns a function
implementing it.
@param {LuCI.rpc.DeclareOptions} options
If any object names are given, this function will return the method
signatures of each given object.
@returns {LuCI.rpc~invokeFn}
Returns a new function implementing the method call described in
`opt... | declare | javascript | openwrt/luci | modules/luci-base/htdocs/luci-static/resources/rpc.js | https://github.com/openwrt/luci/blob/master/modules/luci-base/htdocs/luci-static/resources/rpc.js | Apache-2.0 |
getSessionID() {
return rpcSessionID;
} | Returns the current RPC session id.
@returns {string}
Returns the 32 byte session ID string used for authenticating remote
requests. | getSessionID | javascript | openwrt/luci | modules/luci-base/htdocs/luci-static/resources/rpc.js | https://github.com/openwrt/luci/blob/master/modules/luci-base/htdocs/luci-static/resources/rpc.js | Apache-2.0 |
setSessionID(sid) {
rpcSessionID = sid;
} | Set the RPC session id to use.
@param {string} sid
Sets the 32 byte session ID string used for authenticating remote
requests. | setSessionID | javascript | openwrt/luci | modules/luci-base/htdocs/luci-static/resources/rpc.js | https://github.com/openwrt/luci/blob/master/modules/luci-base/htdocs/luci-static/resources/rpc.js | Apache-2.0 |
getBaseURL() {
return rpcBaseURL;
} | Returns the current RPC base URL.
@returns {string}
Returns the RPC URL endpoint to issue requests against. | getBaseURL | javascript | openwrt/luci | modules/luci-base/htdocs/luci-static/resources/rpc.js | https://github.com/openwrt/luci/blob/master/modules/luci-base/htdocs/luci-static/resources/rpc.js | Apache-2.0 |
setBaseURL(url) {
rpcBaseURL = url;
} | Set the RPC base URL to use.
@param {string} url
Sets the RPC URL endpoint to issue requests against. | setBaseURL | javascript | openwrt/luci | modules/luci-base/htdocs/luci-static/resources/rpc.js | https://github.com/openwrt/luci/blob/master/modules/luci-base/htdocs/luci-static/resources/rpc.js | Apache-2.0 |
getStatusText(statusCode) {
switch (statusCode) {
case 0: return _('Command OK');
case 1: return _('Invalid command');
case 2: return _('Invalid argument');
case 3: return _('Method not found');
case 4: return _('Resource not found');
case 5: return _('No data received');
case 6: return _('Permission de... | Translates a numeric `ubus` error code into a human readable
description.
@param {number} statusCode
The numeric status code.
@returns {string}
Returns the textual description of the code. | getStatusText | javascript | openwrt/luci | modules/luci-base/htdocs/luci-static/resources/rpc.js | https://github.com/openwrt/luci/blob/master/modules/luci-base/htdocs/luci-static/resources/rpc.js | Apache-2.0 |
addInterceptor(interceptorFn) {
if (typeof(interceptorFn) == 'function')
rpcInterceptorFns.push(interceptorFn);
return interceptorFn;
} | Registers a new interceptor function.
@param {LuCI.rpc~interceptorFn} interceptorFn
The interceptor function to register.
@returns {LuCI.rpc~interceptorFn}
Returns the given function value. | addInterceptor | javascript | openwrt/luci | modules/luci-base/htdocs/luci-static/resources/rpc.js | https://github.com/openwrt/luci/blob/master/modules/luci-base/htdocs/luci-static/resources/rpc.js | Apache-2.0 |
removeInterceptor(interceptorFn) {
const oldlen = rpcInterceptorFns.length;
let i = oldlen;
while (i--)
if (rpcInterceptorFns[i] === interceptorFn)
rpcInterceptorFns.splice(i, 1);
return (rpcInterceptorFns.length < oldlen);
} | Removes a registered interceptor function.
@param {LuCI.rpc~interceptorFn} interceptorFn
The interceptor function to remove.
@returns {boolean}
Returns `true` if the given function has been removed or `false`
if it has not been found. | removeInterceptor | javascript | openwrt/luci | modules/luci-base/htdocs/luci-static/resources/rpc.js | https://github.com/openwrt/luci/blob/master/modules/luci-base/htdocs/luci-static/resources/rpc.js | Apache-2.0 |
createSID(conf) {
const v = this.state.values;
const n = this.state.creates;
let sid;
do {
sid = "new%06x".format(Math.random() * 0xFFFFFF);
} while ((n[conf]?.[sid]) || (v[conf]?.[sid]));
return sid;
} | Generates a new, unique section ID for the given configuration.
Note that the generated ID is temporary, it will get replaced by an
identifier in the form `cfgXXXXXX` once the configuration is saved
by the remote `ubus` UCI api.
@param {string} conf
The configuration to generate the new section ID for.
@returns {str... | createSID | javascript | openwrt/luci | modules/luci-base/htdocs/luci-static/resources/uci.js | https://github.com/openwrt/luci/blob/master/modules/luci-base/htdocs/luci-static/resources/uci.js | Apache-2.0 |
resolveSID(conf, sid) {
if (typeof(sid) != 'string')
return sid;
const m = /^@([a-zA-Z0-9_-]+)\[(-?[0-9]+)\]$/.exec(sid);
if (m) {
const type = m[1];
const pos = +m[2];
const sections = this.sections(conf, type);
const section = sections[pos >= 0 ? pos : sections.length + pos];
return section... | Resolves a given section ID in extended notation to the internal
section ID value.
@param {string} conf
The configuration to resolve the section ID for.
@param {string} sid
The section ID to resolve. If the ID is in the form `@typename[#]`,
it will get resolved to an internal anonymous ID in the forms
`cfgXXXXXX`/`ne... | resolveSID | javascript | openwrt/luci | modules/luci-base/htdocs/luci-static/resources/uci.js | https://github.com/openwrt/luci/blob/master/modules/luci-base/htdocs/luci-static/resources/uci.js | Apache-2.0 |
load(packages) {
const self = this;
const pkgs = [ ];
const tasks = [];
if (!Array.isArray(packages))
packages = [ packages ];
for (let i = 0; i < packages.length; i++)
if (!self.state.values[packages[i]]) {
pkgs.push(packages[i]);
tasks.push(self.loadPackage(packages[i]));
}
return Prom... | Loads the given UCI configurations from the remote `ubus` api.
Loaded configurations are cached and only loaded once. Subsequent
load operations of the same configurations will return the cached
data.
To force reloading a configuration, it has to be unloaded with
{@link LuCI.uci#unload uci.unload()} first.
@param {s... | load | javascript | openwrt/luci | modules/luci-base/htdocs/luci-static/resources/uci.js | https://github.com/openwrt/luci/blob/master/modules/luci-base/htdocs/luci-static/resources/uci.js | Apache-2.0 |
unload(packages) {
if (!Array.isArray(packages))
packages = [ packages ];
for (let i = 0; i < packages.length; i++) {
delete this.state.values[packages[i]];
delete this.state.creates[packages[i]];
delete this.state.changes[packages[i]];
delete this.state.deletes[packages[i]];
delete this.loaded[... | Unloads the given UCI configurations from the local cache.
@param {string|string[]} packages
The name of the configuration or an array of configuration
names to unload. | unload | javascript | openwrt/luci | modules/luci-base/htdocs/luci-static/resources/uci.js | https://github.com/openwrt/luci/blob/master/modules/luci-base/htdocs/luci-static/resources/uci.js | Apache-2.0 |
remove(conf, sid) {
const v = this.state.values;
const n = this.state.creates;
const c = this.state.changes;
const d = this.state.deletes;
/* requested deletion of a just created section */
if (n[conf]?.[sid]) {
delete n[conf][sid];
}
else if (v[conf]?.[sid]) {
delete c[conf]?.[sid];
d[conf] ... | Removes the section with the given ID from the given configuration.
@param {string} conf
The name of the configuration to remove the section from.
@param {string} sid
The ID of the section to remove. | remove | javascript | openwrt/luci | modules/luci-base/htdocs/luci-static/resources/uci.js | https://github.com/openwrt/luci/blob/master/modules/luci-base/htdocs/luci-static/resources/uci.js | Apache-2.0 |
set(conf, sid, opt, val) {
const v = this.state.values;
const n = this.state.creates;
const c = this.state.changes;
const d = this.state.deletes;
sid = this.resolveSID(conf, sid);
if (sid == null || opt == null || opt.charAt(0) == '.')
return;
if (n[conf]?.[sid]) {
if (val != null)
n[conf][si... | Sets the value of the given option within the specified section
of the given configuration.
If either config, section or option is null, or if `option` begins
with a dot, the function will do nothing.
@param {string} conf
The name of the configuration to set the option value in.
@param {string} sid
The name or ID of... | set | javascript | openwrt/luci | modules/luci-base/htdocs/luci-static/resources/uci.js | https://github.com/openwrt/luci/blob/master/modules/luci-base/htdocs/luci-static/resources/uci.js | Apache-2.0 |
unset(conf, sid, opt) {
return this.set(conf, sid, opt, null);
} | Remove the given option within the specified section of the given
configuration.
This function is a convenience wrapper around
`uci.set(config, section, option, null)`.
@param {string} conf
The name of the configuration to remove the option from.
@param {string} sid
The name or ID of the section to remove the option... | unset | javascript | openwrt/luci | modules/luci-base/htdocs/luci-static/resources/uci.js | https://github.com/openwrt/luci/blob/master/modules/luci-base/htdocs/luci-static/resources/uci.js | Apache-2.0 |
set_first(conf, type, opt, val) {
let sid = null;
this.sections(conf, type, s => {
sid ??= s['.name'];
});
return this.set(conf, sid, opt, val);
} | Sets the value of the given option within the first found section
of the given configuration matching the specified type or within
the first section of the entire config when no type has is specified.
If either config, type or option is null, or if `option` begins
with a dot, the function will do nothing.
@param {str... | set_first | javascript | openwrt/luci | modules/luci-base/htdocs/luci-static/resources/uci.js | https://github.com/openwrt/luci/blob/master/modules/luci-base/htdocs/luci-static/resources/uci.js | Apache-2.0 |
unset_first(conf, type, opt) {
return this.set_first(conf, type, opt, null);
} | Removes the given option within the first found section of the given
configuration matching the specified type or within the first section
of the entire config when no type has is specified.
This function is a convenience wrapper around
`uci.set_first(config, type, option, null)`.
@param {string} conf
The name of the... | unset_first | javascript | openwrt/luci | modules/luci-base/htdocs/luci-static/resources/uci.js | https://github.com/openwrt/luci/blob/master/modules/luci-base/htdocs/luci-static/resources/uci.js | Apache-2.0 |
move(conf, sid1, sid2, after) {
const sa = this.sections(conf);
let s1 = null;
let s2 = null;
sid1 = this.resolveSID(conf, sid1);
sid2 = this.resolveSID(conf, sid2);
for (let i = 0; i < sa.length; i++) {
if (sa[i]['.name'] != sid1)
continue;
s1 = sa[i];
sa.splice(i, 1);
break;
}
if (... | Move the first specified section within the given configuration
before or after the second specified section.
@param {string} conf
The configuration to move the section within.
@param {string} sid1
The ID of the section to move within the configuration.
@param {string} [sid2]
The ID of the target section for the mov... | move | javascript | openwrt/luci | modules/luci-base/htdocs/luci-static/resources/uci.js | https://github.com/openwrt/luci/blob/master/modules/luci-base/htdocs/luci-static/resources/uci.js | Apache-2.0 |
getValue() {
if (dom.matches(this.node, 'select') || dom.matches(this.node, 'input'))
return this.node.value;
return null;
} | Read the current value of the input widget.
@instance
@memberof LuCI.ui.AbstractElement
@returns {string|string[]|null}
The current value of the input element. For simple inputs like text
fields or selects, the return value type will be a - possibly empty -
string. Complex widgets such as `DynamicList` instances may r... | getValue | javascript | openwrt/luci | modules/luci-base/htdocs/luci-static/resources/ui.js | https://github.com/openwrt/luci/blob/master/modules/luci-base/htdocs/luci-static/resources/ui.js | Apache-2.0 |
setValue(value) {
if (dom.matches(this.node, 'select') || dom.matches(this.node, 'input'))
this.node.value = value;
} | Set the current value of the input widget.
@instance
@memberof LuCI.ui.AbstractElement
@param {string|string[]|null} value
The value to set the input element to. For simple inputs like text
fields or selects, the value should be a - possibly empty - string.
Complex widgets such as `DynamicList` instances may accept st... | setValue | javascript | openwrt/luci | modules/luci-base/htdocs/luci-static/resources/ui.js | https://github.com/openwrt/luci/blob/master/modules/luci-base/htdocs/luci-static/resources/ui.js | Apache-2.0 |
setPlaceholder(value) {
const node = this.node ? this.node.querySelector('input,textarea') : null;
if (node) {
switch (node.getAttribute('type') ?? 'text') {
case 'password':
case 'search':
case 'tel':
case 'text':
case 'url':
if (value != null && value != '')
node.setAttribute('placehold... | Set the current placeholder value of the input widget.
@instance
@memberof LuCI.ui.AbstractElement
@param {string|string[]|null} value
The placeholder to set for the input element. Only applicable to text
inputs, not to radio buttons, selects or similar. | setPlaceholder | javascript | openwrt/luci | modules/luci-base/htdocs/luci-static/resources/ui.js | https://github.com/openwrt/luci/blob/master/modules/luci-base/htdocs/luci-static/resources/ui.js | Apache-2.0 |
isChanged() {
return (this.node ? this.node.getAttribute('data-changed') : null) == 'true';
} | Check whether the input value was altered by the user.
@instance
@memberof LuCI.ui.AbstractElement
@returns {boolean}
Returns `true` if the input value has been altered by the user or
`false` if it is unchanged. Note that if the user modifies the initial
value and changes it back to the original state, it is still rep... | isChanged | javascript | openwrt/luci | modules/luci-base/htdocs/luci-static/resources/ui.js | https://github.com/openwrt/luci/blob/master/modules/luci-base/htdocs/luci-static/resources/ui.js | Apache-2.0 |
isValid() {
return (this.validState !== false);
} | Check whether the current input value is valid.
@instance
@memberof LuCI.ui.AbstractElement
@returns {boolean}
Returns `true` if the current input value is valid or `false` if it does
not meet the validation constraints. | isValid | javascript | openwrt/luci | modules/luci-base/htdocs/luci-static/resources/ui.js | https://github.com/openwrt/luci/blob/master/modules/luci-base/htdocs/luci-static/resources/ui.js | Apache-2.0 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.