jsf.js_next_gen
Version:
A next generation typescript reimplementation of jsf.js
309 lines • 13.5 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.myfaces = exports.faces = void 0;
/*! Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to you under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
const AjaxImpl_1 = require("../impl/AjaxImpl");
const PushImpl_1 = require("../impl/PushImpl");
const OamSubmit_1 = require("../myfaces/OamSubmit");
const Const_1 = require("../impl/core/Const");
//we use modules to get a proper jsdoc and static/map structure in the calls
//as per spec requirement
var faces;
(function (faces) {
/**
* Version of the implementation for the faces.ts.
* <p />
* as specified within the jsf specifications faces.html:
* <ul>
* <li>left two digits major release number</li>
* <li>middle two digits minor spec release number</li>
* <li>right two digits bug release number</li>
* </ul>
* @constant
*/
faces.specversion = 400000;
/**
* Implementation version as specified within the jsf specification.
* <p />
* A number increased with every implementation version
* and reset by moving to a new spec release number
*
* @constant
*/
faces.implversion = 0;
/**
* SeparatorChar as defined by facesContext.getNamingContainerSeparatorChar()
*/
faces.separatorchar = getSeparatorChar();
// noinspection JSUnusedGlobalSymbols
/**
* Context Path as defined externalContext.requestContextPath
*/
faces.contextpath = '#{facesContext.externalContext.requestContextPath}';
// we do not have a fallback here, for now
/**
* This method is responsible for the return of a given project stage as defined
* by the jsf specification.
* <p/>
* Valid return values are:
* <ul>
* <li>"Production"</li>
* <li>"Development"</li>
* <li>"SystemTest"</li>
* <li>"UnitTest"</li>
* </li>
*
* @return {String} the current project state emitted by the server side method:
* <i>jakarta.faces.application.Application.getProjectStage()</i>
*/
function getProjectStage() {
return AjaxImpl_1.Implementation.getProjectStage();
}
faces.getProjectStage = getProjectStage;
/**
* collect and encode data for a given form element (must be of type form)
* find the jakarta.faces.ViewState element and encode its value as well!
* return a concatenated string of the encoded values!
*
* @throws an exception in case of the given element not being of type form!
* https://issues.apache.org/jira/browse/MYFACES-2110
*/
function getViewState(formElement) {
return AjaxImpl_1.Implementation.getViewState(formElement);
}
faces.getViewState = getViewState;
/**
* returns the window identifier for the given node / window
* @return the window identifier or null if none is found
* @param rootNode
*/
function getClientWindow(rootNode) {
return AjaxImpl_1.Implementation.getClientWindow(rootNode);
}
faces.getClientWindow = getClientWindow;
// private helper functions
function getSeparatorChar() {
const sep = '#{facesContext.namingContainerSeparatorChar}';
//We now enable standalone mode, the separator char was not mapped we make a fallback to 2.3 behavior
//the idea is that the separator char is provided from the underlying container, but if not then we
//will perform a fallback (aka 2.3 has the url fallback behavior)
return (sep.match(/\#\{facesContext.namingContainerSeparatorChar\}/gi)) ? AjaxImpl_1.Implementation.getSeparatorChar() : sep;
}
let ajax;
(function (ajax) {
"use strict";
/**
* this function has to send the ajax requests
*
* following request conditions must be met:
* <ul>
* <li> the request must be sent asynchronously! </li>
* <li> the request must be a POST!!! request </li>
* <li> the request url must be the form action attribute </li>
* <li> all requests must be queued with a client side request queue to ensure the request ordering!</li>
* </ul>
*
* @param {String|Node} element: any dom element no matter being it html or jsf, from which the event is emitted
* @param {EVENT} event: any javascript event supported by that object
* @param {Map} options : map of options being pushed into the ajax cycle
*/
function request(element, event, options) {
AjaxImpl_1.Implementation.request(element, event, options);
}
ajax.request = request;
/**
* response handler
* @param request the request object having triggered this response
* @param context the request context
*
*/
function response(request, context) {
AjaxImpl_1.Implementation.response(request, context);
}
ajax.response = response;
/**
* Adds an error handler to our global error queue.
* the error handler must be of the format <i>function errorListener(<errorData>)</i>
* with errorData being of following format:
* <ul>
* <li> errorData.type : "error"</li>
* <li> errorData.status : the error status message</li>
* <li> errorData.serverErrorName : the server error name in case of a server error</li>
* <li> errorData.serverErrorMessage : the server error message in case of a server error</li>
* <li> errorData.source : the issuing source element which triggered the request </li>
* <li> eventData.responseCode: the response code (aka http request response code, 401 etc...) </li>
* <li> eventData.responseText: the request response text </li>
* <li> eventData.responseXML: the request response xml </li>
* </ul>
*
* @param errorFunc error handler must be of the format <i>function errorListener(<errorData>)</i>
*/
function addOnError(errorFunc) {
AjaxImpl_1.Implementation.addOnError(errorFunc);
}
ajax.addOnError = addOnError;
/**
* Adds a global event listener to the ajax event queue. The event listener must be a function
* of following format: <i>function eventListener(<eventData>)</i>
*
* @param eventFunc event must be of the format <i>function eventListener(<eventData>)</i>
*/
function addOnEvent(eventFunc) {
AjaxImpl_1.Implementation.addOnEvent(eventFunc);
}
ajax.addOnEvent = addOnEvent;
})(ajax = faces.ajax || (faces.ajax = {}));
let util;
(function (util) {
/**
* varargs function which executes a chain of code (functions or any other code)
*
* if any of the code returns false, the execution
* is terminated prematurely skipping the rest of the code!
*
* @param {HTMLElement | String} source, the callee object
* @param {Event} event, the event object of the callee event triggering this function
* @param funcs ... arbitrary array of functions or strings
* @returns true if the chain has succeeded false otherwise
*/
function chain(source, event, ...funcs) {
return AjaxImpl_1.Implementation.chain(source, event, ...funcs);
}
util.chain = chain;
})(util = faces.util || (faces.util = {}));
let push;
(function (push) {
/**
* @param socketClientId the sockets client identifier
* @param url the uri to reach the socket
* @param channel the channel name/id
* @param onopen The function to be invoked when the web socket is opened.
* @param onmessage The function to be invoked when a message is received.
* @param onerror The function to be invoked when an error occurs.
* @param onclose The function to be invoked when the web socket is closed.
* @param behaviors functions which are invoked whenever a message is received
* @param autoConnect Whether or not to automatically open the socket. Defaults to <code>false</code>.
*/
function init(socketClientId, url, channel, onopen, onmessage, onerror, onclose, behaviors, autoConnect) {
PushImpl_1.PushImpl.init(socketClientId, url, channel, onopen, onmessage, onerror, onclose, behaviors, autoConnect);
}
push.init = init;
/**
* Open the web socket on the given channel.
* @param socketClientId The name of the web socket channel.
* @throws Error is thrown, if the channel is unknown.
*/
function open(socketClientId) {
PushImpl_1.PushImpl.open(socketClientId);
}
push.open = open;
/**
* Close the web socket on the given channel.
* @param socketClientId The id of the web socket client.
* @throws Error is thrown, if the channel is unknown.
*/
function close(socketClientId) {
PushImpl_1.PushImpl.close(socketClientId);
}
push.close = close;
})(push = faces.push || (faces.push = {}));
})(faces || (exports.faces = faces = {}));
var myfaces;
(function (myfaces) {
/**
* AB function similar to mojarra and Primefaces
* not part of the spec but a convenience accessor method
* Code provided by Thomas Andraschko
*
* @param source the event source
* @param event the event
* @param eventName event name for java.jakarta.faces.behavior.event
* @param execute execute list as passed down in faces.ajax.request
* @param render the render list as string
* @param options the options which need to be merged in
* @param userParameters a set of user parameters which go into the final options under params, they can overide whatever is passed via options
*/
function ab(source, event, eventName, execute, render, options = {}, userParameters = {}) {
var _a, _b;
if (!options) {
options = {};
}
if (!userParameters) {
userParameters = {};
}
if (eventName) {
options[Const_1.CTX_OPTIONS_PARAMS] = (_a = options === null || options === void 0 ? void 0 : options[Const_1.CTX_OPTIONS_PARAMS]) !== null && _a !== void 0 ? _a : {};
options[Const_1.CTX_OPTIONS_PARAMS][(0, Const_1.$nsp)(Const_1.P_BEHAVIOR_EVENT)] = eventName;
}
if (execute) {
options[Const_1.CTX_OPTIONS_EXECUTE] = execute;
}
if (render) {
options[Const_1.CTX_PARAM_RENDER] = render;
}
//we push the users parameters in
if (!options["params"]) {
options["params"] = {};
}
for (let key in userParameters) {
options["params"][key] = userParameters[key];
}
((_b = window === null || window === void 0 ? void 0 : window.faces) !== null && _b !== void 0 ? _b : window.jsf).ajax.request(source, event, options);
}
myfaces.ab = ab;
const onReadyChain = [];
let readyStateListener = null;
// noinspection JSUnusedGlobalSymbols
/**
* Helper function in the myfaces namespace to handle document ready properly for the load case
* the ajax case, does not need proper treatment, since it is deferred anyway.
* Used by command script as helper function!
*
* @param executionFunc the function to be executed upon ready
*/
function onDomReady(executionFunc) {
if (document.readyState !== "complete") {
onReadyChain.push(executionFunc);
if (!readyStateListener) {
readyStateListener = () => {
window.removeEventListener("DOMContentLoaded", readyStateListener);
readyStateListener = null;
try {
onReadyChain.forEach(func => func());
}
finally {
//done we clear now the ready chain
onReadyChain.length = 0;
}
};
window.addEventListener("DOMContentLoaded", readyStateListener);
}
}
else {
if (readyStateListener) {
readyStateListener();
}
executionFunc();
}
}
myfaces.onDomReady = onDomReady;
/**
* legacy oam functions
*/
myfaces.oam = OamSubmit_1.oam;
})(myfaces || (exports.myfaces = myfaces = {}));
//# sourceMappingURL=_api.js.map