const React = require('react');
import ShareContextConsumer from '../ShareContextConsumer'
import PublicLinkField from './Field'
import PublicLinkPermissions from './Permissions'
import PublicLinkSecureOptions from './SecureOptions'
const {ValidPassword} = require('pydio').requireLib('form')
const {RaisedButton, Checkbox, Divider} = require('material-ui')
import Card from '../main/Card'
let PublicLinkPanel = React.createClass({
propTypes: {
linkData:React.PropTypes.object,
pydio:React.PropTypes.instanceOf(Pydio),
shareModel: React.PropTypes.instanceOf(ReactModel.Share),
authorizations: React.PropTypes.object,
showMailer:React.PropTypes.func
},
disableSave: function(){
this.setState({disabled: true});
},
enableSave: function(){
this.setState({disabled:false});
},
componentDidMount: function(){
this.props.shareModel.observe('saving', this.disableSave);
this.props.shareModel.observe('saved', this.enableSave);
},
componendWillUnmount: function(){
this.props.shareModel.stopObserving('saving', this.disableSave);
this.props.shareModel.stopObserving('saved', this.enableSave);
},
toggleLink: function(){
const publicLinks = this.props.shareModel.getPublicLinks();
if(this.state.showTemporaryPassword){
this.setState({showTemporaryPassword: false, temporaryPassword: null});
}else if(!publicLinks.length && ReactModel.Share.getAuthorizations(this.props.pydio).password_mandatory){
this.setState({showTemporaryPassword: true, temporaryPassword: ''});
}else{
this.props.shareModel.togglePublicLink();
}
},
getInitialState: function(){
return {showTemporaryPassword: false, temporaryPassword: null, passValid: false, disabled: false};
},
updateTemporaryPassword: function(value, event){
if(value == undefined) value = event.currentTarget.getValue();
let passValid = this.refs.passField.isValid();
this.setState({temporaryPassword:value, passValid: passValid});
},
enableLinkWithPassword:function(){
this.props.shareModel.enablePublicLinkWithPassword(this.state.temporaryPassword);
this.setState({showTemporaryPassword:false, temporaryPassword:null});
},
render: function(){
let publicLinkPanes, publicLinkField;
if(this.props.linkData) {
publicLinkField = (