Alfresco · Creación personalizada de carpetas en Share

La creación de carpetas en Alfresco Share puede ser personalizada para incluir propiedades adicionales. En este artículo se describe un proceso que permite mostrar al usuario una lista desplegable de procesos, recuperada a través de un WebScript, en el momento de creación de una carpeta.

Inventario de elementos

  • Alfresco
    • customModel.xml – Extensión del modelo de datos para la inclusión del nuevo tipo de carpeta
    • ProcessesListWebScript.java – Implementación del webscript de carga de datos
    • processesList.get.desc.xml – Definición del webscript de carga de datos
    • custom-actions-context.xml – Declaración del webscript de carga de datos
  • Share
    • local-share-config-custom.xml – Configuración de tipos y formularios
    • toobar.js – Personalización de la creación de formularios (aunque también podría sobreescribirse el método onNewFolder a través de Surf para evitar modificar este recurso de Alfresco)
    • custom-process.ftl – Control desplegable utilizable en Alfresco Forms para la gestión de la lista de procesos

Alfresco

customModel.xml
<?xml version="1.0" encoding="UTF-8"?>
<model name="ks:keensoftmodel" xmlns="http://www.alfresco.org/model/dictionary/1.0">

    <description>KS Model</description>
    <author>keensoft</author>
    <version>1.0</version>

    <imports>
        <import uri="http://www.alfresco.org/model/dictionary/1.0" prefix="d" />
        <import uri="http://www.alfresco.org/model/content/1.0" prefix="cm" />
    </imports>

    <namespaces>
        <namespace uri="http://www.keensoft.es/model/content/1.0" prefix="ks" />
    </namespaces>
    
    <types>
        <type name="ks:customFolder">
            <title>Carpeta personalizada</title>
            <parent>cm:folder</parent>          
            <properties>
                <property name="ks:process">
                    <title>Proceso</title>
                    <description>Proceso</description>
                    <type>d:text</type>
                    <mandatory>true</mandatory>
                </property>
            </properties>
        </type>
   </types>

</model>
ProcessesListWebScript.java
package es.keensoft.alfresco.action.webscript;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.json.JSONArray;
import org.springframework.extensions.webscripts.AbstractWebScript;
import org.springframework.extensions.webscripts.WebScriptRequest;
import org.springframework.extensions.webscripts.WebScriptResponse;

import es.keensoft.alfresco.services.CustomScriptServices;

public class ProcessesListWebScript extends AbstractWebScript {
    
    private static final Log logger = LogFactory.getLog(ProcessesListWebScript.class);
    
    @Override
    public void execute(WebScriptRequest request, WebScriptResponse response) throws IOException {
        
        // build a json object
        JSONArray objProcess = new JSONArray();
        
        // Read from database
        List<String> processes = loadDB();
        for (String process : processes) {
                objProcess.put(process);
        }
        
        // build a JSON string and send it back
        String jsonString = objProcess.toString();
        response.setContentEncoding("UTF-8");
        response.getWriter().write(jsonString);
        
    }
    
    protected static List<String> loadDB() {
        
        List<String> processesList = new ArrayList<String>();
        
        // Build some processes list from DB

        return processesList;

    }

}
processesList.get.desc.xml
<webscript>
  <shortname>Get processes list</shortname>
  <description>Get processes list
  To test: curl -v -u admin:admin "http://localhost:8080/alfresco/service/mycompany/processesList"
  </description>
  <url>/mycompany/processesList</url>
  <format default="html"/>
  <authentication>user</authentication>
  <transaction>none</transaction>
</webscript>
custom-actions-context.xml
<?xml version='1.0' encoding='UTF-8'?>
<!DOCTYPE beans PUBLIC '-//SPRING//DTD BEAN//EN'
'http://www.springframework.org/dtd/spring-beans.dtd'>
<beans>

	<!-- Get processes list from Database -->
	<bean id="webscript.es.keensoft.custom-actions.processesList.get" 
	      class="es.keensoft.alfresco.action.webscript.ProcessesListWebScript" parent="webscript"/>
	      
</beans>

Share

local-share-config-custom.xml
<alfresco-config>

   <!-- ks:customFolder type (creating nodes) -->
   <config evaluator="model-type" condition="ks:customFolder">
      <forms>
         <form id="doclib-common-process">
            <field-visibility>
               <show id="cm:name" />
               <show id="cm:title" force="true" />
               <show id="cm:description" force="true" />
               <show id="ks:process" force="true" />
            </field-visibility>
            <create-form template="../documentlibrary/forms/doclib-common.ftl" />
            <appearance>
               <field id="cm:title">
                  <control template="/org/alfresco/components/form/controls/textfield.ftl" />
               </field>
               <field id="ks:process">
                  <control template="/org/alfresco/components/form/controls/custom-process.ftl" />
               </field>
            </appearance>
         </form>
         <form id="search">
            <field-visibility>
               <show id="cm:name" />
               <show id="cm:title" force="true" />
               <show id="cm:description" force="true" />
            </field-visibility>
         </form>
      </forms>
   </config>
   
   <!-- ks:customFolder type (existing nodes) -->
   <config evaluator="node-type" condition="ks:customFolder">
      <forms>
         <!-- Default form configuration for the cm:folder type -->
         <form>
            <field-visibility>
               <show id="cm:name" />
               <show id="cm:title" force="true" />
               <show id="cm:description" force="true" />

               <!-- tags and categories -->
               <show id="cm:taggable" for-mode="edit" force="true" />
               <show id="cm:categories" />

               <!-- emailserver:aliasable aspect -->
               <show id="emailserver:alias" />
               
               <!-- ks:customFolder -->
               <show id="ks:process" />
               
            </field-visibility>
            <appearance>
               <field id="cm:name">
                 <control>
                    <control-param name="maxLength">255</control-param>
                 </control>
               </field>
               <field id="cm:title">
                  <control template="/org/alfresco/components/form/controls/textfield.ftl" />
               </field>
               <field id="cm:description">
                  <control>
                     <control-param name="activateLinks">true</control-param>
                  </control>
               </field>
               <field id="cm:taggable">
                  <control>
                     <control-param name="compactMode">true</control-param>
                     <control-param name="params">aspect=cm:taggable</control-param>
                     <control-param name="createNewItemUri">/api/tag/workspace/SpacesStore</control-param>
                     <control-param name="createNewItemIcon">tag</control-param>
                  </control>
               </field>
               <field id="cm:categories">
                  <control>
                     <control-param name="compactMode">true</control-param>
                  </control>
               </field>
               <!-- ks:customFolder -->
               <field id="ks:process" read-only="true" />
            </appearance>
          </form>

          <!-- Document Library pop-up Edit Metadata form -->
         <form id="doclib-simple-metadata">
            <field-visibility>
               <show id="cm:name" />
               <show id="cm:title" force="true" />
               <show id="cm:description" force="true" />
               <!-- tags and categories -->
               <show id="cm:taggable" for-mode="edit" force="true" />
               <show id="cm:categories" />
               <!-- ks:customFolder -->
               <show id="ks:process" />
            </field-visibility>
            <edit-form template="../documentlibrary/forms/doclib-simple-metadata.ftl" />
            <appearance>
               <field id="cm:name">
                 <control>
                    <control-param name="maxLength">255</control-param>
                 </control>
               </field>
               <field id="cm:title">
                  <control template="/org/alfresco/components/form/controls/textfield.ftl" />
               </field>
               <field id="cm:description">
                  <control>
                     <control-param name="activateLinks">true</control-param>
                  </control>
               </field>
               <field id="cm:taggable">
                  <control>
                     <control-param name="compactMode">true</control-param>
                     <control-param name="params">aspect=cm:taggable</control-param>
                     <control-param name="createNewItemUri">/api/tag/workspace/SpacesStore</control-param>
                     <control-param name="createNewItemIcon">tag</control-param>
                  </control>
               </field>
               <field id="cm:categories">
                  <control>
                     <control-param name="compactMode">true</control-param>
                  </control>
               </field>
               <!-- ks:customFolder -->
               <field id="ks:process" read-only="true" />
            </appearance>
          </form>
      </forms>
   </config>
          
</alfresco-config>
toolbar.js

    onNewFolder: function DLTB_onNewFolder(e, p_obj)
    {

        // Skipped code...

         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: "ks:customFolder",       // Modified
            destination: destination,
            mode: "create",
            submitType: "json",
            formId: "doclib-common-process"  // Modified
         });

        // Skipped code...
        
    }

custom-process.ftl
<#include "/org/alfresco/components/form/controls/common/utils.inc.ftl" />

<#if field.control.params.optionSeparator??>
   <#assign optionSeparator=field.control.params.optionSeparator>
<#else>
   <#assign optionSeparator=",">
</#if>
<#if field.control.params.labelSeparator??>
   <#assign labelSeparator=field.control.params.labelSeparator>
<#else>
   <#assign labelSeparator="|">
</#if>

<#assign fieldValue=field.value>

<#if fieldValue?string == "" && field.control.params.defaultValueContextProperty??>
   <#if context.properties[field.control.params.defaultValueContextProperty]??>
      <#assign fieldValue = context.properties[field.control.params.defaultValueContextProperty]>
   <#elseif args[field.control.params.defaultValueContextProperty]??>
      <#assign fieldValue = args[field.control.params.defaultValueContextProperty]>
   </#if>
</#if>

<div class="form-field">
   <#if form.mode == "view">
      <div class="viewmode-field">
         <#if field.mandatory && !(fieldValue?is_number) && fieldValue?string == "">
            <span class="incomplete-warning"><img src="${url.context}/res/components/form/images/warning-16.png" title="${msg("form.field.incomplete")}" /><span>
         </#if>
         <span class="viewmode-label">${field.label?html}:</span>         
         <#if fieldValue?string == "">
            <#assign valueToShow=msg("form.control.novalue")>
         <#else>
            <#assign valueToShow=fieldValue>
            <#if field.control.params.options?? && field.control.params.options != "">
               <#list field.control.params.options?split(optionSeparator) as nameValue>
                  <#if nameValue?index_of(labelSeparator) == -1>
                     <#if nameValue == fieldValue?string || (fieldValue?is_number && fieldValue?c == nameValue)>
                        <#assign valueToShow=nameValue>
                        <#break>
                     </#if>
                  <#else>
                     <#assign choice=nameValue?split(labelSeparator)>
                     <#if choice[0] == fieldValue?string || (fieldValue?is_number && fieldValue?c == choice[0])>
                        <#assign valueToShow=msgValue(choice[1])>
                        <#break>
                     </#if>
                  </#if>
               </#list>
            </#if>
         </#if>
         <span class="viewmode-value">${valueToShow?html}</span>
      </div>
   <#else>
      <label for="${fieldHtmlId}">${field.label?html}:<#if field.mandatory><span class="mandatory-indicator">${msg("form.required.fields.marker")}</span></#if></label>
         <select id="${fieldHtmlId}" name="${field.name}" tabindex="0"
               <#if field.description??>title="${field.description}"</#if>
               <#if field.control.params.size??>size="${field.control.params.size}"</#if> 
               <#if field.control.params.styleClass??>class="${field.control.params.styleClass}"</#if>
               <#if field.control.params.style??>style="${field.control.params.style}"</#if>
               <#if field.disabled  && !(field.control.params.forceEditable?? && field.control.params.forceEditable == "true")>disabled="true"</#if>>
         </select>
         <@formLib.renderFieldHelp field=field />
   </#if>
</div>

<script type="text/javascript">//<![CDATA[
YAHOO.util.Event.onContentReady("${fieldHtmlId}", function ()
{

    Alfresco.util.Ajax.jsonGet({
       url: Alfresco.constants.PROXY_URI + '/mycompany/processesList',
       successCallback:
       {
          fn: function loadWebscript_successCallback(response, config)
          {
              var obj = eval('(' + response.serverResponse.responseText + ')');
              if (obj)
              {
                 for (var key in obj) {
                     var newOption = document.createElement('option');
                     newOption.text = obj[key];
                     newOption.value = obj[key];
                     YAHOO.util.Dom.get("${fieldHtmlId}").options.add(newOption);
                 }
              }
          }
       }
    });
   
}, this);
//]]></script>

2 comentarios en “Alfresco · Creación personalizada de carpetas en Share

  1. Incluye un desplegable en el formulario de creación de carpeta para seleccionar el identificador de proceso. Los ficheros van en las rutas de extensión estándar de Alfresco (repo y share)

Responder

Introduce tus datos o haz clic en un icono para iniciar sesión:

Logo de WordPress.com

Estás comentando usando tu cuenta de WordPress.com. Cerrar sesión / Cambiar )

Imagen de Twitter

Estás comentando usando tu cuenta de Twitter. Cerrar sesión / Cambiar )

Foto de Facebook

Estás comentando usando tu cuenta de Facebook. Cerrar sesión / Cambiar )

Google+ photo

Estás comentando usando tu cuenta de Google+. Cerrar sesión / Cambiar )

Conectando a %s