Signal-Desktop/js/options.js

122 lines
3.3 KiB
JavaScript
Raw Normal View History

/* vim: ts=4:sw=4
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
2014-05-28 02:40:39 +08:00
function updateNumberColors() {
try {
textsecure.utils.verifyNumber($('#number').val(), $('#countrycode').val());
$('#number').attr('style', '');
2014-05-28 02:40:39 +08:00
$('#countrycode').attr('style', '');
} catch (e) {
if (e.countryCodeValid)
2014-05-28 02:40:39 +08:00
$('#countrycode').attr('style', '');
else
2014-05-28 02:40:39 +08:00
$('#countrycode').attr('style', 'background-color:#ff6666;');
2014-01-10 15:48:05 +08:00
if (e.numberValid)
$('#number').attr('style', '');
else
$('#number').attr('style', 'background-color:#ff6666;');
}
2014-01-10 15:48:05 +08:00
}
2014-05-28 02:40:39 +08:00
$('#number').on('change', updateNumberColors);
$('#countrycode').on('change', updateNumberColors);
function isCodeValid() {
var code = $('#code');
return code.val().replace(/\D/g, '') == code.val() && code.val().length == 6;
}
$('#code').on('change', function() {
if (!isCodeValid())
$('#code').attr('style', 'background-color:#ff6666;');
else
$('#code').attr('style', '');
});
2014-01-10 15:48:05 +08:00
var single_device = false;
2014-01-17 14:08:33 +08:00
$('#init-go-single-client').click(function() {
var number = textsecure.utils.verifyNumber($('#number').val(), $('#countrycode').val());
2014-01-17 14:08:33 +08:00
$('#init-go').html('Setup');
$('#countrycode').prop('disabled', 'disabled');
$('#number').prop('disabled', 'disabled');
$('#init-go-single-client').prop('disabled', 'disabled');
2014-01-17 14:08:33 +08:00
single_device = true;
2014-01-17 14:08:33 +08:00
2014-05-28 03:35:37 +08:00
textsecure.api.requestVerificationCode(number).catch(function(error) {
//TODO: No alerts
if (error.humanReadable)
alert(error.humanReadable);
else
alert(error); // XXX
});
2014-01-17 14:08:33 +08:00
});
2014-01-10 15:48:05 +08:00
$('#init-go').click(function() {
2014-05-28 02:40:39 +08:00
var number = textsecure.utils.verifyNumber($('#number').val(), $('#countrycode').val());
if (!isCodeValid()) {
updateCodeColor();
return;
}
2014-01-10 15:48:05 +08:00
2014-01-12 15:32:13 +08:00
2014-05-28 02:40:39 +08:00
$('#init-setup').hide();
$('#verify1done').html('');
$('#verify2').hide();
$('#verify3done').html('');
$('#verify4done').html('');
$('#verify').show();
2014-01-17 14:08:33 +08:00
2014-05-28 10:03:23 +08:00
textsecure.register(number, $('#code').val(), single_device, function(step) {
2014-05-28 02:40:39 +08:00
switch(step) {
case 1:
$('#verify1done').html('done');
break;
case 2:
$('#verify2done').html('done');
break;
case 3:
$('#verify3done').html('done');
break;
case 4:
$('#complete-number').html(number);
$('#verify').hide();
$('#setup-complete').show();
registrationDone();
}
}).catch(function(error) {
2014-05-28 03:29:44 +08:00
//TODO: No alerts...
if (error.humanError)
alert(error.humanError);
else
alert(error); //XXX
2014-05-28 02:40:39 +08:00
});
2014-01-10 15:48:05 +08:00
});
2014-05-17 13:53:58 +08:00
textsecure.registerOnLoadFunction(function() {
$(function() {
if (!isRegistrationDone()) {
$('#init-setup').show();
} else {
2014-05-28 02:40:39 +08:00
$('#complete-number').html(textsecure.storage.getUnencrypted("number_id").split(".")[0]);//TODO: no
$('#setup-complete').show();
}
});
2014-01-22 14:23:41 +08:00
});