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