From 5d3020b9edd72f5d197bdef988809a05eadf0b66 Mon Sep 17 00:00:00 2001 From: Emily Chao Date: Wed, 14 Jan 2015 13:59:40 -1000 Subject: [PATCH] Refactor phone number input view Moves validation logic to its own view to be shared on index and options pages. --- index.html | 13 ++++++- js/options.js | 41 ++++++-------------- js/views/new_conversation_view.js | 5 ++- js/views/phone-input-view.js | 64 +++++++++++++++++++++++++++++++ options.html | 20 ++++++---- stylesheets/manifest.css | 2 + stylesheets/manifest.css.map | 7 ++++ stylesheets/options.css | 10 ++--- 8 files changed, 117 insertions(+), 45 deletions(-) create mode 100644 js/views/phone-input-view.js create mode 100644 stylesheets/manifest.css.map diff --git a/index.html b/index.html index 5937a5768e76..821ead5910d8 100644 --- a/index.html +++ b/index.html @@ -42,6 +42,16 @@
Add members:
+ + diff --git a/js/options.js b/js/options.js index f097ac093e42..9240b50de4a1 100644 --- a/js/options.js +++ b/js/options.js @@ -15,24 +15,6 @@ */ ;(function() { - function validateNumber() { - try { - var regionCode = $('#regionCode').val(); - var number = $('#number').val(); - - var parsedNumber = libphonenumber.util.verifyNumber(number, regionCode); - - $('#regionCode').val(libphonenumber.util.getRegionCodeForNumber(parsedNumber)); - $('#number-container').removeClass('invalid'); - $('#number-container').addClass('valid'); - $('#request-sms, #request-voice').removeAttr('disabled'); - return parsedNumber; - } catch(e) { - $('#number-container').removeClass('valid'); - $('#request-sms, #request-voice').prop('disabled', 'disabled'); - } - }; - function validateCode() { var verificationCode = $('#code').val().replace(/\D/g, ''); if (verificationCode.length == 6) { @@ -45,18 +27,19 @@ }; $(function() { + var phoneView = new Whisper.PhoneInputView({el: $('#phone-number-input')}); if (textsecure.registration.isDone()) { $('#complete-number').text(textsecure.utils.unencodeNumber(textsecure.storage.getUnencrypted("number_id"))[0]);//TODO: no $('#setup-complete').show().addClass('in'); } else { $('#choose-setup').show().addClass('in'); - $('#number').keyup(validateNumber); - $('#regionCode').change(validateNumber); - $.each(libphonenumber.util.getAllRegionCodes(), function (regionCode, countryName) { - $('#regionCode').append( - $('