Skip to content
Snippets Groups Projects
Commit 28199374 authored by Shane Tomlinson's avatar Shane Tomlinson
Browse files

Remember the last selected email for a site.

Store off the email in localStorage, when we display the list of emails, highlight the previously selected one.

close #1
parent 7ee83250
No related branches found
No related tags found
No related merge requests found
......@@ -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) {
......
......@@ -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)
}
});
......
......@@ -300,6 +300,10 @@ label {
color: #333;
}
.inputs > li > label.preselected {
font-weight: bold;
}
.inputs > li:only-child > label {
cursor: default;
}
......
/*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");
});
});
......@@ -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")
......@@ -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>
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment