2016-04-07 22:21:01 +09:00
|
|
|
import React, { PropTypes, Component } from 'react';
|
2016-06-10 10:25:38 +09:00
|
|
|
import { FormattedMessage } from 'react-intl';
|
2016-04-07 22:21:01 +09:00
|
|
|
import Formsy from 'formsy-react';
|
|
|
|
import FRC from 'formsy-react-components';
|
|
|
|
const Input = FRC.Input;
|
|
|
|
|
|
|
|
class ThumbnailURL extends Component {
|
|
|
|
|
2016-05-07 18:12:02 +09:00
|
|
|
constructor(props) {
|
|
|
|
super(props);
|
|
|
|
this.clearThumbnail = this.clearThumbnail.bind(this);
|
2016-05-12 11:47:13 +09:00
|
|
|
this.showInput = this.showInput.bind(this);
|
2016-05-07 18:12:02 +09:00
|
|
|
this.state = {
|
2016-05-12 11:47:13 +09:00
|
|
|
showInput: false
|
2016-05-07 18:12:02 +09:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
clearThumbnail() {
|
2016-05-12 11:47:13 +09:00
|
|
|
this.context.updateCurrentValue("thumbnailUrl", "");
|
|
|
|
}
|
|
|
|
|
|
|
|
showInput() {
|
2016-05-07 18:12:02 +09:00
|
|
|
this.setState({
|
2016-05-12 11:47:13 +09:00
|
|
|
showInput: true
|
2016-05-07 18:12:02 +09:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2016-04-07 22:21:01 +09:00
|
|
|
renderThumbnail() {
|
2016-05-07 18:12:02 +09:00
|
|
|
return (
|
|
|
|
<div>
|
|
|
|
<img
|
|
|
|
className="embedly-thumbnail"
|
|
|
|
src={this.props.value}
|
2016-07-15 11:15:32 +09:00
|
|
|
style={{
|
|
|
|
"width": 150,
|
|
|
|
"height": Telescope.settings.get('thumbnailHeight', 150) * 150 / Telescope.settings.get('thumbnailWidth', 150)
|
|
|
|
}}
|
2016-05-07 18:12:02 +09:00
|
|
|
/>
|
2016-06-10 10:25:38 +09:00
|
|
|
<a className="thumbnail-url-clear" onClick={this.clearThumbnail}><FormattedMessage id="posts.clear_thumbnail"/></a>
|
2016-05-07 18:12:02 +09:00
|
|
|
</div>
|
|
|
|
)
|
2016-04-07 22:21:01 +09:00
|
|
|
}
|
|
|
|
|
|
|
|
render() {
|
|
|
|
|
|
|
|
const {name, value, label} = this.props;
|
|
|
|
|
2016-05-12 11:47:13 +09:00
|
|
|
const inputType = this.state.showInput ? "text" : "hidden";
|
|
|
|
|
2016-04-07 22:21:01 +09:00
|
|
|
return (
|
|
|
|
<div className="form-group row">
|
|
|
|
<label className="control-label col-sm-3">{label}</label>
|
|
|
|
<div className="col-sm-9">
|
2016-05-12 11:47:13 +09:00
|
|
|
{this.props.value ? this.renderThumbnail() : null}
|
2016-06-28 17:33:30 +09:00
|
|
|
<Input layout="elementOnly" name={name} type={inputType} value={this.props.value} />
|
2016-06-10 10:25:38 +09:00
|
|
|
{!this.state.showInput ? <a className="thumbnail-show-input" onClick={this.showInput}><FormattedMessage id="posts.enter_thumbnail_url"/></a> : null}
|
2016-04-07 22:21:01 +09:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
ThumbnailURL.propTypes = {
|
|
|
|
name: React.PropTypes.string,
|
|
|
|
value: React.PropTypes.any,
|
|
|
|
label: React.PropTypes.string
|
|
|
|
}
|
|
|
|
|
2016-05-07 18:12:02 +09:00
|
|
|
ThumbnailURL.contextTypes = {
|
|
|
|
addToPrefilledValues: React.PropTypes.func,
|
2016-05-12 11:47:13 +09:00
|
|
|
updateCurrentValue: React.PropTypes.func,
|
2016-05-07 18:12:02 +09:00
|
|
|
deleteValue: React.PropTypes.func
|
|
|
|
}
|
|
|
|
|
2016-04-07 22:21:01 +09:00
|
|
|
export default ThumbnailURL;
|