Is it possible to make document picker default to

2019-08-03 10:35发布

问题:

I have a copy of association.ftl which I use for a control added to the advanced search form in share. Unfortunately when opened the default display is companyhome where as I'd rather have it default to the related site's document library. I read this wiki and also tried the changing the parentNodeRef value in the javascript to at least add sites to the path to no success.

The share form config control:

<config evaluator="model-type" condition="cm:content">
    <forms>
        <!-- Search form -->
        <form id="search">
            <field-visibility>
                <show id="cm:name" force="true" />
                <show id="space" force="true" />
            </field-visibility>
            <appearance>
                <field id="cm:name" label-id="prop.search.cm_name" />
                <field id="space" label-id="prop.search.cm_search_in_folder" >
                    <control template="/org/alfresco/components/form/controls/space.ftl">
                        <control-param name="startLocation">{doclib}</control-param>
                    </control>
                </field>
            </appearance>
        </form>
    </forms>
</config>

The freemarker control file :

<#include "common/picker.inc.ftl" />

<#assign controlId = fieldHtmlId + "-cntrl">

<script type="text/javascript">//<![CDATA[
(function()
{
   <@renderPickerJS field "picker" />
   picker.setOptions(
   {
   <#if field.control.params.showTargetLink??>
      showLinkToTarget: ${field.control.params.showTargetLink},
      <#if page?? && page.url.templateArgs.site??>
         targetLinkTemplate: "${url.context}/page/site/${page.url.templateArgs.site!""}/document-details?nodeRef={nodeRef}",
      <#else>
         targetLinkTemplate: "${url.context}/page/document-details?nodeRef={nodeRef}",
      </#if>
   </#if>
   <#if field.control.params.allowNavigationToContentChildren??>
      allowNavigationToContentChildren: ${field.control.params.allowNavigationToContentChildren},
   </#if>
      itemType: "cm:folder",
      multipleSelectMode: false,
      parentNodeRef: "alfresco://company/home/sites", //<== Not the default path
   <#if field.control.params.rootNode??>
      rootNode: "${field.control.params.rootNode}",
   </#if>
      itemFamily: "node",
      displayMode: "${field.control.params.displayMode!"items"}"
   });
})();
//]]></script>

<div class="form-field">
   <#if form.mode == "view">
      <div id="${controlId}" class="viewmode-field">
         <span class="viewmode-label">${field.label?html}:</span>
         <span id="${controlId}-currentValueDisplay" class="viewmode-value current-values"></span>
      </div>
   <#else>
      <label for="${controlId}">${field.label?html}:</label>

      <div id="${controlId}" class="object-finder">

         <div id="${controlId}-currentValueDisplay" class="current-values"></div>

            <input type="hidden" id="${fieldHtmlId}" name="-" value="${field.value?html}" />
            <input type="hidden" id="${controlId}-added" name="${field.name}_added" />
            <input type="hidden" id="${controlId}-removed" name="${field.name}_removed" />
            <div id="${controlId}-itemGroupActions" class="show-picker"></div>

            <@renderPickerHTML controlId />
      </div>
   </#if>
</div>

回答1:

The wiki is pretty clear on how to do this:

Supply a startLocation as parameter to the picker in the forms-config, since you want to go with the documentLibrary of the site the user searches from I would recommend you to implement a NodeLocator as described in the wiki:

https://wiki.alfresco.com/wiki/NodeLocatorService

In fact that seems to already have been implemented for you and seems to reside in the alfresco source:

http://svn.alfresco.com/repos/alfresco-open-mirror/alfresco/COMMUNITYTAGS/V4.2e/root/projects/repository/source/java/org/alfresco/repo/site/DocLibNodeLocator.java

However I cant find the bean declaration so you might have to add it to your spring-bean definitions (or copy the source to an own implementation) to be able to use it properly.