// Copyright (c) 2015 Mattermost, Inc. All Rights Reserved. // See License.txt for license information. import {FormattedMessage} from 'react-intl'; import loadingGif from 'images/load.gif'; import React from 'react'; export default class SettingPicture extends React.Component { constructor(props) { super(props); this.setPicture = this.setPicture.bind(this); this.confirmImage = this.confirmImage.bind(this); } setPicture(file) { if (file) { var reader = new FileReader(); reader.onload = (e) => { const canvas = this.refs.profileImageCanvas; const context = canvas.getContext('2d'); const imageObj = new Image(); imageObj.onload = () => { if (imageObj.width > imageObj.height) { const side = imageObj.height; const rem = imageObj.width - side; const startX = parseInt(rem / 2, 10); context.drawImage(imageObj, startX, 0, side, side, 0, 0, canvas.width, canvas.height); } else { const side = imageObj.width; const rem = imageObj.height - side; const startY = parseInt(rem / 2, 10); context.drawImage(imageObj, 0, startY, side, side, 0, 0, canvas.width, canvas.height); } }; imageObj.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 = (