personalInfo.js 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. /* global OC */
  2. /**
  3. * Copyright (c) 2011, Robin Appelman <icewind1991@gmail.com>
  4. * 2013, Morris Jobke <morris.jobke@gmail.com>
  5. * 2016, Christoph Wurst <christoph@owncloud.com>
  6. * 2017, Arthur Schiwon <blizzz@arthur-schiwon.de>
  7. * 2017, Thomas Citharel <tcit@tcit.fr>
  8. * This file is licensed under the Affero General Public License version 3 or later.
  9. * See the COPYING-README file.
  10. */
  11. OC.Settings = OC.Settings || {};
  12. /**
  13. * The callback will be fired as soon as enter is pressed by the
  14. * user or 1 second after the last data entry
  15. *
  16. * @param {any} callback -
  17. * @param allowEmptyValue if this is set to true the callback is also called when the value is empty
  18. */
  19. jQuery.fn.keyUpDelayedOrEnter = function (callback, allowEmptyValue) {
  20. var cb = callback;
  21. var that = this;
  22. this.on('input', _.debounce(function (event) {
  23. // enter is already handled in keypress
  24. if (event.keyCode === 13) {
  25. return;
  26. }
  27. if (allowEmptyValue || that.val() !== '') {
  28. cb(event);
  29. }
  30. }, 1000));
  31. this.keypress(function (event) {
  32. if (event.keyCode === 13 && (allowEmptyValue || that.val() !== '')) {
  33. event.preventDefault();
  34. cb(event);
  35. }
  36. });
  37. };
  38. window.addEventListener('DOMContentLoaded', function () {
  39. if($('#pass2').length) {
  40. $('#pass2').showPassword().keyup();
  41. }
  42. var showVerifyDialog = function(dialog, howToVerify, verificationCode) {
  43. var dialogContent = dialog.children('.verification-dialog-content');
  44. dialogContent.children(".explainVerification").text(howToVerify);
  45. dialogContent.children(".verificationCode").text(verificationCode);
  46. dialog.css('display', 'block');
  47. };
  48. $(".verify").click(function (event) {
  49. event.stopPropagation();
  50. var verify = $(this);
  51. var indicator = $(this).children('img');
  52. var accountId = indicator.attr('id');
  53. var status = indicator.data('status');
  54. var onlyVerificationCode = false;
  55. if (parseInt(status) === 1) {
  56. onlyVerificationCode = true;
  57. }
  58. if (indicator.hasClass('verify-action')) {
  59. $.ajax(
  60. OC.generateUrl('/settings/users/{account}/verify', {account: accountId}),
  61. {
  62. method: 'GET',
  63. data: {onlyVerificationCode: onlyVerificationCode}
  64. }
  65. ).done(function (data) {
  66. var dialog = verify.children('.verification-dialog');
  67. showVerifyDialog($(dialog), data.msg, data.code);
  68. indicator.attr('data-origin-title', t('settings', 'Verifying …'));
  69. indicator.attr('src', OC.imagePath('core', 'actions/verifying.svg'));
  70. indicator.data('status', '1');
  71. });
  72. }
  73. });
  74. // When the user clicks anywhere outside of the verification dialog we close it
  75. $(document).click(function(event){
  76. var element = event.target;
  77. var isDialog = $(element).hasClass('verificationCode')
  78. || $(element).hasClass('explainVerification')
  79. || $(element).hasClass('verification-dialog-content')
  80. || $(element).hasClass('verification-dialog');
  81. if (!isDialog) {
  82. $(document).find('.verification-dialog').css('display', 'none');
  83. }
  84. });
  85. var settingsEl = $('#personal-settings')
  86. var userSettings = new OC.Settings.UserSettings();
  87. var federationSettingsView = new OC.Settings.FederationSettingsView({
  88. el: settingsEl,
  89. config: userSettings,
  90. showFederatedScope: !!settingsEl.data('federation-enabled'),
  91. showPublishedScope: !!settingsEl.data('lookup-server-upload-enabled'),
  92. });
  93. federationSettingsView.render();
  94. });