settings-personal.js 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. /**
  2. * Copyright (c) 2013, Sam Tuke <samtuke@owncloud.com>
  3. * This file is licensed under the Affero General Public License version 3 or later.
  4. * See the COPYING-README file.
  5. */
  6. OC.Encryption = _.extend(OC.Encryption || {}, {
  7. updatePrivateKeyPassword: function () {
  8. var oldPrivateKeyPassword = $('input:password[id="oldPrivateKeyPassword"]').val();
  9. var newPrivateKeyPassword = $('input:password[id="newPrivateKeyPassword"]').val();
  10. OC.msg.startSaving('#ocDefaultEncryptionModule .msg');
  11. $.post(
  12. OC.generateUrl('/apps/encryption/ajax/updatePrivateKeyPassword'),
  13. {
  14. oldPassword: oldPrivateKeyPassword,
  15. newPassword: newPrivateKeyPassword
  16. }
  17. ).done(function (data) {
  18. OC.msg.finishedSuccess('#ocDefaultEncryptionModule .msg', data.message);
  19. })
  20. .fail(function (jqXHR) {
  21. OC.msg.finishedError('#ocDefaultEncryptionModule .msg', JSON.parse(jqXHR.responseText).message);
  22. });
  23. }
  24. });
  25. window.addEventListener('DOMContentLoaded', function () {
  26. // Trigger ajax on recoveryAdmin status change
  27. $('input:radio[name="userEnableRecovery"]').change(
  28. function () {
  29. var recoveryStatus = $(this).val();
  30. OC.msg.startAction('#userEnableRecovery .msg', 'Updating recovery keys. This can take some time...');
  31. $.post(
  32. OC.generateUrl('/apps/encryption/ajax/userSetRecovery'),
  33. {
  34. userEnableRecovery: recoveryStatus
  35. }
  36. ).done(function (data) {
  37. OC.msg.finishedSuccess('#userEnableRecovery .msg', data.data.message);
  38. })
  39. .fail(function (jqXHR) {
  40. OC.msg.finishedError('#userEnableRecovery .msg', JSON.parse(jqXHR.responseText).data.message);
  41. });
  42. // Ensure page is not reloaded on form submit
  43. return false;
  44. }
  45. );
  46. // update private key password
  47. $('input:password[name="changePrivateKeyPassword"]').keyup(function (event) {
  48. var oldPrivateKeyPassword = $('input:password[id="oldPrivateKeyPassword"]').val();
  49. var newPrivateKeyPassword = $('input:password[id="newPrivateKeyPassword"]').val();
  50. if (newPrivateKeyPassword !== '' && oldPrivateKeyPassword !== '') {
  51. $('button:button[name="submitChangePrivateKeyPassword"]').removeAttr("disabled");
  52. if (event.which === 13) {
  53. OC.Encryption.updatePrivateKeyPassword();
  54. }
  55. } else {
  56. $('button:button[name="submitChangePrivateKeyPassword"]').attr("disabled", "true");
  57. }
  58. });
  59. $('button:button[name="submitChangePrivateKeyPassword"]').click(function () {
  60. OC.Encryption.updatePrivateKeyPassword();
  61. });
  62. });