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