Browse Source

Extract renderScreen* methods into their own mixin

Ryan Lue 6 years ago
parent
commit
4f494b57ac

+ 1 - 16
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}'"

+ 25 - 0
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)
+

+ 7 - 0
app/assets/javascripts/app/views/generic/error/placeholder.jst.eco

@@ -0,0 +1,7 @@
+<div class="fullscreenMessage fullscreenMessage--placeholder">
+  <%- @icon %>
+  <h2><% if @status isnt undefined: %><%- @T('Status Code') %>: <%= @status %>. <% end %><%- @T(@detail) %></h2>
+  <% if @action: %>
+  <div class="btn btn--action js-action"><%= @T(@action) %></div>
+  <% end %>
+</div>