Reduced rerendering of attribute bar in ticket zoom

This commit is contained in:
Martin Edenhofer 2016-03-29 14:57:49 +02:00
parent e0e4fa249c
commit 16ee920cf9
5 changed files with 48 additions and 20 deletions

View file

@ -94,6 +94,7 @@ class App.TaskbarWidget extends App.Controller
new Remove(
key: key
ui: @
event: e
)
return
@ -131,6 +132,6 @@ class Remove extends App.ControllerModal
content: ->
App.i18n.translateContent('Tab has changed, you really want to close it?')
onSubmit: (e) =>
onSubmit: =>
@close()
@ui.remove(e, @key, true)
@ui.remove(@event, @key, true)

View file

@ -51,7 +51,7 @@ class App.TicketZoom extends App.Controller
update = =>
@fetch(@ticket_id, false)
if !@ticketUpdatedAtLastCall || ( new Date(data.updated_at).toString() isnt new Date(@ticketUpdatedAtLastCall).toString() )
@delay( update, 1200, 'ticket-zoom-' + @ticket_id )
@delay(update, 1200, "ticket-zoom-#{@ticket_id}")
)
# rerender view, e. g. on langauge change
@ -100,7 +100,7 @@ class App.TicketZoom extends App.Controller
@activeState = true
# start autosave
@autosaveStart()
@delay(@autosaveStart, 800, "ticket-zoom-auto-save-#{@ticket_id}")
# if ticket is shown the first time
if !@shown
@ -122,6 +122,7 @@ class App.TicketZoom extends App.Controller
@positionPageHeaderStop()
# stop autosave
@clearDelay("ticket-zoom-auto-save-#{@ticket_id}")
@autosaveStop()
changed: =>
@ -687,12 +688,12 @@ class App.TicketZoom extends App.Controller
processData: false
)
# reset edit ticket / reset new article
App.Event.trigger('ui::ticket::taskReset', { ticket_id: @ticket.id })
# hide reset button
@$('.js-reset').addClass('hide')
# reset edit ticket / reset new article
App.Event.trigger('ui::ticket::taskReset', { ticket_id: @ticket.id })
# remove change flag on tab
@$('.tabsSidebar-tab[data-tab="ticket"]').removeClass('is-changed')

View file

@ -1,7 +1,7 @@
class App.TicketZoomAttributeBar extends App.Controller
elements:
'.js-submitDropdown': 'buttonDropdown'
'.js-secondaryActionButtonLabel': 'secondaryActionButton'
'.js-reset': 'resetButton'
events:
'mousedown .js-openDropdownMacro': 'toggleDropdownMacro'
@ -16,7 +16,7 @@ class App.TicketZoomAttributeBar extends App.Controller
@secondaryAction = 'stayOnTab'
@subscribeId = App.Macro.subscribe(@render)
@subscribeId = App.Macro.subscribe(@checkMacroChanges)
@render()
# rerender, e. g. on language change
@ -28,15 +28,31 @@ class App.TicketZoomAttributeBar extends App.Controller
App.Macro.unsubscribe(@subscribeId)
render: =>
# remember current reset state
resetButtonShown = false
if @resetButton.get(0) && !@resetButton.hasClass('hide')
resetButtonShown = true
macros = App.Macro.all()
@macroLastUpdated = App.Macro.lastUpdatedAt()
if _.isEmpty(macros) || !@isRole('Agent')
macroDisabled = true
@html App.view('ticket_zoom/attribute_bar')(
localeEl = $(App.view('ticket_zoom/attribute_bar')(
macros: macros
macroDisabled: macroDisabled
overview_id: @overview_id
)
@setSecondaryAction()
resetButtonShown: resetButtonShown
))
@setSecondaryAction(@secondaryAction, localeEl)
@html localeEl
checkMacroChanges: =>
macroLastUpdated = App.Macro.lastUpdatedAt()
return if macroLastUpdated is @macroLastUpdated
@render()
toggleDropdownMacro: =>
if @buttonDropdown.hasClass 'is-open'
@ -65,12 +81,12 @@ class App.TicketZoomAttributeBar extends App.Controller
chooseSecondaryAction: (e) =>
type = $(e.currentTarget).find('.js-secondaryActionLabel').data('type')
@setSecondaryAction(type)
@setSecondaryAction(type, @el)
setSecondaryAction: (type = @secondaryAction) =>
element = @$(".js-secondaryActionLabel[data-type=#{type}]")
setSecondaryAction: (type, localEl) ->
element = localEl.find(".js-secondaryActionLabel[data-type=#{type}]")
text = element.text()
@$('.js-secondaryAction .js-selectedIcon.is-selected').removeClass('is-selected')
localEl.find('.js-secondaryAction .js-selectedIcon.is-selected').removeClass('is-selected')
element.closest('.js-secondaryAction').find('.js-selectedIcon').addClass('is-selected')
@secondaryActionButton.text(text)
@secondaryActionButton.data('type', type)
localEl.find('.js-secondaryActionButtonLabel').text(text)
localEl.find('.js-secondaryActionButtonLabel').data('type', type)

View file

@ -666,3 +666,13 @@ class App.Model extends Spine.Model
activityMessage: (item) ->
return "Need own activityMessage() in model to generate text (#{@objectDisplayName()}/#{item.type})."
@lastUpdatedAt: ->
updated_at
for item in @all()
if item.updated_at
if !updated_at
updated_at = item.updated_at
else if item.updated_at > updated_at
updated_at = item.updated_at
updated_at

View file

@ -1,4 +1,4 @@
<div class="buttonDropdown btn js-reset hide"><%- @T('Discard your unsaved changes.') %></div>
<div class="buttonDropdown btn js-reset <% if !@resetButtonShown: %>hide<% end %>"><%- @T('Discard your unsaved changes.') %></div>
<div class="buttonDropdown dropdown dropdown--actions dropup">
<div class="btn btn--text btn--icon--last" data-toggle="dropdown">
<span class="js-secondaryActionButtonLabel"></span> <%- @Icon('arrow-up') %>