From 9bed6c8a9b3d9f1105014b86080d251c64b3309d Mon Sep 17 00:00:00 2001 From: Martin Edenhofer Date: Wed, 31 Oct 2018 17:41:35 +0100 Subject: [PATCH] Fixed issue #2324 - Improved error handling of invalid tag for text modules and add current time format (to not use 2018-10-31T08:02:21.917Z format). --- .../javascripts/app/lib/app_post/utils.coffee | 17 ++++++++-- public/assets/tests/html_utils.js | 31 ++++++++++++++++++- 2 files changed, 45 insertions(+), 3 deletions(-) diff --git a/app/assets/javascripts/app/lib/app_post/utils.coffee b/app/assets/javascripts/app/lib/app_post/utils.coffee index 400025117..2288bd41e 100644 --- a/app/assets/javascripts/app/lib/app_post/utils.coffee +++ b/app/assets/javascripts/app/lib/app_post/utils.coffee @@ -709,16 +709,29 @@ class App.Utils key = key.replace(/<.+?>/g, '') levels = key.split(/\./) dataRef = objects + dataRefLast = undefined for level in levels - if level of dataRef + if typeof dataRef is 'object' && level of dataRef + dataRefLast = dataRef dataRef = dataRef[level] else dataRef = '' break + value = undefined if typeof dataRef is 'function' value = dataRef() else if dataRef isnt undefined && dataRef isnt null && dataRef.toString - value = dataRef.toString() + if dataRefLast && dataRefLast.constructor && dataRefLast.constructor.className + localClassRef = App[dataRefLast.constructor.className] + if localClassRef && localClassRef.attributesGet + attributes = localClassRef.attributesGet() + if attributes && attributes[level] + if attributes[level]['tag'] is 'datetime' + value = App.i18n.translateTimestamp(dataRef) + else if attributes[level]['tag'] is 'date' + value = App.i18n.translateDate(dataRef) + if !value + value = dataRef.toString() else value = '' #console.log( "tag replacement #{key}, #{value} env: ", objects) diff --git a/public/assets/tests/html_utils.js b/public/assets/tests/html_utils.js index 4b7f9f3c5..f58d85797 100644 --- a/public/assets/tests/html_utils.js +++ b/public/assets/tests/html_utils.js @@ -1246,7 +1246,7 @@ test("identify signature by HTML", function() { }); // check attachment references -test("check replace tags", function() { +test("check check attachment reference", function() { var message = 'some not existing' var result = false var verify = App.Utils.checkAttachmentReference(message) @@ -1392,6 +1392,35 @@ test("check replace tags", function() { } verify = App.Utils.replaceTags(message, data) equal(verify, result) + + user = new App.User({ + firstname: 'Bob', + lastname: 'Smith', + created_at: '2018-10-31T10:00:00Z', + }) + message = "
#{user.firstname} #{user.created_at}
" + result = '
Bob 10/31/2018 10:00
' + data = { + user: user + } + verify = App.Utils.replaceTags(message, data) + equal(verify, result) + + message = "
#{user.firstname} #{user.created_at.date}
" + result = '
Bob -
' + data = { + user: user + } + verify = App.Utils.replaceTags(message, data) + equal(verify, result) + + message = "
#{user.firstname} #{user.created.date}
" + result = '
Bob -
' + data = { + user: user + } + verify = App.Utils.replaceTags(message, data) + equal(verify, result) }); // check attibute validation