From 4d9ff76cff19ce333b1ba155e984aed62afee819 Mon Sep 17 00:00:00 2001 From: Martin Edenhofer Date: Wed, 7 Jan 2015 11:05:12 +0100 Subject: [PATCH] Improve reply behaviour. --- .../app/controllers/ticket_zoom.js.coffee | 83 +++++++++---------- .../app/lib/app_post/utils.js.coffee | 18 ++++ .../views/ticket_zoom/article_view.jst.eco | 55 ++++++------ app/assets/stylesheets/zammad.css.scss | 4 +- public/assets/tests/html-utils.js | 35 ++++++++ 5 files changed, 121 insertions(+), 74 deletions(-) diff --git a/app/assets/javascripts/app/controllers/ticket_zoom.js.coffee b/app/assets/javascripts/app/controllers/ticket_zoom.js.coffee index 19fbb2aca..85f897f11 100644 --- a/app/assets/javascripts/app/controllers/ticket_zoom.js.coffee +++ b/app/assets/javascripts/app/controllers/ticket_zoom.js.coffee @@ -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('
') 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('') 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 = "


#{selectedText}

" - 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 } ) diff --git a/app/assets/javascripts/app/lib/app_post/utils.js.coffee b/app/assets/javascripts/app/lib/app_post/utils.js.coffee index 58f8444a6..945ece4dd 100644 --- a/app/assets/javascripts/app/lib/app_post/utils.js.coffee +++ b/app/assets/javascripts/app/lib/app_post/utils.js.coffee @@ -147,3 +147,21 @@ class App.Utils .removeAttr( 'class' ) .removeAttr( 'title' ) html + + # signatureNeeded = App.Utils.signatureCheck( message, signature ) + @signatureCheck: (message, signature) -> + messageText = $( '
' + message + '
' ).text().trim() + messageText = messageText.replace(/(\n|\r|\t)/g, '') + signatureText = $( '
' + signature + '
' ).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 + diff --git a/app/assets/javascripts/app/views/ticket_zoom/article_view.jst.eco b/app/assets/javascripts/app/views/ticket_zoom/article_view.jst.eco index 5f04bcaf2..b14ab148a 100644 --- a/app/assets/javascripts/app/views/ticket_zoom/article_view.jst.eco +++ b/app/assets/javascripts/app/views/ticket_zoom/article_view.jst.eco @@ -40,23 +40,36 @@ <% position = 'right' %> <% end %> <%- article.created_by.avatar("40", position) %> -
-
-
- <%- article.html %> - <% if !_.isEmpty( article.attachments ): %> -
-
-

<%- article.attachments.length %> <%- @T('Attached Files') %>

- <% for attachment in article.attachments: %> -
- <%= attachment.filename %> -
<%= attachment.size %>
-
- <% end %> -
- <% end %> +
+
+
+
+ <%- article.html %> + <% if !_.isEmpty( article.attachments ): %> +
+
+

<%- article.attachments.length %> <%- @T('Attached Files') %>

+ <% for attachment in article.attachments: %> +
+ <%= attachment.filename %> +
<%= attachment.size %>
+
+ <% end %> +
+ <% end %> +
+ <% if article.actions: %> +
+
+ <% for action in article.actions: %> + + <%- @T( action.name ) %> + + <% end %> +
+
+ <% end %>
@@ -74,16 +87,6 @@
- - <% if article.actions: %> -
- <% for action in article.actions: %> - - <%- @T( action.name ) %> - - <% end %> -
- <% end %> diff --git a/app/assets/stylesheets/zammad.css.scss b/app/assets/stylesheets/zammad.css.scss index b5a3e0b8a..87374c910 100644 --- a/app/assets/stylesheets/zammad.css.scss +++ b/app/assets/stylesheets/zammad.css.scss @@ -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; diff --git a/public/assets/tests/html-utils.js b/public/assets/tests/html-utils.js index dee6c54ec..3e9a92f71 100644 --- a/public/assets/tests/html-utils.js +++ b/public/assets/tests/html-utils.js @@ -337,4 +337,39 @@ test( "quote", function() { }); +// check signature +test( "check signature", function() { + + var message = "
test 123
" + var signature = '
--
Some Signature
some department
' + var result = App.Utils.signatureCheck( message, signature ) + equal( result, true ) + + message = "
test 123
--
Some Signature
some department\n
" + signature = '
--
Some Signature
some department
' + result = App.Utils.signatureCheck( message, signature ) + equal( result, false ) + + message = "
test 123
--
Some Signature\n
some department\n
" + signature = '
--
Some Signature
some department
' + result = App.Utils.signatureCheck( message, signature ) + equal( result, false ) + + message = "
test 123
--

Some Signature

\n

some department
\n

\n
" + signature = '
--
Some Signature
some department
' + result = App.Utils.signatureCheck( message, signature ) + equal( result, false ) + + message = "" + signature = '
--
Some Signature
some department
' + result = App.Utils.signatureCheck( message, signature ) + equal( result, true ) + + message = "" + signature = "--\nSome Signature\nsome department" + result = App.Utils.signatureCheck( message, signature ) + equal( result, true ) + +}); + } \ No newline at end of file