Browse Source

asset manager added config & logic to set max file(s) size; preventing the user from exceeding their limit.

pull/2227/head
trent 7 years ago
parent
commit
e156af5278
  1. 8
      src/asset_manager/config/config.js
  2. 8
      src/asset_manager/index.js
  3. 8
      src/asset_manager/view/FileUploader.js

8
src/asset_manager/config/config.js

@ -100,5 +100,11 @@ export default {
modalTitle: 'Select Image',
//Default placeholder for input
inputPlaceholder: 'http://path/to/the/image.jpg'
inputPlaceholder: 'http://path/to/the/image.jpg',
//Max file size which can be uploaded in KB, 0 is no limit and default
uploadMaxFileSize: 0,
//alert text when file size limit is reached
uploadMaxFileSizeAlertText: null
};

8
src/asset_manager/index.js

@ -347,6 +347,14 @@ export default () => {
*/
onDblClick(func) {
c.onDblClick = func;
},
/**
* Update config uploadMaxFileSize
* @param {int} maxKb
*/
setUploadMaxFileSize(maxKb) {
c.uploadMaxFileSize = maxKb;
}
};
};

8
src/asset_manager/view/FileUploader.js

@ -115,12 +115,20 @@ export default Backbone.View.extend(
body.append(param, params[param]);
}
var fileSize = 0;
if (this.multiUpload) {
for (let i = 0; i < files.length; i++) {
body.append(`${config.uploadName}[]`, files[i]);
fileSize += files[i].size;
}
} else if (files.length) {
body.append(config.uploadName, files[0]);
fileSize += files[0].size;
}
if (config.uploadMaxFileSize > 0 && config.uploadMaxFileSize <= fileSize / 1024) {
alert(config.uploadMaxFileSizeAlertText || 'The file(s) you have selected to add exceed your space limit');
return;
}
var target = this.target;

Loading…
Cancel
Save