diff --git a/app/assets/javascripts/app/controllers/_application_controller.coffee b/app/assets/javascripts/app/controllers/_application_controller.coffee index 176173dc3..e695c369e 100644 --- a/app/assets/javascripts/app/controllers/_application_controller.coffee +++ b/app/assets/javascripts/app/controllers/_application_controller.coffee @@ -546,6 +546,15 @@ class App.Controller extends Spine.Controller return if !@initLoadingDoneDelay @clearDelay(@initLoadingDoneDelay) + renderScreenError: (data) -> + @html App.view('generic/error/generic')(data) + + renderScreenNotFound: (data) -> + @html App.view('generic/error/not_found')(data) + + renderScreenUnauthorized: (data) -> + @html App.view('generic/error/unauthorized')(data) + class App.ControllerPermanent extends App.Controller constructor: -> super diff --git a/app/assets/javascripts/app/controllers/chat.coffee b/app/assets/javascripts/app/controllers/chat.coffee index a26cbd98f..7bd2133c1 100644 --- a/app/assets/javascripts/app/controllers/chat.coffee +++ b/app/assets/javascripts/app/controllers/chat.coffee @@ -10,11 +10,17 @@ class App.CustomerChat extends App.Controller constructor: -> super - return if !@isRole('Chat') + # access check + if !@isRole('Chat') + @renderScreenUnauthorized(objectName: 'Chat') + return + if !@Config.get('chat') + @renderScreenError(detail: 'Feature disabled!') + return @chatWindows = {} @maxChats = 4 - + @pushStateStarted = false @messageCounter = 0 @meta = active: false @@ -26,21 +32,28 @@ class App.CustomerChat extends App.Controller @on 'layout-has-changed', @propagateLayoutChange + # update navbar on new status @bind( 'chat_status_agent' (data) => @meta = data @updateMeta() - @interval(@pushState, 20000, 'pushState') + if !@pushStateStarted + @pushStateStarted = true + @interval(@pushState, 30000, 'pushState') ) + + # add new chat window @bind( 'chat_session_start' (data) => if data.session @addChat(data.session) ) + + # on new login or on @bind( - 'ws:login' + 'ws:login chat_agent_state' -> App.WebSocket.send(event:'chat_status_agent') ) diff --git a/app/assets/javascripts/app/controllers/ticket_zoom.coffee b/app/assets/javascripts/app/controllers/ticket_zoom.coffee index aaeb4cc7d..e9a6cb1e1 100644 --- a/app/assets/javascripts/app/controllers/ticket_zoom.coffee +++ b/app/assets/javascripts/app/controllers/ticket_zoom.coffee @@ -201,18 +201,18 @@ class App.TicketZoom extends App.Controller if status is 401 || statusText is 'Unauthorized' @taskHead = '» ' + App.i18n.translateInline('Unauthorized') + ' «' @taskIconClass = 'diagonal-cross' - @html App.view('generic/error/unauthorized')( objectName: 'Ticket' ) + @renderScreenUnauthorized(objectName: 'Ticket') else if status is 404 || statusText is 'Not Found' @taskHead = '» ' + App.i18n.translateInline('Not Found') + ' «' @taskIconClass = 'diagonal-cross' - @html App.view('generic/error/not_found')( objectName: 'Ticket' ) + @renderScreenNotFound(objectName: 'Ticket') else @taskHead = '» ' + App.i18n.translateInline('Error') + ' «' @taskIconClass = 'diagonal-cross' if !detail detail = 'General communication error, maybe internet is not available!' - @html App.view('generic/error/generic')( + @renderScreenError( status: status detail: detail objectName: 'Ticket' diff --git a/app/assets/javascripts/app/views/generic/error/generic.jst.eco b/app/assets/javascripts/app/views/generic/error/generic.jst.eco index 180360653..1a97ed816 100644 --- a/app/assets/javascripts/app/views/generic/error/generic.jst.eco +++ b/app/assets/javascripts/app/views/generic/error/generic.jst.eco @@ -1,4 +1,4 @@
<%- @Icon('diagonal-cross', 'icon-error') %> -

<%- @T('Status Code') %>: <%= @status %>. <%= @detail %>

+

<% if @status isnt undefined: %><%- @T('Status Code') %>: <%= @status %>. <% end %><%= @detail %>

\ No newline at end of file diff --git a/lib/sessions/event/chat_agent_state.rb b/lib/sessions/event/chat_agent_state.rb index a201b9c92..4edc40b61 100644 --- a/lib/sessions/event/chat_agent_state.rb +++ b/lib/sessions/event/chat_agent_state.rb @@ -17,6 +17,9 @@ class Sessions::Event::ChatAgentState < Sessions::Event::ChatBase Chat::Agent.state(@session['id'], @data['data']['active']) + # broadcast new state to agents + broadcast_agent_state_update(@session['id']) + { event: 'chat_agent_state', data: { diff --git a/lib/sessions/event/chat_base.rb b/lib/sessions/event/chat_base.rb index cdd9f0587..f630fa893 100644 --- a/lib/sessions/event/chat_base.rb +++ b/lib/sessions/event/chat_base.rb @@ -22,10 +22,11 @@ class Sessions::Event::ChatBase false end - def broadcast_agent_state_update + def broadcast_agent_state_update(ignore_user_id = nil) # send broadcast to agents Chat::Agent.where(active: true).each {|item| + next if item.updated_by_id == ignore_user_id data = { event: 'chat_status_agent', data: Chat.agent_state(item.updated_by_id),