mirror of
https://github.com/ascribe/onion.git
synced 2024-06-28 16:48:04 +02:00
Bring over changes for acl_button from Lumenus
This commit is contained in:
parent
590818cf0b
commit
c242cffdbd
|
@ -16,7 +16,7 @@ import GlobalNotificationActions from '../../actions/global_notification_actions
|
||||||
|
|
||||||
import ApiUrls from '../../constants/api_urls';
|
import ApiUrls from '../../constants/api_urls';
|
||||||
|
|
||||||
import { getAclFormMessage } from '../../utils/form_utils';
|
import { getAclFormMessage, getAclFormDataId } from '../../utils/form_utils';
|
||||||
import { getLangText } from '../../utils/lang_utils';
|
import { getLangText } from '../../utils/lang_utils';
|
||||||
|
|
||||||
let AclButton = React.createClass({
|
let AclButton = React.createClass({
|
||||||
|
@ -30,32 +30,37 @@ let AclButton = React.createClass({
|
||||||
currentUser: React.PropTypes.object,
|
currentUser: React.PropTypes.object,
|
||||||
buttonAcceptName: React.PropTypes.string,
|
buttonAcceptName: React.PropTypes.string,
|
||||||
buttonAcceptClassName: React.PropTypes.string,
|
buttonAcceptClassName: React.PropTypes.string,
|
||||||
|
email: React.PropTypes.string,
|
||||||
handleSuccess: React.PropTypes.func.isRequired,
|
handleSuccess: React.PropTypes.func.isRequired,
|
||||||
className: React.PropTypes.string
|
className: React.PropTypes.string
|
||||||
},
|
},
|
||||||
|
|
||||||
isPiece(){
|
isPiece() {
|
||||||
return this.props.pieceOrEditions.constructor !== Array;
|
return this.props.pieceOrEditions.constructor !== Array;
|
||||||
},
|
},
|
||||||
|
|
||||||
actionProperties(){
|
actionProperties() {
|
||||||
|
let message = getAclFormMessage({
|
||||||
|
aclName: this.props.action,
|
||||||
|
entities: this.props.pieceOrEditions,
|
||||||
|
isPiece: this.isPiece(),
|
||||||
|
senderName: this.props.currentUser.username
|
||||||
|
});
|
||||||
|
|
||||||
let message = getAclFormMessage(this.props.action, this.getTitlesString(), this.props.currentUser.username);
|
if (this.props.action === 'acl_consign') {
|
||||||
|
|
||||||
if (this.props.action === 'acl_consign'){
|
|
||||||
return {
|
return {
|
||||||
title: getLangText('Consign artwork'),
|
title: getLangText('Consign artwork'),
|
||||||
tooltip: getLangText('Have someone else sell the artwork'),
|
tooltip: getLangText('Have someone else sell the artwork'),
|
||||||
form: (
|
form: (
|
||||||
<ConsignForm
|
<ConsignForm
|
||||||
|
email={this.props.email}
|
||||||
message={message}
|
message={message}
|
||||||
id={this.getFormDataId()}
|
id={this.getFormDataId()}
|
||||||
url={ApiUrls.ownership_consigns}/>
|
url={ApiUrls.ownership_consigns}/>
|
||||||
),
|
),
|
||||||
handleSuccess: this.showNotification
|
handleSuccess: this.showNotification
|
||||||
};
|
};
|
||||||
}
|
} else if (this.props.action === 'acl_unconsign') {
|
||||||
if (this.props.action === 'acl_unconsign'){
|
|
||||||
return {
|
return {
|
||||||
title: getLangText('Unconsign artwork'),
|
title: getLangText('Unconsign artwork'),
|
||||||
tooltip: getLangText('Have the owner manage his sales again'),
|
tooltip: getLangText('Have the owner manage his sales again'),
|
||||||
|
@ -64,10 +69,10 @@ let AclButton = React.createClass({
|
||||||
message={message}
|
message={message}
|
||||||
id={this.getFormDataId()}
|
id={this.getFormDataId()}
|
||||||
url={ApiUrls.ownership_unconsigns}/>
|
url={ApiUrls.ownership_unconsigns}/>
|
||||||
),
|
),
|
||||||
handleSuccess: this.showNotification
|
handleSuccess: this.showNotification
|
||||||
};
|
};
|
||||||
}else if (this.props.action === 'acl_transfer') {
|
} else if (this.props.action === 'acl_transfer') {
|
||||||
return {
|
return {
|
||||||
title: getLangText('Transfer artwork'),
|
title: getLangText('Transfer artwork'),
|
||||||
tooltip: getLangText('Transfer the ownership of the artwork'),
|
tooltip: getLangText('Transfer the ownership of the artwork'),
|
||||||
|
@ -79,32 +84,33 @@ let AclButton = React.createClass({
|
||||||
),
|
),
|
||||||
handleSuccess: this.showNotification
|
handleSuccess: this.showNotification
|
||||||
};
|
};
|
||||||
}
|
} else if (this.props.action === 'acl_loan') {
|
||||||
else if (this.props.action === 'acl_loan'){
|
|
||||||
return {
|
return {
|
||||||
title: getLangText('Loan artwork'),
|
title: getLangText('Loan artwork'),
|
||||||
tooltip: getLangText('Loan your artwork for a limited period of time'),
|
tooltip: getLangText('Loan your artwork for a limited period of time'),
|
||||||
form: (<LoanForm
|
form: (
|
||||||
|
<LoanForm
|
||||||
|
email={this.props.email}
|
||||||
message={message}
|
message={message}
|
||||||
id={this.getFormDataId()}
|
id={this.getFormDataId()}
|
||||||
url={this.isPiece() ? ApiUrls.ownership_loans_pieces : ApiUrls.ownership_loans_editions}/>
|
url={this.isPiece() ? ApiUrls.ownership_loans_pieces
|
||||||
|
: ApiUrls.ownership_loans_editions}/>
|
||||||
),
|
),
|
||||||
handleSuccess: this.showNotification
|
handleSuccess: this.showNotification
|
||||||
};
|
};
|
||||||
}
|
} else if (this.props.action === 'acl_loan_request') {
|
||||||
else if (this.props.action === 'acl_loan_request'){
|
|
||||||
return {
|
return {
|
||||||
title: getLangText('Loan artwork'),
|
title: getLangText('Loan artwork'),
|
||||||
tooltip: getLangText('Someone requested you to loan your artwork for a limited period of time'),
|
tooltip: getLangText('Someone requested you to loan your artwork for a limited period of time'),
|
||||||
form: (<LoanRequestAnswerForm
|
form: (
|
||||||
|
<LoanRequestAnswerForm
|
||||||
message={message}
|
message={message}
|
||||||
id={this.getFormDataId()}
|
id={this.getFormDataId()}
|
||||||
url={ApiUrls.ownership_loans_pieces_request_confirm}/>
|
url={ApiUrls.ownership_loans_pieces_request_confirm}/>
|
||||||
),
|
),
|
||||||
handleSuccess: this.showNotification
|
handleSuccess: this.showNotification
|
||||||
};
|
};
|
||||||
}
|
} else if (this.props.action === 'acl_share') {
|
||||||
else if (this.props.action === 'acl_share'){
|
|
||||||
return {
|
return {
|
||||||
title: getLangText('Share artwork'),
|
title: getLangText('Share artwork'),
|
||||||
tooltip: getLangText('Share the artwork'),
|
tooltip: getLangText('Share the artwork'),
|
||||||
|
@ -112,8 +118,9 @@ let AclButton = React.createClass({
|
||||||
<ShareForm
|
<ShareForm
|
||||||
message={message}
|
message={message}
|
||||||
id={this.getFormDataId()}
|
id={this.getFormDataId()}
|
||||||
url={this.isPiece() ? ApiUrls.ownership_shares_pieces : ApiUrls.ownership_shares_editions }/>
|
url={this.isPiece() ? ApiUrls.ownership_shares_pieces
|
||||||
),
|
: ApiUrls.ownership_shares_editions}/>
|
||||||
|
),
|
||||||
handleSuccess: this.showNotification
|
handleSuccess: this.showNotification
|
||||||
};
|
};
|
||||||
} else {
|
} else {
|
||||||
|
@ -121,36 +128,16 @@ let AclButton = React.createClass({
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
showNotification(response){
|
showNotification(response) {
|
||||||
this.props.handleSuccess();
|
this.props.handleSuccess();
|
||||||
if(response.notification) {
|
if (response.notification) {
|
||||||
let notification = new GlobalNotificationModel(response.notification, 'success');
|
let notification = new GlobalNotificationModel(response.notification, 'success');
|
||||||
GlobalNotificationActions.appendGlobalNotification(notification);
|
GlobalNotificationActions.appendGlobalNotification(notification);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
// plz move to share form
|
|
||||||
getTitlesString(){
|
|
||||||
if (this.isPiece()){
|
|
||||||
return '\"' + this.props.pieceOrEditions.title + '\"';
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
return this.props.pieceOrEditions.map(function(edition) {
|
|
||||||
return '- \"' + edition.title + ', ' + getLangText('edition') + ' ' + edition.edition_number + '\"\n';
|
|
||||||
}).join('');
|
|
||||||
}
|
|
||||||
|
|
||||||
},
|
|
||||||
|
|
||||||
getFormDataId(){
|
getFormDataId(){
|
||||||
if (this.isPiece()) {
|
return getAclFormDataId(this.isPiece(), this.props.pieceOrEditions);
|
||||||
return {piece_id: this.props.pieceOrEditions.id};
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
return {bitcoin_id: this.props.pieceOrEditions.map(function(edition){
|
|
||||||
return edition.bitcoin_id;
|
|
||||||
}).join()};
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
|
|
||||||
// Removes the acl_ prefix and converts to upper case
|
// Removes the acl_ prefix and converts to upper case
|
||||||
|
@ -162,7 +149,7 @@ let AclButton = React.createClass({
|
||||||
},
|
},
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
if (this.props.availableAcls){
|
if (this.props.availableAcls) {
|
||||||
let shouldDisplay = this.props.availableAcls[this.props.action];
|
let shouldDisplay = this.props.availableAcls[this.props.action];
|
||||||
let aclProps = this.actionProperties();
|
let aclProps = this.actionProperties();
|
||||||
let buttonClassName = this.props.buttonAcceptClassName ? this.props.buttonAcceptClassName : '';
|
let buttonClassName = this.props.buttonAcceptClassName ? this.props.buttonAcceptClassName : '';
|
||||||
|
@ -184,4 +171,4 @@ let AclButton = React.createClass({
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
export default AclButton;
|
export default AclButton;
|
||||||
|
|
|
@ -2,14 +2,42 @@
|
||||||
|
|
||||||
import { getLangText } from './lang_utils';
|
import { getLangText } from './lang_utils';
|
||||||
|
|
||||||
|
import AppConstants from '../constants/application_constants';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the data ids of the given piece or editions.
|
||||||
|
* @param {boolean} isPiece Is the given entities parameter a piece? (False: array of editions)
|
||||||
|
* @param {(object|object[])} pieceOrEditions Piece or array of editions
|
||||||
|
* @return {(object|object[])} Data IDs of the pieceOrEditions for the form
|
||||||
|
*/
|
||||||
|
export function getAclFormDataId(isPiece, pieceOrEditions) {
|
||||||
|
if (isPiece) {
|
||||||
|
return {piece_id: pieceOrEditions.id};
|
||||||
|
} else {
|
||||||
|
return {bitcoin_id: pieceOrEditions.map(function(edition){
|
||||||
|
return edition.bitcoin_id;
|
||||||
|
}).join()};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Generates a message for submitting a form
|
* Generates a message for submitting a form
|
||||||
* @param {string} aclName Enum name of a acl
|
* @param {object} options Options object for creating the message:
|
||||||
* @param {string} entities Already computed name of entities
|
* @param {string} options.aclName Enum name of an acl
|
||||||
* @param {string} senderName Name of the sender
|
* @param {(object|object[])} options.entities Piece or array of Editions
|
||||||
* @return {string} Completed message
|
* @param {boolean} options.isPiece Is the given entities parameter a piece? (False: array of editions)
|
||||||
|
* @param {string} [options.senderName] Name of the sender
|
||||||
|
* @return {string} Completed message
|
||||||
*/
|
*/
|
||||||
export function getAclFormMessage(aclName, entities, senderName) {
|
export function getAclFormMessage(options) {
|
||||||
|
if (!options || options.aclName === undefined || options.isPiece === undefined ||
|
||||||
|
!(typeof options.entities === 'object' || options.entities.constructor === Array)) {
|
||||||
|
throw new Error('You must specify an acl class, entities in the correct format, and entity type');
|
||||||
|
}
|
||||||
|
|
||||||
|
let aclName = options.aclName;
|
||||||
|
let entityTitles = options.isPiece ? getTitlesStringOfPiece(options.entities)
|
||||||
|
: getTitlesStringOfEditions(options.entities);
|
||||||
let message = '';
|
let message = '';
|
||||||
|
|
||||||
message += getLangText('Hi');
|
message += getLangText('Hi');
|
||||||
|
@ -32,7 +60,7 @@ export function getAclFormMessage(aclName, entities, senderName) {
|
||||||
}
|
}
|
||||||
|
|
||||||
message += ':\n';
|
message += ':\n';
|
||||||
message += entities;
|
message += entityTitles;
|
||||||
|
|
||||||
if(aclName === 'acl_transfer' || aclName === 'acl_loan' || aclName === 'acl_consign') {
|
if(aclName === 'acl_transfer' || aclName === 'acl_loan' || aclName === 'acl_consign') {
|
||||||
message += getLangText('to you');
|
message += getLangText('to you');
|
||||||
|
@ -44,10 +72,22 @@ export function getAclFormMessage(aclName, entities, senderName) {
|
||||||
throw new Error('Your specified aclName did not match a an acl class.');
|
throw new Error('Your specified aclName did not match a an acl class.');
|
||||||
}
|
}
|
||||||
|
|
||||||
message += '\n\n';
|
if (options.senderName) {
|
||||||
message += getLangText('Truly yours,');
|
message += '\n\n';
|
||||||
message += '\n';
|
message += getLangText('Truly yours,');
|
||||||
message += senderName;
|
message += '\n';
|
||||||
|
message += options.senderName;
|
||||||
|
}
|
||||||
|
|
||||||
return message;
|
return message;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function getTitlesStringOfPiece(piece){
|
||||||
|
return '\"' + piece.title + '\"';
|
||||||
|
}
|
||||||
|
|
||||||
|
function getTitlesStringOfEditions(editions) {
|
||||||
|
return editions.map(function(edition) {
|
||||||
|
return '- \"' + edition.title + ', ' + getLangText('edition') + ' ' + edition.edition_number + '\"\n';
|
||||||
|
}).join('');
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user