1
0
mirror of https://github.com/ascribe/onion.git synced 2024-12-23 09:50:31 +01:00
onion/js/components/ascribe_detail/note.js

70 lines
2.2 KiB
JavaScript
Raw Normal View History

'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 InputTextAreaToggable from './../ascribe_forms/input_textarea_toggable';
import { getLangText } from '../../utils/lang_utils';
let Note = React.createClass({
propTypes: {
currentUser: React.PropTypes.object.isRequired,
id: React.PropTypes.func.isRequired,
url: React.PropTypes.string.isRequired,
defaultValue: React.PropTypes.string,
editable: React.PropTypes.bool,
label: React.PropTypes.string,
placeholder: React.PropTypes.string,
show: React.PropTypes.bool,
successMessage: React.PropTypes.string
},
getDefaultProps() {
return {
editable: true,
2015-08-21 16:38:18 +02:00
placeholder: getLangText('Enter a note'),
show: true,
2015-08-21 16:38:18 +02:00
successMessage: getLangText('Note saved')
};
},
showNotification() {
const notification = new GlobalNotificationModel(this.props.successMessage, 'success');
GlobalNotificationActions.appendGlobalNotification(notification);
},
render() {
const { currentUser, defaultValue, editable, id, label, placeholder, show, url } = this.props;
if ((!!currentUser.username && editable || !editable ) && show) {
return (
<Form
url={url}
getFormData={id}
handleSuccess={this.showNotification}
disabled={!editable}>
<Property
name='note'
label={label}>
<InputTextAreaToggable
rows={1}
defaultValue={defaultValue}
placeholder={placeholder} />
</Property>
<hr />
</Form>
);
} else {
return null;
}
}
});
export default Note;