wires

Resolve JavaScript dependencies for automatic widget loading in module#mod_wires. The widget manager uses this model when a do_<name> class has no registered jQuery function yet.

Available Model API Paths

MethodPath patternDescription
get/widget/+nameResolve js/modules/z.<name>.js and return a list containing its asset descriptor.

+name is a single widget name containing letters, digits, underscores or hyphens, without the do_ prefix. Resolution uses the site's library index, including enabled modules. The descriptor contains key, a timestamped url, type, media, rel and title, as returned by z_lib_include:assets/3. The request payload is ignored. The model resolves the asset; it does not load it or initialize the widget.

For example, load the library for do_autofocus in the browser:

cotonic.ready.then(() => cotonic.broker.call(
    'bridge/origin/model/wires/get/widget/autofocus'
)).then(response => {
    if (response.payload.status !== 'ok') {
        throw new Error(response.payload.error);
    }
    return z_assets.ensure(response.payload.result);
});

Normally the widget manager performs this lookup and initializes the widget after loading. The asset loader shares loaded and pending files with lib tags and dynamic updates.

Configuration and errors

Configuration module mod_wires, key widget_autoload, defaults to true. Setting it to false disables resolution through this model; explicitly included widgets continue to work.

ErrorMeaning
disabledAutomatic widget loading is disabled for the site.
badargThe widget name is empty or contains unsupported characters.
enoentThe conventional library file is absent from the site library index.
unknown_pathThe requested model path is not supported.

This read-only model has no additional ACL restriction: it exposes descriptors for public library files. It does not accept arbitrary paths or URLs.

Direct Erlang calls to m_get/3 return {ok, {Assets, Rest}} on success or {error, Reason} on failure. Rest contains any remaining model path segments.

Edit on GitHub