1
0
mirror of https://github.com/ascribe/onion.git synced 2024-06-28 00:28:00 +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';
import React from 'react';
import { History } from 'react-router';
import { History, RouteContext } from 'react-router';
import UserStore from '../../../stores/user_store';
import UserActions from '../../../actions/user_actions';
@ -37,7 +37,9 @@ export default function AuthProxyHandler({to, when}) {
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() {
return UserStore.getState();

View File

@ -1,7 +1,7 @@
'use strict';
import React from 'react/addons';
import { History } from 'react-router';
import { History, Lifecycle } from 'react-router';
import SlidesContainerBreadcrumbs from './slides_container_breadcrumbs';
@ -17,14 +17,16 @@ const SlidesContainer = React.createClass({
pending: string,
complete: string
}),
location: object
location: object,
pageExitWarning: string
},
mixins: [History],
mixins: [History, Lifecycle],
getInitialState() {
return {
containerWidth: 0
containerWidth: 0,
pageExitWarning: null
};
},
@ -41,6 +43,10 @@ const SlidesContainer = React.createClass({
window.removeEventListener('resize', this.handleContainerResize);
},
routerWillLeave() {
return this.props.pageExitWarning;
},
handleContainerResize() {
this.setState({
// +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 { getLangText } from '../../../../../utils/lang_utils';
let IkonotvRegisterPiece = React.createClass({
propTypes: {
handleSuccess: React.PropTypes.func,
@ -47,7 +48,8 @@ let IkonotvRegisterPiece = React.createClass({
PieceListStore.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){
this.refreshPieceList();
// also start loading the piece for the next step
@ -108,7 +109,6 @@ let IkonotvRegisterPiece = React.createClass({
this.incrementStep();
this.refs.slidesContainer.nextSlide();
}
},
handleAdditionalDataSuccess() {
@ -126,6 +126,8 @@ let IkonotvRegisterPiece = React.createClass({
},
handleLoanSuccess(response) {
this.setState({ pageExitWarning: null });
let notification = new GlobalNotificationModel(response.notification, 'success', 10000);
GlobalNotificationActions.appendGlobalNotification(notification);
@ -238,6 +240,8 @@ let IkonotvRegisterPiece = React.createClass({
},
render() {
const { pageExitWarning } = this.state;
return (
<SlidesContainer
ref="slidesContainer"
@ -246,7 +250,8 @@ let IkonotvRegisterPiece = React.createClass({
pending: 'glyphicon glyphicon-chevron-right',
completed: 'glyphicon glyphicon-lock'
}}
location={this.props.location}>
location={this.props.location}
pageExitWarning={pageExitWarning}>
<div data-slide-title={getLangText('Register work')}>
<Row className="no-margin">
<Col xs={12} sm={10} md={8} smOffset={1} mdOffset={2}>