Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Xfasupport #1401

Open
wants to merge 18 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,12 @@

import java.io.IOException;
import java.util.AbstractMap;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashSet;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.Set;
Expand Down Expand Up @@ -61,9 +63,12 @@
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.JsonSerializer;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.SerializerProvider;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.fasterxml.jackson.databind.node.ArrayNode;

public class AbstractFormComponentImpl extends AbstractComponentImpl implements FormComponent {
@ValueMapValue(injectionStrategy = InjectionStrategy.OPTIONAL, name = "dataRef")
Expand Down Expand Up @@ -278,6 +283,10 @@ protected boolean getEditMode() {
if (rulesProperties.size() > 0) {
properties.put(CUSTOM_RULE_PROPERTY_WRAPPER, rulesProperties);
}
List<String> disabledScripts = getDisabledXFAScripts();
if (disabledScripts.size() > 0) {
properties.put("fd:disabledXfaScripts", disabledScripts);
}
return properties;
}

Expand Down Expand Up @@ -506,4 +515,25 @@ public Map<String, Object> getDorProperties() {
}
return customDorProperties;
}

private List<String> getDisabledXFAScripts() {
Set<String> disabledScripts = new HashSet<>();
String xfaScripts = resource.getValueMap().get("fd:xfaScripts", "");
if (StringUtils.isNotEmpty(xfaScripts)) {
// read string xfaScripts to jsonNode
ObjectMapper mapper = new ObjectMapper();
try {
ArrayNode node = (ArrayNode) mapper.readTree(xfaScripts);
// iterate through the array node and add the elements which have disabled property set to true
for (JsonNode jsonNode : node) {
if (jsonNode.has("disabled") && jsonNode.get("disabled").asBoolean()) {
disabledScripts.add(jsonNode.get("activity").asText());
}
}
} catch (IOException e) {
logger.error("Error while parsing xfaScripts {} {}", e, resource.getPath());
}
}
return new ArrayList<>(disabledScripts);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public boolean isEnforceEnum() {

/**
* Function to retrieve enum values and enum names paired together
*
*
* @return map containing enum values and enum names as key-value pairs
*/
private Map<Object, String> getEnumPairs() {
Expand Down Expand Up @@ -106,7 +106,11 @@ public String[] getEnumNames() {
String[] enumName = map.values().toArray(new String[0]);
return Arrays.stream(enumName)
.map(p -> {
return this.translate("enumNames", p);
String value = this.translate("enumNames", p);
if (value == null) {
value = "";
}
return value;
})
.toArray(String[]::new);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<jcr:root xmlns:cq="http://www.day.com/jcr/cq/1.0" xmlns:jcr="http://www.jcp.org/jcr/1.0"
jcr:primaryType="cq:ClientLibraryFolder"
allowProxy="{Boolean}true"
categories="[core.forms.components.commons.v1.tabs]"
dependencies="[core.wcm.components.tabs.v1]"/>
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
###############################################################################
# Copyright 2023 Adobe
#
# Licensed 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.
###############################################################################

#base=js
common.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,169 @@
/*******************************************************************************
* Copyright 2024 Adobe
*
* Licensed 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.
******************************************************************************/


(function () {

function TabsMixin(Base) {
return class extends Base {

/**
* Private property for storing the active tab ID.
* @type {string}
*/
#_active;

/**
* Private property for storing the IS.
* @type {string}
*/
#_IS;
/**
* Private property for storing the namespace.
* @type {string}
*/
#_NS;
/**
* Private property for storing the selectors.
* @type {object}
*/
#_selectors;

constructor(params, ns, is, selectors) {
super(params);
this.#_IS = is;
this.#_NS = ns;
this.#_selectors = selectors;
const { element } = params;
this.#cacheElements(element);
this.#_active = this.getActiveTabId(this.#getCachedTabs());
this.#refreshActive();
}

/**
* Gets the cached tab panels.
* @returns {NodeList} The cached tab panels.
* @private
*/
#getCachedTabPanels() {
return this._elements["tabpanel"]
}

/**
* Gets the cached tabs.
* @returns {NodeList} The cached tabs.
* @private
*/
#getCachedTabs() {
return this._elements["tab"];
}

/**
* Caches the Tabs elements as defined via the {@code data-tabs-hook="ELEMENT_NAME"} markup API.
* @private
* @param {HTMLElement} wrapper - The Tabs wrapper element.
*/
#cacheElements(wrapper) {
this._elements = {};
this._elements.self = wrapper;
var hooks = this._elements.self.querySelectorAll("[data-" + this.#_NS + "-hook-" + this.#_IS + "]");

for (var i = 0; i < hooks.length; i++) {
var hook = hooks[i];
if (hook.closest("[data-cmp-is=" + this.#_IS + "]") === this._elements.self) { // only process own tab elements
var lowerCased = this.#_IS.toLowerCase();
var capitalized = lowerCased.charAt(0).toUpperCase() + lowerCased.slice(1);
var key = hook.dataset[this.#_NS + "Hook" + capitalized];
if (this._elements[key]) {
if (!Array.isArray(this._elements[key])) {
var tmp = this._elements[key];
this._elements[key] = [tmp];
}
this._elements[key].push(hook);
} else {
this._elements[key] = [hook];
}
}
}
}

/**
* Refreshes the tab markup based on the current active index.
* @private
*/
#refreshActive() {
var tabpanels = this.#getCachedTabPanels();
var tabs = this.#getCachedTabs();
if (tabpanels) {
for (var i = 0; i < tabpanels.length; i++) {
if(tabs[i]) {
if (tabs[i].id === this.#_active) {
tabpanels[i].classList.add(this.#_selectors.active.tabpanel);
tabpanels[i].removeAttribute("aria-hidden");
tabs[i].classList.add(this.#_selectors.active.tab);
tabs[i].setAttribute("aria-selected", true);
tabs[i].setAttribute("tabindex", "0");
tabs[i].setAttribute("aria-current", "true");
} else {
tabpanels[i].classList.remove(this.#_selectors.active.tabpanel);
tabpanels[i].setAttribute("aria-hidden", true);
tabs[i].classList.remove(this.#_selectors.active.tab);
tabs[i].setAttribute("aria-selected", false);
tabs[i].setAttribute("tabindex", "-1");
tabs[i].setAttribute("aria-current", "false");
}
}
}
}
}

/**
* Returns the id of the active tab, if no tab is active returns 0th element id
*
* @param {Array} tabs Tab elements
* @returns {Number} Id of the active tab, 0th element id if none is active
*/
getActiveTabId(tabs) {
if (tabs) {
var result = tabs[0].id;
for (var i = 0; i < tabs.length; i++) {
if (tabs[i].classList.contains(this.#_selectors.active.tab)) {
result = tabs[i].id;
break;
}
}
return result;
}
}

/**
* Navigates to the tab at the provided index
*
* @private
* @param {Number} index The index of the tab to navigate to
*/
navigate(index) {
this.#_active = index;
this.#refreshActive();
}
}
}

window.Forms = window.Forms || {};
window.Forms.CoreComponentsCommons = window.Forms.CoreComponentsCommons || {};
window.Forms.CoreComponentsCommons.TabsMixin = TabsMixin;

}());
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,6 @@
data-sly-test="${(wcmmode.edit || wcmmode.preview) && accordion.items.size < 1}"></sly>
<sly data-sly-use.clientlib="core/wcm/components/commons/v1/templates/clientlib.html">
<sly data-sly-test="${wcmmode.edit}"
data-sly-call="${clientlib.js @ categories='core.forms.components.accordion.v1.runtime'}"/>
data-sly-call="${clientlib.js @ categories='core.forms.components.accordion.v1.contentframe'}"/>
</sly>
</div>
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<jcr:root xmlns:cq="http://www.day.com/jcr/cq/1.0" xmlns:jcr="http://www.jcp.org/jcr/1.0"
jcr:primaryType="cq:ClientLibraryFolder"
allowProxy="{Boolean}true"
categories="[core.forms.components.accordion.v1.commons]"
dependencies="[core.wcm.components.accordion.v1]"/>
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
###############################################################################
# Copyright 2023 Adobe
#
# Licensed 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.
###############################################################################

#base=js
common.js
Loading