|
201 | 201 | // The FileUploadController initializes the fileupload widget and
|
202 | 202 | // provides scope methods to control the File Upload functionality:
|
203 | 203 | .controller('FileUploadController', [
|
204 |
| - '$scope', '$element', '$attrs', '$window', 'fileUpload', |
205 |
| - function ($scope, $element, $attrs, $window, fileUpload) { |
| 204 | + '$scope', '$element', '$attrs', '$window', 'fileUpload','$q', |
| 205 | + function ($scope, $element, $attrs, $window, fileUpload, $q) { |
206 | 206 | var uploadMethods = {
|
207 | 207 | progress: function () {
|
208 | 208 | return $element.fileupload('progress');
|
|
264 | 264 | $scope.applyOnQueue = function (method) {
|
265 | 265 | var list = this.queue.slice(0),
|
266 | 266 | i,
|
267 |
| - file; |
| 267 | + file, |
| 268 | + promises = []; |
268 | 269 | for (i = 0; i < list.length; i += 1) {
|
269 | 270 | file = list[i];
|
270 | 271 | if (file[method]) {
|
271 |
| - file[method](); |
| 272 | + promises.push(file[method]()); |
272 | 273 | }
|
273 | 274 | }
|
| 275 | + return $q.all(promises); |
274 | 276 | };
|
275 | 277 | $scope.submit = function () {
|
276 |
| - this.applyOnQueue('$submit'); |
| 278 | + return this.applyOnQueue('$submit'); |
277 | 279 | };
|
278 | 280 | $scope.cancel = function () {
|
279 |
| - this.applyOnQueue('$cancel'); |
| 281 | + return this.applyOnQueue('$cancel'); |
280 | 282 | };
|
281 | 283 | // Add upload methods to the scope:
|
282 | 284 | angular.extend($scope, uploadMethods);
|
|
0 commit comments