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
|
||||
list = App[attribute.relation].all()
|
||||
|
||||
# build options list
|
||||
list.forEach( (item) =>
|
||||
if item.active
|
||||
|
||||
# if active or if active doesn't exist
|
||||
if item.active || !( 'active' of item )
|
||||
name = '???'
|
||||
if item.name
|
||||
name = item.name
|
||||
|
@ -267,6 +270,9 @@ class App.Controller extends Spine.Controller
|
|||
else
|
||||
item = App.view('generic/input')( attribute: attribute )
|
||||
|
||||
if !attribute.display
|
||||
return item
|
||||
else
|
||||
return App.view('generic/attribute')(
|
||||
attribute: attribute,
|
||||
item: item,
|
||||
|
@ -600,26 +606,40 @@ class App.Controller extends Spine.Controller
|
|||
|
||||
# users
|
||||
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
|
||||
if params.data[user] && !params.data[user]['image']
|
||||
params.data[user]['image'] = 'http://placehold.it/48x48'
|
||||
if user && !user['image']
|
||||
user['image'] = 'http://placehold.it/48x48'
|
||||
|
||||
# set realname
|
||||
params.data[user]['realname'] = ''
|
||||
if params.data[user]['firstname']
|
||||
params.data[user]['realname'] = params.data[user]['firstname']
|
||||
if params.data[user]['lastname']
|
||||
if params.data[user]['realname'] isnt ''
|
||||
params.data[user]['realname'] = params.data[user]['realname'] + ' '
|
||||
params.data[user]['realname'] = params.data[user]['realname'] + params.data[user]['lastname']
|
||||
user['realname'] = ''
|
||||
if user['firstname']
|
||||
user['realname'] = user['firstname']
|
||||
if user['lastname']
|
||||
if user['realname'] isnt ''
|
||||
user['realname'] = user['realname'] + ' '
|
||||
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
|
||||
else if params.type == 'Ticket'
|
||||
for ticket in params.data
|
||||
|
||||
# set human time
|
||||
ticket.humanTime = @humanTime(ticket.created_at)
|
||||
|
||||
# priority
|
||||
ticket.ticket_priority = App.TicketPriority.find(ticket.ticket_priority_id)
|
||||
|
||||
|
@ -639,7 +659,8 @@ class App.Controller extends Spine.Controller
|
|||
user = App.User.find(ticket.owner_id)
|
||||
ticket.owner = user
|
||||
|
||||
# load collection
|
||||
# load in collection if needed
|
||||
if !params.collection
|
||||
App.Ticket.refresh( ticket, options: { clear: true } )
|
||||
|
||||
# articles
|
||||
|
@ -656,6 +677,8 @@ class App.Controller extends Spine.Controller
|
|||
article.article_type = App.TicketArticleType.find( article.ticket_article_type_id )
|
||||
article.article_sender = App.TicketArticleSender.find( article.ticket_article_sender_id )
|
||||
|
||||
# load in collection if needed
|
||||
if !params.collection
|
||||
App.TicketArticle.refresh( article, options: { clear: true } )
|
||||
|
||||
# history
|
||||
|
@ -676,13 +699,21 @@ class App.Controller extends Spine.Controller
|
|||
if histroy.history_object_id
|
||||
histroy.object = App.HistoryObject.find( histroy.history_object_id )
|
||||
|
||||
# load in collection if needed
|
||||
if !params.collection
|
||||
App.History.refresh( histroy, options: { clear: true } )
|
||||
|
||||
# all the rest
|
||||
else
|
||||
for object in params.data
|
||||
|
||||
# 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
|
||||
className: 'modal hide fade',
|
||||
tag: 'div',
|
||||
|
|
|
@ -10,59 +10,49 @@ class App.UserInfo extends App.Controller
|
|||
# fetch item on demand
|
||||
fetch_needed = 1
|
||||
if App.User.exists(@user_id)
|
||||
@user = App.User.find(@user_id)
|
||||
@log 'exists', @user
|
||||
@log 'exists.user...', @user_id
|
||||
fetch_needed = 0
|
||||
@render()
|
||||
@render(@user_id)
|
||||
|
||||
if fetch_needed
|
||||
@reload(@user_id)
|
||||
|
||||
reload: (user_id) =>
|
||||
App.User.bind 'refresh', =>
|
||||
@log 'loading....', user_id
|
||||
@user = App.User.find(user_id)
|
||||
@render()
|
||||
@log 'loading.user...', user_id
|
||||
App.User.unbind 'refresh'
|
||||
@render(user_id)
|
||||
App.User.fetch( id: user_id )
|
||||
|
||||
render: ->
|
||||
render: (user_id) ->
|
||||
|
||||
# define links to linked accounts
|
||||
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 default image url
|
||||
if !@user.image
|
||||
@user.image = 'http://placehold.it/48x48'
|
||||
# load user collection
|
||||
user = App.User.find(user_id)
|
||||
@loadCollection( type: 'User', data: { new: user }, collection: true )
|
||||
|
||||
# get display data
|
||||
data = []
|
||||
for item in App.User.configure_attributes
|
||||
if item.name isnt 'firstname'
|
||||
if item.name isnt 'lastname'
|
||||
if item.info #&& ( @user[item.name] || item.name isnt 'note' )
|
||||
if item.name isnt 'firstname' && item.name isnt 'lastname'
|
||||
if item.info
|
||||
data.push item
|
||||
|
||||
# insert data
|
||||
@html App.view('user_info')(
|
||||
user: @user,
|
||||
user: App.User.find(user_id),
|
||||
data: data,
|
||||
)
|
||||
|
||||
@userTicketPopups(
|
||||
selector: '.user-tickets',
|
||||
user_id: @user.id,
|
||||
user_id: user_id,
|
||||
)
|
||||
|
||||
update: (e) =>
|
||||
|
||||
# update changes
|
||||
note = $(e.target).parent().find('[data-type=edit]').val()
|
||||
if @user.note isnt note
|
||||
@user.updateAttributes( note: note )
|
||||
@log 'update', e, note, @user
|
||||
user = App.User.find(@user_id)
|
||||
if user.note isnt note
|
||||
user.updateAttributes( note: note )
|
||||
@log 'update', e, note, user
|
||||
|
|
|
@ -4,10 +4,10 @@
|
|||
<img class="thumbnail" src="<%- @user.image %>" alt="">
|
||||
<% end %>
|
||||
<div class="row">
|
||||
<div class="customer-info" title="Name"><%= @user['firstname'] %></div>
|
||||
<div class="customer-info" title="Name"><%= @user['realname'] %></div>
|
||||
</div>
|
||||
<% for row in @data: %>
|
||||
<% if @user[row.name]: %>
|
||||
<% if @user[row.name] || row.name is 'note': %>
|
||||
<div class="row">
|
||||
<% if row.tag isnt 'textarea': %>
|
||||
<div class="customer-info" title="<%= row.display %>"><%- window.linkify( @user[row.name] ) %></div>
|
||||
|
|
Loading…
Reference in a new issue