Alfresco Share tip: content type
selection when uploading a document
Alfresco Share types and form customization is now well understood and documented, as shown by this google search. But that is not the case when customizing the upload form in order to be able to select the type of the document to be uploaded.
At first, we thought that adding this functionality would require performing complex developments and altering the basic document upload action.
We later discovered that this feature was already implemented in Alfresco Share though it is not documented anywhere (neither in official Alfresco documentation nor in the community sites and blogs).
If you take a look at the file “tomcat\webapps\share\WEB-INF\classes\alfresco\site-webscripts\org\alfresco\components\upload\flash-upload.get.html.ftl”, you’ll notice that while the upload form already contains the required code to generate a select input for the document type, its visibility is conditioned by the test “contentTypes?size == 1”.
<div id="${args.htmlid}-left-div" class="fileupload-left-div">
<span class="fileupload-percentage-span hidden"> </span>
<select class="fileupload-contentType-select <#if (contentTypes?size == 1)>hidden</#if>">
<#if (contentTypes?size > 0)>
<#list contentTypes as contentType>
<option value="${contentType.id}">${msg(contentType.value)}
</option>
</#list>
</#if>
</select>
</div>
And so, it only takes filling in the contentTypes variable in the webscript Javascript controller with the custom document types for the select input to be shown to the final user.
The “contentTypes” variable’s declaration and initialization can be found in this file: “tomcat\webapps\share\WEB-INF\classes\alfresco\site-webscripts\org\alfresco\components\upload\flash-upload.get.js”. This variable consists of an array of objects with 2 fields:
- id: the Alfresco content type identifier.
- value: the content type label’s key in the webscript properties file.
Find below an example of how to initialize contentTypes variable with multiple content types:
var contentTypes = [
{
id: "cm:content",
value: "cm_content"
},
{
id: "custom:docJuri",
value: "custom _docJuri"
},
{
id: "custom:autres",
value: "custom _autres"
},
{
id: "custom:presse",
value: "custom _presse"
},
{
id: "custom:biblio",
value: "custom _biblio"
}
];
As a result, here’s how the upload form will look like:
Figure 1. Upload form
Now, you should be able to easily define types for your documents when adding them to the repository, as with Alfresco explorer, and then fill in their custom metadata as showing in Figure 2.
Figure 2. Edit metadata form
Hope it was useful, your comments are welcome.
Tags: Alfresco, Custom metadata, ECM, GED, Javascript, Offshore, Share, tip, Tunisie, Webscript



15 juin 2010 à 18:17
Actually, there was a blog post on this.
http://loftux.se/en/2010/03/22/set-the-document-type-on-file-upload/
But yours was a bit more elaborate, and features like this needs to be told about.
15 juin 2010 à 18:49
Hi Peter,
Glad it reached you so quickly!
Unfortunately, our Google search haven’t showed up your post which, indeed, talks about the same feature.
It looks that you’ve worked also on advanced search on Share, get a look at our open source extension: http://www.iptechinside.com/labs/projects/show/alfrescoshare
Main features: http://www.iptechinside.com/labs/wiki/alfrescoshare/Features
Your comments are welcome!
29 juillet 2010 à 15:07
Hi,
Thanks for the post, it was very useful. I have a question. How do you relate the Content type to the Aspects or Custom metadata fields. For example. if I select custom _docJuri from the example above. I need only fields related to it on the metadata form.
Thanks,
Croc
3 août 2010 à 10:35
Hello Croc,
Thanks for your interest in this post.
In fact, the configuration explained above suppose that you have already created your custom content types (*Model.xml and *-context.xml files) on the alfresco side, and your form file on the Share side (ex: share-config-custom.xml, wich will enable custom metadata display and control their layout).
Note that the content type id called in “tomcat\\webapps\\share\\WEB-INF\\classes\\alfresco\\site-webscripts\\org\\alfresco\\components\\upload\\flash-upload.get.js” must correspond to a content type id defined in the model file.
12 août 2010 à 13:56
Do I have to hard-code the contentTypes on flash-upload.get.js like the one above or is the a way that it can gets them automatically from the model.xml ?
Thanks,
Croc
21 avril 2011 à 12:29
Small comment ragarding localization tags:
\"value\" in .js file must be exaclty equal to parameters name in .properties file. By default, .js (at least in 3.4.d) contains \"type.cm_content=Content\" . So yo should either change it to \"cm_content=Content\" or to edit .js file\’s value: \"cm_content\" to value \"type.cm_content\".
Please correct me if i\’m wrong, bit it works for me.
20 mai 2011 à 17:14
Hello D_Garry,
Your comment is absolutely correct, and it is important to clarify it: “value” in .js file must be the same as the parameter name specified in the .properties file.
In fact , the “type.cm_content=Content” entry was added to the webscript properties file “flash-upload.get.properties” only from the Alfresco 3.3 version, so it is logic to follow the same syntax for the custom type names to be added.
So, the solution - as you mentioned - is to use the same parameter “cm_content” or “type.cm_content” in both .js and .properties files.
Thanks,
8 septembre 2011 à 9:20
Hi, The artical suggested changes in alfresco code folders. How can it be done by using web-extension folders?
Regards
Sharad