2015-06-05 11:06:36 +02:00
|
|
|
'use strict';
|
|
|
|
|
2015-06-01 18:59:47 +02:00
|
|
|
import React from 'react';
|
|
|
|
import ReactAddons from 'react/addons';
|
|
|
|
|
|
|
|
import Modal from 'react-bootstrap/lib/Modal';
|
|
|
|
|
|
|
|
let ModalWrapper = React.createClass({
|
2015-06-09 16:10:38 +02:00
|
|
|
propTypes: {
|
2015-08-05 17:32:35 +02:00
|
|
|
trigger: React.PropTypes.element.isRequired,
|
|
|
|
title: React.PropTypes.oneOfType([
|
|
|
|
React.PropTypes.arrayOf(React.PropTypes.element),
|
|
|
|
React.PropTypes.element,
|
|
|
|
React.PropTypes.string
|
|
|
|
]).isRequired,
|
2015-06-09 16:10:38 +02:00
|
|
|
handleSuccess: React.PropTypes.func.isRequired,
|
2015-08-05 17:32:35 +02:00
|
|
|
children: React.PropTypes.oneOfType([
|
|
|
|
React.PropTypes.arrayOf(React.PropTypes.element),
|
|
|
|
React.PropTypes.element
|
|
|
|
])
|
2015-06-09 16:10:38 +02:00
|
|
|
},
|
2015-06-01 18:59:47 +02:00
|
|
|
|
2015-08-05 17:32:35 +02:00
|
|
|
getInitialState() {
|
|
|
|
return {
|
|
|
|
showModal: false
|
|
|
|
};
|
2015-07-14 16:29:01 +02:00
|
|
|
},
|
|
|
|
|
2015-08-05 17:32:35 +02:00
|
|
|
show() {
|
|
|
|
this.setState({
|
|
|
|
showModal: true
|
|
|
|
});
|
2015-06-09 16:10:38 +02:00
|
|
|
},
|
2015-06-05 11:06:36 +02:00
|
|
|
|
2015-08-05 17:32:35 +02:00
|
|
|
hide() {
|
|
|
|
this.setState({
|
|
|
|
showModal: false
|
|
|
|
});
|
|
|
|
},
|
2015-06-01 18:59:47 +02:00
|
|
|
|
2015-06-09 16:10:38 +02:00
|
|
|
handleSuccess(response){
|
|
|
|
this.props.handleSuccess(response);
|
2015-08-05 17:32:35 +02:00
|
|
|
this.hide();
|
2015-06-02 11:38:18 +02:00
|
|
|
},
|
2015-06-05 11:06:36 +02:00
|
|
|
|
2015-06-01 18:59:47 +02:00
|
|
|
renderChildren() {
|
2015-06-05 11:06:36 +02:00
|
|
|
return ReactAddons.Children.map(this.props.children, (child) => {
|
2015-06-01 18:59:47 +02:00
|
|
|
return ReactAddons.addons.cloneWithProps(child, {
|
2015-06-02 11:38:18 +02:00
|
|
|
handleSuccess: this.handleSuccess
|
2015-06-01 18:59:47 +02:00
|
|
|
});
|
|
|
|
});
|
|
|
|
},
|
2015-06-05 11:06:36 +02:00
|
|
|
|
2015-06-01 18:59:47 +02:00
|
|
|
render() {
|
2015-08-05 18:00:44 +02:00
|
|
|
// this adds the onClick method show of modal_wrapper to the trigger component
|
|
|
|
// which is in most cases a button.
|
2015-08-05 17:32:35 +02:00
|
|
|
let trigger = React.cloneElement(this.props.trigger, {onClick: this.show});
|
|
|
|
|
2015-06-01 18:59:47 +02:00
|
|
|
return (
|
2015-08-05 17:32:35 +02:00
|
|
|
<span>
|
|
|
|
{trigger}
|
|
|
|
<Modal show={this.state.showModal} onHide={this.hide}>
|
|
|
|
<Modal.Header closeButton>
|
|
|
|
<Modal.Title>
|
|
|
|
{this.props.title}
|
|
|
|
</Modal.Title>
|
|
|
|
</Modal.Header>
|
|
|
|
<div className="modal-body">
|
|
|
|
{this.renderChildren()}
|
|
|
|
</div>
|
|
|
|
</Modal>
|
|
|
|
</span>
|
2015-06-05 11:06:36 +02:00
|
|
|
);
|
2015-06-01 18:59:47 +02:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
export default ModalWrapper;
|