Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

RequirePasswordDialog.js 3.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. /* global APP */
  2. import UIUtil from '../util/UIUtil';
  3. /**
  4. * Show dialog which asks for required conference password.
  5. * @returns {Promise<string>} password or nothing if user canceled
  6. */
  7. export default class RequirePasswordDialog {
  8. constructor() {
  9. this.titleKey = 'dialog.passwordRequired';
  10. this.labelKey = 'dialog.passwordLabel';
  11. this.errorKey = 'dialog.incorrectPassword';
  12. this.errorId = 'passwordRequiredError';
  13. this.inputId = 'passwordRequiredInput';
  14. this.inputErrorClass = 'error';
  15. this.isOpened = false;
  16. }
  17. _registerListeners() {
  18. let el = document.getElementById(this.inputId);
  19. el.addEventListener('keypress', this._hideError.bind(this));
  20. }
  21. _getBodyMessage() {
  22. return (
  23. `<div class="input-control">
  24. <label class="input-control__label"
  25. data-i18n="${this.labelKey}"></label>
  26. <input class="input-control__input" name="lockKey" type="text"
  27. data-i18n="[placeholder]dialog.password"
  28. autofocus id="${this.inputId}">
  29. <p class="input-control__hint input-control__hint_error hide"
  30. id="${this.errorId}"
  31. data-i18n="${this.errorKey}"></p>
  32. </div>`
  33. );
  34. }
  35. askForPassword() {
  36. if (!this.isOpened) {
  37. return this.open();
  38. }
  39. return new Promise((resolve, reject) => {
  40. this.resolve = resolve;
  41. this.reject = reject;
  42. this._showError();
  43. });
  44. }
  45. open() {
  46. let { titleKey } = this;
  47. let msgString = this._getBodyMessage();
  48. return new Promise((resolve, reject) => {
  49. this.resolve = resolve;
  50. this.reject = reject;
  51. let submitFunction = this._submitFunction.bind(this);
  52. let closeFunction = this._closeFunction.bind(this);
  53. APP.UI.messageHandler.openTwoButtonDialog({
  54. titleKey,
  55. msgString,
  56. leftButtonKey: "dialog.Ok",
  57. submitFunction,
  58. closeFunction,
  59. focus: ':input:first'
  60. });
  61. this._registerListeners();
  62. this.isOpened = true;
  63. });
  64. }
  65. _submitFunction(e, v, m, f) {
  66. e.preventDefault();
  67. if (v && f.lockKey) {
  68. this.resolve(UIUtil.escapeHtml(f.lockKey));
  69. } else {
  70. this.reject(APP.UI.messageHandler.CANCEL);
  71. }
  72. }
  73. _closeFunction() {
  74. this._hideError();
  75. this.close();
  76. }
  77. _showError() {
  78. let className = this.inputErrorClass;
  79. document.getElementById(this.errorId).classList.remove('hide');
  80. document.getElementById(this.inputId).classList.add(className);
  81. }
  82. _hideError() {
  83. let className = this.inputErrorClass;
  84. document.getElementById(this.errorId).classList.add('hide');
  85. document.getElementById(this.inputId).classList.remove(className);
  86. }
  87. close() {
  88. APP.UI.messageHandler.closeDialog();
  89. this.isOpened = false;
  90. }
  91. }