const React = require('react'); import ShareContextConsumer from '../ShareContextConsumer' import TargetedUsers from './TargetedUsers' const {RaisedButton, FloatingActionButton, TextField, Paper} = require('material-ui') const ShareModel = require('pydio').requireLib('ReactModelShare') const QRCode = require('qrcode.react'); const Clipboard = require('clipboard'); import ActionButton from '../main/ActionButton' const PathUtils = require('pydio/util/path') const LangUtils = require('pydio/util/lang') let PublicLinkField = React.createClass({ propTypes: { linkData:React.PropTypes.object.isRequired, shareModel: React.PropTypes.instanceOf(ShareModel), editAllowed: React.PropTypes.bool, onChange: React.PropTypes.func, showMailer:React.PropTypes.func }, getInitialState: function(){ return {editLink: false, copyMessage:'', showQRCode: false}; }, toggleEditMode: function(){ if(this.state.editLink && this.state.customLink){ this.props.shareModel.updateCustomLink(this.props.linkData.hash, this.state.customLink); } this.setState({editLink: !this.state.editLink}); }, changeLink:function(event){ let value = event.target.value; value = LangUtils.computeStringSlug(value); this.setState({customLink: value}); }, clearCopyMessage:function(){ global.setTimeout(function(){ this.setState({copyMessage:''}); }.bind(this), 5000); }, attachClipboard: function(){ this.detachClipboard(); if(this.refs['copy-button']){ this._clip = new Clipboard(this.refs['copy-button'], { text: function(trigger) { return this.props.linkData['public_link']; }.bind(this) }); this._clip.on('success', function(){ this.setState({copyMessage:this.props.getMessage('192')}, this.clearCopyMessage); }.bind(this)); this._clip.on('error', function(){ let copyMessage; if( global.navigator.platform.indexOf("Mac") === 0 ){ copyMessage = this.props.getMessage('144'); }else{ copyMessage = this.props.getMessage('143'); } this.refs['public-link-field'].focus(); this.setState({copyMessage:copyMessage}, this.clearCopyMessage); }.bind(this)); } }, detachClipboard: function(){ if(this._clip){ this._clip.destroy(); } }, componentDidUpdate: function(prevProps, prevState){ this.attachClipboard(); }, componentDidMount: function(){ this.attachClipboard(); }, componentWillUnmount: function(){ this.detachClipboard(); }, openMailer: function(){ const mailData = this.props.shareModel.prepareEmail("link", this.props.linkData.hash); this.props.showMailer(mailData.subject, mailData.message, [], this.props.linkData.hash); }, toggleQRCode: function(){ this.setState({showQRCode:!this.state.showQRCode}); }, render: function(){ const publicLink = this.props.linkData['public_link']; const editAllowed = this.props.editAllowed && !this.props.linkData['hash_is_shorten'] && !this.props.isReadonly() && this.props.shareModel.currentIsOwner(); if(this.state.editLink && editAllowed){ return (
{PathUtils.getDirname(publicLink) + '/ '}
{this.props.getMessage('194')}
); }else{ const copyButton = ; const setHtml = function(){ return {__html:this.state.copyMessage}; }.bind(this); const focus = function(e){ e.target.select(); }; let actionLinks = [], qrCode; if(this.props.showMailer){ actionLinks.push(); } if(editAllowed){ actionLinks.push(); } if(ShareModel.qrcodeEnabled()){ actionLinks.push(); } if(actionLinks.length){ actionLinks = (
{actionLinks}
) ; }else{ actionLinks = null; } if(this.state.showQRCode){ qrCode =
; } return (
{copyButton}
{this.props.linkData.target_users && } {actionLinks} {qrCode} ); } } }); PublicLinkField = ShareContextConsumer(PublicLinkField) export {PublicLinkField as default};