Browse Source

Implement max upload size. Fix progress indicator.

pull/96/head
Evan Theurer 11 years ago
parent
commit
72d3d3a641
  1. 22
      static/js/directives/buddypictureupload.js

22
static/js/directives/buddypictureupload.js

@ -25,23 +25,25 @@ define(['jquery', 'underscore', 'text!partials/buddypictureupload.html'], functi
var controller = ['$scope', 'safeApply', '$timeout', '$q', 'translation', function($scope, safeApply, $timeout, $q, translation) { var controller = ['$scope', 'safeApply', '$timeout', '$q', 'translation', function($scope, safeApply, $timeout, $q, translation) {
var previewWidth = 205;
var previewHeight = 205;
var maxUploadMb = 8;
$scope.showUploadPicture = false; $scope.showUploadPicture = false;
$scope.previewUpload = false; $scope.previewUpload = false;
$scope.imgData = null; $scope.imgData = null;
$scope.error = { $scope.error = {
read: "The file couldn't be read", read: "The file couldn't be read",
image: "The file is not an image.", image: "The file is not an image.",
size: "The file is too large. Max upload size is " + maxUploadMb + 'Mb',
current: null current: null
}; };
$scope.text = { $scope.text = {
initial: 'Please choose a picture to upload', initial: 'Please choose a picture to upload, max ' + maxUploadMb + 'Mb',
again: 'Upload a different picture' again: 'Upload a different picture'
}; };
$scope.upload = { $scope.upload = {
status: 0 status: 0
}; };
var previewWidth = 205;
var previewHeight = 205;
var completedUpload = function() { var completedUpload = function() {
$scope.upload.status = 99; $scope.upload.status = 99;
@ -77,10 +79,6 @@ define(['jquery', 'underscore', 'text!partials/buddypictureupload.html'], functi
return; return;
} }
console.log('file', file); console.log('file', file);
$scope.$apply(function(scope) {
$scope.upload.status = 5;
});
var progress = function(event) { var progress = function(event) {
console.log('file progress', event); console.log('file progress', event);
$scope.$apply(function(scope) { $scope.$apply(function(scope) {
@ -107,11 +105,21 @@ define(['jquery', 'underscore', 'text!partials/buddypictureupload.html'], functi
scope.error.current = scope.error.image; scope.error.current = scope.error.image;
}); });
} }
if (event.target.error.name == 'Size') {
$scope.$apply(function(scope) {
scope.error.current = scope.error.size;
});
}
}; };
if (!file.type.match(/image/)) { if (!file.type.match(/image/)) {
error({target: {error: {name: 'NotImage'}}}); error({target: {error: {name: 'NotImage'}}});
} else if (file.size > maxUploadMb * 1024 * 1024) {
error({target: {error: {name: 'Size'}}});
} else { } else {
$scope.$apply(function(scope) {
$scope.upload.status = 5;
});
var reader = new FileReader(); var reader = new FileReader();
reader.readAsDataURL(file); reader.readAsDataURL(file);

Loading…
Cancel
Save