diff --git a/browserid/static/dialog/controllers/dialog_controller.js b/browserid/static/dialog/controllers/dialog_controller.js index 49560e08de033003c50a668bb273d72ffd141d02..1c7a39c8355acc4cefe382dafe0e670d66d3f686 100644 --- a/browserid/static/dialog/controllers/dialog_controller.js +++ b/browserid/static/dialog/controllers/dialog_controller.js @@ -180,7 +180,12 @@ }, doPickEmail: function() { - this.element.pickemail(); + this.element.pickemail({ + // XXX ideal is to get rid of this and have a User function + // that takes care of getting email addresses AND the last used email + // for this site. + origin: user.getHostname() + }); }, doAuthenticate: function(info) { diff --git a/browserid/static/dialog/controllers/pickemail_controller.js b/browserid/static/dialog/controllers/pickemail_controller.js index 1b3679c132953e12afd296df960419aa5a3cb945..a9197a4c60c03029d16fe39de02c24c67f4c0815 100644 --- a/browserid/static/dialog/controllers/pickemail_controller.js +++ b/browserid/static/dialog/controllers/pickemail_controller.js @@ -41,6 +41,8 @@ bid = BrowserID, user = bid.User, errors = bid.Errors, + storage = bid.Storage, + origin, body = $("body"), animationComplete = body.innerWidth() < 640, assertion; @@ -109,6 +111,9 @@ // the animation, hopefully this minimizes the delay the user notices. var self=this; user.getAssertion(email, function(assert) { + // XXX make a user api call that gets the assertion and sets the site + // email as well. + storage.setSiteEmail(origin, email); assertion = assert || null; startAnimation.call(self); }, self.getErrorDialog(errors.getAssertion)); @@ -176,10 +181,16 @@ PageController.extend("Pickemail", {}, { init: function(el, options) { + origin = options.origin; + this._super(el, { bodyTemplate: "pickemail.ejs", bodyVars: { - identities: user.getStoredEmailKeypairs() + identities: user.getStoredEmailKeypairs(), + // XXX ideal is to get rid of this and have a User function + // that takes care of getting email addresses AND the last used email + // for this site. + siteemail: storage.getSiteEmail(options.origin) } }); diff --git a/browserid/static/dialog/css/popup.css b/browserid/static/dialog/css/popup.css index e5f4503f22515f34345a6993ba6c885a472fd836..72f7272faeff8560819e9f5be668f155cee0de7b 100644 --- a/browserid/static/dialog/css/popup.css +++ b/browserid/static/dialog/css/popup.css @@ -300,6 +300,10 @@ label { color: #333; } +.inputs > li > label.preselected { + font-weight: bold; +} + .inputs > li:only-child > label { cursor: default; } diff --git a/browserid/static/dialog/test/qunit/controllers/pickemail_controller_unit_test.js b/browserid/static/dialog/test/qunit/controllers/pickemail_controller_unit_test.js new file mode 100644 index 0000000000000000000000000000000000000000..25730ca41e0bbbd536078a531591c22e5d843992 --- /dev/null +++ b/browserid/static/dialog/test/qunit/controllers/pickemail_controller_unit_test.js @@ -0,0 +1,96 @@ +/*jshint browsers:true, forin: true, laxbreak: true */ +/*global steal: true, test: true, start: true, stop: true, module: true, ok: true, equal: true, BrowserID:true */ +/* ***** BEGIN LICENSE BLOCK ***** + * Version: MPL 1.1/GPL 2.0/LGPL 2.1 + * + * The contents of this file are subject to the Mozilla Public License Version + * 1.1 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * http://www.mozilla.org/MPL/ + * + * Software distributed under the License is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License + * for the specific language governing rights and limitations under the + * License. + * + * The Original Code is Mozilla BrowserID. + * + * The Initial Developer of the Original Code is Mozilla. + * Portions created by the Initial Developer are Copyright (C) 2011 + * the Initial Developer. All Rights Reserved. + * + * Contributor(s): + * + * Alternatively, the contents of this file may be used under the terms of + * either the GNU General Public License Version 2 or later (the "GPL"), or + * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), + * in which case the provisions of the GPL or the LGPL are applicable instead + * of those above. If you wish to allow use of your version of this file only + * under the terms of either the GPL or the LGPL, and not to allow others to + * use your version of this file under the terms of the MPL, indicate your + * decision by deleting the provisions above and replace them with the notice + * and other provisions required by the GPL or the LGPL. If you do not delete + * the provisions above, a recipient may use your version of this file under + * the terms of any one of the MPL, the GPL or the LGPL. + * + * ***** END LICENSE BLOCK ***** */ +steal.plugins("jquery").then("/dialog/controllers/page_controller", "/dialog/controllers/pickemail_controller", function() { + "use strict"; + + var controller, + el = $("body"), + storage = BrowserID.Storage; + + function reset() { + el = $("#controller_head"); + el.find("#formWrap .contents").html(""); + el.find("#wait .contents").html(""); + el.find("#error .contents").html(""); + } + + module("controllers/pickemail_controller", { + setup: function() { + reset(); + storage.clear(); + }, + + teardown: function() { + if (controller) { + controller.destroy(); + } + reset(); + storage.clear(); + } + }); + + + test("pickemail controller with email associated with site", function() { + storage.addEmail("testuser@testuser.com", {priv: "priv", pub: "pub"}); + storage.addEmail("testuser2@testuser.com", {priv: "priv", pub: "pub"}); + storage.setSiteEmail("browserid.org", "testuser2@testuser.com"); + + controller = el.pickemail({origin: "browserid.org"}).controller(); + ok(controller, "controller created"); + + var radioButton = $("input[type=radio]").eq(1); + ok(radioButton.is(":checked"), "the email address we specified is checked"); + + var label = radioButton.parent();; + ok(label.hasClass("preselected"), "the label has the preselected class"); + }); + + test("pickemail controller without email associated with site", function() { + storage.addEmail("testuser@testuser.com", {priv: "priv", pub: "pub"}); + + controller = el.pickemail({origin: "browserid.org"}).controller(); + ok(controller, "controller created"); + + var radioButton = $("input[type=radio]").eq(0); + equal(radioButton.is(":checked"), false, "The email address is not checked"); + + var label = radioButton.parent(); + equal(label.hasClass("preselected"), false, "the label has no class"); + }); + +}); + diff --git a/browserid/static/dialog/test/qunit/qunit.js b/browserid/static/dialog/test/qunit/qunit.js index 450add4ea320c385bc56072036d2781843ffaccb..909773ac04e93ca3c91bfee896ebbc7ba143f4f8 100644 --- a/browserid/static/dialog/test/qunit/qunit.js +++ b/browserid/static/dialog/test/qunit/qunit.js @@ -12,8 +12,8 @@ steal("/dialog/resources/browserid.js", "jquery/view/ejs", "funcunit/qunit") .views('testBodyTemplate.ejs') - .views('wait.ejs') - .then("/dialog/controllers/page_controller.js") + .views('wait.ejs', + 'pickemail.ejs') .then("browserid_unit_test") .then("include_unit_test") .then("pages/add_email_address_test") @@ -23,5 +23,5 @@ steal("/dialog/resources/browserid.js", .then("resources/network_unit_test") .then("resources/user_unit_test") .then("controllers/page_controller_unit_test") - .then("controllers/page_controller_unit_test") + .then("controllers/pickemail_controller_unit_test") diff --git a/browserid/static/dialog/views/pickemail.ejs b/browserid/static/dialog/views/pickemail.ejs index de6582dadd816f542618943c87fd77c27d96a14a..8e0b1669133bb225f96c535f662c0e9f72a0c53b 100644 --- a/browserid/static/dialog/views/pickemail.ejs +++ b/browserid/static/dialog/views/pickemail.ejs @@ -4,8 +4,11 @@ <ul class="inputs"> <% _.each(identities, function(email_obj, email_address) { %> <li> - <label for="<%= email_address %>" class="serif"> - <input type="radio" name="email" id="<%= email_address %>" value="<%= email_address %>" /> + + <label for="<%= email_address %>" class="serif<% if (email_address === siteemail) { %> preselected<% } %>"> + <input type="radio" name="email" id="<%= email_address %>" value="<%= email_address %>" + <% if (email_address === siteemail) { %> checked="checked" <% } %> + /> <%= email_address %> </label> </li>