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

FORMS-16342 commenting test #1404

Open
wants to merge 3 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,17 +17,7 @@

import java.io.IOException;
import java.math.BigDecimal;
import java.util.AbstractMap;
import java.util.Arrays;
import java.util.Calendar;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.Set;
import java.util.*;
import java.util.function.Predicate;
import java.util.regex.Pattern;
import java.util.stream.Collectors;
Expand Down Expand Up @@ -68,9 +58,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 = ReservedProperties.PN_DATAREF)
Expand Down Expand Up @@ -289,6 +282,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 @@ -541,4 +538,24 @@ 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 @@ -107,7 +107,11 @@ public String[] getEnumNames() {
String[] enumName = map.values().toArray(new String[0]);
return Arrays.stream(enumName)
.map(p -> {
return this.translate(ReservedProperties.PN_ENUM_NAMES, p);
String value = this.translate(ReservedProperties.PN_ENUM_NAMES, p);
if (value == null) {
value = "";
}
return value;
})
.toArray(String[]::new);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,12 @@
handler="CQ.FormsCoreComponents.editorhooks.viewQualifiedName"
icon="viewSOMExpression"
text="View Qualified Name"/>
<viewXFAScripts
jcr:primaryType="nt:unstructured"
condition="CQ.FormsCoreComponents.editorhooks.hasXfaScripts"
handler="CQ.FormsCoreComponents.editorhooks.viewXfaScripts"
icon="code"
text="View XFA Scripts"/>
</cq:actionConfigs>
<cq:inplaceEditing
jcr:primaryType="cq:InplaceEditingConfig"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,12 @@
handler="CQ.FormsCoreComponents.editorhooks.viewQualifiedName"
icon="viewSOMExpression"
text="View Qualified Name"/>
<viewXFAScripts
jcr:primaryType="nt:unstructured"
condition="CQ.FormsCoreComponents.editorhooks.hasXfaScripts"
handler="CQ.FormsCoreComponents.editorhooks.viewXfaScripts"
icon="code"
text="View XFA Scripts"/>
</cq:actionConfigs>
<cq:inplaceEditing
jcr:primaryType="cq:InplaceEditingConfig"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,14 +47,18 @@
Utils = window.CQ.FormsCoreComponents.Utils.v1;

var JSON_SCHEMA = 'jsonschema',
NONE = "none",
NONE = 'none',
FORM_DATA_MODEL = "formdatamodel",
FORM_TEMPLATE = 'formtemplates',
SCHEMA_REF = "input[name='./schemaRef']",
XDP_REF = "input[name='./xdpRef']",
SCHEMA_TYPE = "input[name='./schemaType']",
SCHEMA_CONTAINER = ".cmp-adaptiveform-container__schemaselectorcontainer",
FDM_CONTAINER = ".cmp-adaptiveform-container__fdmselectorcontainer",
FORM_TEMPLATE_CONTAINER = ".cmp-adaptiveform-container__formtemplateselectorcontainer",
SCHEMA_DROPDOWN_SELECTOR = ".cmp-adaptiveform-container__schemaselector",
FDM_DROPDOWN_SELECTOR = ".cmp-adaptiveform-container__fdmselector",
FORM_TEMPLATE_DROPDOWN_SELECTOR = ".cmp-adaptiveform-container__formtemplateselector",
FORM_MODEL_SELECTOR = ".cmp-adaptiveform-container__selectformmodel",
FM_AF_ROOT = "/content/forms/af/",
FM_DAM_ROOT ="/content/dam/formsanddocuments/",
Expand Down Expand Up @@ -110,9 +114,18 @@
if (isForm()){
var afAssetPath = getAfAssetMetadataPath();
DAM_SCHEMA_TYPE = "[name='" + afAssetPath + "/formmodel']";
DAM_SCHEMA_REF = "[name='" + afAssetPath + "/schemaRef']";
addFormParameter(afAssetPath + '/formmodel', schemaType);
addFormParameter(afAssetPath + '/schemaRef');
if(schemaType == JSON_SCHEMA){
DAM_SCHEMA_REF = "[name='" + afAssetPath + "/schemaRef']";
addFormParameter(afAssetPath + '/schemaRef');
} else if(schemaType == FORM_TEMPLATE){
DAM_SCHEMA_REF = "[name='" + afAssetPath + "/xdpRef']";
addFormParameter(afAssetPath + '/xdpRef');
// we don't want user to change the data model if form template has been selected
dialog.find('coral-selectlist-item[value="none"]').remove();
dialog.find('coral-selectlist-item[value="jsonschema"]').remove();
dialog.find('coral-selectlist-item[value="formdatamodel"]').remove();
}
}
document.body.appendChild(formModelChangeConfirmationDialog);
prefillSchema(schemaType, dialog);
Expand All @@ -130,6 +143,9 @@

function prefillSchema(schemaType, dialog){
var schemaRef = dialog.find(SCHEMA_REF);
if(schemaType == FORM_TEMPLATE){
schemaRef = dialog.find(XDP_REF);
}
if(schemaRef.length > 0){
schemaRef = schemaRef[0].value;
configuredFormModel = schemaRef;
Expand All @@ -138,6 +154,8 @@
$(SCHEMA_DROPDOWN_SELECTOR).val(schemaRef);
} else if (schemaType == FORM_DATA_MODEL) {
$(FDM_DROPDOWN_SELECTOR).val(schemaRef);
} else if (schemaType == FORM_TEMPLATE) {
$(FORM_TEMPLATE_DROPDOWN_SELECTOR).val(schemaRef);
}
}
};
Expand Down Expand Up @@ -172,6 +190,21 @@
}
};

function formTemplateSelectorOnChanged(dialog) {
var selectedSchema = dialog.find(FORM_TEMPLATE_DROPDOWN_SELECTOR);
if(selectedSchema.length > 0) {
selectedSchema = selectedSchema[0].value;
setElementValue(dialog, SCHEMA_REF, selectedSchema);
setElementValue(dialog, DAM_SCHEMA_REF, selectedSchema);
isSchemaChanged = true;
if (configuredFormModel) {
confirmFormModelChange(selectedSchema, $(FORM_TEMPLATE_DROPDOWN_SELECTOR));
} else {
toBeConfiguredFormModel = selectedSchema;
}
}
};

function setElementValue(dialog, elementRef, value){
var element = dialog.find(elementRef);
if(element.length > 0){
Expand Down Expand Up @@ -205,13 +238,20 @@
function hideContainersExcept(selectedSchemaType) {
if (selectedSchemaType == JSON_SCHEMA) {
$(FDM_CONTAINER).hide();
$(FORM_TEMPLATE_CONTAINER).hide();
$(SCHEMA_CONTAINER).show();
} else if (selectedSchemaType == FORM_DATA_MODEL) {
$(SCHEMA_CONTAINER).hide();
$(FORM_TEMPLATE_CONTAINER).hide();
$(FDM_CONTAINER).show();
} else if (selectedSchemaType == 'none') {
} else if (selectedSchemaType == FORM_TEMPLATE) {
$(FDM_CONTAINER).hide();
$(SCHEMA_CONTAINER).hide();
$(FORM_TEMPLATE_CONTAINER).show();
} else if (selectedSchemaType == NONE) {
$(FDM_CONTAINER).hide();
$(SCHEMA_CONTAINER).hide();
$(FORM_TEMPLATE_CONTAINER).hide();
}
};

Expand All @@ -238,7 +278,8 @@
function initialiseDataModel(dialog) {
var formModelSelector = dialog.find(FORM_MODEL_SELECTOR)[0],
schemaSelector = dialog.find(SCHEMA_DROPDOWN_SELECTOR)[0],
fdmSelector = dialog.find(FDM_DROPDOWN_SELECTOR)[0];
fdmSelector = dialog.find(FDM_DROPDOWN_SELECTOR)[0],
formTemplateSelector = dialog.find(FORM_TEMPLATE_DROPDOWN_SELECTOR)[0];
if (formModelSelector) {
formModelSelector.on("change", function() {
selectFormModelOnChanged(dialog);
Expand All @@ -254,6 +295,11 @@
fdmSelectorOnChanged(dialog);
});
};
if(formTemplateSelector) {
formTemplateSelector.on("change", function() {
formTemplateSelectorOnChanged(dialog);
});
}
selectFormModelOnLoad(dialog);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,10 @@
jcr:primaryType="nt:unstructured"
text="Form Data Model"
value="formdatamodel"/>
<optionFormTemplates
jcr:primaryType="nt:unstructured"
text="Form Templates"
value="formtemplates"/>
</items>
</selectformmodel>
<schemaRef name="./schemaRef"
Expand Down Expand Up @@ -169,6 +173,29 @@
</fdmselector>
</items>
</fdmselectorcontainer>
<formTemplateSelectorContainer
jcr:primaryType="nt:unstructured"
sling:resourceType="granite/ui/components/coral/foundation/container"
granite:class="cmp-adaptiveform-container__formtemplateselectorcontainer">
<items jcr:primaryType="nt:unstructured">
<formTemplateSelector
granite:class="cmp-adaptiveform-container__formtemplateselector"
jcr:primaryType="nt:unstructured"
sling:resourceType="granite/ui/components/coral/foundation/form/select"
name="./xdpRef"
disabled="false"
fieldLabel="Select Form Template *"
validation="datamodel.config"
renderReadOnly="false">
<datasource
jcr:primaryType="nt:unstructured"
sling:resourceType="fd/af/components/commons/datasources/propertyprovider"
guideDataModel="basic"
layoutType="fd/af/layouts/panel"
type="formtemplates"/>
</formTemplateSelector>
</items>
</formTemplateSelectorContainer>
<formmodelparameters
granite:id="formmodelparameters"
jcr:primaryType="nt:unstructured"
Expand Down
Loading