Next step of email reply.

This commit is contained in:
Martin Edenhofer 2014-12-14 20:18:00 +01:00
parent 1d520f3b47
commit 575a29dee5

View file

@ -816,6 +816,22 @@ class Edit extends App.Controller
if @defaults.body or @isIE10() if @defaults.body or @isIE10()
@open_textarea(null, true) @open_textarea(null, true)
@bind(
'ui::ticket::setArticleType'
(data) =>
if data.ticket.id is @ticket.id
#@setArticleType(data.type.name)
# preselect article type
@setArticleType( 'email' )
@open_textarea(null, true)
for key, value of data.article
if key is 'body'
@$('[data-name="' + key + '"]').text(value)
else
@$('[name="' + key + '"]').val(value)
)
isIE10: -> isIE10: ->
Function('/*@cc_on return document.documentMode===10@*/')() Function('/*@cc_on return document.documentMode===10@*/')()
@ -1187,9 +1203,9 @@ class ArticleView extends App.Controller
'click [data-type=internal]': 'public_internal' 'click [data-type=internal]': 'public_internal'
'click .show_toogle': 'show_toogle' 'click .show_toogle': 'show_toogle'
'click [data-type=reply]': 'reply' 'click [data-type=reply]': 'reply'
'click [data-type=replyAll]': 'replyAll'
'click .text-bubble': 'toggle_meta' 'click .text-bubble': 'toggle_meta'
'click .text-bubble a': 'stopPropagation' 'click .text-bubble a': 'stopPropagation'
# 'click [data-type=reply-all]': 'replyall'
constructor: -> constructor: ->
super super
@ -1358,56 +1374,103 @@ class ArticleView extends App.Controller
# update textarea size # update textarea size
@ui.el.find('[name="body"]').trigger('change') @ui.el.find('[name="body"]').trigger('change')
reply: (e) => replyAll: (e) =>
@reply(e, true)
reply: (e, all = false) =>
e.preventDefault() e.preventDefault()
# get reference article
article_id = $(e.target).parents('[data-id]').data('id') article_id = $(e.target).parents('[data-id]').data('id')
article = App.TicketArticle.find( article_id ) article = App.TicketArticle.fullLocal( article_id )
type = App.TicketArticleType.find( article.type_id ) type = App.TicketArticleType.find( article.type_id )
customer = App.User.find( article.created_by_id ) customer = App.User.find( article.created_by_id )
@ui.el.find('.article-add').ScrollTo()
# update form # update form
@checkIfSignatureIsNeeded(type) @checkIfSignatureIsNeeded(type)
# preselect article type
@ui.el.find('[name="type_id"]').find('option:selected').removeAttr('selected')
@ui.el.find('[name="type_id"]').find('[value="' + type.id + '"]').attr('selected',true)
@ui.el.find('[name="type_id"]').trigger('change')
# empty form # empty form
#@ui.el.find('[name="to"]').val('') articleNew = {
#@ui.el.find('[name="cc"]').val('') to: ''
#@ui.el.find('[name="subject"]').val('') cc: ''
@ui.el.find('[name="in_reply_to"]').val('') body: ''
in_reply_to: ''
}
#@ui.el.find('[name="in_reply_to"]').val('')
if article.message_id if article.message_id
@ui.el.find('[name="in_reply_to"]').val(article.message_id) articleNew.in_reply_to = article.message_id
if type.name is 'twitter status' if type.name is 'twitter status'
# set to in body # set to in body
to = customer.accounts['twitter'].username || customer.accounts['twitter'].uid to = customer.accounts['twitter'].username || customer.accounts['twitter'].uid
@ui.el.find('[name="body"]').val('@' + to) articleNew.body = '@' + to
else if type.name is 'twitter direct-message' else if type.name is 'twitter direct-message'
# show to # show to
to = customer.accounts['twitter'].username || customer.accounts['twitter'].uid to = customer.accounts['twitter'].username || customer.accounts['twitter'].uid
@ui.el.find('[name="to"]').val(to) articleNew.to = to
else if type.name is 'email' else if type.name is 'email'
@ui.el.find('[name="to"]').val(article.from) if article.sender.name is 'Agent'
articleNew.to = article.to
else
articleNew.to = article.from
# filter for uniq recipients
recipientAddresses = {}
recipient = emailAddresses.parseAddressList(articleNew.to)
if recipient && recipient[0]
recipientAddresses[ recipient[0].address.toString().toLowerCase() ] = true
if all
addAddresses = (lineNew, addressLine) ->
localAddresses = App.EmailAddress.all()
recipients = emailAddresses.parseAddressList(addressLine)
if recipients
for recipient in recipients
if recipient.address
# check if addess is not local
localAddess = false
for address in localAddresses
if recipient.address.toString().toLowerCase() == address.email.toString().toLowerCase()
localAddess = true
if !localAddess
# filter for uniq recipients
if !recipientAddresses[ recipient.address.toString().toLowerCase() ]
recipientAddresses[ recipient.address.toString().toLowerCase() ] = true
# add recipient
if lineNew
lineNew = lineNew + ', '
lineNew = lineNew + recipient.address
lineNew
if article.from
articleNew.cc = addAddresses(articleNew.cc, article.from)
if article.to
articleNew.cc = addAddresses(articleNew.cc, article.to)
if article.cc
articleNew.cc = addAddresses(articleNew.cc, article.cc)
# add quoted text if needed # add quoted text if needed
selectedText = App.ClipBoard.getSelected() selectedText = App.ClipBoard.getSelected()
console.log('selectedText', selectedText)
if selectedText if selectedText
body = @ui.el.find('[name="body"]').val() || '' body = @ui.el.find('[data-name="body"]').text() || ''
selectedText = selectedText.replace /^(.*)$/mg, (match) => selectedText = selectedText.replace /^(.*)$/mg, (match) =>
'> ' + match '> ' + match
body = selectedText + "\n" + body body = selectedText + "\n" + body
@ui.el.find('[name="body"]').val(body) articleNew.body = body
App.Event.trigger('ui::ticket::setArticleType', { ticket: @ticket, type: type, article: articleNew } )
# update textarea size
@ui.el.find('[name="body"]').trigger('change')
class Article extends App.Controller class Article extends App.Controller
constructor: -> constructor: ->
@ -1483,20 +1546,29 @@ class Article extends App.Controller
type: 'internal' type: 'internal'
} }
] ]
if @article.type.name is 'note' #if @article.type.name is 'note'
# actions.push [] # actions.push []
else if @article.type.name is 'email'
if @article.sender.name is 'Customer'
actions.push { actions.push {
name: 'reply' name: 'reply'
type: 'reply' type: 'reply'
href: '#' href: '#'
} }
# actions.push { recipients = []
# name: 'reply all' if @article.to
# type: 'reply-all' localRecipients = emailAddresses.parseAddressList(@article.to)
# href: '#' if localRecipients
# } recipients = recipients.concat localRecipients
if @article.cc
localRecipients = emailAddresses.parseAddressList(@article.cc)
if localRecipients
recipients = recipients.concat localRecipients
if recipients.length > 0
actions.push {
name: 'reply all'
type: 'replyAll'
href: '#'
}
actions.push { actions.push {
name: 'split' name: 'split'
type: 'split' type: 'split'