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,51 +385,66 @@ class App.Controller extends Spine.Controller
) )
) )
userTicketPopups: (data) -> userTicketPopups: (params) ->
# remove old popovers # remove old popovers
$('.popover').remove() $('.popover').remove()
show = (data, tickets) =>
if !data.position
data.position = 'left'
# show user popup
controller = @
@el.find(data.selector).popover(
trigger: 'hover'
container: 'body'
html: true
delay: { show: 500, hide: 5200 }
placement: data.position
title: ->
$(@).find('[title="*"]').val()
content: ->
type = $(@).filter('[data-type]').data('type')
data = tickets[type] || []
# set human time
for ticket in data
ticket.humanTime = controller.humanTime(ticket.created_at)
# insert data
App.view('popover/user_ticket_list')(
tickets: data,
)
)
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 # get data
tickets = {} tickets = App.Store.get( "user-ticket-popover::#{params.user_id}" )
App.Ajax.request( if tickets
type: 'GET', show( params, tickets )
url: @Config.get('api_path') + '/ticket_customer', @delay(
data: { =>
customer_id: data.user_id, fetch(params)
} 1000
processData: true, 'fetch'
success: (data, status, xhr) => )
tickets = data.tickets else
) fetch(params)
if !data.position
data.position = 'left'
# show user popup
controller = @
@el.find(data.selector).popover(
trigger: 'hover'
container: 'body'
html: true
delay: { show: 500, hide: 5200 }
placement: data.position
title: ->
$(@).find('[title="*"]').val()
content: ->
type = $(@).filter('[data-type]').data('type')
data = tickets[type] || []
# set human time
for ticket in data
ticket.humanTime = controller.humanTime(ticket.created_at)
# insert data
App.view('popover/user_ticket_list')(
tickets: data,
)
)
ws_send: (data) -> ws_send: (data) ->
App.Event.trigger( 'ws:send', JSON.stringify(data) ) App.Event.trigger( 'ws:send', JSON.stringify(data) )