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
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
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
Community moderators have prevented the ability to post new answers.
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
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 && 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.$("<option/>").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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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: * * <parameter name="page" type="confluence-content"/> * <parameter name="name" type="attachment" required="true"> * <alias name=""/> * </parameter>
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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!
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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!
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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/
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
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.