Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Uploading individually files post #53

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .jshintrc
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"unused" : true,
"maxparams" : 10,
"maxdepth" : 5,
"maxstatements" : 25,
"maxstatements" : 27,
"maxcomplexity" : 10,

"asi" : true,
Expand Down
53 changes: 43 additions & 10 deletions components/ngDroplet.js
Original file line number Diff line number Diff line change
Expand Up @@ -581,20 +581,17 @@
}

};

/**
* @method uploadFiles
* @method helperUpload
* @param Individually {boolean}
* @param model {Object}
* @return {$q.promise}
*/
$scope.uploadFiles = function uploadFiles() {

// Reset...
$scope.isError = false;

$scope.helperUpload = function helperUpload(individually, model) {
var httpRequest = new $window.XMLHttpRequest(),
formData = new $window.FormData(),
queuedFiles = $scope.filterFiles($scope.FILE_TYPES.VALID),
fileProperty = $scope.options.useArray ? 'file[]' : 'file',
queuedFiles = $scope.filterFiles($scope.FILE_TYPES.VALID),
requestLength = $scope.getRequestLength(queuedFiles),
deferred = $q.defer();

Expand Down Expand Up @@ -640,15 +637,45 @@

// Iterate all of the valid files to append them to the previously created
// `formData` object.
$angular.forEach(queuedFiles, function forEach(model) {
if (individually) {
formData.append(fileProperty, model.file);
});
} else {
$angular.forEach(queuedFiles, function forEach(model) {
formData.append(fileProperty, model.file);
});
}

// Voila...
$scope.isUploading = true;
httpRequest.send(formData);
return deferred.promise;
};

/**
* @method uploadFilesIndividually
* @return {void}
*/
$scope.uploadFilesIndividually = function uploadFilesIndividually() {

// Reset...
$scope.isError = false;

var queuedFiles = $scope.filterFiles($scope.FILE_TYPES.VALID);

$angular.forEach(queuedFiles, function (model) {
$scope.helperUpload(true, model);
});
};

/**
* @method uploadFiles
* @return {void}
*/
$scope.uploadFiles = function uploadFiles() {

// Reset...
$scope.isError = false;
$scope.helperUpload(false);
};

/**
Expand Down Expand Up @@ -748,6 +775,12 @@
*/
uploadFiles: $scope.uploadFiles,

/**
* @method uploadFilesIndividually
* @return {void}
*/
uploadFilesIndividually: $scope.uploadFilesIndividually,

/**
* @property progress
* @type {Object}
Expand Down