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

@ -273,10 +273,10 @@ class App.TicketZoom extends App.Controller
defaults = _.extend( defaults, task_state ) defaults = _.extend( defaults, task_state )
new App.ControllerForm( new App.ControllerForm(
el: el.find('.edit') el: el.find('.edit')
model: App.Ticket model: App.Ticket
screen: 'edit' screen: 'edit'
params: App.Ticket.find(ticket.id) params: App.Ticket.find(ticket.id)
handlers: [ handlers: [
formChanges formChanges
] ]
@ -300,17 +300,17 @@ class App.TicketZoom extends App.Controller
if !@isRole('Customer') if !@isRole('Customer')
el.append('<div class="tags"></div>') el.append('<div class="tags"></div>')
new App.WidgetTag( new App.WidgetTag(
el: el.find('.tags') el: el.find('.tags')
object_type: 'Ticket' object_type: 'Ticket'
object: @ticket object: @ticket
tags: @tags tags: @tags
) )
el.append('<div class="links"></div>') el.append('<div class="links"></div>')
new App.WidgetLink( new App.WidgetLink(
el: el.find('.links') el: el.find('.links')
object_type: 'Ticket' object_type: 'Ticket'
object: @ticket object: @ticket
links: @links links: @links
) )
showTicketHistory = => showTicketHistory = =>
@ -354,8 +354,8 @@ class App.TicketZoom extends App.Controller
genericObject: 'User' genericObject: 'User'
screen: 'edit' screen: 'edit'
pageData: pageData:
title: 'Users' title: 'Users'
object: 'User' object: 'User'
objects: 'Users' objects: 'Users'
) )
showCustomer = (el) => showCustomer = (el) =>
@ -387,14 +387,14 @@ class App.TicketZoom extends App.Controller
id: @ticket.organization_id, id: @ticket.organization_id,
genericObject: 'Organization' genericObject: 'Organization'
pageData: pageData:
title: 'Organizations' title: 'Organizations'
object: 'Organization' object: 'Organization'
objects: 'Organizations' objects: 'Organizations'
) )
showOrganization = (el) => showOrganization = (el) =>
new App.WidgetOrganization( new App.WidgetOrganization(
el: el el: el
organization_id: @ticket.organization_id organization_id: @ticket.organization_id
) )
items.push { items.push {
head: 'Organization' head: 'Organization'
@ -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
body = @ui.el.find('[data-name="body"]').html() || ''
# 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() selectedText = App.ClipBoard.getSelected()
if selectedText if selectedText
body = @ui.el.find('[data-name="body"]').html() || ''
# quote text # 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,23 +40,36 @@
<% 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="text-bubble"> <div class="internal-border">
<div class="bubble-arrow"></div> <div class="text-bubble">
<%- article.html %> <div class="bubble-arrow"></div>
<% if !_.isEmpty( article.attachments ): %> <%- article.html %>
<div class="attachments"> <% if !_.isEmpty( article.attachments ): %>
<div class="paperclip icon"></div> <div class="attachments">
<h3><%- article.attachments.length %> <%- @T('Attached Files') %></h3> <div class="paperclip icon"></div>
<% for attachment in article.attachments: %> <h3><%- article.attachments.length %> <%- @T('Attached Files') %></h3>
<div class="attachment horizontal"> <% for attachment in article.attachments: %>
<a class="attachment-name u-highlight" href="<%= App.Config.get('api_path') %>/ticket_attachment/<%= article.ticket_id %>/<%= article.id %>/<%= attachment.id %>" target="_blank" data-type="attachment"><%= attachment.filename %></a> <div class="attachment horizontal">
<div class="attachment-size"><%= attachment.size %></div> <a class="attachment-name u-highlight" href="<%= App.Config.get('api_path') %>/ticket_attachment/<%= article.ticket_id %>/<%= article.id %>/<%= attachment.id %>" target="_blank" data-type="attachment"><%= attachment.filename %></a>
</div> <div class="attachment-size"><%= attachment.size %></div>
<% end %> </div>
</div> <% end %>
<% end %> </div>
<% end %>
</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>
@ -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 )
});
} }