Search code examples
javascriptjqueryaemcrx

How to getParent().getNode().getProperty("jcr:title") in JavaScript?


in AEM i'm intercepting the cq:dialog submit of a component because i need to modify some parameters before send them to the default POST.jsp

the following code works for the component!! jcr_root/apps/gare_rfi/clientlibsAuthor/js/dialogSubmit_editorialGare.js

(function(document, $, ns) {
"use strict";
$(document).on("click", ".cq-dialog-submit", function(e) {
var $form = $(this).closest("form.foundation-form");  
$form.find("[name='./tipologia']").val("this_works"); 
var tipologia = $form.find("[name='./tipologia']").val(); 
console.log(tipologia);
});
})(document, Granite.$, Granite.author);

The PROBLEM is that i need to get the properties of the page where the component is, and the properties of the parent of that page.

the JS file above is included in the cq:dialog - content.xml:

<?xml version="1.0" encoding="UTF-8"?>
<jcr:root xmlns:sling="http://sling.apache.org/jcr/sling/1.0" xmlns:cq="http://www.day.com/jcr/cq/1.0" xmlns:jcr="http://www.jcp.org/jcr/1.0" xmlns:nt="http://www.jcp.org/jcr/nt/1.0"
    jcr:primaryType="nt:unstructured"
    jcr:title="Editorial Gare"
    sling:resourceType="cq/gui/components/authoring/dialog"
    extraClientlibs="[gare_rfi.editorialGareAuthor]">
..........

In other words, i would like to have the right expression to do the following:

console.log( this.getPage().getParent().getProperty("jcr:title") );

ps. I don't want to use ajax. thanks

pps. http://blogs.adobe.com/experiencedelivers/experience-management/htl-javascript-use-api/ it works! use(function () { var title = currentPage.properties.get("jcr:title"); what does "use" mean ? anyway i can't merge "use function" with my extraClientlib


Solution

  • Clientlibs run on the browser. The AEM/JCR api you are trying to use won't be available in your current context. All of this is only going to work on the server. Unfortunately you might have to go with ajax [I read the PS] or write a filter.