From 5be771f6acb97f93dc23a2ef390c7be5602ded60 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tim=20Daubensch=C3=BCtz?= Date: Mon, 10 Aug 2015 14:15:32 +0200 Subject: [PATCH] add inline property to form --- js/components/ascribe_detail/edition.js | 3 ++- js/components/ascribe_forms/form.js | 19 +++++++++++++++++-- .../ascribe_forms/form_request_action.js | 4 +++- 3 files changed, 22 insertions(+), 4 deletions(-) diff --git a/js/components/ascribe_detail/edition.js b/js/components/ascribe_detail/edition.js index a1d9af70..0f1477c0 100644 --- a/js/components/ascribe_detail/edition.js +++ b/js/components/ascribe_detail/edition.js @@ -236,7 +236,8 @@ let EditionSummary = React.createClass({ url={ApiUrls.ownership_transfers_withdraw} getFormData={this.getTransferWithdrawData} handleSuccess={this.showNotification} - className='inline'> + className='inline' + isInline={true}> diff --git a/js/components/ascribe_forms/form.js b/js/components/ascribe_forms/form.js index d7e31382..2b956a7e 100644 --- a/js/components/ascribe_forms/form.js +++ b/js/components/ascribe_forms/form.js @@ -6,6 +6,9 @@ import ReactAddons from 'react/addons'; import Button from 'react-bootstrap/lib/Button'; import AlertDismissable from './alert'; +import GlobalNotificationModel from '../../models/global_notification_model'; +import GlobalNotificationActions from '../../actions/global_notification_actions'; + import requests from '../../utils/requests'; import { getLangText } from '../../utils/lang_utils'; @@ -28,7 +31,12 @@ let Form = React.createClass({ buttons: React.PropTypes.oneOfType([ React.PropTypes.element, React.PropTypes.arrayOf(React.PropTypes.element) - ]) + ]), + + // You can use the form for inline requests, like the submit click on a button. + // For the form to then not display the error on top, you need to enable this option. + // It will make use of the GlobalNotification + isInline: React.PropTypes.bool }, getDefaultProps() { @@ -136,7 +144,14 @@ let Form = React.createClass({ } console.logGlobal(err, false, formData); - this.setState({errors: [getLangText('Something went wrong, please try again later')]}); + + if(this.props.isInline) { + let notification = new GlobalNotificationModel(getLangText('Something went wrong, please try again later'), 'danger'); + GlobalNotificationActions.appendGlobalNotification(notification); + } else { + this.setState({errors: [getLangText('Something went wrong, please try again later')]}); + } + } this.setState({submitted: false}); }, diff --git a/js/components/ascribe_forms/form_request_action.js b/js/components/ascribe_forms/form_request_action.js index 519e3a53..dca86da7 100644 --- a/js/components/ascribe_forms/form_request_action.js +++ b/js/components/ascribe_forms/form_request_action.js @@ -54,7 +54,7 @@ let RequestActionForm = React.createClass({ showNotification(option, action, owner) { return () => { - let message = getLangText('You have successfully') + ' ' + option + ' ' + action + ' ' + getLangText('to') + ' ' + owner; + let message = getLangText('You have successfully') + ' ' + option + ' the ' + action + ' request ' + getLangText('from') + ' ' + owner; let notification = new GlobalNotificationModel(message, 'success'); GlobalNotificationActions.appendGlobalNotification(notification); @@ -94,6 +94,7 @@ let RequestActionForm = React.createClass({ url={urls.accept} getFormData={this.getFormData} handleSuccess={this.showNotification(getLangText('denied'), edition.request_action, edition.owner)} + isInline={true} className='inline pull-right'>