Added new Model.fullLocal() to get local full data of object.

This commit is contained in:
Martin Edenhofer 2014-08-13 10:31:50 +02:00
parent 8bb4a842a2
commit 261c9e3214
21 changed files with 116 additions and 74 deletions

View file

@ -294,11 +294,11 @@ class App.Controller extends Spine.Controller
placement: position placement: position
title: -> title: ->
ticket_id = $(@).data('id') ticket_id = $(@).data('id')
ticket = App.Ticket.retrieve( ticket_id ) ticket = App.Ticket.fullLocal( ticket_id )
App.i18n.escape( ticket.title ) App.i18n.escape( ticket.title )
content: -> content: ->
ticket_id = $(@).data('id') ticket_id = $(@).data('id')
ticket = App.Ticket.retrieve( ticket_id ) ticket = App.Ticket.fullLocal( ticket_id )
ticket.humanTime = ui.humanTime(ticket.created_at) ticket.humanTime = ui.humanTime(ticket.created_at)
# insert data # insert data
App.view('popover/ticket')( App.view('popover/ticket')(
@ -328,11 +328,11 @@ class App.Controller extends Spine.Controller
placement: position placement: position
title: -> title: ->
user_id = $(@).data('id') user_id = $(@).data('id')
user = App.User.find( user_id ) user = App.User.fullLocal( user_id )
App.i18n.escape( user.displayName() ) App.i18n.escape( user.displayName() )
content: -> content: ->
user_id = $(@).data('id') user_id = $(@).data('id')
user = App.User.retrieve( user_id ) user = App.User.fullLocal( user_id )
# get display data # get display data
data = [] data = []
@ -374,11 +374,11 @@ class App.Controller extends Spine.Controller
placement: position placement: position
title: -> title: ->
organization_id = $(@).data('id') organization_id = $(@).data('id')
organization = App.Organization.find( organization_id ) organization = App.Organization.fullLocal( organization_id )
App.i18n.escape( organization.name ) App.i18n.escape( organization.name )
content: -> content: ->
organization_id = $(@).data('id') organization_id = $(@).data('id')
organization = App.Organization.retrieve( organization_id ) organization = App.Organization.fullLocal( organization_id )
# insert data # insert data
App.view('popover/organization')( App.view('popover/organization')(
organization: organization, organization: organization,
@ -593,3 +593,31 @@ class App.SessionMessage extends App.ControllerModal
throw "Cant reload page!" throw "Cant reload page!"
class App.UpdateHeader extends App.Controller
constructor: ->
super
# subscribe and reload data / fetch new data if triggered
@subscribeId = @genericObject.subscribe( @render )
release: =>
App[ @genericObject.constructor.className ].unsubscribe(@subscribeId)
render: (genericObject) =>
@el.find( '.page-header h1' ).html( genericObject.displayName() )
class App.UpdateTastbar extends App.Controller
constructor: ->
super
# subscribe and reload data / fetch new data if triggered
@subscribeId = @genericObject.subscribe( @update )
release: =>
App[ @genericObject.constructor.className ].unsubscribe(@subscribeId)
update: (genericObject) =>
# update taskbar with new meta data
App.Event.trigger 'task:render'

View file

@ -37,7 +37,7 @@ class App.ControllerGenericNew extends App.ControllerModal
object.save( object.save(
done: -> done: ->
if ui.callback if ui.callback
item = App[ ui.genericObject ].retrieve(@id) item = App[ ui.genericObject ].fullLocal(@id)
ui.callback( item ) ui.callback( item )
ui.modalHide() ui.modalHide()
@ -84,7 +84,7 @@ class App.ControllerGenericEdit extends App.ControllerModal
@item.save( @item.save(
done: -> done: ->
if ui.callback if ui.callback
item = App[ ui.genericObject ].retrieve(@id) item = App[ ui.genericObject ].fullLocal(@id)
ui.callback( item ) ui.callback( item )
ui.modalHide() ui.modalHide()

View file

@ -90,10 +90,10 @@ class App.DashboardTicket extends App.Controller
while i < end while i < end
i = i + 1 i = i + 1
if @ticket_ids[ i - 1 ] if @ticket_ids[ i - 1 ]
@tickets_in_table.push App.Ticket.retrieve( @ticket_ids[ i - 1 ] ) @tickets_in_table.push App.Ticket.fullLocal( @ticket_ids[ i - 1 ] )
openTicket = (id,e) => openTicket = (id,e) =>
ticket = App.Ticket.retrieve(id) ticket = App.Ticket.fullLocal(id)
@navigate ticket.uiUrl() @navigate ticket.uiUrl()
callbackTicketTitleAdd = (value, object, attribute, attributes, refObject) => callbackTicketTitleAdd = (value, object, attribute, attributes, refObject) =>
attribute.title = object.title attribute.title = object.title

View file

@ -45,7 +45,7 @@ class Index extends App.Controller
) )
success: (data, status, xhr) => success: (data, status, xhr) =>
App.User.retrieve( App.User.full(
App.Session.get( 'id' ), App.Session.get( 'id' ),
=> =>
App.i18n.set( @locale ) App.i18n.set( @locale )

View file

@ -369,7 +369,7 @@ class UserNew extends App.ControllerModal
# start customer info controller # start customer info controller
ui.userInfo( user_id: user.id ) ui.userInfo( user_id: user.id )
ui.modalHide() ui.modalHide()
App.User.retrieve( @id, callbackReload , true ) App.User.full( @id, callbackReload , true )
fail: -> fail: ->
ui.modalHide() ui.modalHide()

View file

@ -29,7 +29,7 @@ class App.TicketMerge extends App.ControllerModal
list = [] list = []
for ticket_id in @ticket_ids_by_customer for ticket_id in @ticket_ids_by_customer
if ticket_id isnt @ticket.id if ticket_id isnt @ticket.id
ticketItem = App.Ticket.retrieve( ticket_id ) ticketItem = App.Ticket.fullLocal( ticket_id )
list.push ticketItem list.push ticketItem
new App.ControllerTable( new App.ControllerTable(
el: @el.find('#ticket-merge-customer-tickets'), el: @el.find('#ticket-merge-customer-tickets'),
@ -42,7 +42,7 @@ class App.TicketMerge extends App.ControllerModal
list = [] list = []
for ticket_id in @ticket_ids_recent_viewed for ticket_id in @ticket_ids_recent_viewed
if ticket_id isnt @ticket.id if ticket_id isnt @ticket.id
ticketItem = App.Ticket.retrieve( ticket_id ) ticketItem = App.Ticket.fullLocal( ticket_id )
list.push ticketItem list.push ticketItem
new App.ControllerTable( new App.ControllerTable(
el: @el.find('#ticket-merge-recent-tickets'), el: @el.find('#ticket-merge-recent-tickets'),
@ -59,7 +59,7 @@ class App.TicketMerge extends App.ControllerModal
@el.delegate('[name="radio"]', 'click', (e) -> @el.delegate('[name="radio"]', 'click', (e) ->
if $(e.target).prop('checked') if $(e.target).prop('checked')
ticket_id = $(e.target).val() ticket_id = $(e.target).val()
ticket = App.Ticket.retrieve( ticket_id ) ticket = App.Ticket.fullLocal( ticket_id )
$(e.target).parents().find('[name="master_ticket_number"]').val( ticket.number ) $(e.target).parents().find('[name="master_ticket_number"]').val( ticket.number )
) )

View file

@ -7,19 +7,17 @@ class App.OrganizationZoom extends App.Controller
@navupdate '#' @navupdate '#'
# subscribe and reload data / fetch new data if triggered App.Organization.full( @organization_id, @render )
@subscribeId = App.Organization.full( @organization_id, @render, false, true )
release: =>
App.Organization.unsubscribe(@subscribeId)
meta: => meta: =>
meta = meta =
url: @url() url: @url()
id: @organization_id id: @organization_id
if @organization
meta.head = @organization.displayName() organization = App.Organization.find( @organization_id )
meta.title = @organization.displayName() if organization
meta.head = organization.displayName()
meta.title = organization.displayName()
meta meta
url: => url: =>
@ -35,25 +33,30 @@ class App.OrganizationZoom extends App.Controller
return true return true
render: (organization) => render: (organization) =>
@organization = organization
# update taskbar with new meta data
App.Event.trigger 'task:render'
@html App.view('organization_zoom')( @html App.view('organization_zoom')(
organization: @organization organization: organization
)
new App.UpdateTastbar(
genericObject: organization
)
new App.UpdateHeader(
el: @el
genericObject: organization
) )
# start action controller # start action controller
new ActionRow( new ActionRow(
el: @el.find('.action') el: @el.find('.action')
organization: @organization organization: organization
ui: @ ui: @
) )
new Widgets( new Widgets(
el: @el.find('.widgets') el: @el.find('.widgets')
organization: @organization organization: organization
ui: @ ui: @
) )

View file

@ -38,4 +38,4 @@ class App.TicketCustomer extends App.ControllerModal
) )
# load user if not already exists # load user if not already exists
App.User.retrieve( @customer_id, callback ) App.User.full( @customer_id, callback )

View file

@ -109,7 +109,7 @@ class Table extends App.ControllerContent
@ticket_list_show = [] @ticket_list_show = []
for ticket_id in @ticket_ids for ticket_id in @ticket_ids
@ticket_list_show.push App.Ticket.retrieve( ticket_id ) @ticket_list_show.push App.Ticket.fullLocal( ticket_id )
# remeber bulk attributes # remeber bulk attributes
@bulk = data.bulk @bulk = data.bulk
@ -185,7 +185,7 @@ class Table extends App.ControllerContent
@el.find('.table-overview').append(table) @el.find('.table-overview').append(table)
else else
openTicket = (id,e) => openTicket = (id,e) =>
ticket = App.Ticket.retrieve(id) ticket = App.Ticket.fullLocal(id)
@navigate ticket.uiUrl() @navigate ticket.uiUrl()
callbackTicketTitleAdd = (value, object, attribute, attributes, refObject) => callbackTicketTitleAdd = (value, object, attribute, attributes, refObject) =>
attribute.title = object.title attribute.title = object.title

View file

@ -38,7 +38,7 @@ class App.TicketZoom extends App.Controller
url: @url() url: @url()
id: @ticket_id id: @ticket_id
if @ticket if @ticket
@ticket = App.Ticket.retrieve( @ticket.id ) @ticket = App.Ticket.fullLocal( @ticket.id )
meta.head = @ticket.title meta.head = @ticket.title
meta.title = '#' + @ticket.number + ' - ' + @ticket.title meta.title = '#' + @ticket.number + ' - ' + @ticket.title
meta meta
@ -118,7 +118,7 @@ class App.TicketZoom extends App.Controller
App.Collection.loadAssets( data.assets ) App.Collection.loadAssets( data.assets )
# get data # get data
@ticket = App.Ticket.retrieve( @ticket_id ) @ticket = App.Ticket.fullLocal( @ticket_id )
# render page # render page
@render(force) @render(force)
@ -217,7 +217,7 @@ class TicketTitle extends App.Controller
constructor: -> constructor: ->
super super
@ticket = App.Ticket.retrieve( @ticket.id ) @ticket = App.Ticket.fullLocal( @ticket.id )
@subscribeId = @ticket.subscribe(@render) @subscribeId = @ticket.subscribe(@render)
@render(@ticket) @render(@ticket)
@ -327,7 +327,7 @@ class Edit extends App.Controller
render: -> render: ->
ticket = App.Ticket.retrieve( @ticket.id ) ticket = App.Ticket.fullLocal( @ticket.id )
@html App.view('ticket_zoom/edit')( @html App.view('ticket_zoom/edit')(
ticket: ticket ticket: ticket
@ -444,7 +444,7 @@ class Edit extends App.Controller
@autosaveStop() @autosaveStop()
params = @formParam(e.target) params = @formParam(e.target)
ticket = App.Ticket.retrieve( @ticket.id ) ticket = App.Ticket.fullLocal( @ticket.id )
@log 'notice', 'update', params, ticket @log 'notice', 'update', params, ticket
@ -574,7 +574,7 @@ class ArticleView extends App.Controller
# get all articles # get all articles
@articles = [] @articles = []
for article_id in @ticket_article_ids for article_id in @ticket_article_ids
article = App.TicketArticle.retrieve( article_id ) article = App.TicketArticle.fullLocal( article_id )
@articles.push article @articles.push article
# rework articles # rework articles

View file

@ -7,20 +7,17 @@ class App.UserZoom extends App.Controller
@navupdate '#' @navupdate '#'
# subscribe and reload data / fetch new data if triggered App.User.full( @user_id, @render )
@subscribeId = App.User.full( @user_id, @render, false, true )
release: =>
App.User.unsubscribe(@subscribeId)
meta: => meta: =>
meta = meta =
url: @url() url: @url()
id: @user_id id: @user_id
if @user
meta.head = @user.displayName() user = App.User.find( @user_id )
meta.title = @user.displayName() if user
meta.head = user.displayName()
meta.title = user.displayName()
meta meta
url: => url: =>
@ -36,29 +33,33 @@ class App.UserZoom extends App.Controller
return true return true
render: (user) => render: (user) =>
@user = user
# update taskbar with new meta data
App.Event.trigger 'task:render'
@html App.view('user_zoom')( @html App.view('user_zoom')(
user: @user user: user
)
new App.UpdateTastbar(
genericObject: user
)
new App.UpdateHeader(
el: @el
genericObject: user
) )
# start action controller # start action controller
new ActionRow( new ActionRow(
el: @el.find('.action') el: @el.find('.action')
user: @user user: user
ui: @ ui: @
) )
new Widgets( new Widgets(
el: @el.find('.widgets') el: @el.find('.widgets')
user: @user user: user
ui: @ ui: @
) )
class Widgets extends App.Controller class Widgets extends App.Controller
constructor: -> constructor: ->
super super

View file

@ -40,7 +40,7 @@ class App.WidgetLink extends App.ControllerDrox
list[ item['link_type'] ] = [] list[ item['link_type'] ] = []
if item['link_object'] is 'Ticket' if item['link_object'] is 'Ticket'
ticket = App.Ticket.retrieve( item['link_object_value'] ) ticket = App.Ticket.fullLocal( item['link_object_value'] )
if ticket.state.name is 'merged' if ticket.state.name is 'merged'
ticket.css = 'merged' ticket.css = 'merged'
list[ item['link_type'] ].push ticket list[ item['link_type'] ].push ticket

View file

@ -88,7 +88,7 @@ class App.Auth
App.Collection.loadAssets( data.assets ) App.Collection.loadAssets( data.assets )
# store user data # store user data
session = App.User.retrieve(data.session.id) session = App.User.fullLocal(data.session.id)
for key, value of session for key, value of session
App.Session.set( key, value ) App.Session.set( key, value )

View file

@ -117,6 +117,9 @@ class App.Model extends Spine.Model
return true if @id[0] isnt 'c' return true if @id[0] isnt 'c'
return false return false
@fullLocal: (id) ->
@_fillUp( App[ @className ].find( id ) )
@full: (id, callback = false, force = false, bind = false) -> @full: (id, callback = false, force = false, bind = false) ->
url = "#{@url}/#{id}?full=true" url = "#{@url}/#{id}?full=true"
console.log('FULL', id, url, bind) console.log('FULL', id, url, bind)
@ -282,9 +285,11 @@ class App.Model extends Spine.Model
# remember record id and callback # remember record id and callback
App[ @constructor.className ].subscribe_item(@id, callback) App[ @constructor.className ].subscribe_item(@id, callback)
@_subscribe_bind: -> @subscribe_item: (id, callback) ->
if !@_bindDone
@_bindDone = true # init bind
if !@_subscribe_item_bindDone
@_subscribe_item_bindDone = true
# subscribe and render data after local change # subscribe and render data after local change
@bind( @bind(
@ -307,14 +312,19 @@ class App.Model extends Spine.Model
events events
(item) => (item) =>
if @SUBSCRIPTION_ITEM && @SUBSCRIPTION_ITEM[ item.id ] if @SUBSCRIPTION_ITEM && @SUBSCRIPTION_ITEM[ item.id ]
@full( item.id, false, true ) genericObject = undefined
if App[ @className ].exists( item.id )
genericObject = App[ @className ].find( item.id )
callback = =>
if !genericObject || ( new Date(item.updated_at).toString() isnt new Date(genericObject.updated_at).toString() )
@full( item.id, false, true )
App.Delay.set(callback, 800, item.id, "full-#{@className}")
'Item::Subscribe::' + @className 'Item::Subscribe::' + @className
) )
@subscribe_item: (id, callback) ->
# init bind
@_subscribe_bind()
# remember item callback # remember item callback
if !@SUBSCRIPTION_ITEM if !@SUBSCRIPTION_ITEM
@SUBSCRIPTION_ITEM = {} @SUBSCRIPTION_ITEM = {}

View file

@ -44,7 +44,7 @@ class App.User extends App.Model
data['accounts'][account]['link'] = 'https://www.facebook.com/profile.php?id=' + data['accounts'][account]['uid'] data['accounts'][account]['link'] = 'https://www.facebook.com/profile.php?id=' + data['accounts'][account]['uid']
# set image url # set image url
data.image = @apiPath + '/users/image/' + data.image data.imageUrl = @apiPath + '/users/image/' + data.image
if data.organization_id if data.organization_id
data.organization = App.Organization.find(data.organization_id) data.organization = App.Organization.find(data.organization_id)

View file

@ -11,7 +11,7 @@
<input type="checkbox" value="<%= ticket.id %>" name="bulk" class="pull-left"/> <input type="checkbox" value="<%= ticket.id %>" name="bulk" class="pull-left"/>
</td> </td>
<td class="span1"> <td class="span1">
<img class="thumbnail user-popover" data-id="<%= ticket.customer_id %>" src="<%= ticket.customer.image %>" alt=""> <img class="thumbnail user-popover" data-id="<%= ticket.customer_id %>" src="<%= ticket.customer.imageUrl %>" alt="">
</td> </td>
<td class="span10"> <td class="span10">
<h3><a href="#" data-type="edit"><%= ticket.title %></a> <small><%= ticket.number %> <span class="humanTimeFromNow" data-time="<%= ticket.created_at %>">?</span></small></h3> <h3><a href="#" data-type="edit"><%= ticket.title %></a> <small><%= ticket.number %> <span class="humanTimeFromNow" data-time="<%= ticket.created_at %>">?</span></small></h3>

View file

@ -6,7 +6,7 @@
<div class="main"> <div class="main">
<div class="page-header"> <div class="page-header">
<h1><%= @organization.displayName() %></h1> <h1></h1>
</div> </div>
<div class="ticket-answer"> <div class="ticket-answer">

View file

@ -2,7 +2,7 @@
<% for article in @articles: %> <% for article in @articles: %>
<div class="ticket-article ticket-article-item <% if article.internal is true: %> internal<% end %>" data-id="<%= article.id %>" id="article-<%= article.id %>"> <div class="ticket-article ticket-article-item <% if article.internal is true: %> internal<% end %>" data-id="<%= article.id %>" id="article-<%= article.id %>">
<div class="avatar"> <div class="avatar">
<img class="thumbnail user-popover" data-id="<%= article.created_by_id %>" src="<%= article.created_by.image %>" alt=""> <img class="thumbnail user-popover" data-id="<%= article.created_by_id %>" src="<%= article.created_by.imageUrl %>" alt="">
<ul> <ul>
<li style="font-size: 10px;"><%- @T(article.type.name) %></li> <li style="font-size: 10px;"><%- @T(article.type.name) %></li>
<% if article.type.name is 'email': %><li style="font-size: 10px;"><a href="<%= App.Config.get('api_path') %>/ticket_article_plain/<%= article.id %>"><%- @T( 'raw' ) %></a></li><% end %> <% if article.type.name is 'email': %><li style="font-size: 10px;"><a href="<%= App.Config.get('api_path') %>/ticket_article_plain/<%= article.id %>"><%- @T( 'raw' ) %></a></li><% end %>

View file

@ -1,7 +1,7 @@
<div class="ticket-article-view"> <div class="ticket-article-view">
<div class="ticket-article well ticket-edit <% if @formChanged: %>form-changed<% end %>"> <div class="ticket-article well ticket-edit <% if @formChanged: %>form-changed<% end %>">
<div class="avatar"> <div class="avatar">
<img class="thumbnail user-popover" data-id="<%= @S('id') %>" src="<%- @S('image') %>" alt=""> <img class="thumbnail user-popover" data-id="<%= @S('id') %>" src="<%- @S('imageUrl') %>" alt="">
</div> </div>
<div class="ticket-article-message"> <div class="ticket-article-message">
<div class="edit-title"> <div class="edit-title">

View file

@ -6,7 +6,7 @@
<div class="main"> <div class="main">
<div class="page-header"> <div class="page-header">
<h1><%= @user.displayName() %></h1> <h1></h1>
</div> </div>
<div class="ticket-answer"> <div class="ticket-answer">

View file

@ -1,7 +1,7 @@
<div class="user-info"> <div class="user-info">
<% if @user.image: %> <% if @user.imageUrl: %>
<img class="thumbnail" src="<%- @user.image %>" alt=""> <img class="thumbnail" src="<%- @user.imageUrl %>" alt="">
<% end %> <% end %>
<div class="customer-info" title="<%- @Ti( 'Name') %>"><%= @user.displayName() %></div> <div class="customer-info" title="<%- @Ti( 'Name') %>"><%= @user.displayName() %></div>
<% for row in @userData: %> <% for row in @userData: %>