1
0
mirror of https://github.com/ascribe/onion.git synced 2024-06-30 13:41:57 +02:00

Add pageExitWarning for SlidesContainer

This commit is contained in:
Tim Daubenschütz 2015-11-25 15:01:23 +01:00
parent 121a1dbb8d
commit 88d1edd45c
3 changed files with 23 additions and 10 deletions

View File

@ -1,7 +1,7 @@
'use strict'; 'use strict';
import React from 'react'; import React from 'react';
import { History } from 'react-router'; import { History, RouteContext } from 'react-router';
import UserStore from '../../../stores/user_store'; import UserStore from '../../../stores/user_store';
import UserActions from '../../../actions/user_actions'; import UserActions from '../../../actions/user_actions';
@ -37,7 +37,9 @@ export default function AuthProxyHandler({to, when}) {
location: object location: object
}, },
mixins: [History], // We need insert `RouteContext` here in order to be able
// to use the `Lifecycle` widget in further down nested components
mixins: [History, RouteContext],
getInitialState() { getInitialState() {
return UserStore.getState(); return UserStore.getState();

View File

@ -1,7 +1,7 @@
'use strict'; 'use strict';
import React from 'react/addons'; import React from 'react/addons';
import { History } from 'react-router'; import { History, Lifecycle } from 'react-router';
import SlidesContainerBreadcrumbs from './slides_container_breadcrumbs'; import SlidesContainerBreadcrumbs from './slides_container_breadcrumbs';
@ -17,14 +17,16 @@ const SlidesContainer = React.createClass({
pending: string, pending: string,
complete: string complete: string
}), }),
location: object location: object,
pageExitWarning: string
}, },
mixins: [History], mixins: [History, Lifecycle],
getInitialState() { getInitialState() {
return { return {
containerWidth: 0 containerWidth: 0,
pageExitWarning: null
}; };
}, },
@ -41,6 +43,10 @@ const SlidesContainer = React.createClass({
window.removeEventListener('resize', this.handleContainerResize); window.removeEventListener('resize', this.handleContainerResize);
}, },
routerWillLeave() {
return this.props.pageExitWarning;
},
handleContainerResize() { handleContainerResize() {
this.setState({ this.setState({
// +30 to get rid of the padding of the container which is 15px + 15px left and right // +30 to get rid of the padding of the container which is 15px + 15px left and right

View File

@ -32,6 +32,7 @@ import ApiUrls from '../../../../../constants/api_urls';
import { mergeOptions } from '../../../../../utils/general_utils'; import { mergeOptions } from '../../../../../utils/general_utils';
import { getLangText } from '../../../../../utils/lang_utils'; import { getLangText } from '../../../../../utils/lang_utils';
let IkonotvRegisterPiece = React.createClass({ let IkonotvRegisterPiece = React.createClass({
propTypes: { propTypes: {
handleSuccess: React.PropTypes.func, handleSuccess: React.PropTypes.func,
@ -47,7 +48,8 @@ let IkonotvRegisterPiece = React.createClass({
PieceListStore.getState(), PieceListStore.getState(),
PieceStore.getState(), PieceStore.getState(),
{ {
step: 0 step: 0,
pageExitWarning: getLangText("If you leave this form now, your work will not be loaned to Ikono TV.")
}); });
}, },
@ -94,7 +96,6 @@ let IkonotvRegisterPiece = React.createClass({
handleRegisterSuccess(response){ handleRegisterSuccess(response){
this.refreshPieceList(); this.refreshPieceList();
// also start loading the piece for the next step // also start loading the piece for the next step
@ -108,7 +109,6 @@ let IkonotvRegisterPiece = React.createClass({
this.incrementStep(); this.incrementStep();
this.refs.slidesContainer.nextSlide(); this.refs.slidesContainer.nextSlide();
} }
}, },
handleAdditionalDataSuccess() { handleAdditionalDataSuccess() {
@ -126,6 +126,8 @@ let IkonotvRegisterPiece = React.createClass({
}, },
handleLoanSuccess(response) { handleLoanSuccess(response) {
this.setState({ pageExitWarning: null });
let notification = new GlobalNotificationModel(response.notification, 'success', 10000); let notification = new GlobalNotificationModel(response.notification, 'success', 10000);
GlobalNotificationActions.appendGlobalNotification(notification); GlobalNotificationActions.appendGlobalNotification(notification);
@ -238,6 +240,8 @@ let IkonotvRegisterPiece = React.createClass({
}, },
render() { render() {
const { pageExitWarning } = this.state;
return ( return (
<SlidesContainer <SlidesContainer
ref="slidesContainer" ref="slidesContainer"
@ -246,7 +250,8 @@ let IkonotvRegisterPiece = React.createClass({
pending: 'glyphicon glyphicon-chevron-right', pending: 'glyphicon glyphicon-chevron-right',
completed: 'glyphicon glyphicon-lock' completed: 'glyphicon glyphicon-lock'
}} }}
location={this.props.location}> location={this.props.location}
pageExitWarning={pageExitWarning}>
<div data-slide-title={getLangText('Register work')}> <div data-slide-title={getLangText('Register work')}>
<Row className="no-margin"> <Row className="no-margin">
<Col xs={12} sm={10} md={8} smOffset={1} mdOffset={2}> <Col xs={12} sm={10} md={8} smOffset={1} mdOffset={2}>