From 36b79bc28ac483324eaaa6a3c9d56368d6205d54 Mon Sep 17 00:00:00 2001 From: Shane Tomlinson <stomlinson@mozilla.com> Date: Tue, 18 Oct 2011 14:26:28 +0100 Subject: [PATCH] Simplifying the error message handling, checking to make sure error messages are printed to the correct DOM elements. --- .../dialog/controllers/page_controller.js | 18 ++++++++---------- browserid/static/dialog/qunit.html | 10 ++++++++-- .../controllers/page_controller_unit_test.js | 19 +++++++++++++++++++ browserid/views/dialog.ejs | 2 -- 4 files changed, 35 insertions(+), 14 deletions(-) diff --git a/browserid/static/dialog/controllers/page_controller.js b/browserid/static/dialog/controllers/page_controller.js index 98c91520b..0c621d11c 100644 --- a/browserid/static/dialog/controllers/page_controller.js +++ b/browserid/static/dialog/controllers/page_controller.js @@ -89,12 +89,17 @@ renderDialog: function(body, body_vars) { this.renderTemplates("#formWrap", body, body_vars); - $("#wait").stop().fadeOut(250); + $("#wait").stop().fadeOut(ANIMATION_TIME); }, renderWait: function(body, body_vars) { this.renderTemplates("#wait", body, body_vars); - $("#wait").stop().css('opacity', 1).hide().fadeIn(250); + $("#wait").stop().css('opacity', 1).hide().fadeIn(ANIMATION_TIME); + }, + + renderError: function(error_vars) { + this.renderTemplates("#error", "wait.ejs", error_vars); + $("#error").stop().css('opacity', 1).hide().fadeIn(ANIMATION_TIME); }, onSubmit: function(event) { @@ -135,14 +140,7 @@ * two fields, message, description. */ errorDialog: function(info) { - $("form").hide(); - - $("#error_dialog .title").text(info.message); - $("#error_dialog .content").text(info.description); - - $("body").removeClass("authenticated").addClass("error"); - - $("#error_dialog").fadeIn(ANIMATION_TIME); + this.renderError({title: info.message, message: info.description}); }, /** diff --git a/browserid/static/dialog/qunit.html b/browserid/static/dialog/qunit.html index 962facb3d..108cc60fd 100644 --- a/browserid/static/dialog/qunit.html +++ b/browserid/static/dialog/qunit.html @@ -13,13 +13,19 @@ <h2 id="qunit-userAgent"></h2> <div id="test-content"> <div id="page_controller"> + <div id="formWrap"> - <div class="contents"></div> + <div class="contents"></div> </div> <div id="wait"> - <div class="contents"></div> + <div class="contents"></div> + </div> + + <div id="error"> + <div class="contents"></div> </div> + </div> </div> <ol id="qunit-tests"></ol> diff --git a/browserid/static/dialog/test/qunit/controllers/page_controller_unit_test.js b/browserid/static/dialog/test/qunit/controllers/page_controller_unit_test.js index 776f361a1..92ed30efc 100644 --- a/browserid/static/dialog/test/qunit/controllers/page_controller_unit_test.js +++ b/browserid/static/dialog/test/qunit/controllers/page_controller_unit_test.js @@ -49,6 +49,7 @@ steal.plugins("jquery").then("/dialog/controllers/page_controller", function() { teardown: function() { el.find("#formWrap .contents").html(""); el.find("#wait .contents").html(""); + el.find("#error .contents").html(""); controller.destroy(); } }); @@ -99,5 +100,23 @@ steal.plugins("jquery").then("/dialog/controllers/page_controller", function() { ok(html.length, "with wait template specified, wait text is loaded"); }); + test("renderError does what it is meant to", function() { + controller = el.page({ + waitTemplate: waitTemplate, + waitVars: { + title: "Test title", + message: "Test message" + } + }).controller(); + + el.page("renderError", { + title: "error title", + message: "error message" + }); + + var html = el.find("#error .contents").html(); + ok(html.length, "with error template specified, error text is loaded"); + }); + }); diff --git a/browserid/views/dialog.ejs b/browserid/views/dialog.ejs index 36f990e6d..4bde9a26a 100644 --- a/browserid/views/dialog.ejs +++ b/browserid/views/dialog.ejs @@ -56,8 +56,6 @@ <section id="error"> <div class="table"> <div class="vertical contents"> - <h2 class="title"></h2> - <p class="content"></p> </div> </div> </section> -- GitLab