Single select Tag in Touch UI - aem

OOTB Tag has multi select functionality, Is it possible to create single select Tag in Touch UI? If yes, can you point me which js file I need to modify?

The cq:tags property is rendered by CUI.TagList widget that can be found within /etc/clientlibs/granite/coralui2/js/coral.js script.
Reading it you can learn that the widget raises itemadded event which might be helpful for you to handle the singular tag handling. An example function that can catch the event might be placed in any clientlibs that will be attached to the admin interface such as cq.authoring.dialog clientlib.
$('*[data-fieldname="./cq:tags"]').on('itemadded', function(ev, value) {
var el = $(ev.target),
div = el.siblings('div'),
input = div.find('input'),
button = div.find('button');
input.prop('disabled', true);
button.remove();
}
To have the fully functional flow you need to handle the itemremoved event as well and make the input field enabled again as well as add the button back to the widget.

Related

Disable a form if the other is updatable

I'm using page fragments to create a view and in the same page I have two forms to view / update specific information.
What I want know if it's possible to disable one form (or button, since it's the way I use to change from readable to updatable) based on if the other is in updatable mode.
Simplifying I have form A and B, both in the same page as readable. When I select A to update I want B to disable the option to edit until A is back to read mode, and the same to B form.
Can anyone help me?
---Update
Flows
A
B
In each fragment (view) I have a button that as an action to the fragment (edit)
What I need is to disable the button from B.view when A button is pressed and vice versa
If the forms are part of separate taskflows and these taskflows are used on the page as regions, then you will need to enable inter-region communication, so that an action in one region can affect the data and behavior of other region:
http://www.oracle.com/technetwork/developer-tools/adf/adfregioninteraction-155145.html
For your use case, contextual events can serve the purpose:
http://rohanwalia.blogspot.com/2013/07/contextual-events-basic-step-by-step.html
http://www.awasthiashish.com/2013/05/using-contextual-event-in-oracle-adf.html
https://blogs.oracle.com/raghuyadav/entry/refresh_bounded_taskflows_acro
To implement your case, follow the tutorials provided above with following changes:
Pass a boolean value in the customPayLoad of event
<event name="DisableButtonEvent" customPayLoad="${'true'}"/>
In the event handler method assign the payLoad value to a scope variable:
public void handleDisableButtonEvent(String payLoad) {
AdfFacesContext adfFacesContext = AdfFacesContext.getCurrentInstance();
Map pageFlowScope = adfFacesContext.getPageFlowScope();
pageFlowScope.put("disableButton", payLoad);
}
Use the scope variable for disabled property of button on second region
<af:commandButton text="EditButoonB" id="cb1"
disabled="#{pageFlowScope.disableButton ne null? pageFlowScope.disableButton : false}"/>

How to get user's input from WicketStuff's TinyMCE

Pretty straight-forward question, but I can't find this anywhere. I'm using WicketStuff's TinyMCE to make a Rich Text Editor in my application, and can't find anywhere how to get the input from the text area. For brevity's sake, the following is a simplified version of the code I'm using.
private String input;
...
TinyMCESettings settings = new TinyMCESettings(TinyMCESettings.Theme.simple);
TextArea<String> textArea = new TextArea<String>("editor", new PropertyModel<String>(this, "input"));
textArea.add(new TinyMceBehavior(settings));
form.add(textArea);
Using this, I would expect the usual manner to simply use my String 'input' since it's set as the model. This always results in null as the model isn't being updated.
I tried using the auto-save plugin in case it was expecting the save button to be clicked (which doesn't update the model either), and neither worked. The only thing I've been able to do to get the user's input is to add a HiddenField, with a new model, and make a JavaScript call like
document.getElementById('hiddenField').value = tinyMCE.get('editor').getContent();
but this has led to other problems with trying to call the JS in the desired place and to get it to work properly. I feel this shouldn't be necessary anyways, as surely someone must have implemented a method to get the contents of the text area being used.
Any help would be greatly appreciated.
Thanks to a blog post at Nevermind Solutions, the way to get the model updated is to add the following JavaScript to the form's submitting button:
onclick="tinyMCE.triggerSave(true,true);"
My text area is inside a panel with the button outside of the panel, so it doesn't directly work for me. The trick was to add the JavaScript call to the button's onSubmit, move the logic into the onAfterSubmit, and to make the button MultiPart so that it could call the save trigger before doing the other logic associated to the model.
Hope this might help some others in the future.
You have to add a modifier to the submit button so that the model can update.
AjaxButton btnSubmit = new AjaxButton("btnSubmit", new Model()) {
#Override
public void onSubmit(AjaxRequestTarget target, Form<?> form) {
doSomething();
}
};
btnSubmit.add(new TinyMceAjaxSubmitModifier());
Have a look here for more info

GTM Reduce number of tags

GTM up and running, main UA tag in place along with a ClickListener tag.
To reduce the number of macros, i use dataLayer variable Macros for event category, action, label, value & interaction, so they can be used for many rules and tags.
So i want to collect data from one link/button (Add to Fav), i add a rule to listen for the click using {{event}} equals gtm.click and {{Event Label}} equals Add_to_Fav (the label i push to the DL via onclick.
All good so far, but i need to create another UA tag (Track Type - event) that fires on the rule made previously. And this is my question, using this method seems to create many tags. If i have another 20 links that i want to collect data from, do i need to keep creating tags like this. Surely, this will affect page load speed with many tags firing on all pages.
Hope thats all clear.
If you need to retrieve the link text to use it as an event label you do not need many many event tracking tags, that would be horribly verbose. Instead you can use a custom javascript macro - the cool thing about them being that you can use existing macros inside your custom function.
If you create a click listener or link click listener this will create a few macros - one of them is {{element}}, which is the DOM element that received a click.
Now you create a macro of the type "custom java script", which must contain an anonymous function with a return value.
The barebones version of a function that retrieves the text of a clicked link would be
function() {
var el = {{element}};
return el.innerText;
}
(actually you do not need the variable assigment, you could use {{element}}.innerText directly).
You name the macro e.g. Linktext and use the macro {{Linktext}} in your single event tracking tag where it will dynamically be set to the value of the text of the clicked link (although you might want to check cross browser support for innerText, or maybe use innerHTML instead which serves in you use case probably the same purpose).

C Builder TForm not allocated or created properly all its controls

I'd like to know how I can check that all the controls on the form are created and initialized.
I have a form I am showing when a user presses the update button. It has only a TProgressBar control.
The handle is not NULL for this control and at random stages it can or can't set the Position/Max values.
When I set TProgressBar->Max value to some integer it remains 0 after.
So the question is:
How to really create the form and all controls on it (i am currently using just Form->Show() method, which as I can check calls the constructor)
Also I have following form creation code in main cpp file:
Application->CreateForm(__classid(TupdateProgramForm), &updateProgramForm);
How to check that all controls on the form are created and PAINTED (showed and visible)
In C++ Builder the form and the controls created at design-time are translated into binary objects through automatic scripts that produce Delphi code.
To view the originated Delphi code just right-click anywhere on form at design-time and select 'View as text'. This will show the Delphi source code of the form and it's controls.
After a form and all child controls created, the OnCreate event of that form invoked and you can place your initialization and checking code in this event, for example:
void __fastcall TfrmMain::updateProgramFormCreate(TObject *Sender)
{
ProgressBar->Max = 100;
ProgressBar->Value = 20;
}

Test to see if you are in a specific content block in TinyMCE and not allow a plugin to add to that content block if in it

So I have a TinyMCE form on my page and it is pre-filled with "sections" (divs with specific class names).
I have a couple of plugins that will add to TinyMCE with more "sections".
I need it so when I push the plugin button it will test to make sure the cursor is not inside a "section" and paste a "section" inside another "section".
Not sure the direction I need to take to accomplish this. Any help would be great.
more info:
So below is an example of a plugin that adds a button that just inserts a simple dov into the editor at the selection/cursor.
ed.addButton('pluginbutton', {
title : 'MyPlugin',
image : 'img/test.png',
onclick : function() {
ed.selection.setContent('<div>test</div>');
}
});
I am currently thinking that onBeforeSetContent is the API event handler I need to set to process whether or not I am in another section and if so send a message to the screen. If not just do the setContent method. I am not sure exactly how to set that up though so I am still figuring that out. Any help here?
Since it seems like you have control over the plugin, here is how I would edit it to work.
Note: I am using the jQuery method closest. I figured since you are on the jQuery core team, you are probably using it for this project. If not, just refactor that line as needed. The important part is that selection.getNode() returns the DOM element that is the parent of both the start and end selection points.:
ed.addButton('pluginbutton', {
title : 'MyPlugin',
image : 'img/test.png',
onclick : function() {
if( !$(ed.selection.getNode()).closest('div.section').length ){
ed.selection.setContent('<div class="section">test</div>');
}
}
});
Additional thoughts
Also, to make your plugin aware enough so it won't put a div as the child of a p tag, you could do something like this:
Replace onclick above with this:
onclick: function(){
var $node = $(ed.selection.getNode());
if( !$node.closest('div.section').length ){
// Get highest element that is a direct child of the `body` tag:
var $parent = $node.closest('body > *');
// Wrap with our special section div
if($parent.length) $parent.wrap('<div class="section"></div>');
}
}
I don't know TinyMCE specifically, but it should be possible to extract the current DOM element from ed.selection. If that is possible (I'm sure it is using some sort of getter function or property), you should be able to do the following:
Mark a "forbidden" area using an id or class ("<div class='protected'> ")
traverse through the selection's ancestry (using the parentNode property of the element) and check whether one of the parent elements has the "protected" class or ID.
If the ID was found, do not execute setContent(); otherwise execute it.