Fetch tickets after new ws connection has been established.

This commit is contained in:
Martin Edenhofer 2016-09-08 08:41:04 +02:00
parent 82188f5024
commit 88487ca3d9

View file

@ -48,6 +48,11 @@ class App.TicketZoom extends App.Controller
@fetchMayBe(data) @fetchMayBe(data)
) )
# after a new websocket connection, check if ticket has changed
@bind('spool:sent', =>
@fetch()
)
fetchMayBe: (data) => fetchMayBe: (data) =>
if @ticketUpdatedAtLastCall if @ticketUpdatedAtLastCall
if new Date(data.updated_at).getTime() is new Date(@ticketUpdatedAtLastCall).getTime() if new Date(data.updated_at).getTime() is new Date(@ticketUpdatedAtLastCall).getTime()
@ -59,7 +64,7 @@ class App.TicketZoom extends App.Controller
fetchDelayed = => fetchDelayed = =>
@fetch() @fetch()
@delay(fetchDelayed, 1200, "ticket-zoom-#{@ticket_id}") @delay(fetchDelayed, 1000, "ticket-zoom-#{@ticket_id}")
fetch: => fetch: =>
return if !@Session.get() return if !@Session.get()
@ -70,6 +75,7 @@ class App.TicketZoom extends App.Controller
type: 'GET' type: 'GET'
url: "#{@apiPath}/tickets/#{@ticket_id}?all=true" url: "#{@apiPath}/tickets/#{@ticket_id}?all=true"
processData: true processData: true
queue: true
success: (data, status, xhr) => success: (data, status, xhr) =>
# check if ticket has changed # check if ticket has changed
@ -152,9 +158,6 @@ class App.TicketZoom extends App.Controller
@ticket = App.Ticket.fullLocal(@ticket_id) @ticket = App.Ticket.fullLocal(@ticket_id)
@ticket.article = undefined @ticket.article = undefined
# remember current data
@ticketUpdatedAtLastCall = @ticket.updated_at
# render page # render page
@render() @render()
@ -702,6 +705,11 @@ class App.TicketZoom extends App.Controller
data: JSON.stringify(ticket.attributes()) data: JSON.stringify(ticket.attributes())
processData: true processData: true
success: (data) => success: (data) =>
# remember current data
newTicketRaw = data.assets.Ticket[ticket.id]
@ticketUpdatedAtLastCall = newTicketRaw.updated_at
App.SessionStorage.set(@key, data) App.SessionStorage.set(@key, data)
@load(data) @load(data)