From 8a7eae4c9b349fb3d562721fc5696cadcae28535 Mon Sep 17 00:00:00 2001 From: Washington Soares Date: Fri, 22 Jul 2016 18:16:13 -0300 Subject: [PATCH] melhorias nos escopos --- build/ng-s3upload.js | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/build/ng-s3upload.js b/build/ng-s3upload.js index eb364df..449b981 100644 --- a/build/ng-s3upload.js +++ b/build/ng-s3upload.js @@ -57,8 +57,6 @@ angular.module('ngS3upload.config', []). this.upload = function (scope, uri, key, acl, type, accessKey, policy, signature, file) { var deferred = $q.defer(); - scope.attempt = true; - var fd = new FormData(); fd.append('key', key); fd.append('acl', acl); @@ -142,18 +140,20 @@ angular.module('ngS3upload.config', []). }; }]); angular.module('ngS3upload.directives', []). - directive('s3Upload', ['$parse', 'S3Uploader', 'ngS3Config', function ($parse, S3Uploader, ngS3Config) { + directive('s3Upload', ['$parse', 'S3Uploader', 'ngS3Config','$timeout', function ($parse, S3Uploader, ngS3Config, $timeout) { return { restrict: 'AC', require: '?ngModel', replace: true, transclude: false, - scope: true, + scope: { + s3UploadOptions: '=' + }, controller: ['$scope', '$element', '$attrs', '$transclude', function ($scope, $element, $attrs, $transclude) { $scope.attempt = false; $scope.success = false; $scope.uploading = false; - var opts = angular.extend({}, $scope.$eval($attrs.s3UploadOptions || $attrs.options)); + var opts = $scope.s3UploadOptions; $scope.accept = opts.accept || ""; $scope.barClass = function () { return { @@ -164,13 +164,12 @@ angular.module('ngS3upload.directives', []). compile: function (element, attr, linker) { return { pre: function ($scope, $element, $attr) { - if (angular.isUndefined($attr.bucket)) { + if (angular.isUndefined($scope.s3UploadOptions.bucket)) { throw Error('bucket is a mandatory attribute'); } }, post: function (scope, element, attrs, ngModel) { - // Build the opts array - var opts = angular.extend({}, scope.$eval(attrs.s3UploadOptions || attrs.options)); + var opts = scope.s3UploadOptions; opts = angular.extend({ submitOnChange: true, getOptionsUri: '/getS3Options', @@ -181,7 +180,7 @@ angular.module('ngS3upload.directives', []). targetFilename: null, accept: '' }, opts); - var bucket = scope.$eval(attrs.bucket); + var bucket = scope.s3UploadOptions.bucket; // Bind the button click event var button = angular.element(element.children()[0]), @@ -213,6 +212,8 @@ angular.module('ngS3upload.directives', []). var s3Uri = 'https://' + bucket + '.s3.amazonaws.com/'; var key = opts.targetFilename ? scope.$eval(opts.targetFilename) : opts.folder + (new Date()).getTime() + '-' + S3Uploader.randomString(16) + "." + ext; + scope.attempt = true; + scope.s3UploadOptions.showProgressBar = true; S3Uploader.upload(scope, s3Uri, key,