cancel
Showing results for 
Search instead for 
Did you mean: 

Create custom control for upload document in create-content wizard

3acascia
Champ in-the-making
Champ in-the-making
Hi All,

I'd like to upload content during creation of custom type using the standard creation form.

 
<config evaluator="model-type" condition="myprefix :mytype">
      <forms>
         <!– Document Library Common form –>
          <form>
           <field-visibility>         
           <show id="myprefix :mytype" force="true"/>            
           <show id="cm:title"/>            
             <show id="cm:content" for-mode="create"/>          
             </field-visibility>
               <appearance>
                  <field id="cm:content" mandatory="true">
                     <control template="/my-upload.ftl"/>
                  </field>
               </appearance>              
         </form>        
     </forms>
   </config>


Is is possible? Currently, my-upload.ftl is defined as follow:


            <div class="file-upload">

               <span id="${fieldHtmlId}-fileUpload-button" class="yui-button yui-push-button">

                  <span class="first-child">

                     <button name="fileUpload">${msg("button.upload")}</button>

                  </span>

               </span>

            </div>


How I can bind uploader to button named "fileUpload" in my-upload.ftl.

Thanks in advance,
Toma
4 REPLIES 4

iblanco
Confirmed Champ
Confirmed Champ
We did just this for a customer some time ago. It is possible but its not very easy, not at least in Alfresco 4.0. Explaining everything detail by detail would be quite long but I'll try to summarize the main steps so that you can make an idea.

1) We created a new page in Alfresco Shared called upload-content y copying standard create-content's file in pages and template-instances.
2) We created a new control that simply renderes a file type input field. We add it as the control for cm:content
3) In the template-instance we changed the create-content region:



      <!– Create Content Form –>
      <component>
         <region-id>create-content</region-id>
         <url>/my/components/upload-file?destination={destination}&amp;itemId={itemId}&amp;path={path}</url>
         <properties>
            <itemKind>type</itemKind>
            <itemId>{itemId}</itemId>
            <mode>create</mode>
            <submitType>multipart/form-data</submitType>
            <showCaption>true</showCaption>
            <showCancelButton>true</showCancelButton>
            <submissionUrl>/my/type/{itemId}/formprocessor</submissionUrl>
            <destination>{destination}</destination>
            <path>{path}</path>
            <formId>{formId}</formId>
         </properties>
      </component>


As you can see here we are saying that we want to send information in multipart/form-data  instead of the typical JSON. In 4.0 the client side forms runtime does not suppport file sending in JSON. We also change the component and the specified form processor. I'm not sure why we changed the component, url probably because we had to calculate the itemId based on the destination and that's not an standar behaviour. What you


4) then we define in Alfresco Explorer the form processor by copying the webscript files of the standard form processor and changing it a little bit in order to write the content. The part that writes the content looks like this:


var nodeRef = model.persistedObject;
var content = null, node = null; redirectUrl = null;
   
for (var i = 0; i < formdata.fields.length; i++)
{
   if(!formdata.fields.isFile) continue;
       content = formdata.fields.content;
       break;
   }
   
   node = search.findNode(nodeRef);
   
   //Anadimos el contenido
   if(content != null && node != null){
   
       node.properties.content.write(content);
       node.properties.content.guessMimetype(node.name);
       try{
     node.save();
   }catch(error){
      
      if(logger && logger.debug){
         logger.debug("Problem by including the file content.");
      }
            
     status.redirect = true;
     status.code = 301;
     status.location = "/share/page/my-upload-content?destination=" + encodeURIComponent(destination) + "&itemId=" + encodeURIComponent(itemId) + "&path=" +  encodeURIComponent(path) + "&errorCode=" + 500;
     return;
     }
         
}
   
    status.redirect = true;
    status.code = 301;
    status.location = "/share/page/document-details?nodeRef=" + nodeRef;
   


5) Then finally you must customize the tool bar so that the upload button points to your page

As you can see quite nasty and note very comfortable. That was in 4.0, maybe 4.2 has improvements in the form processor, don't know.

Goog luck.

3acascia
Champ in-the-making
Champ in-the-making
Thank you Iblanco for your time!
I agree with you that this approach is not so comfortable…but I will try it!
Hoping that 4.2.X has improvements for this feature…

Thank you for your help…
Toma

3acascia
Champ in-the-making
Champ in-the-making
Hi Iblanco,

I would like to define my custom create-content modifing the standard one. I put in /alfresco/site-webscripts/custom-create.ftl file the following code:

<#include "alfresco-template.ftl" />
<@templateHeader />

<@templateBody>
   <@markup id="alf-hd">
   <div id="alf-hd">
      <@region id="header" scope="global" />
      <@region id="title" scope="template" />
      <@region id="navigation" scope="template" />
   </div>
   </@>
   <@markup id="bd">
   <div id="bd">
      <div class="share-form">
         <@region id="create-content-mgr" scope="template" />
         <@region id="create-content" scope="template" />
      </div>
   </div>
   </@>
</@>

<@templateFooter>
   <@markup id="alf-ft">
   <div id="alf-ft">
      <@region id="footer" scope="global" />
   </div>
   </@>
</@>

but include directive fails…

Can you help me?

Thanks in advances,
Toma

vbr
Champ in-the-making
Champ in-the-making
Can you explain how you did it? Thank you!