You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

upload.controller.js 2.4KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. angular.module('app')
  2. .controller('UploadController', ['$scope', '$state', '$mdDialog', 'EffectsBusiness', 'ImagesBusiness', 'luticateAuthCache', 'errorDialogMd',
  3. function($scope, $state, $mdDialog, EffectsBusiness, ImagesBusiness, luticateAuthCache, errorDialogMd) {
  4. $scope.image = null;
  5. var promiseImage = {
  6. id: "promiseImage",
  7. loaderGroups: ["imageView"]
  8. };
  9. $scope.input = angular.element(angular.element("#filePicker")[0]);
  10. $scope.input.on("change", function (e) {
  11. var reader = new FileReader();
  12. var f = e.target.files[0];
  13. reader.readAsBinaryString(f);
  14. reader.onload = (function(file) {
  15. return function(e) {
  16. $scope.$apply(function() {
  17. $scope.fileLoaded(e.target.result, file);
  18. });
  19. };
  20. })(f);
  21. });
  22. $scope.fileLoaded = function(content, file)
  23. {
  24. $scope.image = {
  25. content: content,
  26. name: file.name
  27. };
  28. };
  29. $scope.pickFile = function()
  30. {
  31. $scope.input.click();
  32. };
  33. $scope.applyEffect = function(effect, data)
  34. {
  35. EffectsBusiness.apply({
  36. effect: effect,
  37. image: $scope.image.content,
  38. data: data
  39. }, promiseImage).then(function(data)
  40. {
  41. $scope.image.content = data.image;
  42. }, errorDialogMd.errorDialog);
  43. };
  44. $scope.isUploadVisible = function () {
  45. return luticateAuthCache.getUser() != null;
  46. };
  47. $scope.canUpload = function () {
  48. return $scope.image != null;
  49. };
  50. $scope.upload = function()
  51. {
  52. ImagesBusiness.upload({
  53. image: $scope.image.content,
  54. name: $scope.image.name
  55. }, promiseImage).then(function(data)
  56. {
  57. $state.go("images");
  58. }, errorDialogMd.errorDialog);
  59. };
  60. $scope.test = function()
  61. {
  62. $scope.applyEffect("BlackAndWhite", null);
  63. };
  64. }]);