From 4f494b57ac9859a6cc6cc4337e745be761ad4e6e Mon Sep 17 00:00:00 2001 From: Ryan Lue Date: Tue, 26 Feb 2019 11:27:48 +0100 Subject: [PATCH] Extract renderScreen* methods into their own mixin --- .../_application_controller.coffee | 17 +------------ .../app/lib/mixins/render_screen.coffee | 25 +++++++++++++++++++ .../views/generic/error/placeholder.jst.eco | 7 ++++++ 3 files changed, 33 insertions(+), 16 deletions(-) create mode 100644 app/assets/javascripts/app/lib/mixins/render_screen.coffee create mode 100644 app/assets/javascripts/app/views/generic/error/placeholder.jst.eco diff --git a/app/assets/javascripts/app/controllers/_application_controller.coffee b/app/assets/javascripts/app/controllers/_application_controller.coffee index e082cb166..81918642e 100644 --- a/app/assets/javascripts/app/controllers/_application_controller.coffee +++ b/app/assets/javascripts/app/controllers/_application_controller.coffee @@ -1,5 +1,6 @@ class App.Controller extends Spine.Controller @include App.LogInclude + @include App.RenderScreen constructor: (params) -> @@ -358,22 +359,6 @@ class App.Controller extends Spine.Controller return if !@initLoadingDoneDelay @clearDelay(@initLoadingDoneDelay) - renderScreenSuccess: (data) -> - App.TaskManager.touch(@taskKey) if @taskKey - (data.el || @).html App.view('generic/error/success')(data) - - renderScreenError: (data) -> - App.TaskManager.touch(@taskKey) if @taskKey - (data.el || @).html App.view('generic/error/generic')(data) - - renderScreenNotFound: (data) -> - App.TaskManager.touch(@taskKey) if @taskKey - (data.el || @).html App.view('generic/error/not_found')(data) - - renderScreenUnauthorized: (data) -> - App.TaskManager.touch(@taskKey) if @taskKey - (data.el || @).html App.view('generic/error/unauthorized')(data) - locationVerify: (e) => newLocation = $(e.currentTarget).attr 'href' @log 'debug', "new location '#{newLocation}'" diff --git a/app/assets/javascripts/app/lib/mixins/render_screen.coffee b/app/assets/javascripts/app/lib/mixins/render_screen.coffee new file mode 100644 index 000000000..f60ce6cb5 --- /dev/null +++ b/app/assets/javascripts/app/lib/mixins/render_screen.coffee @@ -0,0 +1,25 @@ +# Methods for displaying a full-screen success or error message + +App.RenderScreen = + renderScreenSuccess: (data) -> + App.TaskManager.touch(@taskKey) if @taskKey + (data.el || @).html App.view('generic/error/success')(data) + + renderScreenError: (data) -> + App.TaskManager.touch(@taskKey) if @taskKey + (data.el || @).html App.view('generic/error/generic')(data) + + renderScreenNotFound: (data) -> + App.TaskManager.touch(@taskKey) if @taskKey + (data.el || @).html App.view('generic/error/not_found')(data) + + renderScreenUnauthorized: (data) -> + App.TaskManager.touch(@taskKey) if @taskKey + (data.el || @).html App.view('generic/error/unauthorized')(data) + + renderScreenPlaceholder: (data) -> + App.TaskManager.touch(@taskKey) if @taskKey + (data.el || @).html App.view('generic/error/placeholder')(data) + if data.action && data.actionCallback + (data.el || @.el).find('.js-action').click(data.actionCallback) + diff --git a/app/assets/javascripts/app/views/generic/error/placeholder.jst.eco b/app/assets/javascripts/app/views/generic/error/placeholder.jst.eco new file mode 100644 index 000000000..2627163d7 --- /dev/null +++ b/app/assets/javascripts/app/views/generic/error/placeholder.jst.eco @@ -0,0 +1,7 @@ +
+ <%- @icon %> +

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

+ <% if @action: %> +
<%= @T(@action) %>
+ <% end %> +
\ No newline at end of file