cancel
Showing results for 
Search instead for 
Did you mean: 

Custom Form for Creation Folder

jriffo
Champ in-the-making
Champ in-the-making
What condition and evaluator should be used to show a form to create a folder in share-form-config.xml?

<!– cm:folder type (creating nodes) –>
   <config evaluator="string-compare" condition="cm:name=OficinaPartes">
      <forms>
         <!– Document Library Common form –>
         <form id="doclib-common">
            <field-visibility>
               <show id="cm:name" />
               <show id="scjmodel:matCarp" />
               <show id="cm:title" force="true" />
               <show id="cm:description" force="true" />
            </field-visibility>
            <create-form template="../documentlibrary/forms/doclib-common.ftl" />
            <appearance>
               <field id="cm:name">
                  <control template="/org/alfresco/components/form/controls/textfield.ftl" >
                     <control-param name="maxLength">255</control-param>
           <control-param name="nombreCarpeta">nombreCarpeta</control-param>
                  </control>
               </field>
               <field id="scjmodel:matCarp">
                  <control template="/org/alfresco/components/form/controls/textfield.ftl" />
               </field>
               <field id="cm:title">
                  <control template="/org/alfresco/components/form/controls/textfield.ftl" />
               </field>
            </appearance>
         </form>
         <!– Search form –>
         <form id="search">
            <field-visibility>
               <show id="cm:name" />
               <show id="scjmodel:matCarp" />
               <show id="cm:title" force="true" />
               <show id="cm:description" force="true" />
            </field-visibility>
         </form>
      </forms>
   </config>

2 REPLIES 2

steven_okennedy
Star Contributor
Star Contributor
Hi

There are a couple of changes you would need to make in order to get this to do what you want.  By default, Share will create a new item of type cm:folder when you click the new folder button - and so will use the form service to request a create form for the type cm:folder.  From your form above, it looks like you want to use a form for a different, custom type.

Firstly, you need to change what happens when you click the new folder button.  The share-documentlibrary-config.xml file contains a section of config that controls what options appear in the "Create…" drop down.  By default it looks like

<config evaluator="string-compare" condition="DocumentLibrary">
    <create-content>
         <content id="plain-text" label="create-content.text" type="pagelink" index="10" icon="text">
            <param name="page">create-content?destination={nodeRef}&amp;itemId=cm:content&amp;mimeType=text/plain</param>
         </content>
         <content id="html" label="create-content.html" type="pagelink" index="20">
            <param name="page">create-content?destination={nodeRef}&amp;itemId=cm:content&amp;mimeType=text/html</param>
         </content>
         <content id="xml" label="create-content.xml" type="pagelink" index="30">
            <param name="page">create-content?destination={nodeRef}&amp;itemId=cm:content&amp;mimeType=text/xml</param>
         </content>
         <content id="folder" label="create-content.folder" icon="folder" index="5" type="javascript">
            <param name="function">onNewFolder</param>
         </content>
      </create-content>
</config>


The last item here adds the New Folder button and controls what it does - calling a Javascript function called "onNewFolder".  To change the behaviour, you will need to override this section of config (put it into your share-config-custom.xml file) and you'll need to specify a new javascript function to call.  You will then need to define and register a new JS handler to be used instead of onNewFolder.  You can register an action by including a javascript file that does something like:

YAHOO.Bubbling.fire("registerAction",
{  
  actionName: "onNewCustomFolder",
  fn: function XXXX_onNewCustomFolder(p_obj)
  {     
  …     
  }
});


This code registers your new function so that it can be found when the user clicks the menu item in the Create… dropdown.  You're best pretty much copying the onNewFolder function as is when creating your new function (you can see the source in share/components/documentlibrary/toolbar.js if you search for "onNewFolder: function DLTB_onNewFolder(e, p_obj)"), just make a change to the part where it calls the forms service, replacing the item id with the name of your custom type:


var templateUrl = YAHOO.lang.substitute(Alfresco.constants.URL_SERVICECONTEXT + "components/form?itemKind={itemKind}&itemId={itemId}&destination={destination}&mode={mode}&submitType={submitType}&formId={formId}&showCancelButton=true",
         {
            itemKind: "type",
            itemId: "———++scjmodel:mytype++—————",
            destination: destination,
            mode: "create",
            submitType: "json",
            formId: "doclib-common"
         });



Lastly, you need to make sure that your form configuration is declared correctly so that it will be picked up by the form service.  You need to use the correct evaluator type and condition, which for a create form will be "model-type" and the name of your type (e.g. "scjmodel:mytype")


<config evaluator="model-type" condition="scjmodel:mytype">
  <forms>
    <!– Document Library Common form –>
    <form id="doclib-common">
      <field-visibility>
     …
      </field-visibility>
      <appearance>
     …
      </appearance>
    </form>
  </forms>
</config>


Whew…

So not quite a straightforward change, and one that could have been made a lot easier if the onNewFolder function could read a "type" argument from the create-content configuration instead of using a hardcoded value of cm:folder…. but that's another day's problem

Regards

Steven

Hi, I was wondering if there was a way to adapt this for space template items? I have a few space templates with custom aspects applied and I'd like the create form to show the metadata fields to be filled in.