mirror of
https://github.com/ascribe/onion.git
synced 2025-01-03 10:25:08 +01:00
refactor: acl buttons message functionality
This commit is contained in:
parent
3c75237275
commit
8ff2dea4df
@ -13,9 +13,11 @@ import AppConstants from '../../constants/application_constants';
|
||||
import GlobalNotificationModel from '../../models/global_notification_model';
|
||||
import GlobalNotificationActions from '../../actions/global_notification_actions';
|
||||
|
||||
import { getLangText } from '../../utils/lang_utils.js';
|
||||
import ApiUrls from '../../constants/api_urls';
|
||||
|
||||
import { getAclFormMessage } from '../../utils/form_utils';
|
||||
import { getLangText } from '../../utils/lang_utils';
|
||||
|
||||
let AclButton = React.createClass({
|
||||
propTypes: {
|
||||
action: React.PropTypes.oneOf(AppConstants.aclList).isRequired,
|
||||
@ -34,13 +36,16 @@ let AclButton = React.createClass({
|
||||
},
|
||||
|
||||
actionProperties(){
|
||||
|
||||
let message = getAclFormMessage(this.props.action, this.getTitlesString(), this.props.currentUser.username);
|
||||
|
||||
if (this.props.action === 'acl_consign'){
|
||||
return {
|
||||
title: getLangText('Consign artwork'),
|
||||
tooltip: getLangText('Have someone else sell the artwork'),
|
||||
form: (
|
||||
<ConsignForm
|
||||
message={this.getConsignMessage()}
|
||||
message={message}
|
||||
id={this.getFormDataId()}
|
||||
url={ApiUrls.ownership_consigns}/>
|
||||
),
|
||||
@ -53,7 +58,7 @@ let AclButton = React.createClass({
|
||||
tooltip: getLangText('Have the owner manage his sales again'),
|
||||
form: (
|
||||
<UnConsignForm
|
||||
message={this.getUnConsignMessage()}
|
||||
message={message}
|
||||
id={this.getFormDataId()}
|
||||
url={ApiUrls.ownership_unconsigns}/>
|
||||
),
|
||||
@ -65,7 +70,7 @@ let AclButton = React.createClass({
|
||||
tooltip: getLangText('Transfer the ownership of the artwork'),
|
||||
form: (
|
||||
<TransferForm
|
||||
message={this.getTransferMessage()}
|
||||
message={message}
|
||||
id={this.getFormDataId()}
|
||||
url={ApiUrls.ownership_transfers}/>
|
||||
),
|
||||
@ -77,7 +82,7 @@ let AclButton = React.createClass({
|
||||
title: getLangText('Loan artwork'),
|
||||
tooltip: getLangText('Loan your artwork for a limited period of time'),
|
||||
form: (<LoanForm
|
||||
message={this.getLoanMessage()}
|
||||
message={message}
|
||||
id={this.getFormDataId()}
|
||||
url={this.isPiece() ? ApiUrls.ownership_loans_pieces : ApiUrls.ownership_loans_editions}/>
|
||||
),
|
||||
@ -90,7 +95,7 @@ let AclButton = React.createClass({
|
||||
tooltip: getLangText('Share the artwork'),
|
||||
form: (
|
||||
<ShareForm
|
||||
message={this.getShareMessage()}
|
||||
message={message}
|
||||
id={this.getFormDataId()}
|
||||
url={this.isPiece() ? ApiUrls.ownership_shares_pieces : ApiUrls.ownership_shares_editions }/>
|
||||
),
|
||||
@ -133,76 +138,6 @@ let AclButton = React.createClass({
|
||||
}
|
||||
},
|
||||
|
||||
// plz move to transfer form
|
||||
getTransferMessage(){
|
||||
return (
|
||||
`${getLangText('Hi')},
|
||||
|
||||
${getLangText('I transfer ownership of')}:
|
||||
${this.getTitlesString()} ${getLangText('to you')}.
|
||||
|
||||
${getLangText('Truly yours')},
|
||||
${this.props.currentUser.username}
|
||||
`
|
||||
);
|
||||
},
|
||||
|
||||
// plz move to transfer form
|
||||
getLoanMessage(){
|
||||
return (
|
||||
`${getLangText('Hi')},
|
||||
|
||||
${getLangText('I loan')}:
|
||||
${this.getTitlesString()} ${getLangText('to you')}.
|
||||
|
||||
${getLangText('Truly yours')},
|
||||
${this.props.currentUser.username}
|
||||
`
|
||||
);
|
||||
},
|
||||
|
||||
// plz move to consign form
|
||||
getConsignMessage(){
|
||||
return (
|
||||
`${getLangText('Hi')},
|
||||
|
||||
${getLangText('I consign')}:
|
||||
${this.getTitlesString()} ${getLangText('to you')}.
|
||||
|
||||
${getLangText('Truly yours')},
|
||||
${this.props.currentUser.username}
|
||||
`
|
||||
);
|
||||
},
|
||||
|
||||
// plz move to consign form
|
||||
getUnConsignMessage(){
|
||||
return (
|
||||
`${getLangText('Hi')},
|
||||
|
||||
${getLangText('I un-consign')}:
|
||||
${this.getTitlesString()} ${getLangText('from you')}.
|
||||
|
||||
${getLangText('Truly yours')},
|
||||
${this.props.currentUser.username}
|
||||
`
|
||||
);
|
||||
},
|
||||
|
||||
// plz move to share form
|
||||
getShareMessage(){
|
||||
return (
|
||||
`${getLangText('Hi')},
|
||||
|
||||
${getLangText('I am sharing')}:
|
||||
${this.getTitlesString()} ${getLangText('with you')}.
|
||||
|
||||
${getLangText('Truly yours')},
|
||||
${this.props.currentUser.username}
|
||||
`
|
||||
);
|
||||
},
|
||||
|
||||
// Removes the acl_ prefix and converts to upper case
|
||||
sanitizeAction() {
|
||||
return this.props.action.split('acl_')[1].toUpperCase();
|
||||
|
51
js/utils/form_utils.js
Normal file
51
js/utils/form_utils.js
Normal file
@ -0,0 +1,51 @@
|
||||
'use strict';
|
||||
|
||||
import { getLangText } from './lang_utils';
|
||||
|
||||
/**
|
||||
* Generates a message for submitting a form
|
||||
* @param {string} aclName Enum name of a acl
|
||||
* @param {string} entities Already computed name of entities
|
||||
* @param {string} senderName Name of the sender
|
||||
* @return {string} Completed message
|
||||
*/
|
||||
export function getAclFormMessage(aclName, entities, senderName) {
|
||||
let message = '';
|
||||
|
||||
message += getLangText('Hi');
|
||||
message += ',\n\n';
|
||||
|
||||
if(aclName === 'acl_transfer') {
|
||||
message += getLangText('I transfer ownership of');
|
||||
} else if(aclName === 'acl_consign') {
|
||||
message += getLangText('I consign');
|
||||
} else if(aclName === 'acl_unconsign') {
|
||||
message += getLangText('I un-consign');
|
||||
} else if(aclName === 'acl_loan') {
|
||||
message += getLangText('I loan');
|
||||
} else if(aclName === 'acl_share') {
|
||||
message += getLangText('I share');
|
||||
} else {
|
||||
throw new Error('Your specified aclName did not match a an acl class.');
|
||||
}
|
||||
|
||||
message += ':\n';
|
||||
message += entities;
|
||||
|
||||
if(aclName === 'acl_transfer' || aclName === 'acl_loan' || aclName === 'acl_consign') {
|
||||
message += getLangText('to you');
|
||||
} else if(aclName === 'acl_unconsign') {
|
||||
message += getLangText('from you');
|
||||
} else if(aclName === 'acl_share') {
|
||||
message += getLangText('with you');
|
||||
} else {
|
||||
throw new Error('Your specified aclName did not match a an acl class.');
|
||||
}
|
||||
|
||||
message += '\n\n';
|
||||
message += getLangText('Truly yours,');
|
||||
message += '\n';
|
||||
message += senderName;
|
||||
|
||||
return message;
|
||||
}
|
Loading…
Reference in New Issue
Block a user