2016-10-27 18:14:58 +00:00
|
|
|
var mpw, error;
|
2014-10-24 00:10:25 +00:00
|
|
|
|
|
|
|
function updateMPW() {
|
2016-10-27 18:14:58 +00:00
|
|
|
mpw = null;
|
|
|
|
startWork();
|
2016-10-27 18:49:02 +00:00
|
|
|
mpw = new MPW( $('#userName')[0].value, $('#masterPassword')[0].value, $('#version')[0].value );
|
2016-10-27 18:14:58 +00:00
|
|
|
mpw.key.then(
|
|
|
|
function() {
|
|
|
|
doneWork();
|
|
|
|
},
|
|
|
|
function(reason) {
|
|
|
|
error = reason;
|
|
|
|
mpw = null;
|
|
|
|
doneWork();
|
|
|
|
}
|
|
|
|
);
|
2014-10-24 00:10:25 +00:00
|
|
|
}
|
2016-10-27 18:14:58 +00:00
|
|
|
function startWork() {
|
|
|
|
update(true);
|
2014-10-24 00:10:25 +00:00
|
|
|
}
|
2016-10-27 18:14:58 +00:00
|
|
|
function doneWork() {
|
|
|
|
update(false);
|
|
|
|
}
|
|
|
|
function update(working) {
|
|
|
|
var screen = mpw? 'site': 'identity';
|
2014-10-24 00:10:25 +00:00
|
|
|
|
2016-10-27 18:14:58 +00:00
|
|
|
// Screen Name
|
|
|
|
if (screen == 'identity') {
|
2014-10-24 00:10:25 +00:00
|
|
|
$('#identity').addClass('active');
|
|
|
|
|
|
|
|
if (!working)
|
|
|
|
$('#userName').focus();
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
$('#identity').removeClass('active');
|
2016-10-27 18:20:14 +00:00
|
|
|
$('#userName')[0].value = $('#masterPassword')[0].value = '';
|
|
|
|
}
|
2016-10-27 18:14:58 +00:00
|
|
|
|
|
|
|
if (screen == 'site') {
|
2014-10-24 00:10:25 +00:00
|
|
|
$('#site').addClass('active');
|
|
|
|
|
|
|
|
if (!working)
|
|
|
|
$('#siteName').focus();
|
|
|
|
}
|
2016-10-27 18:20:14 +00:00
|
|
|
else {
|
2016-10-27 18:14:58 +00:00
|
|
|
$('#site').removeClass('active');
|
2018-06-10 19:31:20 +00:00
|
|
|
$('#siteName').val(null);
|
|
|
|
$('#sitePassword').text(null);
|
2016-10-27 18:20:14 +00:00
|
|
|
}
|
2016-10-27 18:14:58 +00:00
|
|
|
|
|
|
|
// Working
|
|
|
|
if (working && screen == 'identity')
|
|
|
|
$('#identity').addClass('working').find('input, select').attr('disabled', 'disabled');
|
2016-10-27 18:20:14 +00:00
|
|
|
else
|
2016-10-27 18:14:58 +00:00
|
|
|
$('#identity').removeClass('working').find('input, select').removeAttr('disabled');
|
|
|
|
|
|
|
|
if (working && screen == 'site')
|
|
|
|
$('#site').addClass('working');
|
|
|
|
else
|
|
|
|
$('#site').removeClass('working');
|
2014-10-24 00:10:25 +00:00
|
|
|
|
|
|
|
// Error
|
|
|
|
$('#error').text(error);
|
|
|
|
}
|
|
|
|
function updateSite() {
|
2016-10-27 18:14:58 +00:00
|
|
|
if (!mpw) {
|
|
|
|
doneWork();
|
|
|
|
return
|
|
|
|
}
|
2014-10-24 00:10:25 +00:00
|
|
|
|
2016-10-27 18:14:58 +00:00
|
|
|
startWork();
|
|
|
|
mpw.generatePassword( $('#siteName')[0].value, $('#siteCounter')[0].valueAsNumber, $('#siteType')[0].value )
|
|
|
|
.then( function (sitePassword) {
|
|
|
|
$('#sitePassword').text(sitePassword);
|
|
|
|
doneWork();
|
|
|
|
}, function (reason) {
|
|
|
|
error = reason;
|
|
|
|
doneWork();
|
|
|
|
});
|
2014-10-24 00:10:25 +00:00
|
|
|
}
|
|
|
|
function selectText(element) {
|
|
|
|
var doc = document, range, selection;
|
|
|
|
|
|
|
|
if (doc.body.createTextRange) { //ms
|
|
|
|
range = doc.body.createTextRange();
|
|
|
|
range.moveToElementText(element);
|
|
|
|
range.select();
|
|
|
|
} else if (window.getSelection) { //all others
|
|
|
|
selection = window.getSelection();
|
|
|
|
range = doc.createRange();
|
|
|
|
range.selectNodeContents(element);
|
|
|
|
selection.removeAllRanges();
|
|
|
|
selection.addRange(range);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
$(function() {
|
|
|
|
$('#identity form').on('submit', function() {
|
|
|
|
updateMPW();
|
|
|
|
return false;
|
|
|
|
});
|
|
|
|
$('#site input, #site select').on('change input keyup', function() {
|
|
|
|
updateSite();
|
|
|
|
});
|
|
|
|
$('#logout').on('click', function() {
|
|
|
|
mpw = null;
|
2016-10-27 18:14:58 +00:00
|
|
|
doneWork();
|
2014-10-24 00:10:25 +00:00
|
|
|
});
|
|
|
|
$('#sitePassword').on('click', function() {
|
|
|
|
selectText(this);
|
|
|
|
});
|
|
|
|
|
2016-10-27 18:14:58 +00:00
|
|
|
doneWork();
|
2014-10-24 00:10:25 +00:00
|
|
|
});
|