Cosmetic refactoring
Этот коммит содержится в:
@@ -7,6 +7,13 @@ var ChannelStore = require('../stores/channel_store.jsx');
|
|||||||
var utils = require('../utils/utils.jsx');
|
var utils = require('../utils/utils.jsx');
|
||||||
|
|
||||||
module.exports = React.createClass({
|
module.exports = React.createClass({
|
||||||
|
displayName: 'FileUpload',
|
||||||
|
propTypes: {
|
||||||
|
onUploadError: React.PropTypes.func,
|
||||||
|
getFileCount: React.PropTypes.func,
|
||||||
|
onFileUpload: React.PropTypes.func,
|
||||||
|
onUploadStart: React.PropTypes.func
|
||||||
|
},
|
||||||
getInitialState: function() {
|
getInitialState: function() {
|
||||||
return {requests: {}};
|
return {requests: {}};
|
||||||
},
|
},
|
||||||
@@ -21,7 +28,7 @@ module.exports = React.createClass({
|
|||||||
// This looks redundant, but must be done this way due to
|
// This looks redundant, but must be done this way due to
|
||||||
// setState being an asynchronous call
|
// setState being an asynchronous call
|
||||||
var numFiles = 0;
|
var numFiles = 0;
|
||||||
for(var i = 0; i < files.length; i++) {
|
for (var i = 0; i < files.length; i++) {
|
||||||
if (files[i].size <= Constants.MAX_FILE_SIZE) {
|
if (files[i].size <= Constants.MAX_FILE_SIZE) {
|
||||||
numFiles++;
|
numFiles++;
|
||||||
}
|
}
|
||||||
@@ -51,11 +58,11 @@ module.exports = React.createClass({
|
|||||||
var request = client.uploadFile(formData,
|
var request = client.uploadFile(formData,
|
||||||
function(data) {
|
function(data) {
|
||||||
var parsedData = $.parseJSON(data);
|
var parsedData = $.parseJSON(data);
|
||||||
this.props.onFileUpload(parsedData['filenames'], parsedData['client_ids'], channelId);
|
this.props.onFileUpload(parsedData.filenames, parsedData.client_ids, channelId);
|
||||||
|
|
||||||
var requests = this.state.requests;
|
var requests = this.state.requests;
|
||||||
for (var i = 0; i < parsedData['client_ids'].length; i++) {
|
for (var i = 0; i < parsedData.client_ids.length; i++) {
|
||||||
delete requests[parsedData['client_ids'][i]];
|
delete requests[parsedData.client_ids[i]];
|
||||||
}
|
}
|
||||||
this.setState({requests: requests});
|
this.setState({requests: requests});
|
||||||
}.bind(this),
|
}.bind(this),
|
||||||
@@ -100,9 +107,9 @@ module.exports = React.createClass({
|
|||||||
if (items) {
|
if (items) {
|
||||||
for (var i = 0; i < items.length; i++) {
|
for (var i = 0; i < items.length; i++) {
|
||||||
if (items[i].type.indexOf('image') !== -1) {
|
if (items[i].type.indexOf('image') !== -1) {
|
||||||
var ext = items[i].type.split('/')[1].toLowerCase();
|
var testExt = items[i].type.split('/')[1].toLowerCase();
|
||||||
|
|
||||||
if (Constants.IMAGE_TYPES.indexOf(ext) < 0) {
|
if (Constants.IMAGE_TYPES.indexOf(testExt) < 0) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -110,7 +117,7 @@ module.exports = React.createClass({
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var numToUpload = Math.min(Constants.MAX_UPLOAD_FILES - self.props.getFileCount(channelId), numItems);
|
var numToUpload = Math.min(Constants.MAX_UPLOAD_FILES - self.props.getFileCount(ChannelStore.getCurrentId()), numItems);
|
||||||
|
|
||||||
if (numItems > numToUpload) {
|
if (numItems > numToUpload) {
|
||||||
self.props.onUploadError('Uploads limited to ' + Constants.MAX_UPLOAD_FILES + ' files maximum. Please use additional posts for more files.');
|
self.props.onUploadError('Uploads limited to ' + Constants.MAX_UPLOAD_FILES + ' files maximum. Please use additional posts for more files.');
|
||||||
@@ -155,11 +162,11 @@ module.exports = React.createClass({
|
|||||||
var request = client.uploadFile(formData,
|
var request = client.uploadFile(formData,
|
||||||
function(data) {
|
function(data) {
|
||||||
var parsedData = $.parseJSON(data);
|
var parsedData = $.parseJSON(data);
|
||||||
self.props.onFileUpload(parsedData['filenames'], parsedData['client_ids'], channelId);
|
self.props.onFileUpload(parsedData.filenames, parsedData.client_ids, channelId);
|
||||||
|
|
||||||
var requests = self.state.requests;
|
var requests = self.state.requests;
|
||||||
for (var i = 0; i < parsedData['client_ids'].length; i++) {
|
for (var i = 0; i < parsedData.client_ids.length; i++) {
|
||||||
delete requests[parsedData['client_ids'][i]];
|
delete requests[parsedData.client_ids[i]];
|
||||||
}
|
}
|
||||||
self.setState({requests: requests});
|
self.setState({requests: requests});
|
||||||
},
|
},
|
||||||
|
|||||||
Ссылка в новой задаче
Block a user