Fixed issue #187 - Wrong article order after merging of tickets.

This commit is contained in:
Rolf Schmidt 2017-04-25 16:19:07 +02:00 committed by Thorsten Eckel
parent 0a6cd3897e
commit 34293909dd

View file

@ -10,7 +10,7 @@ class App.TicketZoomArticleView extends App.Controller
run: => run: =>
all = [] all = []
for ticket_article_id in @ticket_article_ids for ticket_article_id, index in @ticket_article_ids
controllerKey = ticket_article_id.toString() controllerKey = ticket_article_id.toString()
if !@articleController[controllerKey] if !@articleController[controllerKey]
el = $('<div></div>') el = $('<div></div>')
@ -21,7 +21,8 @@ class App.TicketZoomArticleView extends App.Controller
ui: @ui ui: @ui
highligher: @highligher highligher: @highligher
) )
all.push el if !@ticketArticleInsertByIndex(index, el)
all.push el
@el.append(all) @el.append(all)
# check elements to remove # check elements to remove
@ -34,6 +35,31 @@ class App.TicketZoomArticleView extends App.Controller
controller.remove() controller.remove()
delete @articleController[article_id.toString()] delete @articleController[article_id.toString()]
ticketArticleInsertByIndex: (elIndex, el) =>
return false if !@$('.ticket-article-item').length
# in case of a merge it can happen that there are already
# articles rendered in the ticket, but the new article need
# to be inserted at the correct position in the the ticket
for index in [elIndex .. 0]
article_id = @ticket_article_ids[index]
continue if !article_id
article = @$(".ticket-article-item[data-id=#{article_id}]")
continue if !article.length
article.after(el)
return true
for index in [elIndex .. @ticket_article_ids.length - 1]
article_id = @ticket_article_ids[index]
continue if !article_id
article = @$(".ticket-article-item[data-id=#{article_id}]")
continue if !article.length
article.before(el)
return true
false
class ArticleViewItem extends App.ObserverController class ArticleViewItem extends App.ObserverController
model: 'TicketArticle' model: 'TicketArticle'
observe: observe: