blob: 5363ad217f28bebecda0ff12ccfb2fe436ef6b4f (
plain)
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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
|
// Copyright (c) 2015 Mattermost, Inc. All Rights Reserved.
// See License.txt for license information.
import $ from 'jquery';
import ReactDOM from 'react-dom';
import {FormattedMessage} from 'react-intl';
import {Modal} from 'react-bootstrap';
import React from 'react';
export default class GetLinkModal extends React.Component {
constructor(props) {
super(props);
this.onHide = this.onHide.bind(this);
this.copyLink = this.copyLink.bind(this);
this.selectLinkOnClick = this.selectLinkOnClick.bind(this);
this.state = {
copiedLink: false
};
}
componntWillUnmount() {
$(this.refs.textarea).off('click');
}
onHide() {
this.setState({copiedLink: false});
this.props.onHide();
}
selectLinkOnClick() {
$(this.refs.textarea).on('click', function selectLinkOnClick() {
$(this).select();
this.setSelectionRange(0, this.value.length);
});
}
copyLink() {
var copyTextarea = $(ReactDOM.findDOMNode(this.refs.textarea));
copyTextarea.select();
try {
var successful = document.execCommand('copy');
if (successful) {
this.setState({copiedLink: true});
} else {
this.setState({copiedLink: false});
}
} catch (err) {
this.setState({copiedLink: false});
}
}
render() {
let helpText = null;
if (this.props.helpText) {
helpText = (
<p>
{this.props.helpText}
<br/>
<br/>
</p>
);
}
let copyLink = null;
if (document.queryCommandSupported('copy')) {
copyLink = (
<button
data-copy-btn='true'
type='button'
className='btn btn-primary pull-left'
onClick={this.copyLink}
>
<FormattedMessage
id='get_link.copy'
defaultMessage='Copy Link'
/>
</button>
);
}
const linkText = (
<textarea
className='form-control no-resize min-height'
ref='textarea'
value={this.props.link}
/>
);
var copyLinkConfirm = null;
if (this.state.copiedLink) {
copyLinkConfirm = (
<p className='alert alert-success alert--confirm'>
<i className='fa fa-check'/>
<FormattedMessage
id='get_link.clipboard'
defaultMessage=' Link copied to clipboard.'
/>
</p>
);
}
return (
<Modal
show={this.props.show}
onHide={this.onHide}
onEntered={this.selectLinkOnClick}
>
<Modal.Header closeButton={true}>
<h4 className='modal-title'>{this.props.title}</h4>
</Modal.Header>
<Modal.Body>
{helpText}
{linkText}
</Modal.Body>
<Modal.Footer>
<button
type='button'
className='btn btn-default'
onClick={this.onHide}
>
<FormattedMessage
id='get_link.close'
defaultMessage='Close'
/>
</button>
{copyLink}
{copyLinkConfirm}
</Modal.Footer>
</Modal>
);
}
}
GetLinkModal.propTypes = {
show: React.PropTypes.bool.isRequired,
onHide: React.PropTypes.func.isRequired,
title: React.PropTypes.string.isRequired,
helpText: React.PropTypes.string,
link: React.PropTypes.string.isRequired
};
GetLinkModal.defaultProps = {
helpText: null
};
|