2016-01-13 18:32:41 +03:00
|
|
|
/*
|
|
|
|
Copyright 2015, 2016 OpenMarket Ltd
|
|
|
|
|
|
|
|
Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
you may not use this file except in compliance with the License.
|
|
|
|
You may obtain a copy of the License at
|
|
|
|
|
|
|
|
http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
|
|
|
|
Unless required by applicable law or agreed to in writing, software
|
|
|
|
distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
See the License for the specific language governing permissions and
|
|
|
|
limitations under the License.
|
|
|
|
*/
|
|
|
|
|
2017-01-24 18:54:05 +03:00
|
|
|
import React from 'react';
|
|
|
|
import sdk from '../../../index';
|
2017-05-25 13:39:08 +03:00
|
|
|
import { _t } from '../../../languageHandler';
|
2016-01-13 18:32:41 +03:00
|
|
|
|
2017-01-24 18:54:05 +03:00
|
|
|
export default React.createClass({
|
2016-01-13 18:32:41 +03:00
|
|
|
displayName: 'TextInputDialog',
|
|
|
|
propTypes: {
|
|
|
|
title: React.PropTypes.string,
|
2016-03-18 14:20:00 +03:00
|
|
|
description: React.PropTypes.oneOfType([
|
|
|
|
React.PropTypes.element,
|
|
|
|
React.PropTypes.string,
|
|
|
|
]),
|
2016-01-13 18:32:41 +03:00
|
|
|
value: React.PropTypes.string,
|
|
|
|
button: React.PropTypes.string,
|
|
|
|
focus: React.PropTypes.bool,
|
2017-01-24 18:54:05 +03:00
|
|
|
onFinished: React.PropTypes.func.isRequired,
|
2016-01-13 18:32:41 +03:00
|
|
|
},
|
|
|
|
|
|
|
|
getDefaultProps: function() {
|
|
|
|
return {
|
|
|
|
title: "",
|
|
|
|
value: "",
|
|
|
|
description: "",
|
2017-01-24 18:54:05 +03:00
|
|
|
focus: true,
|
2016-01-13 18:32:41 +03:00
|
|
|
};
|
|
|
|
},
|
2016-06-02 23:07:04 +03:00
|
|
|
|
2016-01-13 18:32:41 +03:00
|
|
|
componentDidMount: function() {
|
|
|
|
if (this.props.focus) {
|
2016-06-02 23:07:04 +03:00
|
|
|
// Set the cursor at the end of the text input
|
|
|
|
this.refs.textinput.value = this.props.value;
|
2016-01-13 18:32:41 +03:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
onOk: function() {
|
|
|
|
this.props.onFinished(true, this.refs.textinput.value);
|
|
|
|
},
|
|
|
|
|
|
|
|
onCancel: function() {
|
|
|
|
this.props.onFinished(false);
|
|
|
|
},
|
|
|
|
|
|
|
|
render: function() {
|
2017-01-24 18:54:05 +03:00
|
|
|
const BaseDialog = sdk.getComponent('views.dialogs.BaseDialog');
|
2016-01-13 18:32:41 +03:00
|
|
|
return (
|
2017-01-24 18:54:05 +03:00
|
|
|
<BaseDialog className="mx_TextInputDialog" onFinished={this.props.onFinished}
|
|
|
|
title={this.props.title}
|
|
|
|
>
|
2017-12-03 23:38:21 +03:00
|
|
|
<form onSubmit={this.onOk}>
|
|
|
|
<div className="mx_Dialog_content">
|
|
|
|
<div className="mx_TextInputDialog_label">
|
|
|
|
<label htmlFor="textinput"> { this.props.description } </label>
|
|
|
|
</div>
|
|
|
|
<div>
|
|
|
|
<input id="textinput" ref="textinput" className="mx_TextInputDialog_input" defaultValue={this.props.value} autoFocus={this.props.focus} size="64" />
|
|
|
|
</div>
|
2016-01-13 18:32:41 +03:00
|
|
|
</div>
|
2017-12-03 23:38:21 +03:00
|
|
|
<div className="mx_Dialog_buttons">
|
|
|
|
<button onClick={this.onCancel}>
|
|
|
|
{ _t("Cancel") }
|
|
|
|
</button>
|
2017-12-08 09:47:08 +03:00
|
|
|
<input type="submit" className="mx_Dialog_primary" value={this.props.button} />
|
2016-01-13 18:32:41 +03:00
|
|
|
</div>
|
2017-12-03 23:38:21 +03:00
|
|
|
</form>
|
2017-01-24 18:54:05 +03:00
|
|
|
</BaseDialog>
|
2016-01-13 18:32:41 +03:00
|
|
|
);
|
2017-01-24 18:54:05 +03:00
|
|
|
},
|
2016-01-13 18:32:41 +03:00
|
|
|
});
|