| Name | Type | Description |
|---|---|---|
env |
Object |
The environment settings to use for the LuCI runtime. |
Classes
Members
-
Class
-
Legacy
L.Classclass alias. New view code should use'require baseclass';to request theLuCI.baseclassclass.- Deprecated
- Yes
-
dom
-
Legacy
L.domclass alias. New view code should use'require dom';to request theLuCI.domclass.- Deprecated
- Yes
-
env
-
The
envobject holds environment settings used by LuCI, such as request timeouts, base URLs, etc. -
naturalComparefunction
-
Compares two values numerically and returns -1, 0, or 1 depending on whether the first value is smaller, equal to, or larger than the second one respectively.
This function is meant to be used as a comparator function for Array.sort().
-
Poll
-
Legacy
L.Pollclass alias. New view code should use'require poll';to request theLuCI.pollclass.- Deprecated
- Yes
-
Request
-
Legacy
L.Requestclass alias. New view code should use'require request';to request theLuCI.requestclass.- Deprecated
- Yes
-
view
-
Legacy
L.viewclass alias. New view code should use'require view';to request theLuCI.viewclass.- Deprecated
- Yes
Methods
-
Return a bound function using the given
selfasthiscontext and any further arguments as parameters to the bound function.Name Type Description fnfunction The function to bind.
self* The value to bind as
thiscontext to the specified function.args* optional repeatable Zero or more variable arguments which are bound to the function as parameters.
Returns:
Type Description function Returns the bound function. -
A wrapper around
raise()which also renders the error either as modal overlay whenui.jsis already loaded or directly into the view body.Name Type Default Description typeError | string Error optional Either a string specifying the type of the error to throw or an existing
Errorinstance to copy.fmtstring Unspecified error optional A format string which is used to form the error message, together with all subsequent optional arguments.
args* optional repeatable Zero or more variable arguments to the supplied format string.
Throws:
-
Throws the created error object with the captured stack trace appended to the message and the type set to the given type argument or copied from the given error instance.
- Type
- Error
-
-
Construct an absolute filesystem path relative to the server document root.
Name Type Description partsstring optional repeatable An array of parts to join into a path.
Returns:
Type Description string Return the joined path. -
Issues a GET request to the given url and invokes the specified callback function. The function is a wrapper around
Request.request().Name Type Description urlstring The URL to request.
argsObject.<string, string> optional Additional query string arguments to append to the URL.
cbLuCI.requestCallbackFn The callback function to invoke when the request finishes.
- Deprecated
- Yes
Returns:
Type Description Promise.<null> Returns a promise resolving to nullwhen concluded. -
Deprecated wrapper around
Poll.stop().- Deprecated
- Yes
Returns:
Type Description boolean Returns truewhen the polling loop has been stopped orfalsewhen it didn't run to begin with. -
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
SessionStoragethroughout the lifetime of the associated tab or browser window.Name Type Description featurestring The feature to test. For a detailed list of known feature flags, see
/modules/luci-base/root/usr/share/rpcd/ucode/luci.subfeaturestring optional Some feature classes like
hostapdprovide sub-feature flags, such assaeor11wsupport. Thesubfeatureargument can be used to query these.Returns:
Type Description boolean | null Return trueif the queried feature (and sub-feature) is available orfalseif the requested feature isn't present or known. Returnnullwhen a sub-feature was queried for a feature which has no sub-features. -
Check whether a view has sufficient permissions.
Returns:
Type Description boolean | null Returns nullif the current session has no permission at all to load resources required by the view. Returnsfalseif readonly permissions are granted ortrueif at least one required ACL group is granted with write permissions. -
Tests whether the passed argument is a function arguments object.
Name Type Description val* optional The value to test
Returns:
Type Description boolean Returns trueif the given value is a function arguments object, else returnsfalse. -
Tests whether the passed argument is a JavaScript object. This function is meant to be an object counterpart to the standard
Array.isArray()function.Name Type Description val* optional The value to test
Returns:
Type Description boolean Returns trueif the given value is of a type object and notnull, else returnsfalse. -
Return the complete URL path to the current view.
Returns:
Type Description string Returns the URL path to the current view. -
Construct a URL path relative to the media resource path of the LuCI ui (usually
/luci-static/$theme_name).The resulting URL is guaranteed to contain only the characters
a-z,A-Z,0-9,_,.,%,,,;, and-as well as/for the path separator. Suffixing '?x=y&foo=bar' URI parameters also limited to the aforementioned characters is permissible.Name Type Description partsstring optional repeatable An array of parts to join into a URL path. Parts may contain slashes and any of the other characters mentioned above.
Returns:
Type Description string Returns the resulting URL path. -
Construct a relative URL path from the given prefix and parts. The resulting URL is guaranteed to contain only the characters
a-z,A-Z,0-9,_,.,%,,,;, and-as well as/for the path separator. Suffixing '?x=y&foo=bar' URI parameters also limited to the aforementioned characters is permissible.Name Type Description prefixstring optional The prefix to join the given parts with. If the
prefixis omitted, it defaults to an empty string.partsstring optional repeatable An array of parts to join into a URL path. Parts may contain slashes and any of the other characters mentioned above.
Returns:
Type Description string Return the joined URL path. -
Register a polling HTTP request that invokes the specified callback function. The function is a wrapper around
Request.poll.add().Name Type Default Description intervalnumber The poll interval to use. If set to a value less than or equal to
0, it will default to the global poll interval configured inLuCI.env.pollinterval.urlstring The URL to request.
argsObject.<string, string> optional Specifies additional arguments for the request. For GET requests, the arguments are appended to the URL as query string, for POST requests, they'll be added to the request body.
cbLuCI.requestCallbackFn The callback function to invoke whenever a request finishes.
postboolean false optional When set to
falseor not specified, poll requests will be made using the GET method. When set totrue, POST requests will be issued. In the case of POST requests, the request body will contain an argumenttokenwith the current value ofLuCI.env.tokenby default, regardless of the parameters specified withargs.- Deprecated
- Yes
Returns:
Type Description function Returns the internally created function that has been passed to Request.poll.add(). This value can be passed toPoll.remove()to remove the polling request. -
Issues a POST request to the given url and invokes the specified callback function. The function is a wrapper around
Request.request(). The request is sent usingapplication/x-www-form-urlencodedencoding and will contain a fieldtokenwith the current value ofLuCI.env.tokenby default.Name Type Description urlstring The URL to request.
argsObject.<string, string> optional Additional post arguments to append to the request body.
cbLuCI.requestCallbackFn The callback function to invoke when the request finishes.
- Deprecated
- Yes
Returns:
Type Description Promise.<null> Returns a promise resolving to nullwhen concluded. -
Captures the current stack trace and throws an error of the specified type as a new exception. Also logs the exception as an error to the debug console if it is available.
Name Type Default Description typeError | string Error optional Either a string specifying the type of the error to throw or an existing
Errorinstance to copy.fmtstring Unspecified error optional A format string which is used to form the error message, together with all subsequent optional arguments.
args* optional repeatable Zero or more variable arguments to the supplied format string.
Throws:
-
Throws the created error object with the captured stack trace appended to the message and the type set to the given type argument or copied from the given error instance.
- Type
- Error
-
-
require(name){Promise.<LuCI.baseclass>}
-
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.
Name Type Description namestring The name of the class to load in dotted notation. Dots will be replaced by spaces and joined with the runtime-determined base URL of LuCI.js to form an absolute URL to load the class file from.
Throws:
-
-
Throws a
DependencyErrorwhen the class to load includes circular dependencies. - Type
- DependencyError
-
-
-
Throws
NetworkErrorwhen the underlyingLuCI.requestcall failed. - Type
- NetworkError
-
-
-
Throws
SyntaxErrorwhen the loaded class file code cannot be interpreted byeval. - Type
- SyntaxError
-
-
-
Throws
TypeErrorwhen the class file could be loaded and interpreted, but when invoking its code did not yield a valid class instance. - Type
- TypeError
-
Returns:
Type Description Promise.<LuCI.baseclass> Returns the instantiated class. -
-
Returns a promise resolving with either the given value or with the given default in case the input value is a rejecting promise.
Name Type Description value* The value to resolve the promise with.
defvalue* The default value to resolve the promise with in case the given input value is a rejecting promise.
Returns:
Type Description Promise.<*> Returns a new promise resolving either to the given input value or to the given default value on error. -
Construct a URL path relative to the global static resource path of the LuCI ui (usually
/luci-static/resources).The resulting URL is guaranteed to contain only the characters
a-z,A-Z,0-9,_,.,%,,,;, and-as well as/for the path separator. Suffixing '?x=y&foo=bar' URI parameters also limited to the aforementioned characters is permissible.Name Type Description partsstring optional repeatable An array of parts to join into a URL path. Parts may contain slashes and any of the other characters mentioned above.
Returns:
Type Description string Returns the resulting URL path. -
Deprecated wrapper around
Poll.start().- Deprecated
- Yes
Returns:
Type Description boolean Returns truewhen the polling loop has been started orfalsewhen it was already running. -
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.
Name Type Description val* The input value to sort (and convert to an array if needed).
- See:
-
- toArray
- naturalCompare
Returns:
Type Description Array.<*> Returns the resulting, numerically sorted array. -
Return an array of sorted object keys, optionally sorted by a different key or a different sorting mode.
Name Type Description objobject The object to extract the keys from. If the given value is not an object, the function will return an empty array.
keystring | null optional Specifies the key to order by. This is mainly useful for nested objects of objects or objects of arrays when sorting shall not be performed by the primary object keys but by some other key pointing to a value within the nested values.
sortmode"addr" | "num" optional Can be either
addrornumto override the natural lexicographic sorting with a sorting suitable for IP/MAC style addresses or numeric values respectively.Returns:
Type Description Array.<string> Returns an array containing the sorted keys of the given object. -
Deprecated wrapper around
Poll.remove().Name Type Description entryfunction The polling function to remove.
- Deprecated
- Yes
Returns:
Type Description boolean Returns truewhen the function has been removed orfalseif it could not be found. -
Converts the given value to an array. If the given value is of type array, it is returned as-is, values of a type object are returned as one-element array containing the object, empty strings and
nullvalues are returned as an empty array, all other values are converted usingString(), trimmed, split on white space and returned as an array.Name Type Description val* The value to convert into an array.
Returns:
Type Description Array.<*> Returns the resulting array. -
Construct a URL with a path relative to the script path of the server side LuCI application (usually
/cgi-bin/luci).The resulting URL is guaranteed to contain only the characters
a-z,A-Z,0-9,_,.,%,,,;, and-as well as/for the path separator. Suffixing '?x=y&foo=bar' URI parameters also limited to the aforementioned characters is permissible.Name Type Description partsstring optional repeatable An array of parts to join into a URL path. Parts may contain slashes and any of the other characters mentioned above.
Returns:
Type Description string Returns the resulting URL path.
Type Definitions
-
The request callback function is invoked whenever an HTTP reply to a request made using the
L.get(),L.post()orL.poll()function is timed out or received successfully.Name Type Description xhrXMLHTTPRequest The XMLHTTPRequest instance used to make the request.
data* The response JSON if the response could be parsed as such, else
null.durationnumber The total duration of the request in milliseconds.