Improve rerender of articles.

This commit is contained in:
Martin Edenhofer 2015-10-07 07:32:28 +02:00
parent 303b3c9769
commit 783b347260

View file

@ -20,7 +20,7 @@ class App.TicketZoomArticleView extends App.Controller
@el.append( all )
class ArticleViewItem extends App.Controller
hasChangedAttributes: ['from', 'to', 'cc', 'subject', 'body', 'internal', 'preferences']
hasChangedAttributes: ['from', 'to', 'cc', 'subject', 'body', 'preferences']
elements:
'.textBubble-content': 'textBubbleContent'
@ -59,7 +59,7 @@ class ArticleViewItem extends App.Controller
App.TicketArticle.unsubscribe(@subscribeId)
setHighlighter: =>
return if !@el.is(':visible')
return if @el.is(':hidden')
# use delay do no ui blocking
#@highligher.loadHighlights(@ticket_article_id)
d = =>
@ -69,19 +69,19 @@ class ArticleViewItem extends App.Controller
hasChanged: (article) =>
# if no last article exists, remember it and return true
if !@article_last_updated
@article_last_updated = {}
if !@articleAttributesLastUpdate
@articleAttributesLastUpdate = {}
for item in @hasChangedAttributes
@article_last_updated[item] = article[item]
@articleAttributesLastUpdate[item] = article[item]
return true
# compare last and current article attributes
article_last_updated_check = {}
articleAttributesLastUpdateCheck = {}
for item in @hasChangedAttributes
article_last_updated_check[item] = article[item]
diff = difference(@article_last_updated, article_last_updated_check)
articleAttributesLastUpdateCheck[item] = article[item]
diff = difference(@articleAttributesLastUpdate, articleAttributesLastUpdateCheck)
return false if !diff || _.isEmpty( diff )
@article_last_updated = article_last_updated_check
@articleAttributesLastUpdate = articleAttributesLastUpdateCheck
true
render: (article) =>
@ -90,16 +90,22 @@ class ArticleViewItem extends App.Controller
@article = App.TicketArticle.fullLocal( @ticket_article_id )
# set @el attributes
if !article
@el.addClass("ticket-article-item #{@article.sender.name.toLowerCase()}")
@el.attr('data-id', @article.id)
@el.attr('id', "article-#{@article.id}")
# set internal change directly in dom, without rerender while article
if !article || ( @lastArticle && @lastArticle.internal isnt @article.internal )
if @article.internal is true
@el.addClass('is-internal')
else
@el.removeClass('is-internal')
@el.attr('data-id', @article.id)
@el.attr('id', "article-#{@article.id}")
# check if rerender is needed
return if !@hasChanged(@article)
if !@hasChanged(@article)
@lastArticle = @article.attributes()
return
# prepare html body
if @article.content_type is 'text/html'
@ -128,14 +134,16 @@ class ArticleViewItem extends App.Controller
# set see more
@shown = false
a = =>
@setSeeMore()
@delay( a, 50 )
# set highlighter
@setHighlighter()
# set see more options
setSeeMore: =>
return if !@el.is(':visible')
return if @el.is(':hidden')
return if @shown
@shown = true