// Copyright (c) 2015 Spinpunch, Inc. All Rights Reserved.
// See License.txt for license information.
import {config} from '../utils/config.js';
export default class SettingPicture extends React.Component {
constructor(props) {
super(props);
this.setPicture = this.setPicture.bind(this);
}
setPicture(file) {
if (file) {
var reader = new FileReader();
var img = React.findDOMNode(this.refs.image);
reader.onload = function load(e) {
$(img).attr('src', e.target.result);
};
reader.readAsDataURL(file);
}
}
componentWillReceiveProps(nextProps) {
if (nextProps.picture) {
this.setPicture(nextProps.picture);
}
}
render() {
var clientError = null;
if (this.props.client_error) {
clientError =
;
}
var serverError = null;
if (this.props.server_error) {
serverError = ;
}
var img = null;
if (this.props.picture) {
img = (
);
} else {
img = (
);
}
var confirmButton;
if (this.props.loadingPicture) {
confirmButton = (
);
} else {
var confirmButtonClass = 'btn btn-sm';
if (this.props.submitActive) {
confirmButtonClass += ' btn-primary';
} else {
confirmButtonClass += ' btn-inactive disabled';
}
confirmButton = (
Save
);
}
var helpText = 'Upload a profile picture in either JPG or PNG format, at least ' + config.ProfileWidth + 'px in width and ' + config.ProfileHeight + 'px height.';
var self = this;
return (
);
}
}
SettingPicture.propTypes = {
client_error: React.PropTypes.string,
server_error: React.PropTypes.string,
src: React.PropTypes.string,
picture: React.PropTypes.object,
loadingPicture: React.PropTypes.bool,
submitActive: React.PropTypes.bool,
submit: React.PropTypes.func,
title: React.PropTypes.string,
pictureChange: React.PropTypes.func
};