jsf.js_next_gen
Version:
A next generation typescript reimplementation of jsf.js
128 lines • 6.21 kB
JavaScript
;
/*! 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.
*/
Object.defineProperty(exports, "__esModule", { value: true });
exports.oam = void 0;
const mona_dish_1 = require("mona-dish");
const Lang_1 = require("../impl/util/Lang");
/**
* legacy code to enable various aspects
* of myfaces, used to be rendered inline
* for jsf 2.0 we can externalize it into its own custom resource
*
* note this is a straight 1:1 port from the existing codebase
* (not too much work has been spent here, the important thing is, that
* the namespace and functions need to be kept intact for legacy code)
*
* we might move the code over in the future, but for now a straight 1:1 port suffices
*/
var oam;
(function (oam) {
var ofAssoc = Lang_1.ExtLang.ofAssoc;
/**
* sets a hidden input field
* @param formName the formName
* @param name the hidden field
* @param value the value to be rendered
*/
oam.setHiddenInput = function (formName, name, value) {
mona_dish_1.DQ.byId(document.forms[formName])
.each(form => {
const input = form.querySelectorAll(`input[type='hidden'][name='${name}']`);
if (input.isPresent()) {
input.inputValue.value = value;
}
else {
const newInput = mona_dish_1.DQ.fromMarkup(`<input type='hidden' id='${name}' name='${name}'>`);
newInput.inputValue.value = value;
newInput.appendTo(form);
}
});
};
/**
* clears a hidden input field
*
* @param formName formName for the input
* @param name the name of the input field
*/
oam.clearHiddenInput = function (formName, name) {
var _a, _b, _c;
let element = (_c = (_b = (_a = document.forms) === null || _a === void 0 ? void 0 : _a[formName]) === null || _b === void 0 ? void 0 : _b.elements) === null || _c === void 0 ? void 0 : _c[name];
if (!element) {
return;
}
mona_dish_1.DQ.byId(element).delete();
};
// noinspection JSUnusedGlobalSymbols,JSUnusedLocalSymbols
/**
* does special form submit remapping
* re-maps the issuing command link into something,
* the "decode" of the command link on the server can understand
*
* @param formName
* @param linkId
* @param target
* @param params
*/
oam.submitForm = function (formName, linkId = null, target = null, params = {}) {
var _a, _b, _c, _d, _e, _f;
//handle a possible incoming null, not sure if this is used that way anywhere, but we allow it
params = (!params) ? {} : params;
let clearFn = 'clearFormHiddenParams_' + formName.replace(/-/g, '\$:').replace(/:/g, '_');
(_a = window === null || window === void 0 ? void 0 : window[clearFn]) === null || _a === void 0 ? void 0 : _a.call(window, formName);
//autoscroll code
if (((_d = (_c = (_b = window === null || window === void 0 ? void 0 : window.myfaces) === null || _b === void 0 ? void 0 : _b.core) === null || _c === void 0 ? void 0 : _c.config) === null || _d === void 0 ? void 0 : _d.autoScroll) && (window === null || window === void 0 ? void 0 : window.getScrolling)) {
myfaces.oam.setHiddenInput(formName, 'autoScroll', window === null || window === void 0 ? void 0 : window.getScrolling());
}
let paramsStream = Array.isArray(params) ? [...params] : ofAssoc(params);
paramsStream.forEach(([key, data]) => myfaces.oam.setHiddenInput(formName, key, data));
//we call the namespaced function, to allow decoration, via a direct call we would
myfaces.oam.setHiddenInput(formName, `${formName}:_idcl`, linkId !== null && linkId !== void 0 ? linkId : '');
mona_dish_1.DQ.byId((_f = (_e = document.forms) === null || _e === void 0 ? void 0 : _e[formName]) !== null && _f !== void 0 ? _f : document.getElementById(formName)).each(form => {
var _a;
const ATTR_TARGET = "target";
const formElement = form.getAsElem(0).value;
const oldTarget = form.getAsElem(0).value.getAttribute("target");
if (target != "null" && target) {
form.getAsElem(0).value.setAttribute("target", target);
}
const result = (_a = formElement === null || formElement === void 0 ? void 0 : formElement.onsubmit) === null || _a === void 0 ? void 0 : _a.call(formElement, null);
try {
if ((!!result) || 'undefined' == typeof result) {
formElement.submit();
}
}
catch (e) {
window === null || window === void 0 ? void 0 : window.console.error(e);
}
finally {
if (oldTarget == null || oldTarget == "null") {
form.getAsElem(0).value.removeAttribute("target");
}
else {
form.getAsElem(0).value.setAttribute("target", oldTarget);
}
// noinspection JSUnusedLocalSymbols
paramsStream.forEach(([key, data]) => {
myfaces.oam.clearHiddenInput(formName, key);
});
myfaces.oam.clearHiddenInput(formName, `${formName}:_idcl`);
}
});
return false;
};
})(oam || (exports.oam = oam = {}));
//# sourceMappingURL=OamSubmit.js.map