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