From 6012a3ce9e4993c2f1dd31159f2245c77189f404 Mon Sep 17 00:00:00 2001 From: Ting-Kuan Date: Thu, 27 Mar 2014 14:35:20 -0400 Subject: [PATCH] Show error message when editor fails to initiate. --- app/templates/editor/article/edit.jade | 4 +++- app/templates/editor/level/edit.jade | 2 ++ app/templates/editor/thang/edit.jade | 2 ++ app/views/editor/article/edit.coffee | 13 +++++++++++++ app/views/editor/level/edit.coffee | 7 +++++++ app/views/editor/thang/edit.coffee | 21 +++++++++++++++++---- app/views/error_view.coffee | 9 +++++++++ 7 files changed, 53 insertions(+), 5 deletions(-) create mode 100644 app/views/error_view.coffee diff --git a/app/templates/editor/article/edit.jade b/app/templates/editor/article/edit.jade index 04fe913ff..4969e30e9 100644 --- a/app/templates/editor/article/edit.jade +++ b/app/templates/editor/article/edit.jade @@ -18,10 +18,12 @@ block content h3(data-i18n="article.edit_article_title") Edit Article span |: "#{article.attributes.name}" - + #article-treema #article-view hr + div#error-view + diff --git a/app/templates/editor/level/edit.jade b/app/templates/editor/level/edit.jade index 67800e66f..f90485b49 100644 --- a/app/templates/editor/level/edit.jade +++ b/app/templates/editor/level/edit.jade @@ -75,4 +75,6 @@ block outer_content div.tab-pane#editor-level-systems-tab-view + div#error-view + block footer \ No newline at end of file diff --git a/app/templates/editor/thang/edit.jade b/app/templates/editor/thang/edit.jade index 09326f99c..1e8ce462d 100644 --- a/app/templates/editor/thang/edit.jade +++ b/app/templates/editor/thang/edit.jade @@ -84,4 +84,6 @@ block content div#spritesheets + div#error-view + .clearfix diff --git a/app/views/editor/article/edit.coffee b/app/views/editor/article/edit.coffee index 42450f90f..5dfa85e41 100644 --- a/app/views/editor/article/edit.coffee +++ b/app/views/editor/article/edit.coffee @@ -1,5 +1,6 @@ View = require 'views/kinds/RootView' VersionHistoryView = require './versions_view' +ErrorView = require '../../error_view' template = require 'templates/editor/article/edit' Article = require 'models/Article' @@ -19,6 +20,18 @@ module.exports = class ArticleEditView extends View super options @article = new Article(_id: @articleID) @article.saveBackups = true + + @listenToOnce(@article, 'error', + () => + @hideLoading() + + # Hack: editor components appear after calling insertSubView. + # So we need to hide them first. + $(@$el).find('.main-content-area').children('*').not('#error-view').remove() + + @insertSubView(new ErrorView()) + ) + @article.fetch() @listenToOnce(@article, 'sync', @onArticleSync) @listenTo(@article, 'schema-loaded', @buildTreema) diff --git a/app/views/editor/level/edit.coffee b/app/views/editor/level/edit.coffee index 6d6b5a774..313308895 100644 --- a/app/views/editor/level/edit.coffee +++ b/app/views/editor/level/edit.coffee @@ -13,6 +13,7 @@ SystemsTabView = require './systems_tab_view' LevelSaveView = require './save_view' LevelForkView = require './fork_view' VersionHistoryView = require './versions_view' +ErrorView = require '../../error_view' module.exports = class EditorLevelView extends View id: "editor-level-view" @@ -43,6 +44,12 @@ module.exports = class EditorLevelView extends View @level = new Level _id: @levelID @listenToOnce(@level, 'sync', @onLevelLoaded) + + @listenToOnce(@supermodel, 'error', + () => + @hideLoading() + @insertSubView(new ErrorView()) + ) @supermodel.populateModel @level showLoading: ($el) -> diff --git a/app/views/editor/thang/edit.coffee b/app/views/editor/thang/edit.coffee index a8a67ff39..ef39d0da4 100644 --- a/app/views/editor/thang/edit.coffee +++ b/app/views/editor/thang/edit.coffee @@ -1,15 +1,16 @@ -View = require 'views/kinds/RootView' -template = require 'templates/editor/thang/edit' ThangType = require 'models/ThangType' SpriteParser = require 'lib/sprites/SpriteParser' SpriteBuilder = require 'lib/sprites/SpriteBuilder' CocoSprite = require 'lib/surface/CocoSprite' Camera = require 'lib/surface/Camera' -ThangComponentEditView = require 'views/editor/components/main' -VersionHistoryView = require './versions_view' DocumentFiles = require 'collections/DocumentFiles' +View = require 'views/kinds/RootView' +ThangComponentEditView = require 'views/editor/components/main' +VersionHistoryView = require './versions_view' ColorsTabView = require './colors_tab_view' +ErrorView = require '../../error_view' +template = require 'templates/editor/thang/edit' CENTER = {x:200, y:300} @@ -43,6 +44,18 @@ module.exports = class ThangTypeEditView extends View @mockThang = $.extend(true, {}, @mockThang) @thangType = new ThangType(_id: @thangTypeID) @thangType.saveBackups = true + + @listenToOnce(@thangType, 'error', + () => + @hideLoading() + + # Hack: editor components appear after calling insertSubView. + # So we need to hide them first. + $(@$el).find('.main-content-area').children('*').not('#error-view').remove() + + @insertSubView(new ErrorView()) + ) + @thangType.fetch() @thangType.loadSchema() @thangType.schema().once 'sync', @onThangTypeSync, @ diff --git a/app/views/error_view.coffee b/app/views/error_view.coffee new file mode 100644 index 000000000..271910482 --- /dev/null +++ b/app/views/error_view.coffee @@ -0,0 +1,9 @@ +View = require 'views/kinds/RootView' + +module.exports = class ErrorView extends View + id: "error-view" + el: "
" + + render: ()-> + super() + @$el.append("

Error: Failed to process request.

") \ No newline at end of file