Skip to content

Commit 59381dc

Browse files
author
Shivam Agarwal
committed
FORMS-16342 commenting test
1 parent a8f06f0 commit 59381dc

File tree

17 files changed

+268
-16
lines changed

17 files changed

+268
-16
lines changed

bundles/af-core/src/main/java/com/adobe/cq/forms/core/components/util/AbstractFormComponentImpl.java

Lines changed: 28 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -17,17 +17,7 @@
1717

1818
import java.io.IOException;
1919
import java.math.BigDecimal;
20-
import java.util.AbstractMap;
21-
import java.util.Arrays;
22-
import java.util.Calendar;
23-
import java.util.Collections;
24-
import java.util.HashMap;
25-
import java.util.HashSet;
26-
import java.util.LinkedHashMap;
27-
import java.util.List;
28-
import java.util.Map;
29-
import java.util.Optional;
30-
import java.util.Set;
20+
import java.util.*;
3121
import java.util.function.Predicate;
3222
import java.util.regex.Pattern;
3323
import java.util.stream.Collectors;
@@ -36,6 +26,9 @@
3626
import javax.annotation.Nonnull;
3727
import javax.annotation.PostConstruct;
3828

29+
import com.fasterxml.jackson.databind.JsonNode;
30+
import com.fasterxml.jackson.databind.ObjectMapper;
31+
import com.fasterxml.jackson.databind.node.ArrayNode;
3932
import org.apache.commons.lang3.StringEscapeUtils;
4033
import org.apache.commons.lang3.StringUtils;
4134
import org.apache.sling.api.resource.Resource;
@@ -289,6 +282,10 @@ protected boolean getEditMode() {
289282
if (rulesProperties.size() > 0) {
290283
properties.put(CUSTOM_RULE_PROPERTY_WRAPPER, rulesProperties);
291284
}
285+
List<String> disabledScripts = getDisabledXFAScripts();
286+
if (disabledScripts.size() > 0) {
287+
properties.put("fd:disabledXfaScripts", disabledScripts);
288+
}
292289
return properties;
293290
}
294291

@@ -541,4 +538,24 @@ public Map<String, Object> getDorProperties() {
541538
return customDorProperties;
542539
}
543540

541+
private List<String> getDisabledXFAScripts() {
542+
Set<String> disabledScripts = new HashSet<>();
543+
String xfaScripts = resource.getValueMap().get("fd:xfaScripts", "");
544+
if (StringUtils.isNotEmpty(xfaScripts)) {
545+
// read string xfaScripts to jsonNode
546+
ObjectMapper mapper = new ObjectMapper();
547+
try {
548+
ArrayNode node = (ArrayNode) mapper.readTree(xfaScripts);
549+
// iterate through the array node and add the elements which have disabled property set to true
550+
for (JsonNode jsonNode : node) {
551+
if (jsonNode.has("disabled") && jsonNode.get("disabled").asBoolean()) {
552+
disabledScripts.add(jsonNode.get("activity").asText());
553+
}
554+
}
555+
} catch (IOException e) {
556+
logger.error("Error while parsing xfaScripts {} {}", e, resource.getPath());
557+
}
558+
}
559+
return new ArrayList<>(disabledScripts);
560+
}
544561
}

bundles/af-core/src/main/java/com/adobe/cq/forms/core/components/util/AbstractOptionsFieldImpl.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,11 @@ public String[] getEnumNames() {
107107
String[] enumName = map.values().toArray(new String[0]);
108108
return Arrays.stream(enumName)
109109
.map(p -> {
110-
return this.translate(ReservedProperties.PN_ENUM_NAMES, p);
110+
String value = this.translate(ReservedProperties.PN_ENUM_NAMES, p);
111+
if (value == null) {
112+
value = "";
113+
}
114+
return value;
111115
})
112116
.toArray(String[]::new);
113117
}

ui.af.apps/src/main/content/jcr_root/apps/core/fd/components/form/base/v1/base/_cq_editConfig.xml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,12 @@
2323
handler="CQ.FormsCoreComponents.editorhooks.viewQualifiedName"
2424
icon="viewSOMExpression"
2525
text="View Qualified Name"/>
26+
<viewXFAScripts
27+
jcr:primaryType="nt:unstructured"
28+
condition="CQ.FormsCoreComponents.editorhooks.hasXfaScripts"
29+
handler="CQ.FormsCoreComponents.editorhooks.viewXfaScripts"
30+
icon="code"
31+
text="View XFA Scripts"/>
2632
</cq:actionConfigs>
2733
<cq:inplaceEditing
2834
jcr:primaryType="cq:InplaceEditingConfig"

ui.af.apps/src/main/content/jcr_root/apps/core/fd/components/form/button/v1/button/_cq_editConfig.xml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,12 @@
2323
handler="CQ.FormsCoreComponents.editorhooks.viewQualifiedName"
2424
icon="viewSOMExpression"
2525
text="View Qualified Name"/>
26+
<viewXFAScripts
27+
jcr:primaryType="nt:unstructured"
28+
condition="CQ.FormsCoreComponents.editorhooks.hasXfaScripts"
29+
handler="CQ.FormsCoreComponents.editorhooks.viewXfaScripts"
30+
icon="code"
31+
text="View XFA Scripts"/>
2632
</cq:actionConfigs>
2733
<cq:inplaceEditing
2834
jcr:primaryType="cq:InplaceEditingConfig"

ui.af.apps/src/main/content/jcr_root/apps/core/fd/components/form/container/v2/container/clientlibs/editorhook/js/qualifiedNameHook.js

Lines changed: 138 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,4 +41,141 @@
4141
});
4242
};
4343

44-
})(window, Granite.author, Coral);
44+
window.CQ.FormsCoreComponents.editorhooks.hasXfaScripts = function (editable) {
45+
const result = $.ajax({
46+
type: 'GET',
47+
async: false,
48+
url: Granite.HTTP.externalize(editable.path + ".json"),
49+
cache: false
50+
});
51+
const json = result.responseJSON;
52+
53+
if (json && json.dataRef?.startsWith('xfa[0]')) {
54+
if (json['fd:xfaScripts']) {
55+
try {
56+
const scripts = JSON.parse(json['fd:xfaScripts']);
57+
return scripts.length > 0;
58+
} catch(e) {
59+
console.error('Error parsing xfaScripts', e, json['fd:xfaScripts']);
60+
}
61+
}
62+
}
63+
return false
64+
}
65+
66+
window.CQ.FormsCoreComponents.editorhooks.viewXfaScripts = function (editable) {
67+
fetch(Granite.HTTP.externalize(editable.path + ".json")).then(async function (resp) {
68+
const json = await resp.json();
69+
// Assuming `resp` contains the JSON string with `fd:xfaScripts`
70+
var xfaScripts = JSON.parse(json['fd:xfaScripts']);
71+
var dialogContent = document.createElement('div');
72+
73+
// Create a Coral Table
74+
var table = document.createElement('coral-table');
75+
76+
// Create the header
77+
var thead = document.createElement('coral-table-head');
78+
var headerRow = document.createElement('coral-table-row');
79+
80+
var eventNameHeader = document.createElement('coral-table-headercell');
81+
eventNameHeader.textContent = 'Event Name';
82+
var eventContentHeader = document.createElement('coral-table-headercell');
83+
eventContentHeader.textContent = 'Event Content';
84+
var disableHeader = document.createElement('coral-table-headercell');
85+
disableHeader.textContent = 'Disable';
86+
87+
headerRow.appendChild(eventNameHeader);
88+
headerRow.appendChild(eventContentHeader);
89+
headerRow.appendChild(disableHeader);
90+
thead.appendChild(headerRow);
91+
table.appendChild(thead);
92+
93+
// Populate the table with data from xfaScripts
94+
var tbody = document.createElement('coral-table-body');
95+
xfaScripts.forEach(function(script) {
96+
var row = document.createElement('coral-table-row');
97+
98+
var nameCell = document.createElement('coral-table-cell');
99+
nameCell.textContent = script.runAt === "server" ? `${script.activity}(server)` : script.activity;
100+
var contentCell = document.createElement('coral-table-cell');
101+
contentCell.innerHTML = script.value.replaceAll("\n", "<br />");
102+
103+
var checkboxCell = document.createElement('coral-table-cell');
104+
var checkbox = new Coral.Checkbox();
105+
checkbox.name = 'disableCheckbox';
106+
checkbox.on('change', function() {
107+
script.disabled = this.checked;
108+
});
109+
checkboxCell.appendChild(checkbox);
110+
checkbox.checked = !!script.disabled;
111+
if (script.runAt === "server") {
112+
checkbox.disabled = true;
113+
}
114+
row.appendChild(nameCell);
115+
row.appendChild(contentCell);
116+
row.appendChild(checkboxCell);
117+
118+
tbody.appendChild(row);
119+
});
120+
table.appendChild(tbody);
121+
122+
dialogContent.appendChild(table);
123+
124+
// Create the dialog
125+
var dialog = new Coral.Dialog().set({
126+
id: 'xfaScriptsDialog',
127+
header: {
128+
innerHTML: 'XFA Scripts'
129+
},
130+
content: {
131+
innerHTML: ''
132+
},
133+
footer: {},
134+
closable: "on"
135+
});
136+
137+
// Add the table to the dialog content
138+
//dialog.content.appendChild(dialogContent);
139+
140+
var okButton = new Coral.Button();
141+
okButton.label.textContent = 'OK';
142+
okButton.variant = Coral.Button.variant.PRIMARY;
143+
okButton.addEventListener('click', function() {
144+
// Prepare the modified xfaScripts for POST request
145+
var modifiedXfaScripts = JSON.stringify({ 'fd:xfaScripts': JSON.stringify(xfaScripts) });
146+
$.ajax({
147+
url: editable.path,
148+
type: 'POST',
149+
data: {
150+
"_charset_" : "UTF-8",
151+
':operation': 'import',
152+
':contentType': 'json',
153+
':content': modifiedXfaScripts,
154+
':replaceProperties': true
155+
},
156+
success: function(response) {
157+
console.log('Successfully posted the data');
158+
dialog.remove();
159+
},
160+
error: function(xhr, status, error) {
161+
console.error('Error posting the data', error);
162+
dialog.remove();
163+
}
164+
});
165+
});
166+
dialog.footer.appendChild(okButton);
167+
168+
// Append and show the dialog
169+
document.body.appendChild(dialog);
170+
171+
// add a listener on dialog show event
172+
dialog.on('coral-overlay:open', function() {
173+
dialog.content.appendChild(dialogContent);
174+
});
175+
dialog.show();
176+
177+
})
178+
return true;
179+
};
180+
181+
})(window, Granite.author, Coral);

ui.af.apps/src/main/content/jcr_root/apps/core/fd/components/form/datepicker/v1/datepicker/clientlibs/site/js/datepickerview.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,10 +99,12 @@
9999
this.widgetObject.setDisplayValue(this._model.value);
100100
this.widgetObject.setCalendarWidgetValue(this._model.value);
101101
this.setInactive();
102+
this.triggerExit();
102103
}, this.getWidget());
103104
this.widgetObject.addEventListener('focus', (e) => {
104105
this.widgetObject.setValue(e.target.value);
105106
this.setActive();
107+
this.triggerEnter();
106108
}, this.getWidget());
107109
this.widgetObject.addEventListener('input', (e) => {
108110
if( e.target.value === '') {
@@ -117,9 +119,11 @@
117119
this.widget.addEventListener('blur', (e) => {
118120
this.setModelValue(e.target.value);
119121
this.setInactive();
122+
this.triggerExit();
120123
});
121124
this.widget.addEventListener('focus', (e) => {
122125
this.setActive();
126+
this.triggerEnter();
123127
});
124128
}
125129
}

ui.af.apps/src/main/content/jcr_root/apps/core/fd/components/form/dropdown/v1/dropdown/clientlibs/site/js/dropdownview.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -208,9 +208,11 @@
208208
});
209209
this.widget.addEventListener('focus', (e) => {
210210
this.setActive();
211+
this.triggerEnter();
211212
});
212213
this.widget.addEventListener('blur', (e) => {
213214
this.setInactive();
215+
this.triggerExit();
214216
});
215217
}
216218

ui.af.apps/src/main/content/jcr_root/apps/core/fd/components/form/emailinput/v1/emailinput/clientlibs/site/js/emailinputview.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,10 +74,12 @@
7474
this.setModelValue(e.target.value);
7575
this.setWidgetValueToDisplayValue();
7676
this.setInactive();
77+
this.triggerExit();
7778
});
7879
this.widget.addEventListener('focus', (e) => {
7980
this.setActive();
8081
this.setWidgetValueToModelValue();
82+
this.triggerEnter();
8183
});
8284
}
8385
}

ui.af.apps/src/main/content/jcr_root/apps/core/fd/components/form/numberinput/v1/numberinput/clientlibs/site/js/numberinputview.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,12 +100,14 @@
100100
this.setModelValue(e.target.value);
101101
if(this.element) {
102102
this.setInactive();
103+
this.triggerExit();
103104
}
104105
});
105106
}
106107
this.getWidget().addEventListener('focus', (e) => {
107108
if (this.element) {
108109
this.setActive();
110+
this.triggerEnter();
109111
}
110112
});
111113
}

ui.af.apps/src/main/content/jcr_root/apps/core/fd/components/form/panelcontainer/v1/panelcontainer/_cq_editConfig.xml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,5 +25,11 @@
2525
handler="CQ.FormsCoreComponents.editorhooks.viewQualifiedName"
2626
icon="viewSOMExpression"
2727
text="View Qualified Name"/>
28+
<viewXFAScripts
29+
jcr:primaryType="nt:unstructured"
30+
condition="CQ.FormsCoreComponents.editorhooks.hasXfaScripts"
31+
handler="CQ.FormsCoreComponents.editorhooks.viewXfaScripts"
32+
icon="code"
33+
text="View XFA Scripts"/>
2834
</cq:actionConfigs>
2935
</jcr:root>

0 commit comments

Comments
 (0)