Commit c0576cccfa2fd8c46f1c0cad3548a9dcb77ac24f
1 parent
d5dac011fe
Exists in
master
code review
Showing
1 changed file
with
1 additions
and
3 deletions
Show diff stats
src/js/controller.js
1 | angular.module('focaModalDetalles') | 1 | angular.module('focaModalDetalles') |
2 | .controller('focaModalDetallesController', | 2 | .controller('focaModalDetallesController', |
3 | [ | 3 | [ |
4 | '$scope', | 4 | '$scope', |
5 | '$uibModalInstance', | 5 | '$uibModalInstance', |
6 | 'focaModalService', | 6 | 'focaModalService', |
7 | 'APP', | 7 | 'APP', |
8 | '$timeout', | 8 | '$timeout', |
9 | 'sugerido', | 9 | 'sugerido', |
10 | function($scope, $uibModalInstance, focaModalService, APP, $timeout, sugerido) { | 10 | function($scope, $uibModalInstance, focaModalService, APP, $timeout, sugerido) { |
11 | $scope.mobile = APP === 'cobranza'; | 11 | $scope.mobile = APP === 'cobranza'; |
12 | $scope.files = []; | 12 | $scope.files = []; |
13 | $scope.importe = Math.abs(sugerido); | 13 | $scope.importe = Math.abs(sugerido); |
14 | 14 | ||
15 | $scope.$watch('files', function() { | 15 | $scope.$watch('files', function() { |
16 | validarExtSize(); | 16 | validarExtSize(); |
17 | }); | 17 | }); |
18 | 18 | ||
19 | $scope.eliminarImg = function(key) { | 19 | $scope.eliminarImg = function(key) { |
20 | $scope.files.splice(key, 1); | 20 | $scope.files.splice(key, 1); |
21 | }; | 21 | }; |
22 | 22 | ||
23 | $scope.cancel = function() { | 23 | $scope.cancel = function() { |
24 | $uibModalInstance.dismiss('cancel'); | 24 | $uibModalInstance.dismiss('cancel'); |
25 | }; | 25 | }; |
26 | 26 | ||
27 | $scope.aceptar = function() { | 27 | $scope.aceptar = function() { |
28 | console.log($scope.files); | ||
29 | $uibModalInstance.close({ | 28 | $uibModalInstance.close({ |
30 | observacion: $scope.observaciones, | 29 | observacion: $scope.observaciones, |
31 | monto: $scope.importe, | 30 | monto: $scope.importe, |
32 | imgs: $scope.files | 31 | imgs: $scope.files |
33 | }); | 32 | }); |
34 | }; | 33 | }; |
35 | 34 | ||
36 | $scope.seleccionarFoto = function() { | 35 | $scope.seleccionarFoto = function() { |
37 | var srcType = Camera.PictureSourceType.SAVEDPHOTOALBUM; | 36 | var srcType = Camera.PictureSourceType.SAVEDPHOTOALBUM; |
38 | var options = setOptions(srcType); | 37 | var options = setOptions(srcType); |
39 | navigator.camera.getPicture(cameraSuccess, cameraError, options); | 38 | navigator.camera.getPicture(cameraSuccess, cameraError, options); |
40 | }; | 39 | }; |
41 | 40 | ||
42 | $scope.tomarFoto = function() { | 41 | $scope.tomarFoto = function() { |
43 | navigator.camera.getPicture(cameraSuccess, cameraError, | 42 | navigator.camera.getPicture(cameraSuccess, cameraError, |
44 | { | 43 | { |
45 | destinationType: Camera.DestinationType.DATA_URL, | 44 | destinationType: Camera.DestinationType.DATA_URL, |
46 | quality: 100 | 45 | quality: 100 |
47 | }); | 46 | }); |
48 | }; | 47 | }; |
49 | 48 | ||
50 | function cameraSuccess(imageBase64) { | 49 | function cameraSuccess(imageBase64) { |
51 | 50 | ||
52 | var fecha = new Date(); | 51 | var fecha = new Date(); |
53 | var size = (imageBase64.length * (3/4)); | 52 | var size = (imageBase64.length * (3/4)); |
54 | 53 | ||
55 | var imagen = { | 54 | var imagen = { |
56 | name: 'imagen_' + fecha.getTime() + '.jpg', | 55 | name: 'imagen_' + fecha.getTime() + '.jpg', |
57 | size: size, | 56 | size: size, |
58 | base64: imageBase64, | 57 | base64: imageBase64, |
59 | }; | 58 | }; |
60 | $timeout(function() { | 59 | $timeout(function() { |
61 | $scope.files.push(imagen); | 60 | $scope.files.push(imagen); |
62 | }); | 61 | }); |
63 | } | 62 | } |
64 | function cameraError(err) { | 63 | function cameraError(err) { |
65 | console.log(err); | 64 | console.log(err); |
66 | } | 65 | } |
67 | function setOptions(srcType) { | 66 | function setOptions(srcType) { |
68 | var options = { | 67 | var options = { |
69 | // Some common settings are 20, 50, and 100 | 68 | // Some common settings are 20, 50, and 100 |
70 | quality: 100, | 69 | quality: 100, |
71 | destinationType: Camera.DestinationType.DATA_URL, | 70 | destinationType: Camera.DestinationType.DATA_URL, |
72 | sourceType: srcType, | 71 | sourceType: srcType, |
73 | |||
74 | encodingType: Camera.EncodingType.JPEG, | 72 | encodingType: Camera.EncodingType.JPEG, |
75 | mediaType: Camera.MediaType.PICTURE, | 73 | mediaType: Camera.MediaType.PICTURE, |
76 | allowEdit: true, | 74 | allowEdit: true, |
77 | correctOrientation: true | 75 | correctOrientation: true |
78 | } | 76 | }; |
79 | return options; | 77 | return options; |
80 | } | 78 | } |
81 | 79 | ||
82 | function validarExtSize() { | 80 | function validarExtSize() { |
83 | var totalSize = 0; | 81 | var totalSize = 0; |
84 | var invalidExt = false; | 82 | var invalidExt = false; |
85 | $scope.files.forEach(function(file) { | 83 | $scope.files.forEach(function(file) { |
86 | //CONVIERTO BYTES A MB | 84 | //CONVIERTO BYTES A MB |
87 | totalSize += file.size / 1000000; | 85 | totalSize += file.size / 1000000; |
88 | var fileExt = file.name.split('.').pop(); | 86 | var fileExt = file.name.split('.').pop(); |
89 | 87 | ||
90 | if(fileExt != 'jpg' && fileExt != 'png') { | 88 | if(fileExt != 'jpg' && fileExt != 'png') { |
91 | invalidExt = true; | 89 | invalidExt = true; |
92 | } | 90 | } |
93 | }); | 91 | }); |
94 | 92 | ||
95 | if (totalSize > 150) { | 93 | if (totalSize > 150) { |
96 | focaModalService.alert('El/los archivo/s exceden la capacidad máxima'); | 94 | focaModalService.alert('El/los archivo/s exceden la capacidad máxima'); |
97 | $scope.files = []; | 95 | $scope.files = []; |
98 | } else if (invalidExt) { | 96 | } else if (invalidExt) { |
99 | focaModalService.alert('Ha ingresado un archivo con extensión inválida'); | 97 | focaModalService.alert('Ha ingresado un archivo con extensión inválida'); |
100 | $scope.files = []; | 98 | $scope.files = []; |
101 | } | 99 | } |
102 | } | 100 | } |
103 | } | 101 | } |
104 | ] | 102 | ] |
105 | ); | 103 | ); |
106 | 104 |