cancel
Showing results for 
Search instead for 
Did you mean: 

Metadata templates - rendering date properties

bengrah
Champ on-the-rise
Champ on-the-rise
Hi guys,

I'm using the metadata-templates available in Alfresco 4.0. I've got metadata being displayed but I'm having trouble when it comes to rendering properties that are dates. I've registered my custom javascript renderer fine using a JAR file, but I don't know how to show a date. Instead of showing a date, the Share document library shows [object Object].

Here's my code. It's a javascript renderer that should display email metadata:

(function() {

   if (Alfresco.DocumentList) {
        YAHOO.Bubbling.fire("registerRenderer", {
      
         propertyName: "emailProperties",
         renderer: function emailProperties_renderer(record, label) {
         
         $html = Alfresco.util.encodeHTML;
         $date = Alfresco.util.formatDate;
           
         var javascriptNode = record.jsNode;
         var emailRecordProperties = javascriptNode.properties;
         var from = emailRecordProperties["imap:messageFrom"];
         var to = emailRecordProperties["imap:messageTo"];
         var sent = emailRecordProperties["imap:dateSent"];
         
         var html = "<span class=\"item\"><em>From</em>: " + $html(from) + "  <em>To</em>: " + $html(to) + "  <em>Sent</em>: "
                  + $html(sent) + "</span>";
         
         return html;
         }
      });
   }
})();

Any ideas?

Thanks,
Ben.
3 REPLIES 3

mikeh
Star Contributor
Star Contributor
Hi Ben

As the properties are probably modelled as date types, they are being automatically decorated on the server so they are returned as an object having two properties: "value" from the value.toString() conversion and a more useful "iso8601" format.

Try using $date(from.iso8601) or $relTime(from.iso8601) which will display either the absolute or relative date depending on what you prefer.

Take a look at the (unfortunately not generic enough for your needs) "date" custom renderer in documentlist.js for OOTB code handling created and modified by dates.

Thanks,
Mike

bengrah
Champ on-the-rise
Champ on-the-rise
Hi Ben

As the properties are probably modelled as date types, they are being automatically decorated on the server so they are returned as an object having two properties: "value" from the value.toString() conversion and a more useful "iso8601" format.

Try using $date(from.iso8601) or $relTime(from.iso8601) which will display either the absolute or relative date depending on what you prefer.

Take a look at the (unfortunately not generic enough for your needs) "date" custom renderer in documentlist.js for OOTB code handling created and modified by dates.

Thanks,
Mike

Hi Mike,

Thanks for your suggestion. This was something I eventually discovered on my own, and I took a look at documentlist.js as well coincidentally.

I got the class for the $date object, get the value for the sent date and then return it to the document library to be rendered :

$date = function $date(date, format) { return Alfresco.util.formatDate(Alfresco.util.fromISO8601(date), format); };
var sent = emailRecordProperties["imap:dateSent"];
html += "  <em>Sent</em>: " + $date(sent.iso8601) + "</span>";
return html;

Is it still possible to render the date while using a defined display? Such as $date("dd yyy MM", dateVar)?

Thanks,
Ben.

jordiv
Champ on-the-rise
Champ on-the-rise
This works for me:


if(jsNode.properties["my:someDate"] != undefined) {
      var myDate = new Date(jsNode.properties["my:someDate"].iso8601);
      return '<span class="item"><em>' + label + '</em>: ' + myDate.getDate() + "/" + (myDate.getMonth() + 1) + "/" + myDate.getFullYear() + '</span>';
}
else {
      return '<span class="item"><em>' + label + '</em> </span>';
}


Hope it helps!


Cheers,
Jordi