2015-08-31 16:36:24 +02:00
|
|
|
'use strict';
|
|
|
|
|
|
|
|
import React from 'react';
|
|
|
|
|
|
|
|
import GlobalNotificationModel from '../../models/global_notification_model';
|
|
|
|
import GlobalNotificationActions from '../../actions/global_notification_actions';
|
|
|
|
|
|
|
|
import Form from '../ascribe_forms/form';
|
|
|
|
import Property from '../ascribe_forms/property';
|
|
|
|
import InputCheckbox from '../ascribe_forms/input_checkbox';
|
|
|
|
import CollapsibleParagraph from '../ascribe_collapsible/collapsible_paragraph';
|
|
|
|
|
2015-09-28 12:00:13 +02:00
|
|
|
import AclProxy from '../acl_proxy';
|
|
|
|
|
2015-09-16 14:07:13 +02:00
|
|
|
import CopyrightAssociationForm from '../ascribe_forms/form_copyright_association';
|
|
|
|
|
2015-08-31 16:36:24 +02:00
|
|
|
import ApiUrls from '../../constants/api_urls';
|
2015-10-12 15:25:21 +02:00
|
|
|
import AscribeSpinner from '../ascribe_spinner';
|
2015-08-31 16:36:24 +02:00
|
|
|
|
|
|
|
import { getLangText } from '../../utils/lang_utils';
|
|
|
|
|
|
|
|
let AccountSettings = React.createClass({
|
2015-09-18 09:46:37 +02:00
|
|
|
propTypes: {
|
2015-09-21 10:57:10 +02:00
|
|
|
currentUser: React.PropTypes.object.isRequired,
|
2015-09-28 12:00:13 +02:00
|
|
|
loadUser: React.PropTypes.func.isRequired,
|
|
|
|
whitelabel: React.PropTypes.object.isRequired
|
2015-08-31 16:36:24 +02:00
|
|
|
},
|
|
|
|
|
2016-02-05 11:53:33 +01:00
|
|
|
handleSuccess() {
|
2015-11-02 11:31:02 +01:00
|
|
|
this.props.loadUser(true);
|
2016-02-05 11:53:33 +01:00
|
|
|
|
|
|
|
const notification = new GlobalNotificationModel(getLangText('Settings succesfully updated'), 'success', 5000);
|
2015-08-31 16:36:24 +02:00
|
|
|
GlobalNotificationActions.appendGlobalNotification(notification);
|
|
|
|
},
|
|
|
|
|
2016-02-05 11:53:33 +01:00
|
|
|
getFormDataProfile() {
|
|
|
|
return { 'email': this.props.currentUser.email };
|
2015-08-31 16:36:24 +02:00
|
|
|
},
|
2016-02-05 10:38:59 +01:00
|
|
|
|
2015-08-31 16:36:24 +02:00
|
|
|
render() {
|
2016-02-05 11:53:33 +01:00
|
|
|
const { currentUser, whitelabel } = this.props;
|
|
|
|
let content = <AscribeSpinner color='dark-blue' size='lg' />;
|
2015-08-31 16:36:24 +02:00
|
|
|
let profile = null;
|
|
|
|
|
2016-02-05 11:53:33 +01:00
|
|
|
if (currentUser.username) {
|
2015-08-31 16:36:24 +02:00
|
|
|
content = (
|
|
|
|
<Form
|
|
|
|
url={ApiUrls.users_username}
|
|
|
|
handleSuccess={this.handleSuccess}>
|
|
|
|
<Property
|
|
|
|
name='username'
|
|
|
|
label={getLangText('Username')}>
|
|
|
|
<input
|
|
|
|
type="text"
|
2016-02-05 11:53:33 +01:00
|
|
|
defaultValue={currentUser.username}
|
2015-08-31 16:36:24 +02:00
|
|
|
placeholder={getLangText('Enter your username')}
|
|
|
|
required/>
|
|
|
|
</Property>
|
|
|
|
<Property
|
|
|
|
name='email'
|
|
|
|
label={getLangText('Email')}
|
2015-09-28 10:02:07 +02:00
|
|
|
overrideForm={true}
|
2015-08-31 16:36:24 +02:00
|
|
|
editable={false}>
|
|
|
|
<input
|
|
|
|
type="text"
|
2016-02-05 11:53:33 +01:00
|
|
|
defaultValue={currentUser.email}
|
2015-08-31 16:36:24 +02:00
|
|
|
placeholder={getLangText('Enter your username')}
|
|
|
|
required/>
|
|
|
|
</Property>
|
|
|
|
<hr />
|
|
|
|
</Form>
|
|
|
|
);
|
|
|
|
profile = (
|
2015-09-28 12:00:13 +02:00
|
|
|
<AclProxy
|
2016-02-05 11:53:33 +01:00
|
|
|
aclObject={whitelabel}
|
2015-09-28 12:00:13 +02:00
|
|
|
aclName="acl_view_settings_account_hash">
|
|
|
|
<Form
|
|
|
|
url={ApiUrls.users_profile}
|
|
|
|
handleSuccess={this.handleSuccess}
|
|
|
|
getFormData={this.getFormDataProfile}>
|
|
|
|
<Property
|
|
|
|
name="hash_locally"
|
2016-02-05 10:38:59 +01:00
|
|
|
className="ascribe-property-collapsible-toggle">
|
2015-09-28 12:00:13 +02:00
|
|
|
<InputCheckbox
|
2016-02-05 11:53:33 +01:00
|
|
|
defaultChecked={currentUser.profile.hash_locally}>
|
2015-09-28 12:00:13 +02:00
|
|
|
<span>
|
|
|
|
{' ' + getLangText('Enable hash option, e.g. slow connections or to keep piece private')}
|
|
|
|
</span>
|
|
|
|
</InputCheckbox>
|
|
|
|
</Property>
|
|
|
|
</Form>
|
|
|
|
</AclProxy>
|
2015-08-31 16:36:24 +02:00
|
|
|
);
|
|
|
|
}
|
|
|
|
return (
|
|
|
|
<CollapsibleParagraph
|
|
|
|
title={getLangText('Account')}
|
|
|
|
defaultExpanded={true}>
|
|
|
|
{content}
|
2015-10-14 16:56:16 +02:00
|
|
|
<AclProxy
|
2016-02-05 11:53:33 +01:00
|
|
|
aclObject={whitelabel}
|
2015-10-14 16:56:16 +02:00
|
|
|
aclName="acl_view_settings_copyright_association">
|
2016-02-05 11:53:33 +01:00
|
|
|
<CopyrightAssociationForm currentUser={currentUser} />
|
2015-10-14 16:56:16 +02:00
|
|
|
</AclProxy>
|
2015-08-31 16:36:24 +02:00
|
|
|
{profile}
|
|
|
|
</CollapsibleParagraph>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2015-10-13 16:42:40 +02:00
|
|
|
export default AccountSettings;
|