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 )
new App.ControllerForm(
el: el.find('.edit')
model: App.Ticket
screen: 'edit'
params: App.Ticket.find(ticket.id)
el: el.find('.edit')
model: App.Ticket
screen: 'edit'
params: App.Ticket.find(ticket.id)
handlers: [
formChanges
]
@ -300,17 +300,17 @@ class App.TicketZoom extends App.Controller
if !@isRole('Customer')
el.append('<div class="tags"></div>')
new App.WidgetTag(
el: el.find('.tags')
object_type: 'Ticket'
object: @ticket
tags: @tags
el: el.find('.tags')
object_type: 'Ticket'
object: @ticket
tags: @tags
)
el.append('<div class="links"></div>')
new App.WidgetLink(
el: el.find('.links')
object_type: 'Ticket'
object: @ticket
links: @links
el: el.find('.links')
object_type: 'Ticket'
object: @ticket
links: @links
)
showTicketHistory = =>
@ -354,8 +354,8 @@ class App.TicketZoom extends App.Controller
genericObject: 'User'
screen: 'edit'
pageData:
title: 'Users'
object: 'User'
title: 'Users'
object: 'User'
objects: 'Users'
)
showCustomer = (el) =>
@ -387,14 +387,14 @@ class App.TicketZoom extends App.Controller
id: @ticket.organization_id,
genericObject: 'Organization'
pageData:
title: 'Organizations'
object: 'Organization'
title: 'Organizations'
object: 'Organization'
objects: 'Organizations'
)
showOrganization = (el) =>
new App.WidgetOrganization(
el: el
organization_id: @ticket.organization_id
el: el
organization_id: @ticket.organization_id
)
items.push {
head: 'Organization'
@ -530,11 +530,13 @@ class App.TicketZoom extends App.Controller
e.stopPropagation()
e.preventDefault()
ticketParams = @formParam( @$('.edit') )
console.log "submit ticket", ticketParams
# validate ticket
ticket = App.Ticket.fullLocal( @ticket.id )
# reset article - should not be resubmited on next ticket update
ticket.article = undefined
# update ticket attributes
for key, value of ticketParams
ticket[key] = value
@ -627,8 +629,6 @@ class App.TicketZoom extends App.Controller
@autosaveStart()
return
console.log "article load", articleParams
#return
article.load(articleParams)
errors = article.validate()
if errors
@ -643,8 +643,7 @@ class App.TicketZoom extends App.Controller
return
ticket.article = article
console.log('ARR', article)
#return
# submit changes
ticket.save(
done: (r) =>
@ -1404,21 +1403,6 @@ class ArticleView extends App.Controller
return true
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) =>
@reply(e, true)
@ -1433,9 +1417,6 @@ class ArticleView extends App.Controller
@ui.el.find('.article-add').ScrollTo()
# update form
@checkIfSignatureIsNeeded(type)
# empty form
articleNew = {
to: ''
@ -1504,21 +1485,31 @@ class ArticleView extends App.Controller
if 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()
if selectedText
body = @ui.el.find('[data-name="body"]').html() || ''
# quote text
# clean selection
selectedText = App.Utils.textCleanup( selectedText )
#selectedText = App.Utils.quote( selectedText )
# convert to html
selectedText = App.Utils.text2html( selectedText )
if selectedText
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 } )

View file

@ -147,3 +147,21 @@ class App.Utils
.removeAttr( 'class' )
.removeAttr( 'title' )
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' %>
<% end %>
<%- article.created_by.avatar("40", position) %>
<div class="flex bubble-gap internal-border">
<div class="text-bubble">
<div class="bubble-arrow"></div>
<%- article.html %>
<% if !_.isEmpty( article.attachments ): %>
<div class="attachments">
<div class="paperclip icon"></div>
<h3><%- article.attachments.length %> <%- @T('Attached Files') %></h3>
<% for attachment in article.attachments: %>
<div class="attachment horizontal">
<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-size"><%= attachment.size %></div>
</div>
<% end %>
</div>
<% end %>
<div class="flex bubble-gap">
<div class="internal-border">
<div class="text-bubble">
<div class="bubble-arrow"></div>
<%- article.html %>
<% if !_.isEmpty( article.attachments ): %>
<div class="attachments">
<div class="paperclip icon"></div>
<h3><%- article.attachments.length %> <%- @T('Attached Files') %></h3>
<% for attachment in article.attachments: %>
<div class="attachment horizontal">
<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-size"><%= attachment.size %></div>
</div>
<% end %>
</div>
<% end %>
</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>
@ -74,16 +87,6 @@
</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>

View file

@ -3162,8 +3162,8 @@ footer {
}
.article-action {
padding: 5px;
margin: 5px 12px;
padding-top: 5px;
margin-top: 5px;
color: black;
font-size: 12px;
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 )
});
}