I want to write a Confluence user macro, which should get a unique uuid. Currently I fail to randomly generate this UUID.
The format should look like "#c199f52d-9724-4911-ad47-479e937d3b88".
I guess I can solve this, if someone shows me how I can access the java function Math.random(); from my user macro.
This is how I do it. I was never able to find a good way to generate a random number or find a way to get at Math.random() but this seems to work well.
#set( $id = $action.dateFormatter.calendar.timeInMillis )
Even when the user macro is used multiple times per page I find that I get different mills. So for velocity I reference it this way ...
<div id="mydiv-$id"></div>
and then I can target it with JavaScript this way.
<script>
var id = '$id';
ASJ.toInit(function(){
var stuff = AJS.$('#' + id).html();
});
</script>
It's a bug , shit, wasted my 2 hours.
https://jira.atlassian.com/browse/CONFSERVER-82741
BTW, confluence does not give a solution to distinct many macro instances of the same macro definition in the same page , No one has this demand?
BTW, #set( $id = $action.dateFormatter.calendar.get(14) ) is better in this scenario.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
For my user macros, I don't worry about that. Confluence will generate what it needs. Even if I am wrapping an existing macro, I delete that reference. It works fine.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I want to modify the rendered results via JavaScript so I need a html object id for reference the right object on the page if a user used the macro multiple times on the same page.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hmm, seems a bit hard. You could create your own ID, but you would then need to increment it each time, which complicated. And seems like a brittle solution to rely on javascript to modify an object based on ID that could change.
Is there a way to do it within the user macro so that it is dynamic?
Maybe sharing a bit more detail on what you are trying to do would help?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
@René Kray could you explain or paste your macro solution to help me get started?
I'm still looking for a solution to generate a unique ID on a page
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Cyrus:
If I remember correctly, I was looking for a solution for the following macro.
In the end, I used id="$paramtitle" as "unique" id. For me it was unique enough, but for a general purpose, I would suggest finding a different solution.
Regards, René
## Macro title: roadmap_panel
## Macro has a body: Y
## Body processing: Selected body processing option
## Output: Selected output option
##
## Developed by: René Kray
## Date created: 2021-03-23
## Installed by: René Kray
## @param title:title=Title|type=string|required=true|default=Title for this panel
## @param o1:title=O1|type=boolean|required=true|default=false
## @param o1ext:title=O1 Ext|type=string|required=false|default=
## @param o2:title=O2|type=boolean|required=true|default=false
## @param o2ext:title=O2 Ext|type=string|required=false|default=
## @param o3:title=O3|type=boolean|required=true|default=false
## @param o3ext:title=O3 Ext|type=string|required=false|default=
## @param health:title=Health|type=boolean|required=true|default=false
<style>
div.roadmap_panel{
border: solid grey 1px;
border-radius: 5px;
background-color: #ddd;
box-shadow: 0 2px 4px 0 rgba(0, 0, 0, 0.2), 0 3px 5px 0 rgba(0, 0, 0, 0.19);
}
div.roadmap_panel div.roadmap_panel_title{
padding: 5px 5px 5px 10px;
border-radius: 5px;
font-weight: bold;
}
div.roadmap_panel div.roadmap_panel_title span.button{
padding: 2px 5px 2px 5px;
float: right;
}
div.roadmap_panel div.roadmap_panel_title span.status{
padding: 2px 5px 2px 5px;
border-radius: 3px;
border: solid black 1px;
color: white;
font-size: 80%;
float: right;
margin-right: 5px;
}
div.roadmap_panel div.roadmap_panel_body{
background-color: white;
padding: 5px;
border-radius: 0 0 5px 5px;
border-top: solid #999 1px;
display: none;
}
</style>
<div class="roadmap_panel" id="$paramtitle">
<div onclick="roadmap_panel_show_hide('$paramtitle')" class="roadmap_panel_title">
<span class="button">+</span>
#if ($paramhealth==true)
<span class="status" style="background-color: green;">Health</span>
#end
#if ($paramo3==true)
<span class="status" style="background-color: red;">
O3
#if ( "$paramo3ext" != "" )
- $paramo3ext
#end
</span>
#end
#if ($paramo2==true)
<span class="status" style="background-color: red;">
O2
#if ( "$paramo2ext" != "" )
- $paramo2ext
#end
</span>
#end
#if ($paramo1==true)
<span class="status" style="background-color: red;">
O1
#if ( "$paramo1ext" != "" )
- $paramo1ext
#end
</span>
#end
<p style="margin:0">$paramtitle</p>
</div>
<div class="roadmap_panel_body">
$body
</div>
</div>
<script>
function roadmap_panel_show_hide(id) {
panel=document.getElementById(id);
button=panel.getElementsByTagName("SPAN")[0];
body=panel.getElementsByTagName("DIV")[1];
if(body.style.getPropertyValue('display')=="block"){
body.style.setProperty('display','none');
button.innerHTML="+";
}else{
body.style.setProperty('display','block');
button.innerHTML="-";
}
}
</script>
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.