forked from instructure/canvas-lms
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathExternalToolModalLauncher.js
More file actions
114 lines (97 loc) · 2.97 KB
/
Copy pathExternalToolModalLauncher.js
File metadata and controls
114 lines (97 loc) · 2.97 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
import _ from 'underscore'
import $ from 'jquery'
import React from 'react'
import Modal from 'jsx/shared/modal'
import ModalContent from 'jsx/shared/modal-content'
export default React.createClass({
displayName: 'ExternalToolModalLauncher',
propTypes: {
tool: React.PropTypes.object,
isOpen: React.PropTypes.bool.isRequired,
onRequestClose: React.PropTypes.func.isRequired,
contextType: React.PropTypes.string.isRequired,
contextId: React.PropTypes.number.isRequired,
launchType: React.PropTypes.string.isRequired,
},
componentDidMount () {
$(window).on('externalContentReady', this.onExternalToolCompleted);
$(window).on('externalContentCancel', this.onExternalToolCompleted);
},
componentWillUnmount () {
$(window).off('externalContentReady', this.onExternalToolCompleted);
$(window).off('externalContentCancel', this.onExternalToolCompleted);
},
onExternalToolCompleted () {
this.props.onRequestClose();
},
getIframeSrc () {
if (this.props.isOpen && this.props.tool) {
return [
'/', this.props.contextType, 's/',
this.props.contextId,
'/external_tools/', this.props.tool.definition_id,
'?display=borderless&launch_type=',
this.props.launchType,
].join('');
}
},
getLaunchDimensions () {
const dimensions = {
'width': 700,
'height': 700,
};
if (
this.props.isOpen &&
this.props.tool &&
this.props.launchType &&
this.props.tool['placements'] &&
this.props.tool['placements'][this.props.launchType]) {
const placement = this.props.tool['placements'][this.props.launchType];
if (placement.launch_width) {
dimensions.width = placement.launch_width;
}
if (placement.launch_height) {
dimensions.height = placement.launch_height;
}
}
return dimensions;
},
getModalLaunchStyle (dimensions) {
return {
...dimensions,
border: 'none',
};
},
getModalBodyStyle (dimensions) {
return {
...dimensions,
padding: 0,
display: 'flex',
};
},
getModalStyle (dimensions) {
return {
width: dimensions.width,
};
},
render () {
const dimensions = this.getLaunchDimensions();
return (
<Modal className="ReactModal__Content--canvas"
overlayClassName="ReactModal__Overlay--canvas"
style={this.getModalStyle(dimensions)}
isOpen={this.props.isOpen}
onRequestClose={this.props.onRequestClose}
title={this.props.title}
>
<ModalContent style={this.getModalBodyStyle(dimensions)}>
<iframe
src={this.getIframeSrc()}
style={this.getModalLaunchStyle(dimensions)}
tabIndex={0}
></iframe>
</ModalContent>
</Modal>
);
}
});