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

Merge with AD-1255

This commit is contained in:
Brett Sun 2015-11-03 11:13:32 +01:00
parent 3a8f91e29e
commit f7259a8ab3
18 changed files with 474 additions and 253 deletions

View File

@ -1,174 +0,0 @@
'use strict';
import React from 'react';
import ConsignForm from '../ascribe_forms/form_consign';
import UnConsignForm from '../ascribe_forms/form_unconsign';
import TransferForm from '../ascribe_forms/form_transfer';
import LoanForm from '../ascribe_forms/form_loan';
import LoanRequestAnswerForm from '../ascribe_forms/form_loan_request_answer';
import ShareForm from '../ascribe_forms/form_share_email';
import ModalWrapper from '../ascribe_modal/modal_wrapper';
import AppConstants from '../../constants/application_constants';
import GlobalNotificationModel from '../../models/global_notification_model';
import GlobalNotificationActions from '../../actions/global_notification_actions';
import ApiUrls from '../../constants/api_urls';
import { getAclFormMessage, getAclFormDataId } from '../../utils/form_utils';
import { getLangText } from '../../utils/lang_utils';
let AclButton = React.createClass({
propTypes: {
action: React.PropTypes.oneOf(AppConstants.aclList).isRequired,
availableAcls: React.PropTypes.object.isRequired,
pieceOrEditions: React.PropTypes.oneOfType([
React.PropTypes.object,
React.PropTypes.array
]).isRequired,
currentUser: React.PropTypes.object,
buttonAcceptName: React.PropTypes.string,
buttonAcceptClassName: React.PropTypes.string,
email: React.PropTypes.string,
handleSuccess: React.PropTypes.func.isRequired,
className: React.PropTypes.string
},
isPiece() {
return this.props.pieceOrEditions.constructor !== Array;
},
actionProperties() {
let message = getAclFormMessage({
aclName: this.props.action,
entities: this.props.pieceOrEditions,
isPiece: this.isPiece(),
senderName: 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
email={this.props.email}
message={message}
id={this.getFormDataId()}
url={ApiUrls.ownership_consigns}/>
),
handleSuccess: this.showNotification
};
} else if (this.props.action === 'acl_unconsign') {
return {
title: getLangText('Unconsign artwork'),
tooltip: getLangText('Have the owner manage his sales again'),
form: (
<UnConsignForm
message={message}
id={this.getFormDataId()}
url={ApiUrls.ownership_unconsigns}/>
),
handleSuccess: this.showNotification
};
} else if (this.props.action === 'acl_transfer') {
return {
title: getLangText('Transfer artwork'),
tooltip: getLangText('Transfer the ownership of the artwork'),
form: (
<TransferForm
message={message}
id={this.getFormDataId()}
url={ApiUrls.ownership_transfers}/>
),
handleSuccess: this.showNotification
};
} 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
email={this.props.email}
message={message}
id={this.getFormDataId()}
url={this.isPiece() ? ApiUrls.ownership_loans_pieces
: ApiUrls.ownership_loans_editions}/>
),
handleSuccess: this.showNotification
};
} 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
message={message}
id={this.getFormDataId()}
url={ApiUrls.ownership_loans_pieces_request_confirm}/>
),
handleSuccess: this.showNotification
};
} else if (this.props.action === 'acl_share') {
return {
title: getLangText('Share artwork'),
tooltip: getLangText('Share the artwork'),
form: (
<ShareForm
message={message}
id={this.getFormDataId()}
url={this.isPiece() ? ApiUrls.ownership_shares_pieces
: ApiUrls.ownership_shares_editions}/>
),
handleSuccess: this.showNotification
};
} else {
throw new Error('Your specified action did not match a form.');
}
},
showNotification(response) {
this.props.handleSuccess();
if (response.notification) {
let notification = new GlobalNotificationModel(response.notification, 'success');
GlobalNotificationActions.appendGlobalNotification(notification);
}
},
getFormDataId(){
return getAclFormDataId(this.isPiece(), this.props.pieceOrEditions);
},
// Removes the acl_ prefix and converts to upper case
sanitizeAction() {
if (this.props.buttonAcceptName) {
return this.props.buttonAcceptName;
}
return this.props.action.split('acl_')[1].toUpperCase();
},
render() {
if (this.props.availableAcls) {
let shouldDisplay = this.props.availableAcls[this.props.action];
let aclProps = this.actionProperties();
let buttonClassName = this.props.buttonAcceptClassName ? this.props.buttonAcceptClassName : '';
return (
<ModalWrapper
trigger={
<button
className={shouldDisplay ? 'btn btn-default btn-sm ' + buttonClassName : 'hidden'}>
{this.sanitizeAction()}
</button>
}
handleSuccess={aclProps.handleSuccess}
title={aclProps.title}>
{aclProps.form}
</ModalWrapper>
);
}
return null;
}
});
export default AclButton;

View File

@ -5,21 +5,25 @@ import React from 'react/addons';
import UserActions from '../../actions/user_actions';
import UserStore from '../../stores/user_store';
import AclButton from '../ascribe_buttons/acl_button';
import ConsignButton from './acls/consign_button';
import LoanButton from './acls/loan_button';
import LoanRequestButton from './acls/loan_request_button';
import ShareButton from './acls/share_button';
import TransferButton from './acls/transfer_button';
import UnconsignButton from './acls/unconsign_button';
import { mergeOptions } from '../../utils/general_utils';
let AclButtonList = React.createClass({
propTypes: {
className: React.PropTypes.string,
editions: React.PropTypes.oneOfType([
pieceOrEditions: React.PropTypes.oneOfType([
React.PropTypes.object,
React.PropTypes.array
]),
availableAcls: React.PropTypes.object,
]).isRequired,
availableAcls: React.PropTypes.object.isRequired,
buttonsStyle: React.PropTypes.object,
handleSuccess: React.PropTypes.func,
handleSuccess: React.PropTypes.func.isRequired,
children: React.PropTypes.oneOfType([
React.PropTypes.arrayOf(React.PropTypes.element),
React.PropTypes.element
@ -78,7 +82,7 @@ let AclButtonList = React.createClass({
const { className,
buttonsStyle,
availableAcls,
editions,
pieceOrEditions,
handleSuccess } = this.props;
const { currentUser } = this.state;
@ -86,34 +90,29 @@ let AclButtonList = React.createClass({
return (
<div className={className}>
<span ref="buttonList" style={buttonsStyle}>
<AclButton
<ShareButton
availableAcls={availableAcls}
action="acl_share"
pieceOrEditions={editions}
pieceOrEditions={pieceOrEditions}
currentUser={currentUser}
handleSuccess={handleSuccess} />
<AclButton
<TransferButton
availableAcls={availableAcls}
action="acl_transfer"
pieceOrEditions={editions}
pieceOrEditions={pieceOrEditions}
currentUser={currentUser}
handleSuccess={handleSuccess}/>
<AclButton
<ConsignButton
availableAcls={availableAcls}
action="acl_consign"
pieceOrEditions={editions}
pieceOrEditions={pieceOrEditions}
currentUser={currentUser}
handleSuccess={handleSuccess} />
<AclButton
<UnconsignButton
availableAcls={availableAcls}
action="acl_unconsign"
pieceOrEditions={editions}
pieceOrEditions={pieceOrEditions}
currentUser={currentUser}
handleSuccess={handleSuccess} />
<AclButton
<LoanButton
availableAcls={availableAcls}
action="acl_loan"
pieceOrEditions={editions}
pieceOrEditions={pieceOrEditions}
currentUser={currentUser}
handleSuccess={handleSuccess} />
{this.renderChildren()}
@ -123,4 +122,4 @@ let AclButtonList = React.createClass({
}
});
export default AclButtonList;
export default AclButtonList;

View File

@ -0,0 +1,83 @@
'use strict';
import React from 'react';
import classNames from 'classnames';
import AclProxy from '../../acl_proxy';
import AclFormFactory from '../../ascribe_forms/acl_form_factory';
import ModalWrapper from '../../ascribe_modal/modal_wrapper';
import AppConstants from '../../../constants/application_constants';
import GlobalNotificationModel from '../../../models/global_notification_model';
import GlobalNotificationActions from '../../../actions/global_notification_actions';
import ApiUrls from '../../../constants/api_urls';
import { getAclFormMessage, getAclFormDataId } from '../../../utils/form_utils';
import { getLangText } from '../../../utils/lang_utils';
let AclButton = React.createClass({
propTypes: {
action: React.PropTypes.oneOf(AppConstants.aclList).isRequired,
availableAcls: React.PropTypes.object.isRequired,
buttonAcceptName: React.PropTypes.string,
buttonAcceptClassName: React.PropTypes.string,
currentUser: React.PropTypes.object.isRequired,
email: React.PropTypes.string,
pieceOrEditions: React.PropTypes.oneOfType([
React.PropTypes.object,
React.PropTypes.array
]).isRequired,
title: React.PropTypes.string,
handleSuccess: React.PropTypes.func.isRequired,
className: React.PropTypes.string
},
// Removes the acl_ prefix and converts to upper case
sanitizeAction() {
if (this.props.buttonAcceptName) {
return this.props.buttonAcceptName;
}
return this.props.action.split('acl_')[1].toUpperCase();
},
render() {
const {
action,
availableAcls,
buttonAcceptClassName,
currentUser,
email,
pieceOrEditions,
handleSuccess,
title } = this.props;
return (
<AclProxy
aclName={action}
aclObject={availableAcls}>
<ModalWrapper
trigger={
<button
className={classNames('btn', 'btn-default', 'btn-sm', buttonAcceptClassName)}>
{this.sanitizeAction()}
</button>
}
handleSuccess={handleSuccess}
title={title}>
<AclFormFactory
action={action}
currentUser={currentUser}
email={email}
pieceOrEditions={pieceOrEditions}
showNotification />
</ModalWrapper>
</AclProxy>
);
}
});
export default AclButton;

View File

@ -0,0 +1,27 @@
'use strict';
import React from 'react';
import AclButton from './acl_button';
import { omitFromObject } from '../../../utils/general_utils';
import { getLangText } from '../../../utils/lang_utils';
let ConsignButton = React.createClass({
propTypes: {
...omitFromObject(AclButton.propTypes, ['action']),
email: React.PropTypes.string
},
render() {
return (
<AclButton
{...this.props}
action='acl_consign'
title={getLangText('Consign artwork')}
tooltip={getLangText('Have someone else sell the artwork')} />
);
}
});
export default ConsignButton;

View File

@ -0,0 +1,27 @@
'use strict';
import React from 'react';
import AclButton from './acl_button';
import { omitFromObject } from '../../../utils/general_utils';
import { getLangText } from '../../../utils/lang_utils';
let LoanButton = React.createClass({
propTypes: {
...omitFromObject(AclButton.propTypes, ['action']),
email: React.PropTypes.string
},
render() {
return (
<AclButton
{...this.props}
action='acl_loan'
title={getLangText('Loan artwork')}
tooltip={getLangText('Loan your artwork for a limited period of time')} />
);
}
});
export default LoanButton;

View File

@ -0,0 +1,24 @@
'use strict';
import React from 'react';
import AclButton from './acl_button';
import { omitFromObject } from '../../../utils/general_utils';
import { getLangText } from '../../../utils/lang_utils';
let LoanButton = React.createClass({
propTypes: omitFromObject(AclButton.propTypes, ['action']),
render() {
return (
<AclButton
{...this.props}
action='acl_loan_request'
title={getLangText('Loan artwork')}
tooltip={getLangText('Someone requested you to loan your artwork for a limited period of time')} />
);
}
});
export default LoanButton;

View File

@ -0,0 +1,24 @@
'use strict';
import React from 'react';
import AclButton from './acl_button';
import { omitFromObject } from '../../../utils/general_utils';
import { getLangText } from '../../../utils/lang_utils';
let ShareButton = React.createClass({
propTypes: omitFromObject(AclButton.propTypes, ['action']),
render() {
return (
<AclButton
{...this.props}
action='acl_share'
title={getLangText('Share artwork')}
tooltip={getLangText('Share the artwork')} />
);
}
});
export default ShareButton;

View File

@ -0,0 +1,24 @@
'use strict';
import React from 'react';
import AclButton from './acl_button';
import { omitFromObject } from '../../../utils/general_utils';
import { getLangText } from '../../../utils/lang_utils';
let TransferButton = React.createClass({
propTypes: omitFromObject(AclButton.propTypes, ['action']),
render() {
return (
<AclButton
{...this.props}
action='acl_transfer'
title={getLangText('Transfer artwork')}
tooltip={getLangText('Transfer the ownership of the artwork')} />
);
}
});
export default TransferButton;

View File

@ -0,0 +1,24 @@
'use strict';
import React from 'react';
import AclButton from './acl_button';
import { omitFromObject } from '../../../utils/general_utils';
import { getLangText } from '../../../utils/lang_utils';
let UnconsignButton = React.createClass({
propTypes: omitFromObject(AclButton.propTypes, ['action']),
render() {
return (
<AclButton
{...this.props}
action='acl_unconsign'
title={getLangText('Unconsign artwork')}
tooltip={getLangText('Have the owner manage his sales again')} />
);
}
});
export default UnconsignButton;

View File

@ -115,7 +115,7 @@ let EditionActionPanel = React.createClass({
<ActionPanelButtonListType
className="ascribe-button-list"
availableAcls={edition.acl}
editions={[edition]}
pieceOrEditions={[edition]}
handleSuccess={this.handleSuccess}>
<AclProxy
aclObject={edition.acl}

View File

@ -207,7 +207,7 @@ let PieceContainer = React.createClass({
<AclButtonList
className="ascribe-button-list"
availableAcls={piece.acl}
editions={piece}
pieceOrEditions={piece}
handleSuccess={this.loadPiece}>
<CreateEditionsButton
label={getLangText('CREATE EDITIONS')}

View File

@ -0,0 +1,128 @@
'use strict';
import React from 'react';
import ConsignForm from '../ascribe_forms/form_consign';
import UnConsignForm from '../ascribe_forms/form_unconsign';
import TransferForm from '../ascribe_forms/form_transfer';
import LoanForm from '../ascribe_forms/form_loan';
import LoanRequestAnswerForm from '../ascribe_forms/form_loan_request_answer';
import ShareForm from '../ascribe_forms/form_share_email';
import AppConstants from '../../constants/application_constants';
import ApiUrls from '../../constants/api_urls';
import GlobalNotificationModel from '../../models/global_notification_model';
import GlobalNotificationActions from '../../actions/global_notification_actions';
import { getAclFormMessage, getAclFormDataId } from '../../utils/form_utils';
let AclFormFactory = React.createClass({
propTypes: {
action: React.PropTypes.oneOf(AppConstants.aclList).isRequired,
currentUser: React.PropTypes.object.isRequired,
email: React.PropTypes.string,
message: React.PropTypes.string,
pieceOrEditions: React.PropTypes.oneOfType([
React.PropTypes.object,
React.PropTypes.array
]).isRequired,
handleSuccess: React.PropTypes.func,
showNotification: React.PropTypes.bool
},
isPiece() {
return this.props.pieceOrEditions.constructor !== Array;
},
getFormDataId() {
return getAclFormDataId(this.isPiece(), this.props.pieceOrEditions);
},
showSuccessNotification(response) {
if (typeof this.props.handleSuccess === 'function') {
this.props.handleSuccess();
}
if (response.notification) {
const notification = new GlobalNotificationModel(response.notification, 'success');
GlobalNotificationActions.appendGlobalNotification(notification);
}
},
render() {
const {
action,
pieceOrEditions,
currentUser,
email,
message,
handleSuccess,
showNotification } = this.props;
const formMessage = message || getAclFormMessage({
aclName: action,
entities: pieceOrEditions,
isPiece: this.isPiece(),
senderName: currentUser.username
});
if (action === 'acl_consign') {
return (
<ConsignForm
email={email}
message={formMessage}
id={this.getFormDataId()}
url={ApiUrls.ownership_consigns}
handleSuccess={showNotification ? this.showSuccessNotification : handleSuccess} />
);
} else if (action === 'acl_unconsign') {
return (
<UnConsignForm
message={formMessage}
id={this.getFormDataId()}
url={ApiUrls.ownership_unconsigns}
handleSuccess={showNotification ? this.showSuccessNotification : handleSuccess} />
);
} else if (action === 'acl_transfer') {
return (
<TransferForm
message={formMessage}
id={this.getFormDataId()}
url={ApiUrls.ownership_transfers}
handleSuccess={showNotification ? this.showSuccessNotification : handleSuccess} />
);
} else if (action === 'acl_loan') {
return (
<LoanForm
email={email}
message={formMessage}
id={this.getFormDataId()}
url={this.isPiece() ? ApiUrls.ownership_loans_pieces
: ApiUrls.ownership_loans_editions}
handleSuccess={showNotification ? this.showSuccessNotification : handleSuccess} />
);
} else if (action === 'acl_loan_request') {
return (
<LoanRequestAnswerForm
message={formMessage}
id={this.getFormDataId()}
url={ApiUrls.ownership_loans_pieces_request_confirm}
handleSuccess={showNotification ? this.showSuccessNotification : handleSuccess} />
);
} else if (action === 'acl_share') {
return (
<ShareForm
message={formMessage}
id={this.getFormDataId()}
url={this.isPiece() ? ApiUrls.ownership_shares_pieces
: ApiUrls.ownership_shares_editions}
handleSuccess={showNotification ? this.showSuccessNotification : handleSuccess} />
);
} else {
throw new Error('Your specified action did not match a form.');
}
}
});
export default AclFormFactory;

View File

@ -2,10 +2,13 @@
import React from 'react';
import AclButton from './../ascribe_buttons/acl_button';
import ActionPanel from '../ascribe_panel/action_panel';
import Form from './form';
import LoanRequestButton from '../ascribe_buttons/acls/loan_request_button';
import UnconsignButton from '../ascribe_buttons/acls/unconsign_button';
import ActionPanel from '../ascribe_panel/action_panel';
import NotificationActions from '../../actions/notification_actions';
import GlobalNotificationModel from '../../models/global_notification_model';
@ -13,9 +16,9 @@ import GlobalNotificationActions from '../../actions/global_notification_actions
import ApiUrls from '../../constants/api_urls';
import { getAclFormDataId } from '../../utils/form_utils';
import { getLangText } from '../../utils/lang_utils.js';
let RequestActionForm = React.createClass({
propTypes: {
pieceOrEditions: React.PropTypes.oneOfType([
@ -27,26 +30,26 @@ let RequestActionForm = React.createClass({
handleSuccess: React.PropTypes.func
},
isPiece(){
isPiece() {
return this.props.pieceOrEditions.constructor !== Array;
},
getUrls() {
let urls = {};
if (this.props.notifications.action === 'consign'){
if (this.props.notifications.action === 'consign') {
urls.accept = ApiUrls.ownership_consigns_confirm;
urls.deny = ApiUrls.ownership_consigns_deny;
} else if (this.props.notifications.action === 'unconsign'){
} else if (this.props.notifications.action === 'unconsign') {
urls.accept = ApiUrls.ownership_unconsigns;
urls.deny = ApiUrls.ownership_unconsigns_deny;
} else if (this.props.notifications.action === 'loan' && !this.isPiece()){
} else if (this.props.notifications.action === 'loan' && !this.isPiece()) {
urls.accept = ApiUrls.ownership_loans_confirm;
urls.deny = ApiUrls.ownership_loans_deny;
} else if (this.props.notifications.action === 'loan' && this.isPiece()){
} else if (this.props.notifications.action === 'loan' && this.isPiece()) {
urls.accept = ApiUrls.ownership_loans_pieces_confirm;
urls.deny = ApiUrls.ownership_loans_pieces_deny;
} else if (this.props.notifications.action === 'loan_request' && this.isPiece()){
} else if (this.props.notifications.action === 'loan_request' && this.isPiece()) {
urls.accept = ApiUrls.ownership_loans_pieces_request_confirm;
urls.deny = ApiUrls.ownership_loans_pieces_request_deny;
}
@ -54,37 +57,28 @@ let RequestActionForm = React.createClass({
return urls;
},
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()};
}
getFormData() {
return getAclFormDataId(this.isPiece(), this.props.pieceOrEditions);
},
showNotification(option, action, owner) {
return () => {
let message = getLangText('You have successfully') + ' ' + option + ' the ' + action + ' request ' + getLangText('from') + ' ' + owner;
let notifications = new GlobalNotificationModel(message, 'success');
const message = getLangText('You have successfully %s the %s request from %s', getLangText(option), getLangText(action), owner);
const notifications = new GlobalNotificationModel(message, 'success');
GlobalNotificationActions.appendGlobalNotification(notifications);
this.handleSuccess();
};
},
handleSuccess() {
if (this.isPiece()){
if (this.isPiece()) {
NotificationActions.fetchPieceListNotifications();
}
else {
} else {
NotificationActions.fetchEditionListNotifications();
}
if(this.props.handleSuccess) {
if (typeof this.props.handleSuccess === 'function') {
this.props.handleSuccess();
}
},
@ -98,21 +92,19 @@ let RequestActionForm = React.createClass({
},
getAcceptButtonForm(urls) {
if(this.props.notifications.action === 'unconsign') {
if (this.props.notifications.action === 'unconsign') {
return (
<AclButton
<UnconsignButton
availableAcls={{'acl_unconsign': true}}
action="acl_unconsign"
buttonAcceptClassName='inline pull-right btn-sm ascribe-margin-1px'
pieceOrEditions={this.props.pieceOrEditions}
currentUser={this.props.currentUser}
handleSuccess={this.handleSuccess} />
);
} else if(this.props.notifications.action === 'loan_request') {
} else if (this.props.notifications.action === 'loan_request') {
return (
<AclButton
<LoanRequestButton
availableAcls={{'acl_loan_request': true}}
action="acl_loan_request"
buttonAcceptName="LOAN"
buttonAcceptClassName='inline pull-right btn-sm ascribe-margin-1px'
pieceOrEditions={this.props.pieceOrEditions}
@ -125,7 +117,7 @@ let RequestActionForm = React.createClass({
url={urls.accept}
getFormData={this.getFormData}
handleSuccess={
this.showNotification(getLangText('accepted'), this.props.notifications.action, this.props.notifications.by)
this.showNotification('accepted', this.props.notifications.action, this.props.notifications.by)
}
isInline={true}
className='inline pull-right'>
@ -140,8 +132,8 @@ let RequestActionForm = React.createClass({
},
getButtonForm() {
let urls = this.getUrls();
let acceptButtonForm = this.getAcceptButtonForm(urls);
const urls = this.getUrls();
const acceptButtonForm = this.getAcceptButtonForm(urls);
return (
<div>
@ -150,13 +142,13 @@ let RequestActionForm = React.createClass({
isInline={true}
getFormData={this.getFormData}
handleSuccess={
this.showNotification(getLangText('denied'), this.props.notifications.action, this.props.notifications.by)
this.showNotification('denied', this.props.notifications.action, this.props.notifications.by)
}
className='inline pull-right'>
<button
type="submit"
className='btn btn-danger btn-delete btn-sm ascribe-margin-1px'>
{getLangText('REJECT')}
{getLangText('REJECT')}
</button>
</Form>
{acceptButtonForm}
@ -168,10 +160,10 @@ let RequestActionForm = React.createClass({
return (
<ActionPanel
content={this.getContent()}
buttons={this.getButtonForm()}/>
buttons={this.getButtonForm()} />
);
}
});
export default RequestActionForm;
export default RequestActionForm;

View File

@ -47,7 +47,7 @@ let WalletActionPanel = React.createClass({
<AclButtonList
className="text-center ascribe-button-list"
availableAcls={availableAcls}
editions={this.props.piece}
pieceOrEditions={this.props.piece}
handleSuccess={this.props.loadPiece}>
<AclProxy
aclObject={this.props.currentUser.acl}
@ -69,4 +69,4 @@ let WalletActionPanel = React.createClass({
}
});
export default WalletActionPanel;
export default WalletActionPanel;

View File

@ -20,6 +20,22 @@ export function getAclFormDataId(isPiece, pieceOrEditions) {
}
}
/**
* 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
* @param {object} options Options object for creating the message:

View File

@ -195,14 +195,41 @@ export function escapeHTML(s) {
return document.createElement('div').appendChild(document.createTextNode(s)).parentNode.innerHTML;
}
export function excludePropFromObject(obj, propList){
let clonedObj = mergeOptions({}, obj);
for (let item in propList){
if (clonedObj[propList[item]]){
delete clonedObj[propList[item]];
/**
* Returns a copy of the given object's own and inherited enumerable
* properties, omitting any keys that pass the given filter function.
*/
function filterObjOnFn(obj, filterFn) {
const filteredObj = {};
for (let key in obj) {
const val = obj[key];
if (filterFn == null || !filterFn(val, key)) {
filteredObj[key] = val;
}
}
return clonedObj;
return filteredObj;
}
/**
* Similar to lodash's _.omit(), this returns a copy of the given object's
* own and inherited enumerable properties, omitting any keys that are
* in the given array or whose value pass the given filter function.
* @param {object} obj Source object
* @param {array|function} filter Array of key names to omit or function to invoke per iteration
* @return {object} The new object
*/
export function omitFromObject(obj, filter) {
if (filter && filter.constructor === Array) {
return filterObjOnFn(obj, (_, key) => {
return filter.indexOf(key) >= 0;
});
} else if (filter && typeof filter === 'function') {
return filterObjOnFn(obj, filter);
} else {
throw new Error('The given filter is not an array or function. Exclude aborted');
}
}
/**

View File

@ -22,15 +22,15 @@ export function getLangText(s, ...args) {
let lang = getLang();
try {
if(lang in languages) {
return formatText(languages[lang][s], args);
return formatText(languages[lang][s], ...args);
} else {
// just use the english language
return formatText(languages['en-US'][s], args);
return formatText(languages['en-US'][s], ...args);
}
} catch(err) {
//if(!(s in languages[lang])) {
//console.warn('Language-string is not in constants file. Add: "' + s + '" to the "' + lang + '" language file. Defaulting to keyname');
return formatText(s, args);
return formatText(s, ...args);
//} else {
// console.error(err);
//}

View File

@ -6,7 +6,7 @@ import { argsToQueryParams, getCookie } from '../utils/fetch_api_utils';
import AppConstants from '../constants/application_constants';
import {excludePropFromObject} from '../utils/general_utils';
import { omitFromObject } from '../utils/general_utils';
class Requests {
_merge(defaults, options) {
@ -138,9 +138,9 @@ class Requests {
return this.request('delete', newUrl);
}
_putOrPost(url, paramsAndBody, method){
let paramsCopy = this._merge(paramsAndBody);
let params = excludePropFromObject(paramsAndBody, ['body']);
_putOrPost(url, paramsAndBody, method) {
let paramsCopy = Object.assign({}, paramsAndBody);
let params = omitFromObject(paramsAndBody, ['body']);
let newUrl = this.prepareUrl(url, params);
let body = null;
if (paramsCopy && paramsCopy.body) {