AnsweredAssumed Answered

Multiples formatos de fecha en alfresco share

Question asked by huarte on Mar 3, 2016
Latest reply on Mar 3, 2016 by huarte
Hola,


Estoy desarrollando un modelo personalizado en share, y tengo la necesidad de tener 2 formatos de fechas diferentes.

Un formato igual que el predefinido, y un segundo formato en que solo se tenga que introducir el año (YYYY).

De momento, he conseguido cambiar los mensajes y ya me salen con el formato que quiero pero, no se si en el template que he creado puedo decile el fomato a introducir a parte del mensaje en el span.


Detallo los pasos que he seguido para modificarlo.

1- En los form controls de alfresco he creado uno nuevo copiando el "date.ftl" a "year.ftl" con el siguiente contenido:



<#if field.control.params.submitTime?? && field.control.params.submitTime == "false"><#assign submitTime=false><#else><#assign submitTime=true></#if>
<#if field.control.params.showTime?? && field.control.params.showTime == "true"><#assign showTime=true><#else><#assign showTime=false></#if>

<#if showTime><#assign viewFormat>${msg("form.control.date-picker.view.time.format.year")}</#assign><#else><#assign viewFormat>${msg("form.control.date-picker.view.date.format.year")}</#assign></#if>

<#assign disabled=field.disabled>
<#if field.control.params.forceEditable?? && field.control.params.forceEditable == "true">
   <#assign disabled=false>
</#if>

<#assign multiValued=false>
<#if field.value != "" && field.value?index_of(",") != -1>
   <#assign multiValued=true>
</#if>

<#if form.capabilities?? && form.capabilities.javascript?? && form.capabilities.javascript == false><#assign jsDisabled=true><#else><#assign jsDisabled=false></#if>

<div class="form-field">
   <#if form.mode == "view">
      <div class="viewmode-field">
         <#if field.mandatory && field.value == "">
            <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 field.value == "">
            <span class="viewmode-value">
            ${msg("form.control.novalue")}
         <#elseif !multiValued>
            <span class="viewmode-value viewmode-value-date" data-date-iso8601="${field.value}" data-show-time="${showTime?string}">
            ${xmldate(field.value)?string(viewFormat)}
         <#else>
            <span class="viewmode-value">
            <#list field.value?split(",") as dateEl>
               ${xmldate(dateEl)?string(viewFormat)}<#if dateEl_has_next>,</#if>
            </#list>
         </#if>
         </span>
      </div>
   <#elseif !multiValued>
      <#if jsDisabled>
         <label for="${fieldHtmlId}">${field.label?html}:<#if field.mandatory><span class="mandatory-indicator">${msg("form.required.fields.marker")}</span></#if></label>
         <input id="${fieldHtmlId}" name="${field.name?html}" type="text" class="date-entry" value="${field.value?html}" <#if field.description??>title="${field.description}"</#if> <#if disabled>disabled="true"<#else>tabindex="0"</#if> />
         <div class="format-info">
            <span class="date-format">${msg("form.control.date-picker.entry.datetime.format.year.nojs")}</span>
         </div>
      <#else>
         <#assign controlId = fieldHtmlId + "-cntrl">
        
         <script type="text/javascript">//<![CDATA[
         (function()
         {
            new Alfresco.DatePicker("${controlId}", "${fieldHtmlId}").setOptions(
            {
               <#if form.mode == "view" || disabled>disabled: true,</#if>
               currentValue: "${field.value?js_string}",
               showTime: ${showTime?string},
               submitTime: ${submitTime?string},
               mandatory: ${field.mandatory?string}
            }).setMessages(
               ${messages}
            );
         })();
         //]]></script>
     
         <input id="${fieldHtmlId}" type="hidden" name="${field.name?html}" value="${field.value?html}" />
     
         <label for="${controlId}-date">${field.label?html}:<#if field.mandatory><span class="mandatory-indicator">${msg("form.required.fields.marker")}</span></#if></label>
         <input id="${controlId}-date" name="-" type="text" class="date-entry" <#if field.description??>title="${field.description}"</#if> <#if disabled>disabled="true"<#else>tabindex="0"</#if> />
     
         <#if disabled == false>
            <a id="${controlId}-icon"><img src="${url.context}/res/components/form/images/calendar.png" class="datepicker-icon" tabindex="0"/></a>
         </#if>
     
         <div id="${controlId}" class="datepicker"></div>
     
         <#if showTime>
            <input id="${controlId}-time" name="-" type="text" class="time-entry" <#if field.description??>title="${field.description}"</#if> <#if disabled>disabled="true"<#else>tabindex="0"</#if> />
         </#if>
        
         <@formLib.renderFieldHelp field=field />
     
         <div class="format-info">
            <span class="date-format">${msg("form.control.date-picker.display.date.format.year")}</span>
            <#if showTime><span class="time-format<#if disabled>-disabled</#if>">${msg("form.control.date-picker.display.time.format.year")}</span></#if>
         </div>
      </#if>
   </#if>
</div>


Como podeis ver he añadido el .year en los msg.

2- En el form.get_es.properties, he creado las propiedades en .year


## Format used for date entry in date picker, 'entry' format is used by date parsing code,
## 'display' format is shown to the user under date entry field
form.control.date-picker.entry.date.format=d/M/yyyy
form.control.date-picker.display.date.format=DD/MM/AAAA
form.control.date-picker.entry.date.format.year=yyyy
form.control.date-picker.display.date.format.year=AAAA

## Format used for time entry in datetime picker, 'entry' format is used by date parsing code,
## 'display' format is shown to the user under time entry field
form.control.date-picker.entry.time.format=HH:mm
form.control.date-picker.display.time.format=HH:MM (24 Horas)

## Format used for date and time when form is in 'view' mode
form.control.date-picker.view.date.format=EEE dd MMM yyyy
form.control.date-picker.view.time.format=EEE dd MMM yyyy HH:mm:ss z
form.control.date-picker.view.date.format.year=yyyy
form.control.date-picker.view.time.format.year=yyyy


## Format used for date and time input field when JavaScript is disabled
form.control.date-picker.entry.datetime.format.nojs=YYYY-MM-DDThh:mm:ss.sTZD
form.control.date-picker.entry.datetime.format.year.nojs=YYYY


Si cambio las por defecto si que me sale correctamente.


3-He puesto el template de control el la propiedad en "share-config-custom.xml"

<control template="/org/alfresco/components/form/controls/year.ftl" />





Creeis que es possible tener 2 formatos o mas de fecha? 



Gracias!

Outcomes