Merge pull request #5 from rgarmsen2295/mm-316
MM-316 Allows users to drag and drop files from their computer to the center pane or RHS to upload them
Этот коммит содержится в:
@@ -21,7 +21,7 @@ module.exports = React.createClass({
|
||||
var element = $(this.refs.fileInput.getDOMNode());
|
||||
var files = element.prop('files');
|
||||
|
||||
var channelId = ChannelStore.getCurrentId();
|
||||
var channelId = this.props.channelId || ChannelStore.getCurrentId();
|
||||
|
||||
this.props.onUploadError(null);
|
||||
|
||||
@@ -87,10 +87,101 @@ module.exports = React.createClass({
|
||||
}
|
||||
} catch(e) {}
|
||||
},
|
||||
handleDrop: function(e) {
|
||||
this.props.onUploadError(null);
|
||||
|
||||
var files = e.originalEvent.dataTransfer.files;
|
||||
if (!files.length) {
|
||||
files = e.originalEvent.dataTransfer.getData('URL');
|
||||
}
|
||||
var channelId = this.props.channelId || ChannelStore.getCurrentId();
|
||||
|
||||
if (typeof files !== 'string' && files.length) {
|
||||
var numFiles = files.length;
|
||||
|
||||
var numToUpload = Math.min(Constants.MAX_UPLOAD_FILES - this.props.getFileCount(channelId), numFiles);
|
||||
|
||||
if (numFiles > numToUpload) {
|
||||
this.props.onUploadError('Uploads limited to ' + Constants.MAX_UPLOAD_FILES + ' files maximum. Please use additional posts for more files.');
|
||||
}
|
||||
|
||||
for (var i = 0; i < files.length && i < numToUpload; i++) {
|
||||
if (files[i].size > Constants.MAX_FILE_SIZE) {
|
||||
this.props.onUploadError('Files must be no more than ' + Constants.MAX_FILE_SIZE / 1000000 + ' MB');
|
||||
continue;
|
||||
}
|
||||
|
||||
// generate a unique id that can be used by other components to refer back to this file upload
|
||||
var clientId = utils.generateId();
|
||||
|
||||
// Prepare data to be uploaded.
|
||||
var formData = new FormData();
|
||||
formData.append('channel_id', channelId);
|
||||
formData.append('files', files[i], files[i].name);
|
||||
formData.append('client_ids', clientId);
|
||||
|
||||
var request = client.uploadFile(formData,
|
||||
function(data) {
|
||||
var parsedData = $.parseJSON(data);
|
||||
this.props.onFileUpload(parsedData['filenames'], parsedData['client_ids'], channelId);
|
||||
|
||||
var requests = this.state.requests;
|
||||
for (var i = 0; i < parsedData['client_ids'].length; i++) {
|
||||
delete requests[parsedData['client_ids'][i]];
|
||||
}
|
||||
this.setState({requests: requests});
|
||||
}.bind(this),
|
||||
function(err) {
|
||||
this.props.onUploadError(err, clientId);
|
||||
}.bind(this)
|
||||
);
|
||||
|
||||
var requests = this.state.requests;
|
||||
requests[clientId] = request;
|
||||
this.setState({requests: requests});
|
||||
|
||||
this.props.onUploadStart([clientId], channelId);
|
||||
}
|
||||
}
|
||||
},
|
||||
componentDidMount: function() {
|
||||
var inputDiv = this.refs.input.getDOMNode();
|
||||
var self = this;
|
||||
|
||||
if (this.props.postType === 'post') {
|
||||
$('.app__content').dragster({
|
||||
enter: function(dragsterEvent, e) {
|
||||
$('.center-file-overlay').removeClass('invisible');
|
||||
$('.center-file-overlay').addClass('visible');
|
||||
},
|
||||
leave: function(dragsterEvent, e) {
|
||||
$('.center-file-overlay').removeClass('visible');
|
||||
$('.center-file-overlay').addClass('invisible');
|
||||
},
|
||||
drop: function(dragsterEvent, e) {
|
||||
$('.center-file-overlay').removeClass('visible');
|
||||
$('.center-file-overlay').addClass('invisible');
|
||||
self.handleDrop(e);
|
||||
}
|
||||
});
|
||||
} else if (this.props.postType === 'comment') {
|
||||
$('.post-right__container').dragster({
|
||||
enter: function(dragsterEvent, e) {
|
||||
$('.right-file-overlay').removeClass('invisible');
|
||||
$('.right-file-overlay').addClass('visible');
|
||||
},
|
||||
leave: function(dragsterEvent, e) {
|
||||
$('.right-file-overlay').removeClass('visible');
|
||||
$('.right-file-overlay').addClass('invisible');
|
||||
},
|
||||
drop: function(dragsterEvent, e) {
|
||||
$('.right-file-overlay').removeClass('visible');
|
||||
$('.right-file-overlay').addClass('invisible');
|
||||
self.handleDrop(e);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
document.addEventListener('paste', function(e) {
|
||||
var textarea = $(inputDiv.parentNode.parentNode).find('.custom-textarea')[0];
|
||||
|
||||
@@ -133,14 +224,13 @@ module.exports = React.createClass({
|
||||
continue;
|
||||
}
|
||||
|
||||
var channelId = ChannelStore.getCurrentId();
|
||||
var channelId = this.props.channelId || ChannelStore.getCurrentId();
|
||||
|
||||
// generate a unique id that can be used by other components to refer back to this file upload
|
||||
var clientId = utils.generateId();
|
||||
|
||||
var formData = new FormData();
|
||||
formData.append('channel_id', channelId);
|
||||
|
||||
var d = new Date();
|
||||
var hour;
|
||||
if (d.getHours() < 10) {
|
||||
|
||||
Ссылка в новой задаче
Block a user