1
0
mirror of https://github.com/ascribe/onion.git synced 2024-06-28 00:28:00 +02:00

public and private note in edition and piece

connection in frontend
This commit is contained in:
diminator 2015-08-21 15:04:38 +02:00
parent 116cb9c2fc
commit edec430109
4 changed files with 117 additions and 58 deletions

View File

@ -37,6 +37,8 @@ import DeleteButton from '../ascribe_buttons/delete_button';
import GlobalNotificationModel from '../../models/global_notification_model';
import GlobalNotificationActions from '../../actions/global_notification_actions';
import Note from './note';
import ApiUrls from '../../constants/api_urls';
import AppConstants from '../../constants/application_constants';
@ -100,7 +102,12 @@ let Edition = React.createClass({
this.transitionTo('pieces');
},
getId() {
return {'bitcoin_id': this.props.edition.bitcoin_id};
},
render() {
console.log(!!this.props.edition.public_note || this.props.edition.acl.acl_edit)
return (
<Row>
<Col md={6}>
@ -153,13 +160,25 @@ let Edition = React.createClass({
title="Notes"
show={(this.state.currentUser.username && true || false) ||
(this.props.edition.acl.acl_edit || this.props.edition.public_note)}>
<EditionPersonalNote
currentUser={this.state.currentUser}
handleSuccess={this.props.loadEdition}
edition={this.props.edition}/>
<EditionPublicEditionNote
handleSuccess={this.props.loadEdition}
edition={this.props.edition}/>
<Note
id={this.getId}
label={getLangText('Personal note (private)')}
defaultValue={this.props.edition.private_note ? this.props.edition.private_note : null}
placeholder='Enter your comments ...'
editable={true}
successMessage='Private note saved'
url={ApiUrls.note_private_edition}
currentUser={this.state.currentUser}/>
<Note
id={this.getId}
label={getLangText('Edition note (public)')}
defaultValue={this.props.edition.public_note ? this.props.edition.public_note : null}
placeholder='Enter your comments ...'
editable={!!this.props.edition.acl.acl_edit}
show={!!this.props.edition.public_note || !!this.props.edition.acl.acl_edit}
successMessage='Public edition note saved'
url={ApiUrls.note_public_edition}
currentUser={this.state.currentUser}/>
</CollapsibleParagraph>
<CollapsibleParagraph
@ -312,7 +331,7 @@ let EditionPersonalNote = React.createClass({
if (this.props.currentUser.username && true || false) {
return (
<Form
url={ApiUrls.note_notes}
url={ApiUrls.note_private_edition}
handleSuccess={this.showNotification}>
<Property
name='note'

View File

@ -0,0 +1,66 @@
'use strict';
import React from 'react';
import Form from './../ascribe_forms/form';
import Property from './../ascribe_forms/property';
import InputTextAreaToggable from './../ascribe_forms/input_textarea_toggable';
import GlobalNotificationModel from '../../models/global_notification_model';
import GlobalNotificationActions from '../../actions/global_notification_actions';
import { getLangText } from '../../utils/lang_utils';
let Note = React.createClass({
propTypes: {
url: React.PropTypes.string,
id: React.PropTypes.func,
label: React.PropTypes.string,
currentUser: React.PropTypes.object,
defaultValue: React.PropTypes.string,
editable: React.PropTypes.bool,
show: React.PropTypes.bool,
placeholder: React.PropTypes.string,
successMessage: React.PropTypes.string
},
getDefaultProps() {
return {
editable: true,
show: true,
placeholder: 'Enter a note',
successMessage: 'Note saved'
};
},
showNotification(){
let notification = new GlobalNotificationModel(this.props.successMessage, 'success');
GlobalNotificationActions.appendGlobalNotification(notification);
},
render() {
if ((this.props.currentUser.username && true || false) && this.props.show) {
return (
<Form
url={this.props.url}
getFormData={this.props.id}
handleSuccess={this.showNotification}>
<Property
name='note'
label={this.props.label}
editable={this.props.editable}>
<InputTextAreaToggable
rows={1}
editable={this.props.editable}
defaultValue={this.props.defaultValue}
placeholder={this.props.placeholder}/>
</Property>
<hr />
</Form>
);
}
return null;
}
});
export default Note

View File

@ -29,9 +29,7 @@ import DeleteButton from '../ascribe_buttons/delete_button';
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 Note from './note';
import ApiUrls from '../../constants/api_urls';
import AppConstants from '../../constants/application_constants';
@ -146,6 +144,10 @@ let PieceContainer = React.createClass({
GlobalNotificationActions.appendGlobalNotification(notification);
},
getId() {
return {'id': this.state.piece.id};
},
render() {
if('title' in this.state.piece) {
return (
@ -193,7 +195,20 @@ let PieceContainer = React.createClass({
<HistoryIterator
history={this.state.piece.loan_history} />
</CollapsibleParagraph>
<CollapsibleParagraph
title="Notes"
show={(this.state.currentUser.username && true || false) ||
(this.state.piece.public_note)}>
<Note
id={this.getId}
label={getLangText('Personal note (private)')}
defaultValue={this.state.piece.private_note ? this.state.piece.private_note : null}
placeholder='Enter your comments ...'
editable={true}
successMessage='Private note saved'
url={ApiUrls.note_private_piece}
currentUser={this.state.currentUser}/>
</CollapsibleParagraph>
<CollapsibleParagraph
title="Further Details"
show={this.state.piece.acl.acl_edit
@ -207,11 +222,7 @@ let PieceContainer = React.createClass({
otherData={this.state.piece.other_data}
handleSuccess={this.loadPiece}/>
</CollapsibleParagraph>
{
//<PersonalNote
// piece={this.state.piece}
// currentUser={this.state.currentUser}/>
}
</Piece>
);
} else {
@ -224,43 +235,4 @@ let PieceContainer = React.createClass({
}
});
let PersonalNote = React.createClass({
propTypes: {
piece: React.PropTypes.object,
currentUser: React.PropTypes.object
},
showNotification(){
let notification = new GlobalNotificationModel(getLangText('Jury note saved'), 'success');
GlobalNotificationActions.appendGlobalNotification(notification);
},
render() {
if (this.props.currentUser.username && true || false) {
return (
<Form
url={ApiUrls.note_notes}
handleSuccess={this.showNotification}>
<Property
name='value'
label={getLangText('Jury note')}
editable={true}>
<InputTextAreaToggable
rows={1}
editable={true}
defaultValue={this.props.piece.note_from_user ? this.props.piece.note_from_user.note : null}
placeholder={getLangText('Enter your comments...')}/>
</Property>
<Property hidden={true} name='piece_id'>
<input defaultValue={this.props.piece.id}/>
</Property>
<hr />
</Form>
);
}
return null;
}
});
export default PieceContainer;

View File

@ -22,8 +22,10 @@ let ApiUrls = {
'editions': AppConstants.apiEndpoint + 'editions/', // this should be moved to the one below
'editions_list': AppConstants.apiEndpoint + 'pieces/${piece_id}/editions/',
'licenses': AppConstants.apiEndpoint + 'ownership/licenses/',
'note_notes': AppConstants.apiEndpoint + 'note/notes/',
'note_edition': AppConstants.apiEndpoint + 'note/edition_notes/',
'note_private_edition': AppConstants.apiEndpoint + 'note/private/editions/',
'note_private_piece': AppConstants.apiEndpoint + 'note/private/pieces/',
'note_public_edition': AppConstants.apiEndpoint + 'note/public/editions/',
'note_public_piece': AppConstants.apiEndpoint + 'note/public/pieces/',
'ownership_consigns': AppConstants.apiEndpoint + 'ownership/consigns/',
'ownership_consigns_confirm': AppConstants.apiEndpoint + 'ownership/consigns/confirm/',
'ownership_consigns_deny': AppConstants.apiEndpoint + 'ownership/consigns/deny/',