diff --git a/app/assets/javascripts/app/controllers/_application_controller.coffee b/app/assets/javascripts/app/controllers/_application_controller.coffee index 044669b66..55c753ccf 100644 --- a/app/assets/javascripts/app/controllers/_application_controller.coffee +++ b/app/assets/javascripts/app/controllers/_application_controller.coffee @@ -100,7 +100,7 @@ class App.Controller extends Spine.Controller disconnectClient: -> App.Delay.reset() App.Interval.reset() - App.WebSocket.close( force: true ) + App.WebSocket.close(force: true) # add @notify methode to create notification notify: (data) -> @@ -574,6 +574,22 @@ class App.Controller extends Spine.Controller e.currentTarget.focus() e.currentTarget.select() + windowReload: (e,url) -> + if e + e.preventDefault() + $('#app').hide().attr('style', 'display: none!important') + if url + window.location = url + return true + if window.location.reload + window.location.reload() + return true + if window.location.href + window.location.href = window.location.href + return true + + throw 'Cant reload page!' + class App.ControllerPermanent extends App.Controller constructor: -> super @@ -726,31 +742,18 @@ class App.ControllerModal extends App.Controller class App.SessionMessage extends App.ControllerModal onCancel: (e) => if @forceReload - @reload(e) + @windowReload(e) onClose: (e) => if @forceReload - @reload(e) + @windowReload(e) onSubmit: (e) => if @forceReload - @reload(e) + @windowReload(e) else @close() - reload: (e) -> - if e - e.preventDefault() - $('#app').hide().attr('style', 'display: none!important') - if window.location.reload - window.location.reload() - return true - if window.location.href - window.location.href = window.location.href - return true - - throw 'Cant reload page!' - class App.UpdateHeader extends App.Controller constructor: -> super diff --git a/app/assets/javascripts/app/controllers/users.coffee b/app/assets/javascripts/app/controllers/users.coffee index 509174dca..bb5301e4e 100644 --- a/app/assets/javascripts/app/controllers/users.coffee +++ b/app/assets/javascripts/app/controllers/users.coffee @@ -76,10 +76,17 @@ class Index extends App.Controller @disconnectClient() $('#app').hide().attr('style', 'display: none!important') @delay( - -> + => App.Auth._logout() - window.location = App.Config.get('api_path') + '/sessions/switch/' + id - 1200 + @ajax( + id: 'user_switch' + type: 'GET' + url: "#{@apiPath}/sessions/switch/#{id}" + success: (data, status, xhr) => + location = "#{window.location.protocol}//#{window.location.host}#{data.location}" + @windowReload(undefined, location) + ) + 800 ) edit = (id, e) => diff --git a/app/assets/javascripts/app/controllers/widget/switch_back_to_user.coffee b/app/assets/javascripts/app/controllers/widget/switch_back_to_user.coffee index 220d09ad0..b5dd14785 100644 --- a/app/assets/javascripts/app/controllers/widget/switch_back_to_user.coffee +++ b/app/assets/javascripts/app/controllers/widget/switch_back_to_user.coffee @@ -34,7 +34,18 @@ class Widget extends App.ControllerWidgetOnDemand e.preventDefault() @disconnectClient() $('#app').hide().attr('style', 'display: none!important') - App.Auth._logout() - window.location = App.Config.get('api_path') + '/sessions/switch_back' + @delay( + => + App.Auth._logout() + @ajax( + id: 'user_switch_back' + type: 'GET' + url: "#{@apiPath}/sessions/switch_back" + success: (data, status, xhr) => + location = "#{window.location.protocol}//#{window.location.host}#{data.location}" + @windowReload(undefined, location) + ) + 800 + ) App.Config.set( 'switch_back_to_user', Widget, 'Widgets' )