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).
This commit is contained in:
parent
d53a848331
commit
9bed6c8a9b
2 changed files with 45 additions and 3 deletions
|
@ -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)
|
||||
|
|
|
@ -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 = "<div>#{user.firstname} #{user.created_at}</div>"
|
||||
result = '<div>Bob 10/31/2018 10:00</div>'
|
||||
data = {
|
||||
user: user
|
||||
}
|
||||
verify = App.Utils.replaceTags(message, data)
|
||||
equal(verify, result)
|
||||
|
||||
message = "<div>#{user.firstname} #{user.created_at.date}</div>"
|
||||
result = '<div>Bob -</div>'
|
||||
data = {
|
||||
user: user
|
||||
}
|
||||
verify = App.Utils.replaceTags(message, data)
|
||||
equal(verify, result)
|
||||
|
||||
message = "<div>#{user.firstname} #{user.created.date}</div>"
|
||||
result = '<div>Bob -</div>'
|
||||
data = {
|
||||
user: user
|
||||
}
|
||||
verify = App.Utils.replaceTags(message, data)
|
||||
equal(verify, result)
|
||||
});
|
||||
|
||||
// check attibute validation
|
||||
|
|
Loading…
Reference in a new issue