Skip to content

Commit 201b498

Browse files
authored
Merge pull request #8 from aem-design/feature/generic-details-variant-name-prefil
#7 update generic details behaviour to update variant name after fragment path has been selected
2 parents 1bc34ef + a3e2f3d commit 201b498

File tree

1 file changed

+83
-20
lines changed
  • aemdesign-aem-common/src/main/content/jcr_root/apps/aemdesign/components/details/generic-details/clientlibs/js

1 file changed

+83
-20
lines changed

aemdesign-aem-common/src/main/content/jcr_root/apps/aemdesign/components/details/generic-details/clientlibs/js/behaviour.js

Lines changed: 83 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -5,28 +5,21 @@ window.AEMDESIGN.components.authoring = AEMDESIGN.components.authoring || {};
55
window.AEMDESIGN.components.authoring.genericdetails = AEMDESIGN.components.authoring.genericdetails || {};
66

77

8-
(function ($, $document, Coral, ns, window, undefined) { //NOSONAR convention for wrapping all modules
8+
(function ($, $document, Granite, Coral, ns, window, undefined) { //NOSONAR convention for wrapping all modules
99

10-
console.log(["dialog-genericdetails-behaviour","ready"]);
11-
$(document).on('dialog-ready', function () {
12-
console.log(["dialog-genericdetails-behaviour","checking"]);
13-
if ($('#dialog-genericdetails')[0]) {
10+
var componentName = "genericdetails";
1411

15-
console.log(["dialog-genericdetails-behaviour","loading"]);
12+
console.log(["dialog-"+componentName+"-behaviour","ready"]);
13+
$(document).on('dialog-ready', function () {
14+
console.log(["dialog-"+componentName+"-behaviour","checking"]);
15+
if ($("#dialog-"+componentName+"")[0]) {
1616

17-
// $document.on('change', '.pageMetaProperty, .pageMetaPropertyContent', function (event) {
18-
//
19-
// var element = event.target,
20-
// parentElement = element.closest('.dialog-genericdetails-costomfields'),
21-
// childpageMetaPropertyElement = parentElement.querySelector('.pageMetaProperty'),
22-
// childpageMetaPropertyContentElement = parentElement.querySelector('.pageMetaPropertyContent')
23-
//
24-
// });
17+
console.log(["dialog-"+componentName+"-behaviour","loading"]);
2518

2619
//load content into field
27-
if ($('#dialog-genericdetails').find('.genericdetails-costomfields')[0]) {
20+
if ($("#dialog-"+componentName+"").find(".pagedetails-pagemetadata")[0]) {
2821

29-
var $form = $("#dialog-genericdetails").closest('form');
22+
var $form = $("#dialog-"+componentName+"").closest('form');
3023
console.log(['$form', $form]);
3124
var formUrl = $form[0].action;
3225
$.getJSON(formUrl + '.json').done(function (data) {
@@ -48,7 +41,7 @@ window.AEMDESIGN.components.authoring.genericdetails = AEMDESIGN.components.auth
4841

4942

5043
fieldconfigKey.forEach(function (key, index) {
51-
var curr = $('#dialog-genericdetails').find('.genericdetails-costomfields')[0].items.add();
44+
var curr = $("#dialog-"+componentName+"").find(".pagedetails-pagemetadata")[0].items.add();
5245
Coral.commons.ready(curr, function (readyCurr) {
5346
$(readyCurr).find('[name="./pageMetaProperty"]')[0].value = fieldconfigKey[index];
5447
$(readyCurr).find('[name="./pageMetaPropertyContent"]')[0].value = fieldconfigValue[index];
@@ -57,19 +50,89 @@ window.AEMDESIGN.components.authoring.genericdetails = AEMDESIGN.components.auth
5750
});
5851
}
5952
else {
60-
//$('.genericdetails-costomfields')[0].items.add();
53+
//add empty row if needed
54+
//$(".pagedetails-pagemetadata")[0].items.add();
6155
}
6256

6357

6458
});
6559

6660
} else {
67-
console.log(["dialog-genericdetails-behaviour","genericdetails-costomfields","not found"]);
61+
console.log(["dialog-"+componentName+"-behaviour","pagemetadata","not found"]);
62+
}
63+
64+
65+
//load content into variationName field after fragmentPath is changed
66+
if ($("#dialog-"+componentName+"").find("[name='./fragmentPath']")[0]) {
67+
var fragmentPath = $("#dialog-"+componentName+"").find("[name='./fragmentPath']")[0];
68+
69+
console.log(["fragmentPath",fragmentPath,fragmentPath.value]);
70+
71+
72+
//load content into field
73+
if ($("#dialog-"+componentName+"").find("[name='./variationName']")[0]) {
74+
var variationName = $("#dialog-"+componentName+"").find("[name='./variationName']")[0];
75+
var variationNamePath = variationName.dataset.fieldPath;
76+
77+
console.log(["variationName",variationName,variationNamePath]);
78+
79+
$(fragmentPath).on("foundation-field-change", function() {
80+
81+
var data = {
82+
fragmentPath: fragmentPath.value
83+
};
84+
85+
var url = Granite.HTTP.externalize(variationNamePath) + ".html";
86+
var variationNameRequest = $.get({
87+
url: url,
88+
data: data
89+
});
90+
91+
92+
// $.getJSON(url).done(function (data) {
93+
// console.log(["variationName",data]);
94+
// });
95+
96+
console.log(["variationNameRequest",variationNameRequest]);
97+
98+
$.when(variationNameRequest).then(function(variantResult) {
99+
100+
console.log(["variantResult",variantResult]);
101+
var SELECTOR_VARIATION_NAME = "[name='./variationName']";
102+
var newVariationName = $(variantResult).find(SELECTOR_VARIATION_NAME)[0];
103+
// get the fields from the resulting markup and create a test state
104+
Coral.commons.ready(newVariationName, function() {
105+
106+
console.log(["variationNameRequest",newVariationName,variantResult]);
107+
108+
variationName = variationName.parentNode.replaceChild(newVariationName, variationName);
109+
variationName = $("#dialog-"+componentName+"").find("[name='./variationName']")[0];
110+
variationName.removeAttribute("disabled");
111+
112+
});
113+
114+
}, function(ex) {
115+
// display error dialog if one of the requests failed
116+
// ui.prompt(errorDialogTitle, errorDialogMessage, "error");
117+
console.log(["error",ex]);
118+
variationName.setAttribute("disabled", "");
119+
});
120+
121+
122+
});
123+
124+
125+
} else {
126+
console.log(["dialog-"+componentName+"-behaviour","variationName","not found"]);
127+
}
128+
129+
} else {
130+
console.log(["dialog-"+componentName+"-behaviour","fragmentPath","not found"]);
68131
}
69132

70133

71134
}
72135
});
73136

74137

75-
})($, $(document), Coral, AEMDESIGN.components.authoring.genericdetails, this); //pass in additional dependencies
138+
})($, $(document), Granite, Coral, AEMDESIGN.components.authoring.genericdetails, window); //pass in additional dependencies

0 commit comments

Comments
 (0)