2017-04-13 00:23:43 +00:00
|
|
|
import React, { Component } from 'react';
|
|
|
|
import { connect } from 'react-redux';
|
|
|
|
|
|
|
|
import { setPassword } from '../../base/conference';
|
|
|
|
import { translate } from '../../base/i18n';
|
|
|
|
|
|
|
|
/**
|
2017-04-18 21:49:52 +00:00
|
|
|
* A React {@code Component} for locking a JitsiConference with a password.
|
2017-04-13 00:23:43 +00:00
|
|
|
*/
|
|
|
|
class AddPasswordForm extends Component {
|
|
|
|
/**
|
2017-04-18 21:49:52 +00:00
|
|
|
* {@code AddPasswordForm}'s property types.
|
2017-04-13 00:23:43 +00:00
|
|
|
*
|
|
|
|
* @static
|
|
|
|
*/
|
|
|
|
static propTypes = {
|
|
|
|
/**
|
|
|
|
* The JitsiConference on which to lock and set a password.
|
|
|
|
*
|
|
|
|
* @type {JitsiConference}
|
|
|
|
*/
|
|
|
|
conference: React.PropTypes.object,
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Invoked to set a password on the conference.
|
|
|
|
*/
|
|
|
|
dispatch: React.PropTypes.func,
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Invoked to obtain translated strings.
|
|
|
|
*/
|
|
|
|
t: React.PropTypes.func
|
2017-06-02 02:01:50 +00:00
|
|
|
};
|
2017-04-13 00:23:43 +00:00
|
|
|
|
|
|
|
/**
|
2017-04-18 21:49:52 +00:00
|
|
|
* Initializes a new {@code AddPasswordForm} instance.
|
2017-04-13 00:23:43 +00:00
|
|
|
*
|
|
|
|
* @param {Object} props - The read-only properties with which the new
|
|
|
|
* instance is to be initialized.
|
|
|
|
*/
|
|
|
|
constructor(props) {
|
|
|
|
super(props);
|
|
|
|
|
|
|
|
this.state = {
|
2017-04-18 21:49:52 +00:00
|
|
|
/**
|
|
|
|
* The current value to display in {@code AddPasswordForm}
|
|
|
|
* component's input field. The value is also used as the desired
|
|
|
|
* new password when creating a {@code setPassword} action.
|
|
|
|
*
|
|
|
|
* @type {string}
|
|
|
|
*/
|
2017-04-13 00:23:43 +00:00
|
|
|
password: ''
|
|
|
|
};
|
|
|
|
|
2017-04-18 21:49:52 +00:00
|
|
|
// Bind event handlers so they are only bound once for every instance.
|
2017-04-13 00:23:43 +00:00
|
|
|
this._onKeyDown = this._onKeyDown.bind(this);
|
|
|
|
this._onPasswordChange = this._onPasswordChange.bind(this);
|
|
|
|
this._onSubmit = this._onSubmit.bind(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Implements React's {@link Component#render()}.
|
|
|
|
*
|
|
|
|
* @inheritdoc
|
|
|
|
* @returns {ReactElement}
|
|
|
|
*/
|
|
|
|
render() {
|
2017-04-18 21:49:52 +00:00
|
|
|
const { t } = this.props;
|
|
|
|
|
2017-04-13 00:23:43 +00:00
|
|
|
return (
|
|
|
|
<div
|
|
|
|
className = 'form-control'
|
|
|
|
onSubmit = { this._onSubmit } >
|
|
|
|
<div className = 'form-control__container'>
|
|
|
|
<input
|
|
|
|
autoFocus = { true }
|
|
|
|
className = 'input-control'
|
|
|
|
id = 'newPasswordInput'
|
|
|
|
onChange = { this._onPasswordChange }
|
|
|
|
onKeyDown = { this._onKeyDown }
|
2017-04-18 21:49:52 +00:00
|
|
|
placeholder = { t('dialog.createPassword') }
|
2017-04-13 00:23:43 +00:00
|
|
|
type = 'text' />
|
|
|
|
<button
|
|
|
|
className = 'button-control button-control_light'
|
|
|
|
disabled = { !this.state.password }
|
|
|
|
id = 'addPasswordBtn'
|
|
|
|
onClick = { this._onSubmit }
|
|
|
|
type = 'button'>
|
2017-04-18 21:49:52 +00:00
|
|
|
{ t('dialog.add') }
|
2017-04-13 00:23:43 +00:00
|
|
|
</button>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Mimics form behavior by listening for enter key press and submitting the
|
|
|
|
* entered password.
|
|
|
|
*
|
|
|
|
* @param {Object} event - DOM Event for keydown.
|
|
|
|
* @private
|
|
|
|
* @returns {void}
|
|
|
|
*/
|
|
|
|
_onKeyDown(event) {
|
|
|
|
event.stopPropagation();
|
|
|
|
|
|
|
|
if (event.keyCode === /* Enter */ 13) {
|
|
|
|
this._onSubmit();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Updates the internal state of the entered password.
|
|
|
|
*
|
|
|
|
* @param {Object} event - DOM Event for value change.
|
|
|
|
* @private
|
|
|
|
* @returns {void}
|
|
|
|
*/
|
|
|
|
_onPasswordChange(event) {
|
|
|
|
this.setState({ password: event.target.value });
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Dispatches a request to lock the conference with a password.
|
|
|
|
*
|
|
|
|
* @private
|
|
|
|
* @returns {void}
|
|
|
|
*/
|
|
|
|
_onSubmit() {
|
|
|
|
if (!this.state.password) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-04-18 21:49:52 +00:00
|
|
|
const { conference } = this.props;
|
2017-04-13 00:23:43 +00:00
|
|
|
|
|
|
|
this.props.dispatch(setPassword(
|
|
|
|
conference,
|
|
|
|
conference.lock,
|
|
|
|
this.state.password
|
|
|
|
));
|
|
|
|
|
|
|
|
this.setState({ password: '' });
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export default translate(connect()(AddPasswordForm));
|