Hi everyone,
I am working on a confluence plugin which has two macros. I only need users to have one macro per page (either macro 1 or macro 2. Not both or not 2 from one macro). If users add the second macro i need to display an AUI error message and restrict user from saving the page with two macros.
Thank you
Andrian
Community moderators have prevented the ability to post new answers.
One approach to try would be this : if the macro is rendered from a vm, then give the div containing the vm a unique id. That way if two macros are rendered, you can replace it with a simple message as shown in the below html:
<div id = "id1"> Hey </div> <div id = "id1"> Hey 2 </div> <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script> <script> var x = $('div[id=id1]').length; console.log("X is " + x); if (x > 1) { $("html").html("Page has two divs"); } </script>
Hi guys,
I was able to come up with the below code and it worked.
jQuery(document).bind('DOMSubtreeModified', function(event) { var noOfMacro1=jQuery('#wysiwyg iframe').contents().find('table[data-macro-name="macro1"]').length; var noOfMacro2=jQuery('#wysiwyg iframe').contents().find('table[data-macro-name="macro2"]').length; var totalMacros=noOfMacro1+noOfMacro2; if(totalMacros>1){ jQuery('#moreThanOneMacroError').removeClass('hidden'); var message= '<div id="moreThanOneMacroError" class="aui-message aui-message-error closeable"><p class="title"><strong>Error!</strong></p><p>Only one macro1 or macro2 macro is allowed per page.</p></div>'; if(jQuery('#moreThanOneMacroError').length<1){ jQuery('#editor-messages').append(message); } }else{ jQuery('#moreThanOneMacroError').addClass('hidden'); } });
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Thank you for sharing Andrian. This is really interesting, and is a much better solution than hiding the Save/Preview buttons (users would get confused, probably think the system is borked)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Thank you for the quick reply Steven..i agree with you. I also thought about disabling the Save and Preview button as long as there's more than one macro. Then i hope i only have to worry about the front end..Was not sure whether this will be a good approach...any thoughts ?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
My initial thought is that the most simple way would be to validate this when they submit the page for Save or Preview, and reject it if the conditions aren't met. Adding a javascript check to the layer would be an improvement, but you should still validate it server-side to ensure that your conditions are met.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Community moderators have prevented the ability to post new answers.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.