Improve reply behaviour.

This commit is contained in:
Martin Edenhofer 2015-01-07 11:05:12 +01:00
parent a938618228
commit 4d9ff76cff
5 changed files with 121 additions and 74 deletions

View file

@ -530,11 +530,13 @@ class App.TicketZoom extends App.Controller
e.stopPropagation() e.stopPropagation()
e.preventDefault() e.preventDefault()
ticketParams = @formParam( @$('.edit') ) ticketParams = @formParam( @$('.edit') )
console.log "submit ticket", ticketParams
# validate ticket # validate ticket
ticket = App.Ticket.fullLocal( @ticket.id ) ticket = App.Ticket.fullLocal( @ticket.id )
# reset article - should not be resubmited on next ticket update
ticket.article = undefined
# update ticket attributes # update ticket attributes
for key, value of ticketParams for key, value of ticketParams
ticket[key] = value ticket[key] = value
@ -627,8 +629,6 @@ class App.TicketZoom extends App.Controller
@autosaveStart() @autosaveStart()
return return
console.log "article load", articleParams
#return
article.load(articleParams) article.load(articleParams)
errors = article.validate() errors = article.validate()
if errors if errors
@ -643,8 +643,7 @@ class App.TicketZoom extends App.Controller
return return
ticket.article = article ticket.article = article
console.log('ARR', article)
#return
# submit changes # submit changes
ticket.save( ticket.save(
done: (r) => done: (r) =>
@ -1404,21 +1403,6 @@ class ArticleView extends App.Controller
return true return true
false false
checkIfSignatureIsNeeded: (type) =>
console.log('checkIfSignatureIsNeeded', type, @ui.signature)
# add signature
if @ui.signature && @ui.signature.body && type.name is 'email'
body = @ui.el.find('[data-name="body"]').html() || ''
# convert to html
signature = @ui.signature.body
signature = App.Utils.text2html( signature )
regexp = new RegExp( escapeRegExp( signature ) , 'im')
#console.log('aaa', body, regexp)
if !body || !body.match(regexp)
body = body + signature
@ui.el.find('[data-name="body"]').html( body )
replyAll: (e) => replyAll: (e) =>
@reply(e, true) @reply(e, true)
@ -1433,9 +1417,6 @@ class ArticleView extends App.Controller
@ui.el.find('.article-add').ScrollTo() @ui.el.find('.article-add').ScrollTo()
# update form
@checkIfSignatureIsNeeded(type)
# empty form # empty form
articleNew = { articleNew = {
to: '' to: ''
@ -1504,21 +1485,31 @@ class ArticleView extends App.Controller
if article.cc if article.cc
articleNew.cc = addAddresses(articleNew.cc, article.cc) articleNew.cc = addAddresses(articleNew.cc, article.cc)
# add quoted text if needed # get current body
selectedText = App.ClipBoard.getSelected()
if selectedText
body = @ui.el.find('[data-name="body"]').html() || '' body = @ui.el.find('[data-name="body"]').html() || ''
# quote text # check if signature need to be added
if @ui.signature && @ui.signature.body && type.name is 'email'
signature = App.Utils.text2html( @ui.signature.body )
if App.Utils.signatureCheck( body, signature )
body = body + signature
# check if quote need to be added
selectedText = App.ClipBoard.getSelected()
if selectedText
# clean selection
selectedText = App.Utils.textCleanup( selectedText ) selectedText = App.Utils.textCleanup( selectedText )
#selectedText = App.Utils.quote( selectedText )
# convert to html # convert to html
selectedText = App.Utils.text2html( selectedText ) selectedText = App.Utils.text2html( selectedText )
if selectedText if selectedText
selectedText = "<div><br><br/></div><div><blockquote type=\"cite\">#{selectedText}</blockquote></div><div><br></div>" selectedText = "<div><br><br/></div><div><blockquote type=\"cite\">#{selectedText}</blockquote></div><div><br></div>"
articleNew.body = selectedText + body # add selected text to body
body = selectedText + body
articleNew.body = body
App.Event.trigger('ui::ticket::setArticleType', { ticket: @ticket, type: type, article: articleNew } ) App.Event.trigger('ui::ticket::setArticleType', { ticket: @ticket, type: type, article: articleNew } )

View file

@ -147,3 +147,21 @@ class App.Utils
.removeAttr( 'class' ) .removeAttr( 'class' )
.removeAttr( 'title' ) .removeAttr( 'title' )
html html
# signatureNeeded = App.Utils.signatureCheck( message, signature )
@signatureCheck: (message, signature) ->
messageText = $( '<div>' + message + '</div>' ).text().trim()
messageText = messageText.replace(/(\n|\r|\t)/g, '')
signatureText = $( '<div>' + signature + '</div>' ).text().trim()
signatureText = signatureText.replace(/(\n|\r|\t)/g, '')
quote = (str) ->
(str + '').replace(/[.?*+^$[\]\\(){}|-]/g, "\\$&")
console.log('SC', messageText, signatureText, quote(signatureText))
regex = new RegExp( quote(signatureText), 'mi' )
if messageText.match(regex)
false
else
true

View file

@ -40,7 +40,8 @@
<% position = 'right' %> <% position = 'right' %>
<% end %> <% end %>
<%- article.created_by.avatar("40", position) %> <%- article.created_by.avatar("40", position) %>
<div class="flex bubble-gap internal-border"> <div class="flex bubble-gap">
<div class="internal-border">
<div class="text-bubble"> <div class="text-bubble">
<div class="bubble-arrow"></div> <div class="bubble-arrow"></div>
<%- article.html %> <%- article.html %>
@ -58,6 +59,18 @@
<% end %> <% end %>
</div> </div>
</div> </div>
<% if article.actions: %>
<div>
<div class="article-actions horizontal stretch">
<% for action in article.actions: %>
<a href="<%= action.href %>" data-type="<%= action.type %>" class="article-action u-clickable<% if action.class: %> <%= action.class %><% end %>">
<span class="<%= action.type %> action icon"></span><%- @T( action.name ) %>
</a>
<% end %>
</div>
</div>
<% end %>
</div>
</div> </div>
<div class="article-meta-clip bottom"> <div class="article-meta-clip bottom">
@ -74,16 +87,6 @@
</div> </div>
</div> </div>
</div> </div>
<% if article.actions: %>
<div class="article-actions horizontal stretch">
<% for action in article.actions: %>
<a href="<%= action.href %>" data-type="<%= action.type %>" class="article-action u-clickable<% if action.class: %> <%= action.class %><% end %>">
<span class="<%= action.type %> action icon"></span><%- @T( action.name ) %>
</a>
<% end %>
</div>
<% end %>
</div> </div>
</div> </div>

View file

@ -3162,8 +3162,8 @@ footer {
} }
.article-action { .article-action {
padding: 5px; padding-top: 5px;
margin: 5px 12px; margin-top: 5px;
color: black; color: black;
font-size: 12px; font-size: 12px;
text-align: center; text-align: center;

View file

@ -337,4 +337,39 @@ test( "quote", function() {
}); });
// check signature
test( "check signature", function() {
var message = "<div>test 123 </div>"
var signature = '<div>--<br>Some Signature<br>some department</div>'
var result = App.Utils.signatureCheck( message, signature )
equal( result, true )
message = "<div>test 123 <div>--<br>Some Signature<br>some department\n</div></div>"
signature = '<div>--<br>Some Signature<br>some department</div>'
result = App.Utils.signatureCheck( message, signature )
equal( result, false )
message = "<div>test 123 <div>--<br>Some Signature\n<br>some department\n</div></div>"
signature = '<div>--<br>Some Signature<br>some department</div>'
result = App.Utils.signatureCheck( message, signature )
equal( result, false )
message = "<div>test 123 <div>--<p>Some Signature</p>\n<p><div>some department</div>\n</p>\n</div></div>"
signature = '<div>--<br>Some Signature<br>some department</div>'
result = App.Utils.signatureCheck( message, signature )
equal( result, false )
message = ""
signature = '<div>--<br>Some Signature<br>some department</div>'
result = App.Utils.signatureCheck( message, signature )
equal( result, true )
message = ""
signature = "--\nSome Signature\nsome department"
result = App.Utils.signatureCheck( message, signature )
equal( result, true )
});
} }