summaryrefslogtreecommitdiffstats
path: root/webapp
diff options
context:
space:
mode:
Diffstat (limited to 'webapp')
-rw-r--r--webapp/action_creators/global_actions.jsx10
-rw-r--r--webapp/client/client.jsx8
-rw-r--r--webapp/components/get_public_link_modal.jsx80
-rw-r--r--webapp/components/needs_team.jsx2
-rw-r--r--webapp/components/view_image.jsx28
-rw-r--r--webapp/components/view_image_popover_bar.jsx4
-rw-r--r--webapp/stores/modal_store.jsx1
-rw-r--r--webapp/utils/async_client.jsx30
-rw-r--r--webapp/utils/constants.jsx1
9 files changed, 140 insertions, 24 deletions
diff --git a/webapp/action_creators/global_actions.jsx b/webapp/action_creators/global_actions.jsx
index ae7352e5d..78c56dd12 100644
--- a/webapp/action_creators/global_actions.jsx
+++ b/webapp/action_creators/global_actions.jsx
@@ -281,6 +281,16 @@ export function showGetPostLinkModal(post) {
});
}
+export function showGetPublicLinkModal(channelId, userId, filename) {
+ AppDispatcher.handleViewAction({
+ type: ActionTypes.TOGGLE_GET_PUBLIC_LINK_MODAL,
+ value: true,
+ channelId,
+ userId,
+ filename
+ });
+}
+
export function showGetTeamInviteLinkModal() {
AppDispatcher.handleViewAction({
type: Constants.ActionTypes.TOGGLE_GET_TEAM_INVITE_LINK_MODAL,
diff --git a/webapp/client/client.jsx b/webapp/client/client.jsx
index 73cc6120f..56eb4a137 100644
--- a/webapp/client/client.jsx
+++ b/webapp/client/client.jsx
@@ -1325,7 +1325,13 @@ export default class Client {
end(this.handleResponse.bind(this, 'getFileInfo', success, error));
}
- getPublicLink = (data, success, error) => {
+ getPublicLink = (channelId, userId, filename, success, error) => {
+ const data = {
+ channel_id: channelId,
+ user_id: userId,
+ filename
+ };
+
request.
post(`${this.getFilesRoute()}/get_public_link`).
set(this.defaultHeaders).
diff --git a/webapp/components/get_public_link_modal.jsx b/webapp/components/get_public_link_modal.jsx
new file mode 100644
index 000000000..7f83651cd
--- /dev/null
+++ b/webapp/components/get_public_link_modal.jsx
@@ -0,0 +1,80 @@
+// Copyright (c) 2015 Mattermost, Inc. All Rights Reserved.
+// See License.txt for license information.
+
+import React from 'react';
+
+import * as AsyncClient from 'utils/async_client.jsx';
+import Constants from 'utils/constants.jsx';
+import ModalStore from 'stores/modal_store.jsx';
+import PureRenderMixin from 'react-addons-pure-render-mixin';
+import * as Utils from 'utils/utils.jsx';
+
+import GetLinkModal from './get_link_modal.jsx';
+
+export default class GetPublicLinkModal extends React.Component {
+ constructor(props) {
+ super(props);
+
+ this.handlePublicLink = this.handlePublicLink.bind(this);
+ this.handleToggle = this.handleToggle.bind(this);
+ this.hide = this.hide.bind(this);
+
+ this.shouldComponentUpdate = PureRenderMixin.shouldComponentUpdate.bind(this);
+
+ this.state = {
+ show: false,
+ channelId: '',
+ userId: '',
+ filename: '',
+ link: ''
+ };
+ }
+
+ componentDidMount() {
+ ModalStore.addModalListener(Constants.ActionTypes.TOGGLE_GET_PUBLIC_LINK_MODAL, this.handleToggle);
+ }
+
+ componentDidUpdate(prevProps, prevState) {
+ if (this.state.show && !prevState.show) {
+ AsyncClient.getPublicLink(this.state.channelId, this.state.userId, this.state.filename, this.handlePublicLink);
+ }
+ }
+
+ componentWillUnmount() {
+ ModalStore.removeModalListener(Constants.ActionTypes.TOGGLE_GET_PUBLIC_LINK_MODAL, this.handleToggle);
+ }
+
+ handlePublicLink(link) {
+ this.setState({
+ link
+ });
+ }
+
+ handleToggle(value, args) {
+ this.setState({
+ show: value,
+ channelId: args.channelId,
+ userId: args.userId,
+ filename: args.filename,
+ link: ''
+ });
+ }
+
+ hide() {
+ this.setState({
+ show: false
+ });
+ }
+
+ render() {
+ return (
+ <GetLinkModal
+ show={this.state.show}
+ onHide={this.hide}
+ title={Utils.localizeMessage('get_public_link_modal.title', 'Copy Public Link')}
+ helpText={Utils.localizeMessage('get_public_link_modal.help', 'The link below allows anyone to see this file without being registered on this server.')}
+ link={this.state.link}
+ />
+ );
+ }
+}
diff --git a/webapp/components/needs_team.jsx b/webapp/components/needs_team.jsx
index 92c6fc0ce..c2f450f98 100644
--- a/webapp/components/needs_team.jsx
+++ b/webapp/components/needs_team.jsx
@@ -24,6 +24,7 @@ import Navbar from 'components/navbar.jsx';
// Modals
import GetPostLinkModal from 'components/get_post_link_modal.jsx';
+import GetPublicLinkModal from 'components/get_public_link_modal.jsx';
import GetTeamInviteLinkModal from 'components/get_team_invite_link_modal.jsx';
import EditPostModal from 'components/edit_post_modal.jsx';
import DeletePostModal from 'components/delete_post_modal.jsx';
@@ -125,6 +126,7 @@ export default class NeedsTeam extends React.Component {
{content}
<GetPostLinkModal/>
+ <GetPublicLinkModal/>
<GetTeamInviteLinkModal/>
<InviteMemberModal/>
<ImportThemeModal/>
diff --git a/webapp/components/view_image.jsx b/webapp/components/view_image.jsx
index bd4aeaa41..b88df19d4 100644
--- a/webapp/components/view_image.jsx
+++ b/webapp/components/view_image.jsx
@@ -3,7 +3,7 @@
import $ from 'jquery';
import * as AsyncClient from 'utils/async_client.jsx';
-import Client from 'utils/web_client.jsx';
+import * as GlobalActions from 'action_creators/global_actions.jsx';
import * as Utils from 'utils/utils.jsx';
import AudioVideoPreview from './audio_video_preview.jsx';
import Constants from 'utils/constants.jsx';
@@ -43,7 +43,7 @@ class ViewImageModal extends React.Component {
this.onFileStoreChange = this.onFileStoreChange.bind(this);
- this.getPublicLink = this.getPublicLink.bind(this);
+ this.handleGetPublicLink = this.handleGetPublicLink.bind(this);
this.onMouseEnterImage = this.onMouseEnterImage.bind(this);
this.onMouseLeaveImage = this.onMouseLeaveImage.bind(this);
@@ -194,24 +194,10 @@ class ViewImageModal extends React.Component {
}
}
- getPublicLink() {
- var data = {};
- data.channel_id = this.props.channelId;
- data.user_id = this.props.userId;
- data.filename = this.props.filenames[this.state.imgId];
- Client.getPublicLink(
- data,
- (serverData) => {
- if (Utils.isMobile()) {
- window.location.href = serverData.public_link;
- } else {
- window.open(serverData.public_link);
- }
- },
- () => {
- //Do Nothing on error
- }
- );
+ handleGetPublicLink() {
+ this.props.onModalDismissed();
+
+ GlobalActions.showGetPublicLinkModal(this.props.channelId, this.props.userId, this.props.filenames[this.state.imgId]);
}
onMouseEnterImage() {
@@ -349,7 +335,7 @@ class ViewImageModal extends React.Component {
totalFiles={this.props.filenames.length}
filename={name}
fileURL={fileUrl}
- getPublicLink={this.getPublicLink}
+ onGetPublicLink={this.handleGetPublicLink}
/>
</div>
</div>
diff --git a/webapp/components/view_image_popover_bar.jsx b/webapp/components/view_image_popover_bar.jsx
index 55299ef74..5b9b2362f 100644
--- a/webapp/components/view_image_popover_bar.jsx
+++ b/webapp/components/view_image_popover_bar.jsx
@@ -15,7 +15,7 @@ export default class ViewImagePopoverBar extends React.Component {
href='#'
className='public-link text'
data-title='Public Image'
- onClick={this.props.getPublicLink}
+ onClick={this.props.onGetPublicLink}
>
<FormattedMessage
id='view_image_popover.publicLink'
@@ -79,5 +79,5 @@ ViewImagePopoverBar.propTypes = {
totalFiles: React.PropTypes.number.isRequired,
filename: React.PropTypes.string.isRequired,
fileURL: React.PropTypes.string.isRequired,
- getPublicLink: React.PropTypes.func.isRequired
+ onGetPublicLink: React.PropTypes.func.isRequired
};
diff --git a/webapp/stores/modal_store.jsx b/webapp/stores/modal_store.jsx
index 2a7921c40..0595daaf9 100644
--- a/webapp/stores/modal_store.jsx
+++ b/webapp/stores/modal_store.jsx
@@ -37,6 +37,7 @@ class ModalStoreClass extends EventEmitter {
case ActionTypes.TOGGLE_GET_POST_LINK_MODAL:
case ActionTypes.TOGGLE_GET_TEAM_INVITE_LINK_MODAL:
case ActionTypes.TOGGLE_REGISTER_APP_MODAL:
+ case ActionTypes.TOGGLE_GET_PUBLIC_LINK_MODAL:
this.emit(type, value, args);
break;
}
diff --git a/webapp/utils/async_client.jsx b/webapp/utils/async_client.jsx
index 57888f722..ac651a7bb 100644
--- a/webapp/utils/async_client.jsx
+++ b/webapp/utils/async_client.jsx
@@ -1343,3 +1343,33 @@ export function regenCommandToken(id) {
}
);
}
+
+export function getPublicLink(channelId, userId, filename, success, error) {
+ const callName = 'getPublicLink' + channelId + userId + filename;
+
+ if (isCallInProgress(callName)) {
+ return;
+ }
+
+ callTracker[callName] = utils.getTimestamp();
+
+ Client.getPublicLink(
+ channelId,
+ userId,
+ filename,
+ (link) => {
+ callTracker[callName] = 0;
+
+ success(link);
+ },
+ (err) => {
+ callTracker[callName] = 0;
+
+ if (error) {
+ error(err);
+ } else {
+ dispatchError(err, 'getPublicLink');
+ }
+ }
+ );
+} \ No newline at end of file
diff --git a/webapp/utils/constants.jsx b/webapp/utils/constants.jsx
index 3ae99d7fa..fb4086c7a 100644
--- a/webapp/utils/constants.jsx
+++ b/webapp/utils/constants.jsx
@@ -110,6 +110,7 @@ export default {
TOGGLE_GET_POST_LINK_MODAL: null,
TOGGLE_GET_TEAM_INVITE_LINK_MODAL: null,
TOGGLE_REGISTER_APP_MODAL: null,
+ TOGGLE_GET_PUBLIC_LINK_MODAL: null,
SUGGESTION_PRETEXT_CHANGED: null,
SUGGESTION_RECEIVED_SUGGESTIONS: null,