diff --git a/app/assets/javascripts/app/controllers/agent_ticket_create.coffee b/app/assets/javascripts/app/controllers/agent_ticket_create.coffee
index 641586170..774a9f3d2 100644
--- a/app/assets/javascripts/app/controllers/agent_ticket_create.coffee
+++ b/app/assets/javascripts/app/controllers/agent_ticket_create.coffee
@@ -232,23 +232,21 @@ class App.TicketCreate extends App.Controller
if signature isnt undefined && signature.body && type is 'email-out'
signatureFinished = App.Utils.replaceTags(signature.body, { user: App.Session.get() })
- # get current body
- body = @$('[data-name="body"]').html() || ''
- if App.Utils.signatureCheck(body, signatureFinished)
+ body = @$('[data-name=body]')
+ if App.Utils.signatureCheck(body.html() || '', signatureFinished)
- # if signature has changed, replace it
+ # if signature has changed, in case remove old signature
signature_id = @$('[data-signature=true]').data('signature-id')
if signature_id && signature_id.toString() isnt signature.id.toString()
- # remove old signature
@$('[data-signature="true"]').remove()
- body = @$('[data-name="body"]').html() || ''
- if !App.Utils.lastLineEmpty(body)
- body = body + '
'
- body = body + "
"
-
- @$('[data-name="body"]').html(body)
+ if !App.Utils.htmlLastLineEmpty(body)
+ body.append('
')
+ signature = $("#{signatureFinished}
")
+ App.Utils.htmlStrip(signature)
+ body.append(signature)
+ @$('[data-name=body]').replaceWith(body)
# remove old signature
else
diff --git a/app/assets/javascripts/app/lib/app_post/utils.coffee b/app/assets/javascripts/app/lib/app_post/utils.coffee
index 9d6f4c0fd..747351799 100644
--- a/app/assets/javascripts/app/lib/app_post/utils.coffee
+++ b/app/assets/javascripts/app/lib/app_post/utils.coffee
@@ -109,6 +109,33 @@ class App.Utils
.replace(/"/g, '"')
.replace(/'/g, ''')
+ # App.Utils.htmlStrip(element)
+ @htmlStrip: (element) ->
+ loop
+ el = element.get(0)
+ break if !el
+ child = el.firstChild
+ break if !child
+ break if child.nodeType isnt 1 || child.tagName isnt 'BR'
+ child.remove()
+
+ loop
+ el = element.get(0)
+ break if !el
+ child = el.lastChild
+ break if !child
+ break if child.nodeType isnt 1 || child.tagName isnt 'BR'
+ child.remove()
+
+ # true|false = App.Utils.htmlLastLineEmpty(element)
+ @htmlLastLineEmpty: (element) ->
+ el = element.get(0)
+ return false if !el
+ child = el.lastChild
+ return false if !child
+ return false if child.nodeType isnt 1 || child.tagName isnt 'BR'
+ true
+
# textWithoutTags = App.Utils.htmlRemoveTags(html)
@htmlRemoveTags: (html) ->
html = @_checkTypeOf(html)
@@ -503,13 +530,6 @@ class App.Utils
value
)
- # true|false = App.Utils.lastLineEmpty(message)
- @lastLineEmpty: (message) ->
- messageCleanup = message.replace(/>\s+<').replace(/(\n|\r|\t)/g, '').trim()
- return true if messageCleanup.match(/<(br|\s+?|\/)>$/im)
- return true if messageCleanup.match(/<\/div>$/im)
- false
-
# string = App.Utils.removeEmptyLines(stringWithEmptyLines)
@removeEmptyLines: (string) ->
string.replace(/^\s*[\r\n]/gm, '')