-
-
Save possamai/765c390b3e9155da286e to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
angular.module('App').directive('gallery',function(){ | |
return { | |
templateUrl:'/admin/angular/templates/gallery.html', | |
replace:true, | |
scope:{ | |
gallery:'=' | |
}, | |
controller:['$scope','$http',function(scope,http){ | |
scope.button = 'Selecione uma imagem'; | |
var xhr = new XMLHttpRequest(); | |
xhr.upload.addEventListener('progress',function(evt){ | |
scope.button = parseInt(evt.loaded/evt.total*100)+'%'; | |
if(!scope.$$phase) scope.$apply(); | |
}); | |
xhr.addEventListener('load',function(evt){ | |
console.log(evt); | |
scope.button = 'Selecione uma imagem'; | |
scope.gallery.push(JSON.parse(evt.target.responseText)); | |
if(!scope.$$phase) scope.$apply(); | |
}); | |
scope.send = function(file){ | |
var fd = new FormData(); | |
fd.append('data[file]',file); | |
fd.append('data[model]','Noticia'); | |
xhr.open('POST',base+'/administrar/gallery/receive'); | |
xhr.send(fd); | |
} | |
scope.remove = function(foto){ | |
http.post(base+'/administrar/gallery/delete',{id:foto.id}).success(function(evt){ | |
if(evt.status == 'ok'){ | |
scope.gallery = scope.gallery.filter(function(curr){ | |
return curr.id != foto.id ; | |
}); | |
} | |
}); | |
} | |
}] | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment