2015-08-10 15:57:20 +02:00
|
|
|
'use strict';
|
|
|
|
|
|
|
|
import { getLangText } from './lang_utils';
|
|
|
|
|
2015-10-23 14:19:44 +02:00
|
|
|
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] || {};
|
|
|
|
}
|
|
|
|
|
2015-08-10 15:57:20 +02:00
|
|
|
/**
|
|
|
|
* Generates a message for submitting a form
|
2015-10-23 14:19:44 +02:00
|
|
|
* @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
|
2015-08-10 15:57:20 +02:00
|
|
|
*/
|
2015-10-23 14:19:44 +02:00
|
|
|
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);
|
2015-08-10 15:57:20 +02:00
|
|
|
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');
|
2015-08-26 09:50:38 +02:00
|
|
|
} else if(aclName === 'acl_loan_request') {
|
|
|
|
message += getLangText('I request to loan');
|
2015-08-10 15:57:20 +02:00
|
|
|
} 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';
|
2015-10-23 14:19:44 +02:00
|
|
|
message += entityTitles;
|
2015-08-10 15:57:20 +02:00
|
|
|
|
|
|
|
if(aclName === 'acl_transfer' || aclName === 'acl_loan' || aclName === 'acl_consign') {
|
|
|
|
message += getLangText('to you');
|
2015-08-26 09:50:38 +02:00
|
|
|
} else if(aclName === 'acl_unconsign' || aclName === 'acl_loan_request') {
|
2015-08-10 15:57:20 +02:00
|
|
|
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.');
|
|
|
|
}
|
|
|
|
|
2015-10-23 14:19:44 +02:00
|
|
|
if (options.senderName) {
|
|
|
|
message += '\n\n';
|
|
|
|
message += getLangText('Truly yours,');
|
|
|
|
message += '\n';
|
|
|
|
message += options.senderName;
|
|
|
|
}
|
2015-08-10 15:57:20 +02:00
|
|
|
|
|
|
|
return message;
|
2015-10-23 14:19:44 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
function getTitlesStringOfPiece(piece){
|
|
|
|
return '\"' + piece.title + '\"';
|
|
|
|
}
|
|
|
|
|
|
|
|
function getTitlesStringOfEditions(editions) {
|
|
|
|
return editions.map(function(edition) {
|
|
|
|
return '- \"' + edition.title + ', ' + getLangText('edition') + ' ' + edition.edition_number + '\"\n';
|
|
|
|
}).join('');
|
|
|
|
}
|