Reducred render() count on ui:rerender (e. g. language change).

This commit is contained in:
Martin Edenhofer 2016-07-07 18:32:26 +02:00
parent 2894764697
commit 4e01b0c229
18 changed files with 184 additions and 154 deletions

View file

@ -463,7 +463,7 @@ class App.Controller extends Spine.Controller
fetch = (params) => fetch = (params) =>
@ajax( @ajax(
type: 'GET' type: 'GET'
url: @Config.get('api_path') + '/ticket_customer' url: "#{@Config.get('api_path')}/ticket_customer"
data: data:
customer_id: params.user_id customer_id: params.user_id
processData: true processData: true

View file

@ -768,6 +768,7 @@ class App.CollectionController extends App.Controller
sortBy: 'name' sortBy: 'name'
order: 'ASC', order: 'ASC',
insertPosition: 'after' insertPosition: 'after'
globalRerender: true
constructor: -> constructor: ->
@events = @constructor.events unless @events @events = @constructor.events unless @events
@ -788,6 +789,7 @@ class App.CollectionController extends App.Controller
@subscribeId = App[@model].subscribe(@collectionSync) @subscribeId = App[@model].subscribe(@collectionSync)
# render on generic ui call # render on generic ui call
if @globalRerender
@bind('ui:rerender', => @bind('ui:rerender', =>
@queue.push ['renderAll'] @queue.push ['renderAll']
@uIRunner() @uIRunner()
@ -1074,6 +1076,7 @@ class App.CollectionController extends App.Controller
class App.ObserverController extends App.Controller class App.ObserverController extends App.Controller
model: 'Ticket' model: 'Ticket'
template: 'ticket_zoom/title' template: 'ticket_zoom/title'
globalRerender: true
### ###
observe: observe:
@ -1096,7 +1099,9 @@ class App.ObserverController extends App.Controller
@maybeRender(object) @maybeRender(object)
# rerender, e. g. on language change # rerender, e. g. on language change
if @globalRerender
@bind('ui:rerender', => @bind('ui:rerender', =>
console.log('REREN')
@lastAttributres = undefined @lastAttributres = undefined
object = App[@model].fullLocal(@object_id) object = App[@model].fullLocal(@object_id)
@maybeRender(object) @maybeRender(object)

View file

@ -10,11 +10,6 @@ class App.OrganizationProfile extends App.Controller
# fetch new data if needed # fetch new data if needed
App.Organization.full(@organization_id, @render) App.Organization.full(@organization_id, @render)
# rerender view, e. g. on langauge change
@bind 'ui:rerender', =>
return if !@authenticate(true)
@render(App.Organization.fullLocal(@organization_id))
meta: => meta: =>
meta = meta =
url: @url() url: @url()
@ -48,6 +43,11 @@ class App.OrganizationProfile extends App.Controller
organization: organization organization: organization
)) ))
new ActionRow(
el: elLocal.find('.js-action')
object_id: organization.id
)
new Object( new Object(
el: elLocal.find('.js-object-container') el: elLocal.find('.js-object-container')
object_id: organization.id object_id: organization.id
@ -65,6 +65,50 @@ class App.OrganizationProfile extends App.Controller
genericObject: organization genericObject: organization
) )
class ActionRow extends App.ObserverController
model: 'Organization'
observe:
member_ids: true
render: (organization) =>
# start action controller
showHistory = ->
new App.OrganizationHistory(
organization_id: organization.id
container: @el.closest('.content')
)
editOrganization = =>
new App.ControllerGenericEdit(
id: organization.id
genericObject: 'Organization'
screen: 'edit'
pageData:
title: 'Organizations'
object: 'Organization'
objects: 'Organizations'
container: @el.closest('.content')
)
actions = [
{
name: 'edit'
title: 'Edit'
callback: editOrganization
}
{
name: 'history'
title: 'History'
callback: showHistory
}
]
new App.ActionRow(
el: @el
items: actions
)
class Object extends App.ObserverController class Object extends App.ObserverController
model: 'Organization' model: 'Organization'
observeNot: observeNot:
@ -124,43 +168,6 @@ class Object extends App.ObserverController
members.push el members.push el
@$('.js-userList').html(members) @$('.js-userList').html(members)
# start action controller
showHistory = ->
new App.OrganizationHistory(
organization_id: organization.id
container: @el.closest('.content')
)
editOrganization = =>
new App.ControllerGenericEdit(
id: organization.id
genericObject: 'Organization'
screen: 'edit'
pageData:
title: 'Organizations'
object: 'Organization'
objects: 'Organizations'
container: @el.closest('.content')
)
actions = [
{
name: 'edit'
title: 'Edit'
callback: editOrganization
}
{
name: 'history'
title: 'History'
callback: showHistory
}
]
new App.ActionRow(
el: @el.find('.js-action')
items: actions
)
update: (e) => update: (e) =>
name = $(e.target).attr('data-name') name = $(e.target).attr('data-name')
value = $(e.target).html() value = $(e.target).html()
@ -179,6 +186,7 @@ class Member extends App.ObserverController
lastname: true lastname: true
login: true login: true
email: true email: true
globalRerender: false
render: (user) => render: (user) =>
@html App.view('organization_profile/member')( @html App.view('organization_profile/member')(

View file

@ -53,17 +53,10 @@ class App.TicketZoom extends App.Controller
@delay(update, 1200, "ticket-zoom-#{@ticket_id}") @delay(update, 1200, "ticket-zoom-#{@ticket_id}")
) )
# rerender view, e. g. on langauge change fetchStart: =>
@bind('ui:rerender', => if @fetchIsRunning
@fetch(true)
)
fetchStart: (force) =>
if !force && @fetchIsRunning
@fetchIsRunningAgain = true @fetchIsRunningAgain = true
return false return false
if force
@fetchIsRunningAgain = false
@fetchIsRunning = true @fetchIsRunning = true
true true
@ -73,9 +66,9 @@ class App.TicketZoom extends App.Controller
@fetchIsRunningAgain = false @fetchIsRunningAgain = false
@fetch() @fetch()
fetch: (force) => fetch: =>
return if !@Session.get() return if !@Session.get()
return if !@fetchStart(force) return if !@fetchStart()
# get data # get data
@ajax( @ajax(
@ -88,7 +81,7 @@ class App.TicketZoom extends App.Controller
# check if ticket has changed # check if ticket has changed
newTicketRaw = data.assets.Ticket[@ticket_id] newTicketRaw = data.assets.Ticket[@ticket_id]
if @ticketUpdatedAtLastCall && !force if @ticketUpdatedAtLastCall
# return if ticket hasnt changed # return if ticket hasnt changed
return if @ticketUpdatedAtLastCall is newTicketRaw.updated_at return if @ticketUpdatedAtLastCall is newTicketRaw.updated_at

View file

@ -2,6 +2,7 @@ class App.TicketCustomerAvatar extends App.ObserverController
model: 'Ticket' model: 'Ticket'
observe: observe:
customer_id: true customer_id: true
globalRerender: false
render: (ticket) => render: (ticket) =>
new App.WidgetAvatar( new App.WidgetAvatar(

View file

@ -3,6 +3,7 @@ class Edit extends App.ObserverController
observeNot: observeNot:
created_at: true created_at: true
updated_at: true updated_at: true
globalRerender: false
render: (ticket, diff) => render: (ticket, diff) =>
defaults = ticket.attributes() defaults = ticket.attributes()

View file

@ -3,6 +3,7 @@ class App.TicketZoomTitle extends App.ObserverController
template: 'ticket_zoom/title' template: 'ticket_zoom/title'
observe: observe:
title: true title: true
globalRerender: false
events: events:
'blur .js-objectTitle': 'update' 'blur .js-objectTitle': 'update'

View file

@ -10,11 +10,6 @@ class App.UserProfile extends App.Controller
# fetch new data if needed # fetch new data if needed
App.User.full(@user_id, @render) App.User.full(@user_id, @render)
# rerender view, e. g. on langauge change
@bind 'ui:rerender', =>
return if !@authenticate(true)
@render(App.User.fullLocal(@user_id))
meta: => meta: =>
meta = meta =
url: @url() url: @url()
@ -48,6 +43,11 @@ class App.UserProfile extends App.Controller
user: user user: user
)) ))
new ActionRow(
el: elLocal.find('.js-action')
object_id: user.id
)
new Object( new Object(
el: elLocal.find('.js-object-container') el: elLocal.find('.js-object-container')
object_id: user.id object_id: user.id
@ -65,6 +65,50 @@ class App.UserProfile extends App.Controller
genericObject: user genericObject: user
) )
class ActionRow extends App.ObserverController
model: 'User'
observe:
organization_id: true
render: (user) =>
# start action controller
showHistory = =>
new App.UserHistory(
user_id: user.id
container: @el.closest('.content')
)
editUser = =>
new App.ControllerGenericEdit(
id: user.id
genericObject: 'User'
screen: 'edit'
pageData:
title: 'Users'
object: 'User'
objects: 'Users'
container: @el.closest('.content')
)
actions = [
{
name: 'edit'
title: 'Edit'
callback: editUser
}
{
name: 'history'
title: 'History'
callback: showHistory
}
]
new App.ActionRow(
el: @el
items: actions
)
class Object extends App.ObserverController class Object extends App.ObserverController
model: 'User' model: 'User'
observeNot: observeNot:
@ -122,43 +166,6 @@ class Object extends App.ObserverController
el: @$('.js-organization') el: @$('.js-organization')
) )
# start action controller
showHistory = =>
new App.UserHistory(
user_id: user.id
container: @el.closest('.content')
)
editUser = =>
new App.ControllerGenericEdit(
id: user.id
genericObject: 'User'
screen: 'edit'
pageData:
title: 'Users'
object: 'User'
objects: 'Users'
container: @el.closest('.content')
)
actions = [
{
name: 'edit'
title: 'Edit'
callback: editUser
}
{
name: 'history'
title: 'History'
callback: showHistory
}
]
new App.ActionRow(
el: @el.find('.js-action')
items: actions
)
update: (e) => update: (e) =>
name = $(e.target).attr('data-name') name = $(e.target).attr('data-name')
value = $(e.target).html() value = $(e.target).html()

View file

@ -6,6 +6,7 @@ class App.WidgetAvatar extends App.ObserverController
lastname: true lastname: true
email: true email: true
image: true image: true
globalRerender: false
render: (user) => render: (user) =>
@html(user.avatar @size, @position, undefined, false, false, @type) @html(user.avatar @size, @position, undefined, false, false, @type)

View file

@ -51,6 +51,12 @@ class App.OnlineNotificationWidget extends App.Controller
@createContainer() @createContainer()
# rerender view, e. g. on langauge change
@bind('ui:rerender', =>
@createContainer()
'online_notification'
)
release: -> release: ->
$(window).off 'click.notifications' $(window).off 'click.notifications'
$(window).off 'keydown.notifications' $(window).off 'keydown.notifications'
@ -202,6 +208,7 @@ class App.OnlineNotificationContentWidget extends App.CollectionController
order: 'DESC' order: 'DESC'
alreadyShown: {} alreadyShown: {}
insertPosition: 'before' insertPosition: 'before'
globalRerender: false
onRenderEnd: => onRenderEnd: =>
@container.counterGen() @container.counterGen()

View file

@ -18,6 +18,11 @@ class App.TicketStats extends App.Controller
else if @organization else if @organization
@subscribeIdOrganization = App.Organization.full(@organization.id, @load, false, true) @subscribeIdOrganization = App.Organization.full(@organization.id, @load, false, true)
# rerender view, e. g. on langauge change
@bind 'ui:rerender', =>
return if !@authenticate(true)
@render()
release: => release: =>
if @subscribeIdUser if @subscribeIdUser
App.User.unsubscribe(@subscribeIdUser) App.User.unsubscribe(@subscribeIdUser)
@ -35,13 +40,14 @@ class App.TicketStats extends App.Controller
user_id: @user.id user_id: @user.id
organization_id: @user.organization_id organization_id: @user.organization_id
@ajax( @ajax(
id: 'ticket_stats_' + ajaxKey id: "ticket_stats_#{ajaxKey}"
type: 'GET' type: 'GET'
url: @apiPath + '/ticket_stats' url: "#{@apiPath}/ticket_stats"
data: data data: data
processData: true processData: true
success: (data) => success: (data) =>
App.Collection.loadAssets(data.assets) App.Collection.loadAssets(data.assets)
@data = data
@render(data) @render(data)
) )
@ -58,6 +64,8 @@ class App.TicketStats extends App.Controller
@orgTab.addClass('hide') @orgTab.addClass('hide')
render: (data) => render: (data) =>
if !data
data = @data
@html App.view('widget/ticket_stats')( @html App.view('widget/ticket_stats')(
user: @user user: @user

View file

@ -359,8 +359,8 @@ class App.Model extends Spine.Model
if param.clear is true || param.clear is false if param.clear is true || param.clear is false
clear = param.clear clear = param.clear
if !@initFetchActive if !@initFetchActive
@one 'refresh', (collection) =>
@initFetchActive = true @initFetchActive = true
@one 'refresh', (collection) ->
callback(collection) callback(collection)
@fetchFull( @fetchFull(
-> ->

View file

@ -1,5 +1,12 @@
<div class="profile"> <div class="profile">
<div class="profile-window"> <div class="profile-window">
<div class="profile-section vertical centered">
<div class="align-right profile-action js-action"></div>
<div class="profile-organizationIcon">
<%- @Icon('organization') %>
</div>
<h1><%= @organization.displayName() %></h1>
</div>
<div class="js-object-container"></div> <div class="js-object-container"></div>
<div class="profile-section js-ticket-stats"></div> <div class="profile-section js-ticket-stats"></div>
</div> </div>

View file

@ -1,22 +1,15 @@
<div class="profile-section vertical centered">
<div class="align-right profile-action js-action"></div>
<div class="profile-organizationIcon">
<%- @Icon('organization') %>
</div>
<h1><%= @organization.displayName() %></h1>
</div>
<div class="profile-section"> <div class="profile-section">
<div class="profile-details horizontal wrap"> <div class="profile-details horizontal wrap">
<% for row in @organizationData: %> <% for row in @organizationData: %>
<% if row.tag is 'richtext': %> <% if row.tag is 'richtext': %>
<div class="profile-detailsEntry" style="width: 100%;"> <div class="profile-detailsEntry" style="width: 100%;">
<label><%- @Ti( row.display ) %></label> <label><%- @T(row.display) %></label>
<div contenteditable="true" data-name="<%= row.name %>" data-type="update" data-placeholder="<%- @Ti('Add a Note') %>"><%- @organization[row.name] %></div> <div contenteditable="true" data-name="<%= row.name %>" data-type="update" data-placeholder="<%- @Ti('Add a Note') %>"><%- @organization[row.name] %></div>
</div> </div>
<% else: %> <% else: %>
<% if @organization[row.name]: %> <% if @organization[row.name]: %>
<div class="profile-detailsEntry"> <div class="profile-detailsEntry">
<label><%- @Ti( row.display ) %></label> <label><%- @T(row.display) %></label>
<%- @P(@organization, row.name) %> <%- @P(@organization, row.name) %>
</div> </div>
<% end %> <% end %>

View file

@ -1,6 +1,14 @@
<div class="profile"> <div class="profile">
<div class="profile-window"> <div class="profile-window">
<div class="js-object-container"></div> <div class="profile-section vertical centered">
<div class="align-right profile-action js-action"></div>
<%- @user.avatar("80") %>
<h1><%= @user.displayName() %></h1>
<% if @user.organization: %>
<div class="profile-organization js-organization"></div>
<% end %>
</div>
<div class="profile-section js-object-container"></div>
<div class="profile-section js-ticket-stats"></div> <div class="profile-section js-ticket-stats"></div>
</div> </div>
</div> </div>

View file

@ -1,27 +1,17 @@
<div class="profile-section vertical centered">
<div class="align-right profile-action js-action"></div>
<%- @user.avatar("80") %>
<h1><%= @user.displayName() %></h1>
<% if @user.organization: %>
<div class="profile-organization js-organization"></div>
<% end %>
</div>
<div class="profile-section">
<div class="profile-details horizontal wrap"> <div class="profile-details horizontal wrap">
<% for row in @userData: %> <% for row in @userData: %>
<% if row.tag is 'richtext': %> <% if row.tag is 'richtext': %>
<div class="profile-detailsEntry" style="width: 100%;"> <div class="profile-detailsEntry" style="width: 100%;">
<label><%- @Ti( row.display ) %></label> <label><%- @T(row.display) %></label>
<div contenteditable="true" data-name="<%= row.name %>" data-type="update" data-placeholder="<%- @Ti('Add a Note') %>"><%- @user[row.name] %></div> <div contenteditable="true" data-name="<%= row.name %>" data-type="update" data-placeholder="<%- @Ti('Add a Note') %>"><%- @user[row.name] %></div>
</div> </div>
<% else: %> <% else: %>
<% if @user[row.name]: %> <% if @user[row.name]: %>
<div class="profile-detailsEntry"> <div class="profile-detailsEntry">
<label><%- @Ti( row.display ) %></label> <label><%- @T(row.display) %></label>
<%- @P(@user, row.name) %> <%- @P(@user, row.name) %>
</div> </div>
<% end %> <% end %>
<% end %> <% end %>
<% end %> <% end %>
</div> </div>
</div>