From 781ef7577cbac1f85167ac4e970fb75102ddecf0 Mon Sep 17 00:00:00 2001
From: Pankaj
Date: Mon, 13 Jan 2025 12:36:15 +0530
Subject: [PATCH] FORMS-16201 Register auto save in publish(disabled) mode only
---
.../models/v2/form/FormContainerImpl.java | 10 +++++-
.../components/models/form/FormContainer.java | 11 +++++++
.../components/models/form/package-info.java | 2 +-
.../models/v2/form/FormContainerImplTest.java | 19 ++++++++---
.../exporter-formcontainerv2.json | 3 --
.../form/container/v2/container/README.md | 5 ++-
.../clientlibs/site/js/formcontainerview.js | 6 +++-
.../container/v2/container/container.html | 3 +-
ui.frontend/package-lock.json | 32 +++++++++----------
ui.frontend/package.json | 4 +--
10 files changed, 64 insertions(+), 31 deletions(-)
diff --git a/bundles/af-core/src/main/java/com/adobe/cq/forms/core/components/internal/models/v2/form/FormContainerImpl.java b/bundles/af-core/src/main/java/com/adobe/cq/forms/core/components/internal/models/v2/form/FormContainerImpl.java
index 15c39469ae..dd00390751 100644
--- a/bundles/af-core/src/main/java/com/adobe/cq/forms/core/components/internal/models/v2/form/FormContainerImpl.java
+++ b/bundles/af-core/src/main/java/com/adobe/cq/forms/core/components/internal/models/v2/form/FormContainerImpl.java
@@ -354,7 +354,9 @@ public String getLanguageDirection() {
}
properties.put(FD_ROLE_ATTRIBUTE, getRoleAttribute());
properties.put(FD_FORM_DATA_ENABLED, formDataEnabled);
- properties.put(ReservedProperties.FD_AUTO_SAVE_PROPERTY_WRAPPER, this.autoSaveConfig);
+ if (this.autoSaveConfig != null && this.autoSaveConfig.isEnableAutoSave()) {
+ properties.put(ReservedProperties.FD_AUTO_SAVE_PROPERTY_WRAPPER, this.autoSaveConfig);
+ }
properties.put(FD_CUSTOM_FUNCTIONS_URL, getCustomFunctionUrl());
properties.put(FD_DATA_URL, getDataUrl());
@@ -416,4 +418,10 @@ public String getCustomFunctionUrl() {
return getContextPath() + ADOBE_GLOBAL_API_ROOT + FORMS_RUNTIME_API_GLOBAL_ROOT + "/customfunctions/" + getId();
}
+ @JsonIgnore
+ @Override
+ public AutoSaveConfiguration getAutoSaveConfig() {
+ return autoSaveConfig;
+ }
+
}
diff --git a/bundles/af-core/src/main/java/com/adobe/cq/forms/core/components/models/form/FormContainer.java b/bundles/af-core/src/main/java/com/adobe/cq/forms/core/components/models/form/FormContainer.java
index e74933fec9..67717dffd6 100644
--- a/bundles/af-core/src/main/java/com/adobe/cq/forms/core/components/models/form/FormContainer.java
+++ b/bundles/af-core/src/main/java/com/adobe/cq/forms/core/components/models/form/FormContainer.java
@@ -385,4 +385,15 @@ default String getCustomFunctionUrl() {
return null;
}
+ /**
+ * Returns the auto save configuration
+ *
+ * @return auto save configuration
+ * @since com.adobe.cq.forms.core.components.models.form 5.11.0
+ */
+ @JsonIgnore
+ default AutoSaveConfiguration getAutoSaveConfig() {
+ return null;
+ }
+
}
diff --git a/bundles/af-core/src/main/java/com/adobe/cq/forms/core/components/models/form/package-info.java b/bundles/af-core/src/main/java/com/adobe/cq/forms/core/components/models/form/package-info.java
index a659eb1155..a95db0c399 100644
--- a/bundles/af-core/src/main/java/com/adobe/cq/forms/core/components/models/form/package-info.java
+++ b/bundles/af-core/src/main/java/com/adobe/cq/forms/core/components/models/form/package-info.java
@@ -35,7 +35,7 @@
*
*/
-@Version("5.10.0")
+@Version("5.11.0")
package com.adobe.cq.forms.core.components.models.form;
import org.osgi.annotation.versioning.Version;
diff --git a/bundles/af-core/src/test/java/com/adobe/cq/forms/core/components/internal/models/v2/form/FormContainerImplTest.java b/bundles/af-core/src/test/java/com/adobe/cq/forms/core/components/internal/models/v2/form/FormContainerImplTest.java
index 785821eeae..5baa31712a 100644
--- a/bundles/af-core/src/test/java/com/adobe/cq/forms/core/components/internal/models/v2/form/FormContainerImplTest.java
+++ b/bundles/af-core/src/test/java/com/adobe/cq/forms/core/components/internal/models/v2/form/FormContainerImplTest.java
@@ -47,11 +47,7 @@
import com.adobe.cq.forms.core.Utils;
import com.adobe.cq.forms.core.components.internal.form.FormConstants;
import com.adobe.cq.forms.core.components.internal.form.ReservedProperties;
-import com.adobe.cq.forms.core.components.models.form.FieldType;
-import com.adobe.cq.forms.core.components.models.form.FormClientLibManager;
-import com.adobe.cq.forms.core.components.models.form.FormContainer;
-import com.adobe.cq.forms.core.components.models.form.TextInput;
-import com.adobe.cq.forms.core.components.models.form.ThankYouOption;
+import com.adobe.cq.forms.core.components.models.form.*;
import com.adobe.cq.forms.core.context.FormsCoreComponentTestContext;
import com.day.cq.i18n.I18n;
import com.day.cq.wcm.api.NameConstants;
@@ -79,6 +75,8 @@ public class FormContainerImplTest {
private static final String CONTENT_DAM_ROOT = "/content/dam/formsanddocuments/demo";
private static final String PATH_FORM_1 = CONTENT_ROOT + "/formcontainerv2";
private static final String PATH_FORM_WITHOUT_FIELDTYPE = CONTENT_ROOT + "/formcontainerv2-without-fieldtype";
+
+ private static final String PATH_FORM_WITH_AUTO_SAVE = CONTENT_ROOT + "/formcontainerv2WithAutoSave";
private static final String PATH_FORM_1_WITHOUT_REDIRECT = CONTENT_ROOT + "/formcontainerv2WithoutRedirect";
private static final String CONTENT_FORM_WITHOUT_PREFILL_ROOT = "/content/forms/af/formWithoutPrefill";
private static final String PATH_FORM_WITHOUT_PREFILL = CONTENT_FORM_WITHOUT_PREFILL_ROOT + "/formcontainerv2WithoutPrefill";
@@ -555,4 +553,15 @@ void testCustomFunctionUrl() throws Exception {
FormContainer formContainer = Utils.getComponentUnderTest(PATH_FORM_1, FormContainer.class, context);
assertEquals("/adobe/forms/af/customfunctions/L2NvbnRlbnQvZm9ybXMvYWYvZGVtbw==", formContainer.getCustomFunctionUrl());
}
+
+ @Test
+ public void testGetAutoSaveProperties() throws Exception {
+ context.load().json(BASE + "/test-content-auto-save.json", PATH_FORM_WITH_AUTO_SAVE);
+ FormContainer formContainer = Utils.getComponentUnderTest(PATH_FORM_WITH_AUTO_SAVE,
+ FormContainer.class, context);
+ assertNotNull(formContainer.getAutoSaveConfig());
+ assertTrue(formContainer.getAutoSaveConfig().isEnableAutoSave());
+ assertEquals(AutoSaveConfiguration.AutoSaveStrategyType.TIME, formContainer.getAutoSaveConfig().getAutoSaveStrategyType());
+ }
+
}
diff --git a/bundles/af-core/src/test/resources/form/formcontainer/exporter-formcontainerv2.json b/bundles/af-core/src/test/resources/form/formcontainer/exporter-formcontainerv2.json
index 3cd882cce8..a2e27f5321 100644
--- a/bundles/af-core/src/test/resources/form/formcontainer/exporter-formcontainerv2.json
+++ b/bundles/af-core/src/test/resources/form/formcontainer/exporter-formcontainerv2.json
@@ -8,9 +8,6 @@
"dorType": "generate",
"dorTemplateRef": "xyz"
},
- "fd:autoSave": {
- "fd:enableAutoSave":false
- },
"fd:path": "/content/forms/af/demo/jcr:content/formcontainerv2",
"fd:isHamburgerMenuEnabled": false,
"fd:schemaType": "BASIC",
diff --git a/ui.af.apps/src/main/content/jcr_root/apps/core/fd/components/form/container/v2/container/README.md b/ui.af.apps/src/main/content/jcr_root/apps/core/fd/components/form/container/v2/container/README.md
index ec989bc26c..ecb44cc22f 100644
--- a/ui.af.apps/src/main/content/jcr_root/apps/core/fd/components/form/container/v2/container/README.md
+++ b/ui.af.apps/src/main/content/jcr_root/apps/core/fd/components/form/container/v2/container/README.md
@@ -24,6 +24,7 @@ Adaptive Form container written in HTL.
* Thank you page
* Thank you message
* Ability to drop other adaptive form components
+* Auto save feature for Drafts
### Use Object
The Adaptive Form Container component uses the `com.adobe.cq.forms.core.components.models.form.FormContainer` Sling Model for its Use-object.
@@ -88,4 +89,6 @@ Apply a `data-cmp-is="adaptiveFormContainer"` attribute to the `cmp-adaptiveform
Applying `data-cmp-adaptiveform-container-loader` attribute to the div specifically for applying the loader class on it, it is to ensure that the loading icon should not appear over components.
Applying `data-cmp-custom-functions-module-url` attribute to the div to point to the edge delivery URL of the custom functions file. Custom Functions exported from this file will be registered in Function Runtime.
-This Url should whitelist the AEM author/publish domain in the Cross Origin Resource Sharing (CORS) configuration.
\ No newline at end of file
+This Url should whitelist the AEM author/publish domain in the Cross Origin Resource Sharing (CORS) configuration.
+
+Applying `data-cmp-auto-save` attribute to the `cmp-adaptiveform-container` block to control the auto-save functionality. If the attribute's value is set to true, auto-save will be enabled for the form; otherwise, it will not be triggered. This attribute will be set to true in published mode if enableAutoSave is enabled.
diff --git a/ui.af.apps/src/main/content/jcr_root/apps/core/fd/components/form/container/v2/container/clientlibs/site/js/formcontainerview.js b/ui.af.apps/src/main/content/jcr_root/apps/core/fd/components/form/container/v2/container/clientlibs/site/js/formcontainerview.js
index e5cca15f6d..177f5853e9 100644
--- a/ui.af.apps/src/main/content/jcr_root/apps/core/fd/components/form/container/v2/container/clientlibs/site/js/formcontainerview.js
+++ b/ui.af.apps/src/main/content/jcr_root/apps/core/fd/components/form/container/v2/container/clientlibs/site/js/formcontainerview.js
@@ -88,7 +88,7 @@
*/
#setupAutoSave(formModel) {
const autoSaveProperties = formModel?.properties?.['fd:autoSave'];
- const enableAutoSave = autoSaveProperties?.['fd:enableAutoSave'];
+ const enableAutoSave = this.#getAutoSaveAttribute();
if (enableAutoSave) {
const autoSaveStrategyType = autoSaveProperties['fd:autoSaveStrategyType'];
const autoSaveInterval = autoSaveProperties['fd:autoSaveInterval'];
@@ -103,6 +103,10 @@
}
}
}
+
+ #getAutoSaveAttribute() {
+ return this.getFormElement()?.getAttribute('data-cmp-auto-save') === 'true';
+ }
}
async function onDocumentReady() {
diff --git a/ui.af.apps/src/main/content/jcr_root/apps/core/fd/components/form/container/v2/container/container.html b/ui.af.apps/src/main/content/jcr_root/apps/core/fd/components/form/container/v2/container/container.html
index 54edd6e60e..6d368ae1f9 100644
--- a/ui.af.apps/src/main/content/jcr_root/apps/core/fd/components/form/container/v2/container/container.html
+++ b/ui.af.apps/src/main/content/jcr_root/apps/core/fd/components/form/container/v2/container/container.html
@@ -36,6 +36,7 @@
data-sly-use.templates="core/wcm/components/commons/v1/templates.html"
action="${container.metadata.action}"
id="${container.id}"
+ data-cmp-auto-save="${wcmmode.disabled && container.autoSaveConfig && container.autoSaveConfig.enableAutoSave ? 'true' : 'false'}"
data-cmp-is="adaptiveFormContainer"
data-cmp-context-path="${request.contextPath}"
data-cmp-page-lang="${container.containingPageLang}"
@@ -76,4 +77,4 @@
-
\ No newline at end of file
+
diff --git a/ui.frontend/package-lock.json b/ui.frontend/package-lock.json
index bfe27a044c..9c253d02c2 100644
--- a/ui.frontend/package-lock.json
+++ b/ui.frontend/package-lock.json
@@ -9,9 +9,9 @@
"version": "1.0.0",
"license": "Apache-2.0",
"dependencies": {
- "@aemforms/af-core": "^0.22.112",
+ "@aemforms/af-core": "^0.22.114",
"@aemforms/af-custom-functions": "1.0.13",
- "@aemforms/af-formatters": "^0.22.109"
+ "@aemforms/af-formatters": "^0.22.114"
},
"devDependencies": {
"@babel/preset-env": "^7.18.2",
@@ -107,12 +107,12 @@
}
},
"node_modules/@aemforms/af-core": {
- "version": "0.22.112",
- "resolved": "https://registry.npmjs.org/@aemforms/af-core/-/af-core-0.22.112.tgz",
- "integrity": "sha512-cyUbPYu/l+w9elyTLEWhyQj2qLp/PlI2fXDX/2kpTcGfb+ckRqXRzpItbPqa66m4scjcNpK0RpwfThcSRb1S3w==",
+ "version": "0.22.114",
+ "resolved": "https://registry.npmjs.org/@aemforms/af-core/-/af-core-0.22.114.tgz",
+ "integrity": "sha512-9nbhRfvGgpJZQcrn5u2hL9N1cInuQxWRts96x1ln1s+7uinAy2aLFMApzbPTLqD/vv/A/p9ZhnCb0DVSNBYI0w==",
"dependencies": {
"@adobe/json-formula": "0.1.50",
- "@aemforms/af-formatters": "^0.22.112"
+ "@aemforms/af-formatters": "^0.22.114"
}
},
"node_modules/@aemforms/af-custom-functions": {
@@ -121,9 +121,9 @@
"integrity": "sha512-thtSn92qpkZg0uldYMaiN81MGxyttv+kyO2h34YA1Li8V79DYFp3JJWE3duhCgo+tslCLGamqryVwJbMdSJV6Q=="
},
"node_modules/@aemforms/af-formatters": {
- "version": "0.22.112",
- "resolved": "https://registry.npmjs.org/@aemforms/af-formatters/-/af-formatters-0.22.112.tgz",
- "integrity": "sha512-hnscUtTMxfEWNcBiatYY5lzGCCtRn1lbCdKemPTqMMRIzBCWFJXx1mxV84ysyktXXW7R+PS64P0A2K8IBVtVFw=="
+ "version": "0.22.114",
+ "resolved": "https://registry.npmjs.org/@aemforms/af-formatters/-/af-formatters-0.22.114.tgz",
+ "integrity": "sha512-kIrWTAzLgv2Te2sq8IQl4P0AtFAN1t3znnXXgMPp9MO6P+pB4mqaFlF+DUdE1BpbYdeEYdUxZioL/oq5NVtNag=="
},
"node_modules/@ampproject/remapping": {
"version": "2.2.1",
@@ -11122,12 +11122,12 @@
"integrity": "sha512-dmlLYfbty8NPVIdxvI9cJ+ZdXsrRCFrCdmL1+aR2auEzXJ86rD0bm1qu+S4NOpFiZLKIyx0zvUTykms40vNjsA=="
},
"@aemforms/af-core": {
- "version": "0.22.112",
- "resolved": "https://registry.npmjs.org/@aemforms/af-core/-/af-core-0.22.112.tgz",
- "integrity": "sha512-cyUbPYu/l+w9elyTLEWhyQj2qLp/PlI2fXDX/2kpTcGfb+ckRqXRzpItbPqa66m4scjcNpK0RpwfThcSRb1S3w==",
+ "version": "0.22.114",
+ "resolved": "https://registry.npmjs.org/@aemforms/af-core/-/af-core-0.22.114.tgz",
+ "integrity": "sha512-9nbhRfvGgpJZQcrn5u2hL9N1cInuQxWRts96x1ln1s+7uinAy2aLFMApzbPTLqD/vv/A/p9ZhnCb0DVSNBYI0w==",
"requires": {
"@adobe/json-formula": "0.1.50",
- "@aemforms/af-formatters": "^0.22.112"
+ "@aemforms/af-formatters": "^0.22.114"
}
},
"@aemforms/af-custom-functions": {
@@ -11136,9 +11136,9 @@
"integrity": "sha512-thtSn92qpkZg0uldYMaiN81MGxyttv+kyO2h34YA1Li8V79DYFp3JJWE3duhCgo+tslCLGamqryVwJbMdSJV6Q=="
},
"@aemforms/af-formatters": {
- "version": "0.22.112",
- "resolved": "https://registry.npmjs.org/@aemforms/af-formatters/-/af-formatters-0.22.112.tgz",
- "integrity": "sha512-hnscUtTMxfEWNcBiatYY5lzGCCtRn1lbCdKemPTqMMRIzBCWFJXx1mxV84ysyktXXW7R+PS64P0A2K8IBVtVFw=="
+ "version": "0.22.114",
+ "resolved": "https://registry.npmjs.org/@aemforms/af-formatters/-/af-formatters-0.22.114.tgz",
+ "integrity": "sha512-kIrWTAzLgv2Te2sq8IQl4P0AtFAN1t3znnXXgMPp9MO6P+pB4mqaFlF+DUdE1BpbYdeEYdUxZioL/oq5NVtNag=="
},
"@ampproject/remapping": {
"version": "2.2.1",
diff --git a/ui.frontend/package.json b/ui.frontend/package.json
index dd5ed20f1e..e80c729ef3 100644
--- a/ui.frontend/package.json
+++ b/ui.frontend/package.json
@@ -23,8 +23,8 @@
"webpack-merge": "^5.8.0"
},
"dependencies": {
- "@aemforms/af-core": "^0.22.112",
- "@aemforms/af-formatters": "^0.22.109",
+ "@aemforms/af-core": "^0.22.114",
+ "@aemforms/af-formatters": "^0.22.114",
"@aemforms/af-custom-functions": "1.0.13"
}
}