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

Save As Fragment #1433

Open
wants to merge 24 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 20 commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
d942347
Save As Fragment button in authoring accordion, tabs on top, wizard a…
TalmizAhmed Apr 27, 2023
da5bc6b
Merge branch 'dev' into saveAsFragment
TalmizAhmed Apr 27, 2023
9e3f782
Authoring tests
TalmizAhmed May 2, 2023
59516ad
Fix crashing of cypress
TalmizAhmed May 2, 2023
0722eb7
Changes from comments
TalmizAhmed Jun 14, 2023
5668a5f
Dialog name change
TalmizAhmed Jun 14, 2023
e8e4118
Merge branch 'fragment' into saveAsFragment
TalmizAhmed Jun 14, 2023
2779112
Merge branch 'fragment' into saveAsFragment
TalmizAhmed Jun 19, 2023
f998f9c
API data object
TalmizAhmed Jun 23, 2023
27a05aa
Minor changes to dialog content.xml
TalmizAhmed Jun 26, 2023
f07043b
Merge branch 'fragment' into saveAsFragment
TalmizAhmed Jun 26, 2023
2be1d13
Reverting dor hook change
TalmizAhmed Jul 3, 2023
87bd533
Merge branch 'dev' of https://github.com/adobe/aem-core-forms-compone…
dmaurya929 Sep 26, 2024
2437bc4
FORMS-16112 Save as fragment
dmaurya929 Oct 3, 2024
a7d97f3
Merge branch 'dev' of https://github.com/adobe/aem-core-forms-compone…
dmaurya929 Oct 3, 2024
a855a8f
FORMS-16112 Save panel as fragment support
dmaurya929 Oct 14, 2024
6340fbc
FORMS-16112 fix validation and tests
dmaurya929 Oct 15, 2024
7b961c6
FORMS-16112 fix validation and tests
dmaurya929 Oct 15, 2024
2eb8d6a
FORMS-16112 moving code
dmaurya929 Oct 29, 2024
aa04649
Merge branch 'dev' of https://github.com/adobe/aem-core-forms-compone…
dmaurya929 Nov 4, 2024
6c0614f
FORMS-16112 review comment and move fragment template code to server-…
dmaurya929 Nov 13, 2024
e03180e
FORMS-17206 review comment
dmaurya929 Nov 26, 2024
38139df
FORMS-16112 review comment
dmaurya929 Dec 2, 2024
751e5e1
FORMS-16112 review comment
dmaurya929 Dec 3, 2024
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 @@ -160,6 +160,7 @@ public List<String> getTitleListOfChildren() {
public Map<String, Object> getProperties() {
Map<String, Object> properties = super.getProperties();
properties.put(CUSTOM_FRAGMENT_PROPERTY_WRAPPER, true);
properties.put(ReservedProperties.PN_VIEWTYPE, "fragment");
return properties;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<jcr:root xmlns:jcr="http://www.jcp.org/jcr/1.0" xmlns:nt="http://www.jcp.org/jcr/nt/1.0" xmlns:cq="http://www.day.com/jcr/cq/1.0"
<jcr:root xmlns:jcr="http://www.jcp.org/jcr/1.0" xmlns:nt="http://www.jcp.org/jcr/nt/1.0" xmlns:cq="http://www.day.com/jcr/cq/1.0" xmlns:fd="http://www.adobe.com/aemfd/fd/1.0"
jcr:primaryType="nt:unstructured"
jcr:title="Fragment"
fd:viewType="fragment"
dmaurya929 marked this conversation as resolved.
Show resolved Hide resolved
fieldType="panel"/>
Original file line number Diff line number Diff line change
@@ -0,0 +1,281 @@
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
~ 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($, channel, Coral) {
dmaurya929 marked this conversation as resolved.
Show resolved Hide resolved
dmaurya929 marked this conversation as resolved.
Show resolved Hide resolved
"use strict";

window.CQ = window.CQ || {};
dmaurya929 marked this conversation as resolved.
Show resolved Hide resolved
window.CQ.FormsCoreComponents = window.CQ.FormsCoreComponents || {};
window.CQ.FormsCoreComponents.Utils = window.CQ.FormsCoreComponents.Utils || {};
const DataModel = window.CQ.FormsCoreComponents.Utils.DataModel = window.CQ.FormsCoreComponents.Utils.DataModel || {};

var FORM_CONTAINER_SELECTOR = "[data-cmp-is='adaptiveFormContainer']";
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

None of this code is going to be changed by core component developers, let's move this code to cq-guides (like we have done for replace / rule editor etc), since this logic is very specific

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, these codes should not require any customization. In that case Data Model code will also required to moved to avoid duplicacy right ?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I agree that the data model code shouldn't be included here. We should keep the codebase clean by only including the relevant components that are customizable or useful for developers


var JSON_SCHEMA = 'jsonschema',
NONE = "none",
FORM_DATA_MODEL = "formdatamodel",
CONNECTOR = "connector",
SCHEMA_REF = "input[name='./schemaRef']",
SCHEMA_TYPE = "input[name='./schemaType']",
SCHEMA_CONTAINER = ".cmp-adaptiveform-container__schemaselectorcontainer",
FDM_CONTAINER = ".cmp-adaptiveform-container__fdmselectorcontainer",
CONNECTOR_CONTAINER = ".cmp-adaptiveform-container__marketoselectorcontainer",
SCHEMA_DROPDOWN_SELECTOR = ".cmp-adaptiveform-container__schemaselector",
FDM_DROPDOWN_SELECTOR = ".cmp-adaptiveform-container__fdmselector",
CONNECTOR_DROPDOWN_SELECTOR = ".cmp-adaptiveform-container__marketoselector",
FORM_MODEL_SELECTOR = ".cmp-adaptiveform-container__selectformmodel",
FM_AF_ROOT = "/content/forms/af/",
FM_DAM_ROOT ="/content/dam/formsanddocuments/",
DAM_SCHEMA_TYPE,
DAM_SCHEMA_REF;

var configuredFormModel,
toBeConfiguredFormModel,
isConfirmationDialogAccept = false,
doNotShowDialogFlag = false,
isSchemaChanged = false,
dialogHeader = Granite.I18n.get("Form Model"),
dialogContent = "<p>" + Granite.I18n.get("When you replace the old data model with a new model, some data bindings might break and lead to form submission errors.") + "</p>" + "<coral-checkbox id='doNotShowDialogCheckBox'>" + Granite.I18n.get("Don't show this again") + "</coral-checkbox>",
dialogFooter = '<button id="formModelDialogCancelButton" is="coral-button" variant="default" coral-close>' + Granite.I18n.get("Cancel") + '</button><button id="formModelDialogAcceptButton" is="coral-button" variant="primary" coral-close>' + Granite.I18n.get("Ok") + '</button>';

var formModelChangeConfirmationDialog = new Coral.Dialog().set({
id: 'formModelChange',
header: {
innerHTML: dialogHeader
},
content: {
innerHTML: dialogContent
},
footer: {
innerHTML: dialogFooter
},
variant : 'warning'
});

channel.on("dialog-success", function (e) {
configuredFormModel = toBeConfiguredFormModel;
isConfirmationDialogAccept = false;
if(isForm() && isSchemaChanged){
var customEvent = document.createEvent("CustomEvent");
customEvent.initCustomEvent("data-model-selected", true, true);
window.dispatchEvent(customEvent);
}
});

channel.on('change', '#doNotShowDialogCheckBox', function(e) {
if (this.checked) {
doNotShowDialogFlag = true;
} else {
doNotShowDialogFlag = false;
}
});

function selectFormModelOnLoad(dialog) {
var schemaType = dialog.find(FORM_MODEL_SELECTOR);
if(schemaType.length > 0){
schemaType = schemaType[0].value;
hideContainersExcept(schemaType);
if (isForm()){
var afAssetPath = getAfAssetMetadataPath();
DAM_SCHEMA_TYPE = "[name='" + afAssetPath + "/formmodel']";
DAM_SCHEMA_REF = "[name='" + afAssetPath + "/schemaRef']";
addFormParameter(afAssetPath + '/formmodel', schemaType);
addFormParameter(afAssetPath + '/schemaRef');
}
document.body.appendChild(formModelChangeConfirmationDialog);
prefillSchema(schemaType, dialog);
}
}

function selectFormModelOnChanged(dialog) {
var schemaTypeSelected = dialog.find(FORM_MODEL_SELECTOR);
if(schemaTypeSelected.length > 0){
schemaTypeSelected = schemaTypeSelected[0].value;
setElementValue(dialog, DAM_SCHEMA_TYPE, schemaTypeSelected)
hideContainersExcept(schemaTypeSelected);
}
}

function prefillSchema(schemaType, dialog){
var schemaRef = dialog.find(SCHEMA_REF);
if(schemaRef.length > 0){
schemaRef = schemaRef[0].value;
configuredFormModel = schemaRef;
setElementValue(dialog, DAM_SCHEMA_REF, schemaRef);
if (schemaType == JSON_SCHEMA) {
$(SCHEMA_DROPDOWN_SELECTOR).val(schemaRef);
} else if (schemaType == FORM_DATA_MODEL) {
$(FDM_DROPDOWN_SELECTOR).val(schemaRef);
} else if (schemaType == CONNECTOR) {
$(CONNECTOR_DROPDOWN_SELECTOR).val(schemaRef);
}
}
}

function schemaSelectorOnChanged(dialog) {
var selectedSchema = dialog.find(SCHEMA_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, $(SCHEMA_DROPDOWN_SELECTOR));
} else {
toBeConfiguredFormModel = selectedSchema;
}
}
};

function fdmSelectorOnChanged(dialog) {
var selectedSchema = dialog.find(FDM_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, $(FDM_DROPDOWN_SELECTOR));
} else {
toBeConfiguredFormModel = selectedSchema;
}
}
};

function connectorSelectorOnChanged(dialog) {
var selectedSchema = dialog.find(CONNECTOR_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, $(CONNECTOR_DROPDOWN_SELECTOR));
} else {
toBeConfiguredFormModel = selectedSchema;
}
}
};

function setElementValue(dialog, elementRef, value){
var element = dialog.find(elementRef);
if(element.length > 0){
element[0].value = value;
}
}

function getAfAssetMetadataPath() {
return getGuideContainerPath().replace(FM_AF_ROOT, FM_DAM_ROOT).replace("/guideContainer", "/metadata");
}

function getGuideContainerPath() {
var afWindow = (Granite.author ? Granite.author.ContentFrame.contentWindow : window);
return afWindow.$(FORM_CONTAINER_SELECTOR).data("cmp-path");
};

function isForm(){
return Granite.author.page.path.startsWith(FM_AF_ROOT);
}

function addFormParameter(name, value) {
var input = channel[0].createElement('input');
input.setAttribute("type", "hidden");
input.setAttribute("name", name);
if(value) {
input.setAttribute("value", value);
}
$("#formmodelparameters").append(input);
}

function hideContainersExcept(selectedSchemaType) {
if (selectedSchemaType == JSON_SCHEMA) {
$(FDM_CONTAINER).hide();
$(CONNECTOR_CONTAINER).hide();
$(SCHEMA_CONTAINER).show();
} else if (selectedSchemaType == FORM_DATA_MODEL) {
$(SCHEMA_CONTAINER).hide();
$(CONNECTOR_CONTAINER).hide();
$(FDM_CONTAINER).show();
} else if (selectedSchemaType == CONNECTOR) {
$(SCHEMA_CONTAINER).hide();
$(FDM_CONTAINER).hide();
$(CONNECTOR_CONTAINER).show();
} else if (selectedSchemaType == 'none') {
$(FDM_CONTAINER).hide();
$(CONNECTOR_CONTAINER).hide();
$(SCHEMA_CONTAINER).hide();
}
};

function confirmFormModelChange(selectedSchema, dataModelSelector) {
if (!isConfirmationDialogAccept && Granite.author.preferences.cookie.get("form-model-change-dialog") !== "disabled") {
if (configuredFormModel !== selectedSchema) {
formModelChangeConfirmationDialog.show();
$("#formModelDialogCancelButton").on("click", function () {
dataModelSelector.val(configuredFormModel);
});
$("#formModelDialogAcceptButton").on("click", function () {
if (doNotShowDialogFlag) {
Granite.author.preferences.cookie.set("form-model-change-dialog","disabled");
} else {
Granite.author.preferences.cookie.set("form-model-change-dialog","enabled");
}
isConfirmationDialogAccept = true;
});
}
}
toBeConfiguredFormModel = selectedSchema;
}

$(window).adaptTo("foundation-registry").register("foundation.validation.validator", {
selector : "[data-validation~='datamodel.config']",
validate : function (el) {
let $el = $(el);
if($el.is(":visible") && $el[0].value === '') {
return Granite.I18n.getMessage("This is a required field");
}
}
});

DataModel.initialiseDataModel = function (dialog) {
var formModelSelector = dialog.find(FORM_MODEL_SELECTOR)[0],
schemaSelector = dialog.find(SCHEMA_DROPDOWN_SELECTOR)[0],
fdmSelector = dialog.find(FDM_DROPDOWN_SELECTOR)[0],
connectorSelector = dialog.find(CONNECTOR_DROPDOWN_SELECTOR)[0];
if (formModelSelector) {
formModelSelector.on("change", function() {
selectFormModelOnChanged(dialog);
});
}
if (schemaSelector) {
schemaSelector.on("change", function() {
schemaSelectorOnChanged(dialog);
});
}
if (fdmSelector) {
fdmSelector.on("change", function() {
fdmSelectorOnChanged(dialog);
});
}
if (connectorSelector) {
connectorSelector.on("change", function() {
connectorSelectorOnChanged(dialog);
});
};
selectFormModelOnLoad(dialog);
}

})(jQuery, jQuery(document), Coral);
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,5 @@
# limitations under the License.
###############################################################################

utils.js
utils.js
datamodel.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,11 @@
handler="CQ.FormsCoreComponents.editorhooks.replace"
icon="shuffle"
text="Replace"/>
<saveAsFragment
jcr:primaryType="nt:unstructured"
handler="CQ.FormsCoreComponents.editorhooks.saveAsFragment"
icon="fragmentAdd"
text="Save as Fragment"/>
<qualifiedName
jcr:primaryType="nt:unstructured"
handler="CQ.FormsCoreComponents.editorhooks.viewQualifiedName"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,6 @@
handleAssistPriority(dialog);
Utils.prefillMultifieldValues(dialog, BASE_ENUMNAMES_VISIBLE, BASE_ENUMNAMES_HIDDEN);
showHideDoRBindRefField(dialog);
validateName();
handleDialogSubmit(dialog);
if (isTitleRichText) {
resolveRichText(dialog, isTitleRichText, false);
Expand Down Expand Up @@ -316,6 +315,9 @@
});
};

// Registering validator for node name
validateName();

Utils.initializeEditDialog(EDIT_DIALOG)(initialise, updateRichTextTitleOnChange, updateEnumNamesOnAdd, updateEnumNamesOnChange);

})(jQuery, Granite.author, jQuery(document));
Loading
Loading