const React = require('react'); import ShareContextConsumer from '../ShareContextConsumer' const {FlatButton, TextField, DatePicker} = require('material-ui') const {ValidPassword} = require('pydio').requireLib('form') const ShareModel = require('pydio').requireLib('ReactModelShare'); import Card from '../main/Card' let PublicLinkSecureOptions = React.createClass({ propTypes: { linkData: React.PropTypes.object.isRequired, shareModel: React.PropTypes.instanceOf(ShareModel), style: React.PropTypes.object }, updateDLExpirationField: function(event){ var newValue = event.currentTarget.value; if(parseInt(newValue) < 0) newValue = - parseInt(newValue); this.props.shareModel.setExpirationFor(this.props.linkData.hash, "downloads", newValue); }, updateDaysExpirationField: function(event, newValue){ if(!newValue){ newValue = event.currentTarget.getValue(); } this.props.shareModel.setExpirationFor(this.props.linkData.hash, "days", newValue); }, onDateChange: function(event, value){ var today = new Date(); var date1 = Date.UTC(today.getFullYear(), today.getMonth(), today.getDate()); var date2 = Date.UTC(value.getFullYear(), value.getMonth(), value.getDate()); var ms = Math.abs(date1-date2); var integerVal = Math.floor(ms/1000/60/60/24); //floor should be unnecessary, but just in case this.updateDaysExpirationField(event, integerVal); }, resetPassword: function(){ this.props.shareModel.resetPassword(this.props.linkData.hash); }, updatePassword: function(newValue, oldValue){ if(newValue && !this.refs.passField.isValid()){ this.props.shareModel.setValidStatus(false); } else{ this.props.shareModel.setValidStatus(true); } this.props.shareModel.updatePassword(this.props.linkData.hash, newValue); }, renderPasswordContainer: function(){ var linkId = this.props.linkData.hash; var passwordField; if(this.props.shareModel.hasHiddenPassword(linkId)){ var resetPassword = ( ); passwordField = ( ); }else if(!this.props.isReadonly()){ passwordField = ( ); } if(passwordField){ return (
{passwordField}
{resetPassword &&
{resetPassword}
}
); }else{ return null; } }, formatDate : function(dateObject){ var dateFormatDay = this.props.getMessage('date_format', '').split(' ').shift(); return dateFormatDay .replace('Y', dateObject.getFullYear()) .replace('m', dateObject.getMonth() + 1) .replace('d', dateObject.getDate()); }, render: function(){ const linkId = this.props.linkData.hash; const passContainer = this.renderPasswordContainer(); const crtLinkDLAllowed = this.props.shareModel.getPublicLinkPermission(linkId, 'download'); let dlLimitValue = this.props.shareModel.getExpirationFor(linkId, 'downloads') === 0 ? "" : this.props.shareModel.getExpirationFor(linkId, 'downloads'); const expirationDateValue = this.props.shareModel.getExpirationFor(linkId, 'days') === 0 ? "" : this.props.shareModel.getExpirationFor(linkId, 'days'); const auth = ShareModel.getAuthorizations(this.props.pydio); const today = new Date(); let calIcon = ; let expDate, maxDate, maxDownloads = null, dateExpired = false, dlExpired = false; if(parseInt(auth.max_expiration) > 0){ maxDate = new Date(); maxDate.setDate(today.getDate() + parseInt(auth.max_expiration)); } if(parseInt(auth.max_downloads) > 0){ maxDownloads = parseInt(auth.max_downloads); dlLimitValue = Math.min(dlLimitValue, maxDownloads); } if(expirationDateValue){ if(expirationDateValue < 0){ dateExpired = true; } expDate = new Date(); expDate.setDate(today.getDate() + parseInt(expirationDateValue)); var clearValue = function(){ this.props.shareModel.setExpirationFor(linkId, "days", ""); }.bind(this); calIcon = ; var calLabel = {this.props.getMessage(dateExpired?'21b':'21')} } if(dlLimitValue){ var dlCounter = this.props.shareModel.getDownloadCounter(linkId); var resetDl = function(){ if(window.confirm(this.props.getMessage('106'))){ this.props.shareModel.resetDownloadCounter(linkId, function(){}); } }.bind(this); if(dlCounter) { var resetLink = ({this.props.getMessage('16')}); if(dlCounter >= dlLimitValue){ dlExpired = true; } } var dlCounterString = {dlCounter+ '/'+ dlLimitValue} {resetLink}; } return (
{this.props.getMessage('24')}
{passContainer}
{calIcon}
0 ? dlLimitValue : ''} onChange={this.updateDLExpirationField} fullWidth={true} style={{flex: 1}} /> {dlCounterString}
); } }); PublicLinkSecureOptions = ShareContextConsumer(PublicLinkSecureOptions) export {PublicLinkSecureOptions as default}