1
0
mirror of https://github.com/ascribe/onion.git synced 2024-12-23 01:39:36 +01:00
Special white label form settings only defined for consign form for
now, but could be added to others as needed.
This commit is contained in:
Brett Sun 2015-10-23 14:19:44 +02:00
parent e226477424
commit 3dedc93d2e
5 changed files with 97 additions and 55 deletions

View File

@ -34,15 +34,19 @@ let AclButton = React.createClass({
className: React.PropTypes.string
},
isPiece(){
isPiece() {
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 {
title: getLangText('Consign artwork'),
tooltip: getLangText('Have someone else sell the artwork'),
@ -51,11 +55,10 @@ let AclButton = React.createClass({
message={message}
id={this.getFormDataId()}
url={ApiUrls.ownership_consigns}/>
),
),
handleSuccess: this.showNotification
};
}
if (this.props.action === 'acl_unconsign'){
} else if (this.props.action === 'acl_unconsign') {
return {
title: getLangText('Unconsign artwork'),
tooltip: getLangText('Have the owner manage his sales again'),
@ -64,10 +67,10 @@ let AclButton = React.createClass({
message={message}
id={this.getFormDataId()}
url={ApiUrls.ownership_unconsigns}/>
),
),
handleSuccess: this.showNotification
};
}else if (this.props.action === 'acl_transfer') {
} else if (this.props.action === 'acl_transfer') {
return {
title: getLangText('Transfer artwork'),
tooltip: getLangText('Transfer the ownership of the artwork'),
@ -79,32 +82,32 @@ let AclButton = React.createClass({
),
handleSuccess: this.showNotification
};
}
else if (this.props.action === 'acl_loan'){
} else if (this.props.action === 'acl_loan') {
return {
title: getLangText('Loan artwork'),
tooltip: getLangText('Loan your artwork for a limited period of time'),
form: (<LoanForm
form: (
<LoanForm
message={message}
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
};
}
else if (this.props.action === 'acl_loan_request'){
} else if (this.props.action === 'acl_loan_request') {
return {
title: getLangText('Loan artwork'),
tooltip: getLangText('Someone requested you to loan your artwork for a limited period of time'),
form: (<LoanRequestAnswerForm
form: (
<LoanRequestAnswerForm
message={message}
id={this.getFormDataId()}
url={ApiUrls.ownership_loans_pieces_request_confirm}/>
),
handleSuccess: this.showNotification
};
}
else if (this.props.action === 'acl_share'){
} else if (this.props.action === 'acl_share') {
return {
title: getLangText('Share artwork'),
tooltip: getLangText('Share the artwork'),
@ -112,8 +115,9 @@ let AclButton = React.createClass({
<ShareForm
message={message}
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
};
} else {
@ -121,32 +125,18 @@ let AclButton = React.createClass({
}
},
showNotification(response){
showNotification(response) {
this.props.handleSuccess();
if(response.notification) {
if (response.notification) {
let notification = new GlobalNotificationModel(response.notification, 'success');
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(){
if (this.isPiece()) {
return {piece_id: this.props.pieceOrEditions.id};
}
else {
} else {
return {bitcoin_id: this.props.pieceOrEditions.map(function(edition){
return edition.bitcoin_id;
}).join()};
@ -162,7 +152,7 @@ let AclButton = React.createClass({
},
render() {
if (this.props.availableAcls){
if (this.props.availableAcls) {
let shouldDisplay = this.props.availableAcls[this.props.action];
let aclProps = this.actionProperties();
let buttonClassName = this.props.buttonAcceptClassName ? this.props.buttonAcceptClassName : '';

View File

@ -11,6 +11,7 @@ import InputTextAreaToggable from './input_textarea_toggable';
import AscribeSpinner from '../ascribe_spinner';
import { getLangText } from '../../utils/lang_utils.js';
import { getSubdomainFormSettings } from '../../utils/form_utils';
let ConsignForm = React.createClass({
propTypes: {
@ -25,6 +26,8 @@ let ConsignForm = React.createClass({
},
render() {
let envSettings = getSubdomainFormSettings('consign');
return (
<Form
ref='form'
@ -49,10 +52,13 @@ let ConsignForm = React.createClass({
</div>}>
<Property
name='consignee'
label={getLangText('Email')}>
label={getLangText('Email')}
editable={!envSettings.consigneeDisabled}
overrideForm={true}>
<input
type="email"
placeholder={getLangText('Email of the consignee')}
defaultValue={envSettings.consignee}
required/>
</Property>
<Property

View File

@ -220,7 +220,12 @@ let CylandRegisterPiece = React.createClass({
<Col xs={12} sm={10} md={8} smOffset={1} mdOffset={2}>
<LoanForm
loanHeading={getLangText('Loan to Cyland archive')}
message={getAclFormMessage('acl_loan', '\"' + this.state.piece.title + '\"', this.state.currentUser.username)}
message={getAclFormMessage({
aclName: 'acl_loan',
entities: this.state.piece,
isPiece: true,
senderName: this.state.currentUser.username
})}
id={{piece_id: this.state.piece.id}}
url={ApiUrls.ownership_loans_pieces}
email={this.state.whitelabel.user}

View File

@ -52,7 +52,13 @@ let constants = {
'name': 'Lumenus',
'logo': 'https://s3-us-west-2.amazonaws.com/ascribe0/whitelabel/lumenus/lumenus-logo.png',
'permissions': ['register', 'edit', 'share', 'del_from_collection'],
'type': 'wallet'
'type': 'wallet',
'formSettings': {
'consign': {
'consignee': 'submissions@lumenus.co',
'consigneeDisabled': true
}
}
}
],
'defaultDomain': {

View File

@ -2,14 +2,37 @@
import { getLangText } from './lang_utils';
import AppConstants from '../constants/application_constants';
/**
* Gets a dictionary of settings for a form based on the environment
* (ie. if on a whitelabel)
* @param {string} formName Name of the form
* @return {object} Settings key-val dictionary
*/
export function getSubdomainFormSettings(formName) {
let subdomainFormSettings = AppConstants.whitelabel.formSettings || {};
return subdomainFormSettings[formName] || {};
}
/**
* 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
* @param {object} options Options object for creating the message:
* @param {string} options.aclName Enum name of an acl
* @param {(object|object[])} options.entities Piece or 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 = '';
message += getLangText('Hi');
@ -32,7 +55,7 @@ export function getAclFormMessage(aclName, entities, senderName) {
}
message += ':\n';
message += entities;
message += entityTitles;
if(aclName === 'acl_transfer' || aclName === 'acl_loan' || aclName === 'acl_consign') {
message += getLangText('to you');
@ -44,10 +67,22 @@ export function getAclFormMessage(aclName, entities, senderName) {
throw new Error('Your specified aclName did not match a an acl class.');
}
message += '\n\n';
message += getLangText('Truly yours,');
message += '\n';
message += senderName;
if (options.senderName) {
message += '\n\n';
message += getLangText('Truly yours,');
message += '\n';
message += options.senderName;
}
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('');
}