UNPKG

jsf.js_next_gen

Version:

A next generation typescript reimplementation of jsf.js

105 lines 4.28 kB
"use strict"; /*! 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.resolveSourceForm = exports.resolveSourceElement = exports.resolveContexts = exports.resolveResponseXML = void 0; const mona_dish_1 = require("mona-dish"); const Assertions_1 = require("../util/Assertions"); const mona_dish_2 = require("mona-dish"); const Const_1 = require("../core/Const"); const ExtDomQuery_1 = require("../util/ExtDomQuery"); /** * Resolver functions for various aspects of the response data * * stateless because it might be called from various * parts of the response classes */ /** * fetches the response XML * as XML Query object * * @param request the request hosting the responseXML * * Throws an error in case of non-existent or wrong xml data * */ function resolveResponseXML(request) { let ret = new mona_dish_1.XMLQuery((0, Const_1.$nsp)(request.getIf(Const_1.SEL_RESPONSE_XML).value)); Assertions_1.Assertions.assertValidXMLResponse(ret); return ret; } exports.resolveResponseXML = resolveResponseXML; /** * Splits the incoming pass-through context apart * in an internal and an external normalized context * the internal one is just for our internal processing * * @param context the root context as associative array */ function resolveContexts(context) { /** * we split the context apart into the external one and * some internal values */ let externalContext = ExtDomQuery_1.ExtConfig.fromNullable(context); let internalContext = externalContext.getIf(Const_1.CTX_PARAM_MF_INTERNAL); if (!internalContext.isPresent()) { internalContext = ExtDomQuery_1.ExtConfig.fromNullable({}); } /** * prepare storage for some deferred operations */ internalContext.assign(Const_1.DEFERRED_HEAD_INSERTS).value = []; internalContext.assign(Const_1.UPDATE_FORMS).value = []; internalContext.assign(Const_1.UPDATE_ELEMS).value = []; return { externalContext, internalContext }; } exports.resolveContexts = resolveContexts; /** * fetches the source element out of our contexts * * @param context the external context which should host the source id * @param internalContext internal pass-through fall back * */ function resolveSourceElement(context, internalContext) { let elemId = resolveSourceElementId(context, internalContext); return mona_dish_2.DQ.byId(elemId.value, true); } exports.resolveSourceElement = resolveSourceElement; /** * fetches the source form if it still exists * also embedded forms and parent forms are taken into consideration * as fallbacks * * @param internalContext * @param elem */ function resolveSourceForm(internalContext, elem) { let sourceFormId = internalContext.getIf(Const_1.CTX_PARAM_SRC_FRM_ID); let sourceForm = new mona_dish_2.DQ(sourceFormId.isPresent() ? document.forms[sourceFormId.value] : null); sourceForm = sourceForm.orElseLazy(() => elem.firstParent(Const_1.HTML_TAG_FORM)) .orElseLazy(() => elem.querySelectorAll(Const_1.HTML_TAG_FORM)) .orElseLazy(() => mona_dish_2.DQ.querySelectorAll(Const_1.HTML_TAG_FORM)); return sourceForm; } exports.resolveSourceForm = resolveSourceForm; function resolveSourceElementId(context, internalContext) { //?internal context?? used to be external one return internalContext.getIf(Const_1.CTX_PARAM_SRC_CTL_ID) .orElseLazy(() => context.getIf(Const_1.SOURCE, "id").value); } //# sourceMappingURL=ResonseDataResolver.js.map