Files
mattermost/webapp/components/get_link_modal.jsx
Asaad Mahmood f91b9d4a65 PLT-3418, PLT-2950, PLT-3375, PLT-3382, PLT-3446, PLT-3465: Multiple UI Improvements (#3449)
Improving help text margins

Updating changes for get link and create post files

Fixing icon for select team screen

Fixing styles for select team button

Adding improvements to posts UI

Adding improvement to post layout

Updating changes for post controls

Updating z-index for sidebar--right

Updating help text position

Fixing code for posts

Fixing css for post view

Pushing improvements for posts view

Updating changes for post view

Updating post layout

Fixing system time css

Updating header for system posts

Updating post css

Removing opacity and changing color for system messages

Simplifying root post and system post behaviour

Removing images from compact view

Updating help text for display

Updating embed preview text for advanced option

PLT-3490 - Fixing RHS issue on Edge
2016-07-05 15:46:36 -04:00

152 lines
4.1 KiB
JavaScript

// 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'></i>
<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
};