settings-admin.js 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. /**
  2. * Copyright (c) 2013
  3. * Sam Tuke <samtuke@owncloud.com>
  4. * Robin Appelman <icewind1991@gmail.com>
  5. * Bjoern Schiessle <schiessle@owncloud.com>
  6. * This file is licensed under the Affero General Public License version 3 or later.
  7. * See the COPYING-README file.
  8. */
  9. window.addEventListener('DOMContentLoaded', function () {
  10. $('input:button[name="enableRecoveryKey"]').click(function () {
  11. var recoveryStatus = $(this).attr('status');
  12. var newRecoveryStatus = (1 + parseInt(recoveryStatus)) % 2;
  13. var buttonValue = $(this).attr('value');
  14. var recoveryPassword = $('#encryptionRecoveryPassword').val();
  15. var confirmPassword = $('#repeatEncryptionRecoveryPassword').val();
  16. OC.msg.startSaving('#encryptionSetRecoveryKey .msg');
  17. $.post(
  18. OC.generateUrl('/apps/encryption/ajax/adminRecovery'),
  19. {
  20. adminEnableRecovery: newRecoveryStatus,
  21. recoveryPassword: recoveryPassword,
  22. confirmPassword: confirmPassword
  23. }
  24. ).done(function (data) {
  25. OC.msg.finishedSuccess('#encryptionSetRecoveryKey .msg', data.data.message);
  26. if (newRecoveryStatus === 0) {
  27. $('p[name="changeRecoveryPasswordBlock"]').addClass("hidden");
  28. $('input:button[name="enableRecoveryKey"]').attr('value', 'Enable recovery key');
  29. $('input:button[name="enableRecoveryKey"]').attr('status', '0');
  30. } else {
  31. $('input:password[name="changeRecoveryPassword"]').val("");
  32. $('p[name="changeRecoveryPasswordBlock"]').removeClass("hidden");
  33. $('input:button[name="enableRecoveryKey"]').attr('value', 'Disable recovery key');
  34. $('input:button[name="enableRecoveryKey"]').attr('status', '1');
  35. }
  36. })
  37. .fail(function (jqXHR) {
  38. $('input:button[name="enableRecoveryKey"]').attr('value', buttonValue);
  39. $('input:button[name="enableRecoveryKey"]').attr('status', recoveryStatus);
  40. OC.msg.finishedError('#encryptionSetRecoveryKey .msg', JSON.parse(jqXHR.responseText).data.message);
  41. });
  42. });
  43. $("#repeatEncryptionRecoveryPassword").keyup(function (event) {
  44. if (event.keyCode == 13) {
  45. $("#enableRecoveryKey").click();
  46. }
  47. });
  48. // change recovery password
  49. $('button:button[name="submitChangeRecoveryKey"]').click(function () {
  50. var oldRecoveryPassword = $('#oldEncryptionRecoveryPassword').val();
  51. var newRecoveryPassword = $('#newEncryptionRecoveryPassword').val();
  52. var confirmNewPassword = $('#repeatedNewEncryptionRecoveryPassword').val();
  53. OC.msg.startSaving('#encryptionChangeRecoveryKey .msg');
  54. $.post(
  55. OC.generateUrl('/apps/encryption/ajax/changeRecoveryPassword'),
  56. {
  57. oldPassword: oldRecoveryPassword,
  58. newPassword: newRecoveryPassword,
  59. confirmPassword: confirmNewPassword
  60. }
  61. ).done(function (data) {
  62. OC.msg.finishedSuccess('#encryptionChangeRecoveryKey .msg', data.data.message);
  63. })
  64. .fail(function (jqXHR) {
  65. OC.msg.finishedError('#encryptionChangeRecoveryKey .msg', JSON.parse(jqXHR.responseText).data.message);
  66. });
  67. });
  68. $('#encryptHomeStorage').change(function() {
  69. $.post(
  70. OC.generateUrl('/apps/encryption/ajax/setEncryptHomeStorage'),
  71. {
  72. encryptHomeStorage: this.checked
  73. }
  74. );
  75. });
  76. });