Improved loading of users.
This commit is contained in:
parent
9208927be9
commit
44f80201ee
3 changed files with 74 additions and 53 deletions
|
@ -149,8 +149,11 @@ class App.Controller extends Spine.Controller
|
||||||
else
|
else
|
||||||
list = App[attribute.relation].all()
|
list = App[attribute.relation].all()
|
||||||
|
|
||||||
|
# build options list
|
||||||
list.forEach( (item) =>
|
list.forEach( (item) =>
|
||||||
if item.active
|
|
||||||
|
# if active or if active doesn't exist
|
||||||
|
if item.active || !( 'active' of item )
|
||||||
name = '???'
|
name = '???'
|
||||||
if item.name
|
if item.name
|
||||||
name = item.name
|
name = item.name
|
||||||
|
@ -162,7 +165,7 @@ class App.Controller extends Spine.Controller
|
||||||
name = name + item.lastname
|
name = name + item.lastname
|
||||||
|
|
||||||
attribute.options.push {
|
attribute.options.push {
|
||||||
name: name,
|
name: name,
|
||||||
value: item.id,
|
value: item.id,
|
||||||
note: item.note,
|
note: item.note,
|
||||||
}
|
}
|
||||||
|
@ -267,10 +270,13 @@ class App.Controller extends Spine.Controller
|
||||||
else
|
else
|
||||||
item = App.view('generic/input')( attribute: attribute )
|
item = App.view('generic/input')( attribute: attribute )
|
||||||
|
|
||||||
return App.view('generic/attribute')(
|
if !attribute.display
|
||||||
attribute: attribute,
|
return item
|
||||||
item: item,
|
else
|
||||||
)
|
return App.view('generic/attribute')(
|
||||||
|
attribute: attribute,
|
||||||
|
item: item,
|
||||||
|
)
|
||||||
|
|
||||||
# get all params of the form
|
# get all params of the form
|
||||||
formParam: (form, errors) ->
|
formParam: (form, errors) ->
|
||||||
|
@ -600,26 +606,40 @@ class App.Controller extends Spine.Controller
|
||||||
|
|
||||||
# users
|
# users
|
||||||
if params.type == 'User'
|
if params.type == 'User'
|
||||||
for user of params.data
|
for user_id, user of params.data
|
||||||
|
|
||||||
|
# set socal media links
|
||||||
|
if user['accounts']
|
||||||
|
for account of user['accounts']
|
||||||
|
if account == 'twitter'
|
||||||
|
user['accounts'][account]['link'] = 'http://twitter.com/' + user['accounts'][account]['username']
|
||||||
|
if account == 'facebook'
|
||||||
|
user['accounts'][account]['link'] = 'https://www.facebook.com/profile.php?id=' + user['accounts'][account]['uid']
|
||||||
|
|
||||||
# set image url
|
# set image url
|
||||||
if params.data[user] && !params.data[user]['image']
|
if user && !user['image']
|
||||||
params.data[user]['image'] = 'http://placehold.it/48x48'
|
user['image'] = 'http://placehold.it/48x48'
|
||||||
|
|
||||||
# set realname
|
# set realname
|
||||||
params.data[user]['realname'] = ''
|
user['realname'] = ''
|
||||||
if params.data[user]['firstname']
|
if user['firstname']
|
||||||
params.data[user]['realname'] = params.data[user]['firstname']
|
user['realname'] = user['firstname']
|
||||||
if params.data[user]['lastname']
|
if user['lastname']
|
||||||
if params.data[user]['realname'] isnt ''
|
if user['realname'] isnt ''
|
||||||
params.data[user]['realname'] = params.data[user]['realname'] + ' '
|
user['realname'] = user['realname'] + ' '
|
||||||
params.data[user]['realname'] = params.data[user]['realname'] + params.data[user]['lastname']
|
user['realname'] = user['realname'] + user['lastname']
|
||||||
|
|
||||||
App.User.refresh( params.data[user], options: { clear: true } )
|
# load in collection if needed
|
||||||
|
if !params.collection
|
||||||
|
App.User.refresh( user, options: { clear: true } )
|
||||||
|
|
||||||
# tickets
|
# tickets
|
||||||
else if params.type == 'Ticket'
|
else if params.type == 'Ticket'
|
||||||
for ticket in params.data
|
for ticket in params.data
|
||||||
|
|
||||||
|
# set human time
|
||||||
|
ticket.humanTime = @humanTime(ticket.created_at)
|
||||||
|
|
||||||
# priority
|
# priority
|
||||||
ticket.ticket_priority = App.TicketPriority.find(ticket.ticket_priority_id)
|
ticket.ticket_priority = App.TicketPriority.find(ticket.ticket_priority_id)
|
||||||
|
|
||||||
|
@ -639,8 +659,9 @@ class App.Controller extends Spine.Controller
|
||||||
user = App.User.find(ticket.owner_id)
|
user = App.User.find(ticket.owner_id)
|
||||||
ticket.owner = user
|
ticket.owner = user
|
||||||
|
|
||||||
# load collection
|
# load in collection if needed
|
||||||
App.Ticket.refresh( ticket, options: { clear: true } )
|
if !params.collection
|
||||||
|
App.Ticket.refresh( ticket, options: { clear: true } )
|
||||||
|
|
||||||
# articles
|
# articles
|
||||||
else if params.type == 'TicketArticle'
|
else if params.type == 'TicketArticle'
|
||||||
|
@ -656,7 +677,9 @@ class App.Controller extends Spine.Controller
|
||||||
article.article_type = App.TicketArticleType.find( article.ticket_article_type_id )
|
article.article_type = App.TicketArticleType.find( article.ticket_article_type_id )
|
||||||
article.article_sender = App.TicketArticleSender.find( article.ticket_article_sender_id )
|
article.article_sender = App.TicketArticleSender.find( article.ticket_article_sender_id )
|
||||||
|
|
||||||
App.TicketArticle.refresh( article, options: { clear: true } )
|
# load in collection if needed
|
||||||
|
if !params.collection
|
||||||
|
App.TicketArticle.refresh( article, options: { clear: true } )
|
||||||
|
|
||||||
# history
|
# history
|
||||||
else if params.type == 'History'
|
else if params.type == 'History'
|
||||||
|
@ -676,12 +699,20 @@ class App.Controller extends Spine.Controller
|
||||||
if histroy.history_object_id
|
if histroy.history_object_id
|
||||||
histroy.object = App.HistoryObject.find( histroy.history_object_id )
|
histroy.object = App.HistoryObject.find( histroy.history_object_id )
|
||||||
|
|
||||||
App.History.refresh( histroy, options: { clear: true } )
|
# load in collection if needed
|
||||||
|
if !params.collection
|
||||||
|
App.History.refresh( histroy, options: { clear: true } )
|
||||||
|
|
||||||
# all the rest
|
# all the rest
|
||||||
else
|
else
|
||||||
for object in params.data
|
for object in params.data
|
||||||
App[params.type].refresh( object, options: { clear: true } )
|
|
||||||
|
# load in collection if needed
|
||||||
|
if !params.collection
|
||||||
|
App[params.type].refresh( object, options: { clear: true } )
|
||||||
|
|
||||||
|
ws_send: (data) ->
|
||||||
|
Spine.trigger( 'ws:send', JSON.stringify(data) )
|
||||||
|
|
||||||
class App.ControllerModal extends App.Controller
|
class App.ControllerModal extends App.Controller
|
||||||
className: 'modal hide fade',
|
className: 'modal hide fade',
|
||||||
|
|
|
@ -10,59 +10,49 @@ class App.UserInfo extends App.Controller
|
||||||
# fetch item on demand
|
# fetch item on demand
|
||||||
fetch_needed = 1
|
fetch_needed = 1
|
||||||
if App.User.exists(@user_id)
|
if App.User.exists(@user_id)
|
||||||
@user = App.User.find(@user_id)
|
@log 'exists.user...', @user_id
|
||||||
@log 'exists', @user
|
|
||||||
fetch_needed = 0
|
fetch_needed = 0
|
||||||
@render()
|
@render(@user_id)
|
||||||
|
|
||||||
if fetch_needed
|
if fetch_needed
|
||||||
@reload(@user_id)
|
@reload(@user_id)
|
||||||
|
|
||||||
reload: (user_id) =>
|
reload: (user_id) =>
|
||||||
App.User.bind 'refresh', =>
|
App.User.bind 'refresh', =>
|
||||||
@log 'loading....', user_id
|
@log 'loading.user...', user_id
|
||||||
@user = App.User.find(user_id)
|
|
||||||
@render()
|
|
||||||
App.User.unbind 'refresh'
|
App.User.unbind 'refresh'
|
||||||
|
@render(user_id)
|
||||||
App.User.fetch( id: user_id )
|
App.User.fetch( id: user_id )
|
||||||
|
|
||||||
render: ->
|
render: (user_id) ->
|
||||||
|
|
||||||
# define links to linked accounts
|
# load user collection
|
||||||
if @user['accounts']
|
user = App.User.find(user_id)
|
||||||
for account of @user['accounts']
|
@loadCollection( type: 'User', data: { new: user }, collection: true )
|
||||||
if account == 'twitter'
|
|
||||||
@user['accounts'][account]['link'] = 'http://twitter.com/' + @user['accounts'][account]['username']
|
|
||||||
if account == 'facebook'
|
|
||||||
@user['accounts'][account]['link'] = 'https://www.facebook.com/profile.php?id=' + @user['accounts'][account]['uid']
|
|
||||||
|
|
||||||
# set default image url
|
|
||||||
if !@user.image
|
|
||||||
@user.image = 'http://placehold.it/48x48'
|
|
||||||
|
|
||||||
# get display data
|
# get display data
|
||||||
data = []
|
data = []
|
||||||
for item in App.User.configure_attributes
|
for item in App.User.configure_attributes
|
||||||
if item.name isnt 'firstname'
|
if item.name isnt 'firstname' && item.name isnt 'lastname'
|
||||||
if item.name isnt 'lastname'
|
if item.info
|
||||||
if item.info #&& ( @user[item.name] || item.name isnt 'note' )
|
data.push item
|
||||||
data.push item
|
|
||||||
|
|
||||||
# insert data
|
# insert data
|
||||||
@html App.view('user_info')(
|
@html App.view('user_info')(
|
||||||
user: @user,
|
user: App.User.find(user_id),
|
||||||
data: data,
|
data: data,
|
||||||
)
|
)
|
||||||
|
|
||||||
@userTicketPopups(
|
@userTicketPopups(
|
||||||
selector: '.user-tickets',
|
selector: '.user-tickets',
|
||||||
user_id: @user.id,
|
user_id: user_id,
|
||||||
)
|
)
|
||||||
|
|
||||||
update: (e) =>
|
update: (e) =>
|
||||||
|
|
||||||
# update changes
|
# update changes
|
||||||
note = $(e.target).parent().find('[data-type=edit]').val()
|
note = $(e.target).parent().find('[data-type=edit]').val()
|
||||||
if @user.note isnt note
|
user = App.User.find(@user_id)
|
||||||
@user.updateAttributes( note: note )
|
if user.note isnt note
|
||||||
@log 'update', e, note, @user
|
user.updateAttributes( note: note )
|
||||||
|
@log 'update', e, note, user
|
||||||
|
|
|
@ -4,10 +4,10 @@
|
||||||
<img class="thumbnail" src="<%- @user.image %>" alt="">
|
<img class="thumbnail" src="<%- @user.image %>" alt="">
|
||||||
<% end %>
|
<% end %>
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="customer-info" title="Name"><%= @user['firstname'] %></div>
|
<div class="customer-info" title="Name"><%= @user['realname'] %></div>
|
||||||
</div>
|
</div>
|
||||||
<% for row in @data: %>
|
<% for row in @data: %>
|
||||||
<% if @user[row.name]: %>
|
<% if @user[row.name] || row.name is 'note': %>
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<% if row.tag isnt 'textarea': %>
|
<% if row.tag isnt 'textarea': %>
|
||||||
<div class="customer-info" title="<%= row.display %>"><%- window.linkify( @user[row.name] ) %></div>
|
<div class="customer-info" title="<%= row.display %>"><%- window.linkify( @user[row.name] ) %></div>
|
||||||
|
|
Loading…
Reference in a new issue