How to make drop-down values to be easily authorable content in CQ - aem

I was trying to understand how can we make drop-down values in dialog box easily authorable?

Select lists in dialogs can load their options dynamically from anywhere, so long as they are provided as an array of values in JSON format (from the docs):
[
{
value: "pink",
text: "Pink",
qtip: "Real Pink"
}
]
So one solution would be to:
Create a new template that would allow an editor to add/remove values from a list — make this editable for content authors as per any other content (e.g. using the page properties, or components that you can drag onto that template).
Create a Servlet that will parse those values & output them in the expected JSON.
Register that servlet, e.g. via a path (/bin/selectvalues).
Using the cqinclude xtype to load in your values:
i.e.
<select
type="select"
xtype="selection"
options="/bin/selectvalues"/>

If you are looking for a drop-in solution for this, take a look at http://adobe-consulting-services.github.io/acs-aem-commons/features/generic-lists.html. This supports easily authorable lists of name/value pairs which can be used (without writing additional code) in:
Classic UI Dialogs
Touch UI Dialogs
Touch UI Asset Metadata Editor

Related

Setting Date as a prop in Adobe DTM

I'm trying to use Adobe DTM to pass the date to a prop variable but haven't had much success. The final output should be a prop report in Adobe that'll provide me traffic data for specific dates (5/11/16, 6/15/15 etc). The ultimate goal for setting the dates as a prop is to be able to classify a range of dates based on various business needs.
Could anyone point me in the right direction for getting this done? I am assuming I'll have to add a line of code in the s.code file that'll define s.prop5 = ...
Thanks
Based on your comments, it sounds like you are just looking to pop something with the current date stamp with "MM-DD-YYYY" format.
As Gigazelle mentioned, you can create a Data Element to return the value, and then reference it for setting your prop. However, throwing a data layer into the mix may be overkill for you, depending on your needs/limitations.
Data layers are meant for exposing data that DTM can't feasibly/reliably automate on its own via built-in features or hosting an autonomous js snippet.
The only reason you might want to consider having your site push it to a data layer, is if you want to generate the date via server-side coding to ensure the date is generated within the same timezone setting for all visitors. If you generate it client-side, it will be generated according to the visitor's browser/system settings. Since visitors are from all over the world in different timezones, the data may not be as consistent (even if you add additional code to change the timezone offset, it still may not be 100% based on browser version/security settings, or visitors who alter their browser/system date/timezone settings).
So, if you want to ensure the best accuracy, then I suggest you output the value via server-side code, and put into a data layer. How you do that depends on your server and what language you have at your disposal for your web pages being served up. Here is a very basic example using PHP:
<script>
var dataLayer = {
currentDate : '<?php echo date('m-d-Y'); ?>'
}
</script>
This will have the server generate the date stamp and output a js object called dataLayer with a property currentDate you can reference. You can create a Data Element as Type "JS Object" and for Path, put dataLayer.currentDate, and then reference your Data Element elsewhere (see below).
If that's too much trouble for you or if you want to keep it pure client-side/DTM and are okay with the potentially lower consistency...
Within DTM, go to Rules > Data Elements, and click Create New Data Element.
Name it "currentDate" (no quotes).
For Type, choose "Custom Script", and click Open Editor, and add the following:
var t=new Date(),d,m,y;
d=t.getDate();
d=d<10?'0'+d:d;
m=t.getMonth()+1;
m=m<10?'0'+m:m;
y=t.getFullYear();
return m+'-'+d+'-'+y;
Click Save and Close and Save Data Element.
Now you can reference the data element to pop prop5. How you do it depends on how you've setup Adobe Analytics within DTM. For example, if you set it up as a tool and only want it to pop on initial page view, you can open your AA tool config, go to the Global Variables dropdown, and set prop5 there. You reference it as %currentDate%
You can do the same %currentDate% syntax in a Page Load Rule or other rule or any other place that uses DTM's built-in fields.
Alternatively, if you need to reference it within javascript code (e.g. if you are setting prop5 within s.doPlugins or some other Custom Script box, you can reference the data element like this:
s.prop5 = _satellite.getVar('currentDate');
Set a JS variable on your site (such as within a data layer) that outputs the date in the format you wish to collect it in. Something like var d = Date();
In DTM, go to Rules > Data Elements and create a data element that maps to the JS variable you created on your site
If you want prop5 to be defined on every page, click the gear icon and map prop5 to your data element name by using %DataElementName% (whatever you named your data element in step 2, wrapped in percent signs). If you don't want it defined on every page, go to Rules and create a page load rule, event based rule or direct call rule depending on when you want the variable to trigger. Under the Adobe Analytics section of the rule, map prop5 to %DataElementName% .
This will allow you to collect dates as values, which can then be used in classifications.

VS Code Completion for custom HTML elements

Is there a way to add custom HTML elements with custom attributes to VS Code so that I will get some autocomplete / intellisense on it?
For example in my framework (here Aurelia) I have added a <my-component is-telling-lies="true" aria-type="hidden" default-target="north">Do you believe?</my-component> and would like to have the element show up when starting to type a new element and inside it the attribute when typing in the attribute space of the element.
Yes, there's a way.
You can extend VS Code's HTML support through a declarative custom data format. By setting html.customData to a list of JSON files following the custom data format, you can enhance VS Code's understanding of new HTML tags, attributes and attribute values. VS Code will then offer language support such as completion & hover information for the provided tags, attributes and attribute values.
See: https://code.visualstudio.com/docs/languages/html#_html-custom-data
You can read more about using custom data in the vscode-custom-data repository.

In AEM SiteAdmin, how can I use 'name' instead of 'title' in the left navigation pane?

From the SiteAdmin view, the "Websites" tab in the left-hand navigation pane displays the "Title" attribute from nodes, but sorts according to the "name" attribute. Which file(s) would need to be edited to output the "name" value in that pane instead of "title"?
The script responsible for rendering siteadmin is - /libs/cq/ui/widgets/source/widgets/wcm/SiteAdmin.js
If you look at line number 340, it has configuration like -
The call /bin/wcm/siteadmin/tree.json is handled by SiteAdminTreeServlet which generates the JSON used in rendering the tree (and sorting it). You could overlay this to use your own Servlet that gives the result in the sorted order of field you need (not recommended unless you know the nitty–gritty of this servlet).
If you still want to proceed with the changes you need to do two things -
Add configurations to disable SiteAdminTreeServlet, use OSGI component disable logic to achieve this or you could refer to AEM ACS Commons here
Provide your own implementation as Servlet to handle the requests to the path /bin/wcm/siteadmin/tree and handle json extension explicitly (path based servlet will ignore extensions).
You can try invoking this servlet as http://localhost:4502/bin/wcm/siteadmin/tree.json?path=/content
In CQ/AEM /libs/cq/ui/widgets/source/ext/override/widgets/tree/TreeNodeUI.js script renders the left hand side of siteadmin. You can directly make a minor change in this script to display page name instead of page title in the CQ siteadmin.
Click here to look at the code
CQ.shared.XSS.getXSSValue(n.text.replace(/</g, "<")) should be changed to CQ.shared.XSS.getXSSValue(n.attributes.name.replace(/</g, "<")) at line number 71 in /libs/cq/ui/widgets/source/ext/override/widgets/tree/TreeNodeUI.js and it works great

How can we get value from DOM Properties in JMeter?

I'm trying to record a scenario of SAP CRM.
But I have a problem due to that everytime I login SAP CRM generates a new hashed token and will be used in URL like below:
See Image 1 Here
I tried to check where is the information stored, and in firebug and I found it in DOM tab:
See Image 2 Here
Is there any way to get the value from this DOM Properties using Jmeter?
Usually the choices are in:
CSS/JQuery Extractor
XPath Extractor
Regular Expression Extractor
Choose the one, you're most familiar with. Usually it is Regular Expression Extractor, however parsing HTML with regular expressions is not a good idea, moreover you will be very sensitive to DOM changes (part of the element goes to next line, attributes change positions, etc.).
So I would recommend choosing between CSS and XPath, but choose them wisely. I.e. if the number of styles on the page is not too big - go for CSS, if there are a lot of styles but the DOM itself is not very complicated - choose XPath.

Can you use Chosen with dynamically created form elements?

I've created a simple form containing two selectbox elements. I also have a button which dynamically adds these selectboxes at the user's discretion. The selectbox options will be quite long, so I've applied the jQuery Chosen plugin to be more useful.
Everything works fine until a new element is dynamically added using jQuery clone. I am unable to select any options in my new element selectboxes, and they also carry the prior results.
In searching the forum, others have 'reset' Chosen after a selection, by calling: $("#form_field").trigger("liszt:updated"); . I tried this as well, but it will just clear all the selections (which I don't want) and continue to freeze the dropdown action.
Anyone have experience with using Chosen (or any other autocomplete-type selectbox enhancement) with dynamic elements?
Found a solution that works - albeit without using the Chosen plugin.
I changed my dynamically created form elements by replacing the selectboxes with input fields tied to a basic jQueryUI autocomplete plugin. Here is a link to their implementation : http://jqueryui.com/autocomplete/#default.
The main difference is that the select "options" in this case, were listed as the source from which the box would look for autocomplete options. My list was 70 items long, so the initial setup took some time.
The jQuery text was generically as follows:
$("input#search").autocomplete({
source: [item1, item2, item3, item 4, ... item5]);