2015-08-21 15:04:38 +02:00
|
|
|
'use strict';
|
|
|
|
|
|
|
|
import React from 'react';
|
|
|
|
|
2016-02-05 11:53:33 +01:00
|
|
|
import GlobalNotificationModel from '../../models/global_notification_model';
|
|
|
|
import GlobalNotificationActions from '../../actions/global_notification_actions';
|
|
|
|
|
2015-08-21 15:04:38 +02:00
|
|
|
import Form from './../ascribe_forms/form';
|
|
|
|
import Property from './../ascribe_forms/property';
|
|
|
|
import InputTextAreaToggable from './../ascribe_forms/input_textarea_toggable';
|
|
|
|
|
|
|
|
import { getLangText } from '../../utils/lang_utils';
|
|
|
|
|
|
|
|
let Note = React.createClass({
|
|
|
|
propTypes: {
|
2016-02-05 11:53:33 +01:00
|
|
|
currentUser: React.PropTypes.object.isRequired,
|
|
|
|
id: React.PropTypes.func.isRequired,
|
|
|
|
url: React.PropTypes.string.isRequired,
|
|
|
|
|
2015-08-21 15:04:38 +02:00
|
|
|
defaultValue: React.PropTypes.string,
|
|
|
|
editable: React.PropTypes.bool,
|
2016-02-05 11:53:33 +01:00
|
|
|
label: React.PropTypes.string,
|
2015-08-21 15:04:38 +02:00
|
|
|
placeholder: React.PropTypes.string,
|
2016-02-05 11:53:33 +01:00
|
|
|
show: React.PropTypes.bool,
|
2015-08-21 15:04:38 +02:00
|
|
|
successMessage: React.PropTypes.string
|
|
|
|
},
|
|
|
|
|
|
|
|
getDefaultProps() {
|
|
|
|
return {
|
|
|
|
editable: true,
|
2015-08-21 16:38:18 +02:00
|
|
|
placeholder: getLangText('Enter a note'),
|
2016-02-05 11:53:33 +01:00
|
|
|
show: true,
|
2015-08-21 16:38:18 +02:00
|
|
|
successMessage: getLangText('Note saved')
|
2015-08-21 15:04:38 +02:00
|
|
|
};
|
|
|
|
},
|
|
|
|
|
2016-02-05 11:53:33 +01:00
|
|
|
showNotification() {
|
|
|
|
const notification = new GlobalNotificationModel(this.props.successMessage, 'success');
|
2015-08-21 15:04:38 +02:00
|
|
|
GlobalNotificationActions.appendGlobalNotification(notification);
|
|
|
|
},
|
|
|
|
|
|
|
|
render() {
|
2016-02-05 11:53:33 +01:00
|
|
|
const { currentUser, defaultValue, editable, id, label, placeholder, show, url } = this.props;
|
|
|
|
|
|
|
|
if ((!!currentUser.username && editable || !editable ) && show) {
|
2015-08-21 15:04:38 +02:00
|
|
|
return (
|
|
|
|
<Form
|
2016-02-05 11:53:33 +01:00
|
|
|
url={url}
|
|
|
|
getFormData={id}
|
2015-09-21 12:05:42 +02:00
|
|
|
handleSuccess={this.showNotification}
|
2016-02-05 11:53:33 +01:00
|
|
|
disabled={!editable}>
|
2015-08-21 15:04:38 +02:00
|
|
|
<Property
|
|
|
|
name='note'
|
2016-02-05 11:53:33 +01:00
|
|
|
label={label}>
|
2015-08-21 15:04:38 +02:00
|
|
|
<InputTextAreaToggable
|
|
|
|
rows={1}
|
2016-02-05 11:53:33 +01:00
|
|
|
defaultValue={defaultValue}
|
|
|
|
placeholder={placeholder} />
|
2015-08-21 15:04:38 +02:00
|
|
|
</Property>
|
|
|
|
<hr />
|
|
|
|
</Form>
|
|
|
|
);
|
2016-02-05 11:53:33 +01:00
|
|
|
} else {
|
|
|
|
return null;
|
2015-08-21 15:04:38 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2016-02-05 11:53:33 +01:00
|
|
|
export default Note;
|