Skip to content

Commit

Permalink
melhorias nos escopos
Browse files Browse the repository at this point in the history
  • Loading branch information
washingtonsoares committed Jul 22, 2016
1 parent 09b965c commit 8a7eae4
Showing 1 changed file with 10 additions and 9 deletions.
19 changes: 10 additions & 9 deletions build/ng-s3upload.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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 {
Expand All @@ -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',
Expand All @@ -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]),
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit 8a7eae4

Please sign in to comment.