1
0
mirror of https://github.com/ascribe/onion.git synced 2024-11-15 01:25:17 +01:00

Merge branch 'AD-846-loan-request-action-panel-on-piec' into AD-613-cyland-white-label-page

This commit is contained in:
diminator 2015-08-24 11:36:30 +02:00
commit 440dcd9785
6 changed files with 104 additions and 52 deletions

View File

@ -242,7 +242,9 @@ let EditionSummary = React.createClass({
actions = (
<RequestActionForm
currentUser={this.props.currentUser}
editions={ [this.props.edition] }
pieceOrEditions={ [this.props.edition] }
requestAction={this.props.edition.request_action}
requestUser={this.props.edition.owner}
handleSuccess={this.showNotification}/>);
}

View File

@ -82,6 +82,7 @@ let FurtherDetails = React.createClass({
setIsUploadReady={this.setIsUploadReady}
isReadyForFormSubmission={isReadyForFormSubmission}
editable={this.props.editable}
overrideForm={true}
pieceId={this.props.pieceId}
otherData={this.props.otherData}
multiple={true}/>

View File

@ -26,6 +26,8 @@ import CreateEditionsForm from '../ascribe_forms/create_editions_form';
import CreateEditionsButton from '../ascribe_buttons/create_editions_button';
import DeleteButton from '../ascribe_buttons/delete_button';
import RequestActionForm from '../ascribe_forms/form_request_action';
import GlobalNotificationModel from '../../models/global_notification_model';
import GlobalNotificationActions from '../../actions/global_notification_actions';
@ -148,6 +150,38 @@ let PieceContainer = React.createClass({
return {'id': this.state.piece.id};
},
getActions(){
if (this.state.piece &&
this.state.piece.request_action &&
this.state.piece.request_action.length > 0) {
return (
<RequestActionForm
currentUser={this.state.currentUser}
pieceOrEditions={ this.state.piece }
requestAction={this.state.piece.request_action}
requestUser={this.state.piece.user_registered}
handleSuccess={this.loadPiece}/>);
}
else {
return (
<AclButtonList
className="text-center ascribe-button-list"
availableAcls={this.state.piece.acl}
editions={this.state.piece}
handleSuccess={this.loadPiece}>
<CreateEditionsButton
label={getLangText('CREATE EDITIONS')}
className="btn-sm"
piece={this.state.piece}
toggleCreateEditionsDialog={this.toggleCreateEditionsDialog}
onPollingSuccess={this.handlePollingSuccess}/>
<DeleteButton
handleSuccess={this.handleDeleteSuccess}
piece={this.state.piece}/>
</AclButtonList>
);
}
},
render() {
if('title' in this.state.piece) {
return (
@ -170,23 +204,7 @@ let PieceContainer = React.createClass({
<DetailProperty label={getLangText('ID')} value={ this.state.piece.bitcoin_id } ellipsis={true} />
</div>
}
buttons={
<AclButtonList
className="text-center ascribe-button-list"
availableAcls={this.state.piece.acl}
editions={this.state.piece}
handleSuccess={this.loadPiece}>
<CreateEditionsButton
label={getLangText('CREATE EDITIONS')}
className="btn-sm"
piece={this.state.piece}
toggleCreateEditionsDialog={this.toggleCreateEditionsDialog}
onPollingSuccess={this.handlePollingSuccess}/>
<DeleteButton
handleSuccess={this.handleDeleteSuccess}
piece={this.state.piece}/>
</AclButtonList>
}>
buttons={this.getActions()}>
{this.getCreateEditionsDialog()}
<CollapsibleParagraph

View File

@ -16,40 +16,49 @@ import { getLangText } from '../../utils/lang_utils.js';
let RequestActionForm = React.createClass({
propTypes: {
editions: React.PropTypes.arrayOf(React.PropTypes.object),
pieceOrEditions: React.PropTypes.oneOfType([
React.PropTypes.object,
React.PropTypes.array
]).isRequired,
requestAction: React.PropTypes.string,
requestUser: React.PropTypes.string,
currentUser: React.PropTypes.object,
handleSuccess: React.PropTypes.func
},
isPiece(){
return this.props.pieceOrEditions.constructor !== Array;
},
getUrls() {
let edition = this.props.editions[0];
let urls = {};
if (edition.request_action === 'consign'){
if (this.props.requestAction === 'consign'){
urls.accept = ApiUrls.ownership_consigns_confirm;
urls.deny = ApiUrls.ownership_consigns_deny;
} else if (edition.request_action === 'unconsign'){
} else if (this.props.requestAction === 'unconsign'){
urls.accept = ApiUrls.ownership_unconsigns;
urls.deny = ApiUrls.ownership_unconsigns_deny;
} else if (edition.request_action === 'loan'){
} else if (this.props.requestAction === 'loan' && !this.isPiece()){
urls.accept = ApiUrls.ownership_loans_confirm;
urls.deny = ApiUrls.ownership_loans_deny;
} else if (this.props.requestAction === 'loan' && this.isPiece()){
urls.accept = ApiUrls.ownership_loans_pieces_confirm;
urls.deny = ApiUrls.ownership_loans_pieces_deny;
}
return urls;
},
getBitcoinIds(){
return this.props.editions.map(function(edition){
return edition.bitcoin_id;
});
},
getFormData() {
return {
bitcoin_id: this.getBitcoinIds().join()
};
getFormData(){
if (this.isPiece()) {
return {piece_id: this.props.pieceOrEditions.id};
}
else {
return {bitcoin_id: this.props.pieceOrEditions.map(function(edition){
return edition.bitcoin_id;
}).join()};
}
},
showNotification(option, action, owner) {
@ -66,8 +75,7 @@ let RequestActionForm = React.createClass({
},
getContent() {
let edition = this.props.editions[0];
let message = edition.owner + ' ' + getLangText('requests you') + ' ' + edition.request_action + ' ' + getLangText('this edition%s', '.');
let message = this.props.requestUser + ' ' + getLangText('requests you') + ' ' + this.props.requestAction + ' ' + getLangText('this edition%s', '.');
return (
<span>
@ -77,14 +85,12 @@ let RequestActionForm = React.createClass({
},
getAcceptButtonForm(urls) {
let edition = this.props.editions[0];
if(edition.request_action === 'unconsign') {
if(this.props.requestAction === 'unconsign') {
return (
<AclButton
availableAcls={{'acl_unconsign': true}}
action="acl_unconsign"
pieceOrEditions={this.props.editions}
pieceOrEditions={this.props.pieceOrEditions}
currentUser={this.props.currentUser}
handleSuccess={this.props.handleSuccess} />
);
@ -93,7 +99,9 @@ let RequestActionForm = React.createClass({
<Form
url={urls.accept}
getFormData={this.getFormData}
handleSuccess={this.showNotification(getLangText('accepted'), edition.request_action, edition.owner)}
handleSuccess={
this.showNotification(getLangText('accepted'), this.props.requestAction, this.props.requestUser)
}
isInline={true}
className='inline pull-right'>
<button
@ -107,8 +115,6 @@ let RequestActionForm = React.createClass({
},
getButtonForm() {
let edition = this.props.editions[0];
let urls = this.getUrls();
let acceptButtonForm = this.getAcceptButtonForm(urls);
@ -118,7 +124,9 @@ let RequestActionForm = React.createClass({
url={urls.deny}
isInline={true}
getFormData={this.getFormData}
handleSuccess={this.showNotification(getLangText('denied'), edition.request_action, edition.owner)}
handleSuccess={
this.showNotification(getLangText('denied'), this.props.requestAction, this.props.requestUser)
}
className='inline pull-right'>
<button
type="submit"

View File

@ -17,10 +17,13 @@ import InputTextAreaToggable from '../../../../../../components/ascribe_forms/in
import CollapsibleParagraph from '../../../../../../components/ascribe_collapsible/collapsible_paragraph';
import HistoryIterator from '../../../../../ascribe_detail/history_iterator';
import Note from '../../../../../ascribe_detail/note';
import FurtherDetailsFileuploader from '../../../../../ascribe_detail/further_details_fileuploader';
import DetailProperty from '../../../../../ascribe_detail/detail_property';
import ApiUrls from '../../../../../../constants/api_urls';
import { getLangText } from '../../../../../../utils/lang_utils';
import { mergeOptions } from '../../../../../../utils/general_utils';
@ -39,6 +42,13 @@ let CylandPieceContainer = React.createClass({
UserStore.listen(this.onChange);
},
componentWillReceiveProps(nextProps) {
if(this.props.params.pieceId !== nextProps.params.pieceId) {
PieceActions.updatePiece({});
PieceActions.fetchOne(nextProps.params.pieceId);
}
},
componentWillUnmount() {
// Every time we're leaving the piece detail page,
// just reset the piece that is saved in the piece store
@ -49,13 +59,6 @@ let CylandPieceContainer = React.createClass({
UserStore.unlisten(this.onChange);
},
componentWillReceiveProps(nextProps) {
if(this.props.params.pieceId !== nextProps.params.pieceId) {
PieceActions.updatePiece({});
PieceActions.fetchOne(nextProps.params.pieceId);
}
},
onChange(state) {
this.setState(state);
},
@ -64,6 +67,11 @@ let CylandPieceContainer = React.createClass({
PieceActions.fetchOne(this.props.params.pieceId);
},
getId() {
return {'id': this.state.piece.id};
},
render() {
if('title' in this.state.piece) {
return (
@ -93,7 +101,20 @@ let CylandPieceContainer = React.createClass({
<HistoryIterator
history={this.state.piece.loan_history} />
</CollapsibleParagraph>
<CollapsibleParagraph
title={getLangText('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={getLangText('Enter your comments ...')}
editable={true}
successMessage={getLangText('Private note saved')}
url={ApiUrls.note_private_piece}
currentUser={this.state.currentUser}/>
</CollapsibleParagraph>
<CylandPieceDetails piece={this.state.piece}/>
</Piece>
);

View File

@ -30,6 +30,8 @@ let ApiUrls = {
'ownership_consigns_confirm': AppConstants.apiEndpoint + 'ownership/consigns/confirm/',
'ownership_consigns_deny': AppConstants.apiEndpoint + 'ownership/consigns/deny/',
'ownership_loans_pieces': AppConstants.apiEndpoint + 'ownership/loans/pieces/',
'ownership_loans_pieces_confirm': AppConstants.apiEndpoint + 'ownership/loans/pieces/confirm/',
'ownership_loans_pieces_deny': AppConstants.apiEndpoint + 'ownership/loans/pieces/deny/',
'ownership_loans_editions': AppConstants.apiEndpoint + 'ownership/loans/editions/',
'ownership_loans_confirm': AppConstants.apiEndpoint + 'ownership/loans/editions/confirm/',
'ownership_loans_deny': AppConstants.apiEndpoint + 'ownership/loans/editions/deny/',