nextcloud/apps/encryption/js/settings-personal.js

70 lines
2.4 KiB
JavaScript
Raw Normal View History

2015-03-27 03:35:36 +03:00
/**
* Copyright (c) 2013, Sam Tuke <samtuke@owncloud.com>
* This file is licensed under the Affero General Public License version 3 or later.
* See the COPYING-README file.
*/
OC.Encryption = _.extend(OC.Encryption || {}, {
2015-04-22 17:41:47 +03:00
updatePrivateKeyPassword: function () {
2015-04-21 13:01:56 +03:00
var oldPrivateKeyPassword = $('input:password[id="oldPrivateKeyPassword"]').val();
var newPrivateKeyPassword = $('input:password[id="newPrivateKeyPassword"]').val();
OC.msg.startSaving('#ocDefaultEncryptionModule .msg');
2015-04-21 13:01:56 +03:00
$.post(
OC.generateUrl('/apps/encryption/ajax/updatePrivateKeyPassword'),
2015-04-22 17:41:47 +03:00
{
oldPassword: oldPrivateKeyPassword,
newPassword: newPrivateKeyPassword
}
).done(function (data) {
OC.msg.finishedSuccess('#ocDefaultEncryptionModule .msg', data.message);
2015-04-22 17:41:47 +03:00
})
.fail(function (jqXHR) {
OC.msg.finishedError('#ocDefaultEncryptionModule .msg', JSON.parse(jqXHR.responseText).message);
2015-04-22 17:41:47 +03:00
});
2015-04-21 13:01:56 +03:00
}
});
2015-04-21 13:01:56 +03:00
2015-04-22 17:41:47 +03:00
$(document).ready(function () {
2015-03-27 03:35:36 +03:00
// Trigger ajax on recoveryAdmin status change
2015-04-22 17:41:47 +03:00
$('input:radio[name="userEnableRecovery"]').change(
function () {
var recoveryStatus = $(this).val();
2015-03-27 03:35:36 +03:00
OC.msg.startAction('#userEnableRecovery .msg', 'Updating recovery keys. This can take some time...');
$.post(
2015-04-22 17:41:47 +03:00
OC.generateUrl('/apps/encryption/ajax/userSetRecovery'),
{
userEnableRecovery: recoveryStatus
2015-03-27 03:35:36 +03:00
}
2015-04-22 17:41:47 +03:00
).done(function (data) {
OC.msg.finishedSuccess('#userEnableRecovery .msg', data.data.message);
})
.fail(function (jqXHR) {
OC.msg.finishedError('#userEnableRecovery .msg', JSON.parse(jqXHR.responseText).data.message);
});
2015-03-27 03:35:36 +03:00
// Ensure page is not reloaded on form submit
return false;
}
);
// update private key password
2015-04-22 17:41:47 +03:00
$('input:password[name="changePrivateKeyPassword"]').keyup(function (event) {
2015-03-27 03:35:36 +03:00
var oldPrivateKeyPassword = $('input:password[id="oldPrivateKeyPassword"]').val();
var newPrivateKeyPassword = $('input:password[id="newPrivateKeyPassword"]').val();
2015-04-22 17:41:47 +03:00
if (newPrivateKeyPassword !== '' && oldPrivateKeyPassword !== '') {
2015-03-27 03:35:36 +03:00
$('button:button[name="submitChangePrivateKeyPassword"]').removeAttr("disabled");
2015-04-22 17:41:47 +03:00
if (event.which === 13) {
2015-04-21 13:01:56 +03:00
OC.Encryption.updatePrivateKeyPassword();
2015-03-27 03:35:36 +03:00
}
} else {
$('button:button[name="submitChangePrivateKeyPassword"]').attr("disabled", "true");
}
});
2015-04-22 17:41:47 +03:00
$('button:button[name="submitChangePrivateKeyPassword"]').click(function () {
2015-04-21 13:01:56 +03:00
OC.Encryption.updatePrivateKeyPassword();
2015-03-27 03:35:36 +03:00
});
});