Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

Documentation for AJS.MacroBrowser.activateSmartFieldsAttachmentsOnPage() ? Need help auto-populating attachment dropdown in the Macro Browser

Jim Bethancourt
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
January 18, 2012

I'm trying to modify the Multimedia macro to allow for universal video playback using the Media Element player, and I'm having trouble getting files attached to the page to show up in the Macro Browser in the attachment type parameter. I noticed the AJS.MacroBrowser.activateSmartFieldsAttachmentsOnPage() call in confluence-core-macro-fields.js, and I would be silly to think this doesn't have a role in the population of the attachment dropdown values.

I have come across both

https://answers.atlassian.com/questions/17345/how-can-i-set-attachment-parameter-to-confluence-macro

and

https://jira.atlassian.com/browse/CONF-24016

and read through

https://developer.atlassian.com/display/CONFDEV/Including+Information+in+your+Macro+for+the+Macro+Browser

but none provide much documentation on how to use it.

The closest I can get is

http://forums.atlassian.com/thread.jspa?messageID=257376131

and

http://www.slideshare.net/GoAtlassian/atlascamp-2010-making-confluence-macros-easy-for-the-user-dave-taylor

but they both only make mention of it as well, but not much else.

I would like to understand what I need to do to have attachments show up in the attachments dropdown.

Many thanks,

Jim

7 answers

1 accepted

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

3 votes
Answer accepted
Alexander Küken
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
February 13, 2012

Hello Jim,

here an example from one of my projects how to configure the attachment field for the Macro Browser:

<xhtml-macro name="MyMacro" key="my-macro" class="MyMacro">
    	<category name="development" />
    	<parameters>
    		<default>
        		<option key="showValueInPlaceholder" value="true" />
    		</default>
    		<parameter name="myAttachment" type="confluence-content">
    			<option key="type" value="attachment"/>
    			<option key="showKeyInPlaceholder" value="false" />
        		<option key="showValueInPlaceholder" value="true" />
    		</parameter>
    	</parameters>
    </xhtml-macro>

Sometimes the auto-completion field for attachments in the macro browser has a strange behaviour. If you create a new page, add an attachment and call the Macro browser, the auto completion does not find the newly added attachment.

Perhaps this will help you.

Cheers,
Alexander

2 votes
Adrien Ragot 2
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
August 17, 2013
If you want to override the way one field is displayed in the Macro Browser:
var jsOverrides = {
        "fields" : {
            "string" : function(params, options){ // "string" is the field type
                if (params &amp;&amp; params.name != "myFieldName") {
                    return AJS.MacroBrowser.ParameterFields["string"](params, options);
                }

                var paramDiv = $(Confluence.Templates.MacroBrowser.macroParameterSelect());
                var $select = $("select", paramDiv);
                $(["a, b, c", "d, e, f"]).each(function() {
                    $select.append(AJS.$("&lt;option/&gt;").attr("value", this).html("" + this));
                });

                var field = AJS.MacroBrowser.Field(paramDiv, input, options);

            }
        }
    };
    AJS.MacroBrowser.setMacroJsOverride("my-macro-name", jsOverrides);


You can look at the file macro-browser.js and macro-browser-fields.js in the Confluence source.
2 votes
Jim Bethancourt
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
February 27, 2012

Turns out I had to modify the confluence-core-macro-fields.js file and refer to it using a web-resource

In atlassian-plugin.xml, add the following web-resource item:

<web-resource key="macro-browser-smart-fields" name="Macro Browser Smart Fields">
    <resource type="download" name="confluence-core-macro-fields.js" location="javascript/confluence-core-macro-fields.js" />
    <dependency>confluence.editor.actions:editor-macro-browser</dependency>
    <context>macro-browser</context>
</web-resource>

Add a confluence-core-macro-fields.js file to the javascript directory (you will need to create this directory and put the javascript file in it) with the contents:

(function($) {
   AJS.MacroBrowser.activateSmartFieldsAttachmentsOnPage("macro-name", ["mp4", "mp3", "wmv"]);
})(AJS.$);

I also found that when I had added file types to this list, sometimes I would have to uninstall the plugin and then re-install it instead of simply re-installing it.

Martin Mitry May 9, 2012

Hi Jim,

thanks for your posting.

With your descibed solution, did you get an autocomplete field or an enum (drop-down) field?

What did you use for paramters? Same as Alexander?

Thanks

Martin

Jim Bethancourt
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
May 9, 2012

I got an enum (drop-down). I specified that the attachment be required, but that was the only parameter I specified for the attachment:

<parameter name="name" type="attachment" required="true">

<alias name=""/>

</parameter>

Cheers,

Jim

Martin Mitry May 9, 2012

thanks for your quick reply

i tried (slightly) the same but it did not work.

turns out that the value for 'name' has to be ="name", otherwise the list is empty.

Regards, Martin

Martin Mitry May 10, 2012

and also the following is required:

<parameter name="page" type="confluence-content"/>

btw, this is described here:
<confluence-install-dir>\includes\js\macro-browser-smartfields.js:

* Activates smart fields support for a pair of Page / Attachment fields in a macro.
 * 
 * Expects the following macro parameters for the "macroName" to be defined:
 * 
 *   &lt;parameter name="page" type="confluence-content"/&gt;
 *   &lt;parameter name="name" type="attachment" required="true"&gt;
 *     &lt;alias name=""/&gt;
 *   &lt;/parameter&gt;

Roman Krapf September 26, 2012

Hello together

Sorry, but that doesn't work for me. I have tried to do the same as you, but it doesn't work. :( My dropdown is allways empty. Can you please post the hole files or the hole plugin source code? I'm desperate.

Cheers Jammon

Aviram Gabay
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
October 29, 2012

Hi guys,
Thanks for this post, but its not working for me either.
My dropdown is also always empty.
Please help, I could really use this feature.

Thanks!

Aviram Gabay
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
October 29, 2012

Hi Guys,

Thanks for this, really helped me a lot.
Is it possible to create more than 1 field of this type for the same macro?

Thanks!

1 vote
shess July 14, 2015

Come on Atlassian!

That question is more than 4 years old and still has no sufficient solution. Referring to your developer documentation (see here), you simply need a macro parameter of type "attachment" to get that autocomplete to work. But it still doesn't work. 

As we read above, you still need to ... name your macro parameter "name" ... add an extra parameter of type "page" ... call an extra js function name "activateSmartFieldsAttachmentsOnPage".

Really? This can not be true.

0 votes
fwoon April 23, 2019

1) Make sure your java file is parked under macros/<your java>.java

2) Make sure it is also specified in your atlassian-plugin.xml

<xhtml-macro key='<mykey>' name="<mykey>" class="com.ilm.plugins.macros.<your java>"

Also read up on : https://developer.atlassian.com/server/confluence/accessing-confluence-components-from-plugin-modules/

 

0 votes
Roger Maschewski May 17, 2014

Hi,

I followed the exampels og Jim and Adrien to implement a selection of attachments and to offer a parameter field as an textarea. It worked fine within the development area and the testing area. But in the production site, I didn't observe any change to the former version of the plugin. Jim's hint to uninstall the plugin completely before to re-install it, didn't help. So didn't, flushing the cashes of the site.

In my case, the solution was to clear the temporary internet files of the browser.

I hope this hint can be helpful as well.

Cheers, Roger

Adrien Ragot 2
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
May 17, 2014
Yes, this is terrible: Sometimes the browser doesn't notice that the plugin has changed and keeps the cached copy. I personnaly go to the javascript file, load it in a separate tab, and press Ctrl+R to force a reload without cache. I wondered how that worked in production, thank you for your hint.
0 votes
Martin Mitry May 9, 2012

thanks for your quick reply

i tried (slightly) the same but it did not work.

turns out that the value for 'name' has to be ="name", otherwise the list is empty.

Regards, Martin

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

TAGS
AUG Leaders

Atlassian Community Events