2015-06-14 23:53:32 -08:00
// Copyright (c) 2015 Spinpunch, Inc. All Rights Reserved.
// See License.txt for license information.
2015-09-01 17:06:31 -07:00
export default class SettingPicture extends React . Component {
constructor ( props ) {
super ( props ) ;
this . setPicture = this . setPicture . bind ( this ) ;
}
setPicture ( file ) {
2015-06-14 23:53:32 -08:00
if ( file ) {
var reader = new FileReader ( ) ;
2015-09-02 15:56:13 -04:00
var img = React . findDOMNode ( this . refs . image ) ;
2015-09-01 17:06:31 -07:00
reader . onload = function load ( e ) {
2015-07-29 14:40:55 -07:00
$ ( img ) . attr ( 'src' , e . target . result ) ;
2015-06-14 23:53:32 -08:00
} ;
reader . readAsDataURL ( file ) ;
}
2015-09-01 17:06:31 -07:00
}
componentWillReceiveProps ( nextProps ) {
2015-06-14 23:53:32 -08:00
if ( nextProps . picture ) {
this . setPicture ( nextProps . picture ) ;
}
2015-09-01 17:06:31 -07:00
}
render ( ) {
2015-08-03 13:52:24 -07:00
var clientError = null ;
if ( this . props . client _error ) {
clientError = < div className = 'form-group has-error' > < label className = 'control-label' > { this . props . client _error } < / label > < / div > ;
}
var serverError = null ;
if ( this . props . server _error ) {
serverError = < div className = 'form-group has-error' > < label className = 'control-label' > { this . props . server _error } < / label > < / div > ;
}
2015-06-14 23:53:32 -08:00
var img = null ;
if ( this . props . picture ) {
2015-09-01 17:06:31 -07:00
img = (
< img
ref = 'image'
className = 'profile-img'
src = ''
/ >
) ;
2015-06-14 23:53:32 -08:00
} else {
2015-09-01 17:06:31 -07:00
img = (
< img
ref = 'image'
className = 'profile-img'
src = { this . props . src }
/ >
) ;
2015-06-14 23:53:32 -08:00
}
2015-08-03 13:52:24 -07:00
var confirmButton ;
if ( this . props . loadingPicture ) {
2015-09-01 17:06:31 -07:00
confirmButton = (
< img
className = 'spinner'
src = '/static/images/load.gif'
/ >
) ;
2015-08-03 13:52:24 -07:00
} else {
var confirmButtonClass = 'btn btn-sm' ;
if ( this . props . submitActive ) {
confirmButtonClass += ' btn-primary' ;
} else {
confirmButtonClass += ' btn-inactive disabled' ;
}
2015-09-01 17:06:31 -07:00
confirmButton = (
< a
className = { confirmButtonClass }
onClick = { this . props . submit }
> Save < / a >
) ;
2015-08-03 13:52:24 -07:00
}
2015-09-15 18:59:14 -07:00
var helpText = 'Upload a profile picture in either JPG or PNG format, at least ' + global . window . config . ProfileWidth + 'px in width and ' + global . window . config . ProfileHeight + 'px height.' ;
2015-06-14 23:53:32 -08:00
2015-08-03 13:52:24 -07:00
var self = this ;
2015-06-14 23:53:32 -08:00
return (
2015-07-29 14:40:55 -07:00
< ul className = 'section-max' >
< li className = 'col-xs-12 section-title' > { this . props . title } < / li >
< li className = 'col-xs-offset-3 col-xs-8' >
< ul className = 'setting-list' >
< li className = 'setting-list-item' >
2015-06-14 23:53:32 -08:00
{ img }
< / li >
2015-08-20 17:02:47 -07:00
< li className = 'setting-list-item' >
{ helpText }
< / li >
2015-07-29 14:40:55 -07:00
< li className = 'setting-list-item' >
2015-08-03 13:52:24 -07:00
{ serverError }
{ clientError }
2015-09-03 10:49:36 -04:00
< span className = 'btn btn-sm btn-primary btn-file sel-btn' >
Select
< input
ref = 'input'
accept = '.jpg,.png,.bmp'
type = 'file'
onChange = { this . props . pictureChange }
2015-09-01 17:06:31 -07:00
/ >
< / span >
2015-08-03 13:52:24 -07:00
{ confirmButton }
2015-09-01 17:06:31 -07:00
< a
className = 'btn btn-sm theme'
href = '#'
onClick = { self . props . updateSection }
> Cancel < / a >
2015-06-14 23:53:32 -08:00
< / li >
< / ul >
< / li >
< / ul >
) ;
}
2015-09-01 17:06:31 -07:00
}
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
2015-09-02 15:56:13 -04:00
} ;