Improved userTicketPopups feature.

This commit is contained in:
Martin Edenhofer 2014-04-03 15:25:33 +02:00
parent f023a34d76
commit 8db7b51c32

View file

@ -385,23 +385,12 @@ class App.Controller extends Spine.Controller
)
)
userTicketPopups: (data) ->
userTicketPopups: (params) ->
# remove old popovers
$('.popover').remove()
# get data
tickets = {}
App.Ajax.request(
type: 'GET',
url: @Config.get('api_path') + '/ticket_customer',
data: {
customer_id: data.user_id,
}
processData: true,
success: (data, status, xhr) =>
tickets = data.tickets
)
show = (data, tickets) =>
if !data.position
data.position = 'left'
@ -431,6 +420,32 @@ class App.Controller extends Spine.Controller
)
)
fetch = (params) =>
@ajax(
type: 'GET',
url: @Config.get('api_path') + '/ticket_customer',
data: {
customer_id: params.user_id,
}
processData: true,
success: (data, status, xhr) =>
App.Store.write( "user-ticket-popover::#{params.user_id}", data.tickets )
show( params, data.tickets )
)
# get data
tickets = App.Store.get( "user-ticket-popover::#{params.user_id}" )
if tickets
show( params, tickets )
@delay(
=>
fetch(params)
1000
'fetch'
)
else
fetch(params)
ws_send: (data) ->
App.Event.trigger( 'ws:send', JSON.stringify(data) )