Browse Source

Implemented issue #571 - Original e-mail inclusion at the bottom of sent e-mails.

Martin Edenhofer 7 years ago
parent
commit
bd061fb5c1

+ 17 - 1
app/assets/javascripts/app/controllers/ticket_zoom/article_actions.coffee

@@ -391,6 +391,7 @@ class App.TicketZoomArticleActions extends App.Controller
     body = @el.closest('.ticketZoom').find('.article-add [data-name="body"]').html() || ''
 
     # check if quote need to be added
+    signaturePosition = 'bottom'
     selected = App.ClipBoard.getSelected('html')
     if selected
       selected = App.Utils.htmlCleanup(selected).html()
@@ -399,6 +400,16 @@ class App.TicketZoomArticleActions extends App.Controller
       if selected
         selected = App.Utils.textCleanup(selected)
         selected = App.Utils.text2html(selected)
+
+    # full quote, if needed
+    if !selected && article && App.Config.get('ui_ticket_zoom_article_email_full_quote')
+      signaturePosition = 'top'
+      if article.content_type.match('html')
+        selected = App.Utils.textCleanup(article.body)
+      if article.content_type.match('plain')
+        selected = App.Utils.textCleanup(selected)
+        selected = App.Utils.text2html(selected)
+
     if selected
       selected = "<div><br><br/></div><div><blockquote type=\"cite\">#{selected}</blockquote></div><div><br></div>"
 
@@ -409,7 +420,12 @@ class App.TicketZoomArticleActions extends App.Controller
 
     type = App.TicketArticleType.findByAttribute(name:'email')
 
-    App.Event.trigger('ui::ticket::setArticleType', { ticket: @ticket, type: type, article: articleNew } )
+    App.Event.trigger('ui::ticket::setArticleType', {
+      ticket: @ticket
+      type: type
+      article: articleNew
+      signaturePosition: signaturePosition
+    })
 
   telegramPersonalMessageReply: (e) =>
     e.preventDefault()

+ 20 - 3
app/assets/javascripts/app/controllers/ticket_zoom/article_new.coffee

@@ -59,7 +59,7 @@ class App.TicketZoomArticleNew extends App.Controller
           @$('[name="' + key + '"]').val(value).trigger('change')
 
       # preselect article type
-      @setArticleType(data.type.name)
+      @setArticleType(data.type.name, data.signaturePosition)
 
       # set focus at end of field
       if data.position is 'end'
@@ -483,7 +483,7 @@ class App.TicketZoomArticleNew extends App.Controller
 
     @$('[name=internal]').val('')
 
-  setArticleType: (type) =>
+  setArticleType: (type, signaturePosition = 'bottom') =>
     wasScrolledToBottom = @isScrolledToBottom()
     @type = type
     @$('[name=type]').val(type).trigger('change')
@@ -532,7 +532,10 @@ class App.TicketZoomArticleNew extends App.Controller
           body.append('<br><br>')
         signature = $("<div data-signature=\"true\" data-signature-id=\"#{signature.id}\">#{signatureFinished}</div>")
         App.Utils.htmlStrip(signature)
-        body.append(signature)
+        if signaturePosition is 'top'
+          body.prepend(signature)
+        else
+          body.append(signature)
         @$('[data-name=body]').replaceWith(body)
 
     # remove old signature
@@ -566,6 +569,20 @@ class App.TicketZoomArticleNew extends App.Controller
             @delay(@updateLetterCount, 600)
             @$('.js-textSizeLimit').removeClass('hide')
 
+    # convert remote src images to data uri
+    @$('[data-name=body] img').each( (i,image) ->
+      $image = $(image)
+      src = $image.attr('src')
+      if !_.isEmpty(src) && !src.match(/^data:image/i)
+        canvas = document.createElement('canvas')
+        canvas.width = image.width
+        canvas.height = image.height
+        ctx = canvas.getContext('2d')
+        ctx.drawImage(image, 0, 0)
+        dataURL = canvas.toDataURL()
+        $image.attr('src', dataURL)
+    )
+
     @scrollToBottom() if wasScrolledToBottom
 
   isScrolledToBottom: ->

+ 28 - 1
db/migrate/20170630000001_ticket_zoom_setting.rb → db/migrate/20170713000001_ticket_zoom_setting2.rb

@@ -1,4 +1,4 @@
-class TicketZoomSetting < ActiveRecord::Migration
+class TicketZoomSetting2 < ActiveRecord::Migration
   def up
 
     # return if it's a new setup
@@ -67,6 +67,33 @@ class TicketZoomSetting < ActiveRecord::Migration
       },
       frontend: true
     )
+    Setting.create_if_not_exists(
+      title: 'Email - full quote',
+      name: 'ui_ticket_zoom_article_email_full_quote',
+      area: 'UI::TicketZoom',
+      description: 'Enable if you want to quote the full email in your answer. The quoted email will be put at the end of your answer. If you just want to quote a certain phrase, just mark the text and press reply (this feature is always available).',
+      options: {
+        form: [
+          {
+            display: '',
+            null: true,
+            name: 'ui_ticket_zoom_article_email_full_quote',
+            tag: 'boolean',
+            translate: true,
+            options: {
+              true  => 'yes',
+              false => 'no',
+            },
+          },
+        ],
+      },
+      state: false,
+      preferences: {
+        prio: 220,
+        permission: ['admin.ui'],
+      },
+      frontend: true
+    )
     Setting.create_if_not_exists(
       title: 'Twitter - tweet initials',
       name: 'ui_ticket_zoom_article_twitter_initials',

+ 27 - 0
db/seeds/settings.rb

@@ -600,6 +600,33 @@ Setting.create_if_not_exists(
   },
   frontend: true
 )
+Setting.create_if_not_exists(
+  title: 'Email - full quote',
+  name: 'ui_ticket_zoom_article_email_full_quote',
+  area: 'UI::TicketZoom',
+  description: 'Enable if you want to quote the full email in your answer. The quoted email will be put at the end of your answer. If you just want to quote a certain phrase, just mark the text and press reply (this feature is always available).',
+  options: {
+    form: [
+      {
+        display: '',
+        null: true,
+        name: 'ui_ticket_zoom_article_email_full_quote',
+        tag: 'boolean',
+        translate: true,
+        options: {
+          true  => 'yes',
+          false => 'no',
+        },
+      },
+    ],
+  },
+  state: false,
+  preferences: {
+    prio: 220,
+    permission: ['admin.ui'],
+  },
+  frontend: true
+)
 Setting.create_if_not_exists(
   title: 'Twitter - tweet initials',
   name: 'ui_ticket_zoom_article_twitter_initials',