|
@@ -9,11 +9,23 @@ import { createSubscribedElement } from '../UnstatedUtils';
|
|
|
import AppContainer from '../../services/AppContainer';
|
|
import AppContainer from '../../services/AppContainer';
|
|
|
import PersonalContainer from '../../services/PersonalContainer';
|
|
import PersonalContainer from '../../services/PersonalContainer';
|
|
|
|
|
|
|
|
|
|
+import ImageCropModal from './ImageCropModal';
|
|
|
|
|
+
|
|
|
class ProfileImageSettings extends React.Component {
|
|
class ProfileImageSettings extends React.Component {
|
|
|
|
|
|
|
|
constructor(appContainer) {
|
|
constructor(appContainer) {
|
|
|
super();
|
|
super();
|
|
|
|
|
|
|
|
|
|
+ this.state = {
|
|
|
|
|
+ show: false,
|
|
|
|
|
+ src: null,
|
|
|
|
|
+ };
|
|
|
|
|
+
|
|
|
|
|
+ this.imageRef = null;
|
|
|
|
|
+ this.onSelectFile = this.onSelectFile.bind(this);
|
|
|
|
|
+ this.hideModal = this.hideModal.bind(this);
|
|
|
|
|
+ this.cancelModal = this.cancelModal.bind(this);
|
|
|
|
|
+ this.onCropCompleted = this.onCropCompleted.bind(this);
|
|
|
this.onClickSubmit = this.onClickSubmit.bind(this);
|
|
this.onClickSubmit = this.onClickSubmit.bind(this);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -35,8 +47,35 @@ class ProfileImageSettings extends React.Component {
|
|
|
return `https://gravatar.com/avatar/${hash}`;
|
|
return `https://gravatar.com/avatar/${hash}`;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ onSelectFile(e) {
|
|
|
|
|
+ if (e.target.files && e.target.files.length > 0) {
|
|
|
|
|
+ const reader = new FileReader();
|
|
|
|
|
+ reader.addEventListener('load', () => this.setState({ src: reader.result }));
|
|
|
|
|
+ reader.readAsDataURL(e.target.files[0]);
|
|
|
|
|
+ this.setState({ show: true });
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ onCropCompleted(croppedImageUrl) {
|
|
|
|
|
+ this.props.personalContainer.setState({ croppedImageUrl });
|
|
|
|
|
+ this.hideModal();
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ showModal() {
|
|
|
|
|
+ this.setState({ show: true });
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ hideModal() {
|
|
|
|
|
+ this.setState({ show: false });
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ cancelModal() {
|
|
|
|
|
+ this.hideModal();
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
render() {
|
|
render() {
|
|
|
const { t, personalContainer } = this.props;
|
|
const { t, personalContainer } = this.props;
|
|
|
|
|
+ const { croppedImageUrl, isGravatarEnabled } = personalContainer.state;
|
|
|
|
|
|
|
|
return (
|
|
return (
|
|
|
<React.Fragment>
|
|
<React.Fragment>
|
|
@@ -49,7 +88,7 @@ class ProfileImageSettings extends React.Component {
|
|
|
id="radioGravatar"
|
|
id="radioGravatar"
|
|
|
form="formImageType"
|
|
form="formImageType"
|
|
|
name="imagetypeForm[isGravatarEnabled]"
|
|
name="imagetypeForm[isGravatarEnabled]"
|
|
|
- checked={personalContainer.state.isGravatarEnabled}
|
|
|
|
|
|
|
+ checked={isGravatarEnabled}
|
|
|
onChange={() => { personalContainer.changeIsGravatarEnabled(true) }}
|
|
onChange={() => { personalContainer.changeIsGravatarEnabled(true) }}
|
|
|
/>
|
|
/>
|
|
|
<label htmlFor="radioGravatar">
|
|
<label htmlFor="radioGravatar">
|
|
@@ -72,7 +111,7 @@ class ProfileImageSettings extends React.Component {
|
|
|
id="radioUploadPicture"
|
|
id="radioUploadPicture"
|
|
|
form="formImageType"
|
|
form="formImageType"
|
|
|
name="imagetypeForm[isGravatarEnabled]"
|
|
name="imagetypeForm[isGravatarEnabled]"
|
|
|
- checked={!personalContainer.state.isGravatarEnabled}
|
|
|
|
|
|
|
+ checked={!isGravatarEnabled}
|
|
|
onChange={() => { personalContainer.changeIsGravatarEnabled(false) }}
|
|
onChange={() => { personalContainer.changeIsGravatarEnabled(false) }}
|
|
|
/>
|
|
/>
|
|
|
<label htmlFor="radioUploadPicture">
|
|
<label htmlFor="radioUploadPicture">
|
|
@@ -80,16 +119,33 @@ class ProfileImageSettings extends React.Component {
|
|
|
</label>
|
|
</label>
|
|
|
</div>
|
|
</div>
|
|
|
</h4>
|
|
</h4>
|
|
|
- <div className="form-group">
|
|
|
|
|
- <div id="pictureUploadFormMessage"></div>
|
|
|
|
|
|
|
+ <div className="row mb-3">
|
|
|
<label className="col-sm-4 control-label">
|
|
<label className="col-sm-4 control-label">
|
|
|
{ t('Current Image') }
|
|
{ t('Current Image') }
|
|
|
</label>
|
|
</label>
|
|
|
- {/* TDOO GW-1198 uproad profile image */}
|
|
|
|
|
|
|
+ <div className="col-sm-8">
|
|
|
|
|
+ {croppedImageUrl && (<p><img src={croppedImageUrl} className="picture picture-lg img-circle" id="settingUserPicture" /></p>)}
|
|
|
|
|
+ <button type="button" className="btn btn-danger">{ t('Delete Image') }</button>
|
|
|
|
|
+ </div>
|
|
|
|
|
+ </div>
|
|
|
|
|
+ <div className="row">
|
|
|
|
|
+ <label className="col-sm-4 control-label">
|
|
|
|
|
+ {t('Upload new image')}
|
|
|
|
|
+ </label>
|
|
|
|
|
+ <div className="col-sm-8">
|
|
|
|
|
+ <input type="file" onChange={this.onSelectFile} name="profileImage" accept="image/*" />
|
|
|
|
|
+ </div>
|
|
|
</div>
|
|
</div>
|
|
|
</div>
|
|
</div>
|
|
|
</div>
|
|
</div>
|
|
|
|
|
|
|
|
|
|
+ <ImageCropModal
|
|
|
|
|
+ show={this.state.show}
|
|
|
|
|
+ src={this.state.src}
|
|
|
|
|
+ onModalClose={this.cancelModal}
|
|
|
|
|
+ onCropCompleted={this.onCropCompleted}
|
|
|
|
|
+ />
|
|
|
|
|
+
|
|
|
<div className="row my-3">
|
|
<div className="row my-3">
|
|
|
<div className="col-xs-offset-4 col-xs-5">
|
|
<div className="col-xs-offset-4 col-xs-5">
|
|
|
<button type="button" className="btn btn-primary" onClick={this.onClickSubmit} disabled={personalContainer.state.retrieveError != null}>
|
|
<button type="button" className="btn btn-primary" onClick={this.onClickSubmit} disabled={personalContainer.state.retrieveError != null}>
|