From 0187e21638c4e277c21246425338c9333cccd1e5 Mon Sep 17 00:00:00 2001 From: Shane Tomlinson <stomlinson@mozilla.com> Date: Tue, 11 Oct 2011 12:23:00 +0100 Subject: [PATCH] Warn the user they are cancelling their account if they remove the last email. Warning the user, clearing all BrowserID stored info, and redirecting to main page when action is complete. close #394 issue #137 close #404 --- browserid/static/js/pages/manage_account.js | 34 ++++++++++++++------- 1 file changed, 23 insertions(+), 11 deletions(-) diff --git a/browserid/static/js/pages/manage_account.js b/browserid/static/js/pages/manage_account.js index b90bb9746..e3dc52a25 100644 --- a/browserid/static/js/pages/manage_account.js +++ b/browserid/static/js/pages/manage_account.js @@ -1,4 +1,4 @@ -/*globals BrowserID:true, _: true, confirm: true, syncAndDisplayEmails: true, displayEmails: true, onRemoveEmail: true*/ +/*globals BrowserID:true, _: true, confirm: true, displayEmails: true */ /* ***** BEGIN LICENSE BLOCK ***** * Version: MPL 1.1/GPL 2.0/LGPL 2.1 * @@ -136,6 +136,25 @@ }); } + function onRemoveEmail(email, event) { + event.preventDefault(); + + var emails = User.getStoredEmailKeypairs(); + + if (_.size(emails) > 1) { + if (confirm("Remove " + email + " from your BrowserID?")) { + User.removeEmail(email, syncAndDisplayEmails); + } + } + else { + if (confirm('Removing the last address will cancel your BrowserID account,\nare you sure you want to continute?')) { + User.cancelUser(function() { + document.location="/"; + }); + } + } + } + function displayEmails(emails) { var list = $("#emailList").empty(); @@ -161,17 +180,10 @@ } - function onRemoveEmail(email, event) { - event.preventDefault(); - - if (confirm("Remove " + email + " from your BrowserID?")) { - User.removeEmail(email, syncAndDisplayEmails); - } - } - BrowserID.manageAccount = function() { - $('#cancelAccount').click(function() { - if (confirm('Are you sure you want to cancel your account?')) { + $('#cancelAccount').click(function(event) { + event.preventDefault(); + if (confirm('Are you sure you want to cancel your BrowserID account?')) { User.cancelUser(function() { document.location="/"; }); -- GitLab