Files
citas-getter/controllers_full.js

927 lines
36 KiB
JavaScript
Raw Permalink Normal View History

angular.module('CitaPreviaAlicante.controllers',[]).
controller('iniCitaController', function ($rootScope, $scope, $translate, $filter) {
$scope.changeLanguage = function (key) {
$translate.use(key);
if (key == 'es'){
$rootScope.localizador = 'es';
}else{
$rootScope.localizador = 'ca';
}
};
}).
controller('consultarCitaController', function($rootScope, $scope, $window, citaPreviaServices, $translate, $filter){
$scope.changeLanguage = function (key) {
$translate.use(key);
};
$scope.tipos_doc = [];
$scope.consulta={
tipoDocumento:"",
nif:"",
codigoCita:""
};
$scope.consultar=function(){
if ($scope.formulario.$valid){
//alert("Consultando los datos de la cita: " + $scope.consulta.nif);
//$window.location.href = './#/verCita/'+$scope.consulta.nif+'/'+$scope.consulta.codigoCita;
$window.location.href = './#/verCita/'+$scope.consulta.nif+'/'+$scope.consulta.codigoCita+'/NEW';
}else {
alert($filter('translate')('CONSULTAR_ERROR_CAMPOS'));
//alert("Debe rellenar los campos obligatorios.");
}
}
var onFetchCompletedTiposDocumento = function (data){
$scope.tipos_doc = data.data.items;
}
var onFetchError = function(message){
alert("Error: "+message);
};
var getTiposDocumentoController = function (){
citaPreviaServices.obtenerTipoDocumento().then(onFetchCompletedTiposDocumento, onFetchError);
}
getTiposDocumentoController();
}).
controller('anularCitaController', function($scope, $window, citaPreviaServices, $translate, $filter){
$scope.changeLanguage = function (key) {
$translate.use(key);
};
$scope.tipos_doc = [];
$scope.consulta={
tipoDocumento:"",
nif:"",
codigoCita:""
};
$scope.consultar=function(){
if ($scope.formulario.$valid){
//alert("Consultando los datos de la cita: " + $scope.consulta.nif);
$window.location.href = './#/verAnularCita/'+$scope.consulta.nif+'/'+$scope.consulta.codigoCita;
}else {
alert($filter('translate')('CONSULTAR_ERROR_CAMPOS'));
//alert("Debe rellenar los campos obligatorios.");
}
}
var onFetchCompletedTiposDocumento = function (data){
$scope.tipos_doc = data.data.items;
}
var onFetchError = function(message){
alert("Error: "+message);
};
var getTiposDocumentoController = function (){
citaPreviaServices.obtenerTipoDocumento().then(onFetchCompletedTiposDocumento, onFetchError);
}
getTiposDocumentoController();
}).
controller('pedirCitaController', function($rootScope, $scope, $routeParams, $window, citaPreviaServices, $translate, $filter){
$scope.changeLanguage = function (key) {
$translate.use(key);
};
/*Variables globales de pantalla*/
$scope.servicios = [];
$scope.gestiones = [];
$scope.horascitas = [];
$scope.tipos_doc = [];
$scope.max_dias_citas = 0;
$scope.colaMotivoValor = 'N';
$scope.resumen = {
id_servicio:"",
servicio:"",
id_gestion:"",
gestion:"",
oficina:"",
fecha:"",
hora:"",
nombre:"",
primer_apellido:"",
segundo_apellido:"",
num_documento:"",
telefono:"",
email:"",
ip:"",
tipo_documento:"",
impuestos:"",
comentario: ""
};
$scope.ip = "0.0.0.0";
$scope.resumen.ip = "0.0.0.0";
$scope.descOficina = "";
$scope.urlColaDesc = "";
/*Variables y funciones del componente calendario*/
$scope.hoy = _removeTime(moment(new Date));
$scope.day = moment(new Date());
$scope.hora;
$scope.isWeekend = function (day){
return day.isSaturday || day.isSunday;
};
$scope.disableWeekend = function (day){
//return day.isSaturday || day.isSunday;
return false;
};
$scope.buscando_citas = function (day){
var servicio = $scope.idServicio || '';
var cola = $scope.idGestion || '';
var fecha = day.date.format("DD-MM-YYYY");
if (day.date.isSame($scope.selected)){
//day.hayCitas = true;
}else{
day.hayCitas = false;
var manyana = $scope.hoy.clone().add(1, 'd');
var ultimoDia = $scope.hoy.clone().add($scope.max_dias_citas, 'd');
if (!$scope.disableWeekend(day)) {
if (day.date.isSameOrAfter(manyana)) {
if (day.date.isSameOrBefore(ultimoDia)) {
citaPreviaServices.obtenerCitasDisponible(servicio, cola, fecha).success(
function (response){
var horasCitasTodo = JSON.parse(response.result);
if (horasCitasTodo.length > 0){
day.hayCitas = true;
}else{
day.hayCitas = false;
}
}
)
}
}
}
}
};
function _removeTime (date) {
return date.hour(0).minute(0).second(0).millisecond(0);
};
function _buildMonth(start, month) {
$scope.weeks = [];
var done = false, date = start.clone(), monthIndex = date.month(), count = 0;
while (!done) {
$scope.weeks.push({ days: _buildWeek(date.clone(), month) });
date.add(1, "w");
done = count++ > 2 && monthIndex !== date.month();
monthIndex = date.month();
}
}
function _buildWeek(date, month) {
var days = [];
for (var i = 0; i < 7; i++) {
days.push({
name: date.format("dd").substring(0, 1),
number: date.date(),
isCurrentMonth: date.month() === month.month(),
isToday: date.isSame(new Date(), "day"),
date: date,
isSaturday: date.weekday() === 6,
isSunday: date.weekday() === 0,
hayCitas: false
});
$scope.buscando_citas (days[i]);
date = date.clone();
date.add(1, "d");
}
return days;
}
$scope.selected = _removeTime($scope.selected || moment());
$scope.month = $scope.selected.clone();
$scope.monthVisual = $scope.selected.clone();
$scope.firstDay = $scope.selected.clone().startOf("month");
$scope.unaFecha = $scope.selected.clone();
_buildMonth($scope.firstDay.startOf("isoWeek"), $scope.month);
$scope.pintar = function (day){
if (day.date.isSame($scope.selected)){
return false;
}else{
return day.hayCitas;
}
/*var esHabil = false;
var manyana = $scope.hoy.clone().add(1, 'd');
var ultimoDia = $scope.hoy.clone().add($scope.max_dias_citas, 'd');
if (!$scope.disableWeekend(day)) {
if (day.date.isSameOrAfter(manyana)) {
if (day.date.isSameOrBefore(ultimoDia)) {
esHabil = true;
}
}
}
return esHabil;*/
};
$scope.diaHabil = function (day){
/*if (!day.hayCitas){
resetearHorasCitas();
}*/
return day.hayCitas;
};
$scope.select = function(day) {
$scope.selected = day.date;
$scope.textopp = day.date;
getCitasPrueba ($scope.idServicio,$scope.idGestion,$scope.selected.format("DD-MM-YYYY"));
$scope.resumen.fecha = $scope.selected.format("DD-MM-YYYY");
};
$scope.next = function() {
var next = $scope.month.clone();
next.add(1,'M').startOf('month');
$scope.month.add(1,'M');
_buildMonth(next.startOf("isoWeek"), $scope.month);
$scope.monthVisual = $scope.month.clone();
};
$scope.previous = function() {
var previous = $scope.month.clone();
previous.subtract(1,'M').startOf('month');
$scope.month.subtract(1,'M');
_buildMonth(previous.startOf("isoWeek"), $scope.month);
$scope.monthVisual = $scope.month.clone();
};
function resetearHorasCitas (){
while ($scope.horascitas.length > 0) {
$scope.horascitas.pop();
}
}
function getCitasPrueba (servicio, cola, fecha){
resetearHorasCitas();
getCitasDisponibles(servicio, cola, fecha);
//serviciosCitas.obtenerCitasDisponible(servicio,cola,fecha).then(onFetchCompletedHorasCitas,onFetchError);
//var horas = ["08:00","08:30","09:00","09:30","10:00","10:30","11:00","11:30","12:00","12:30","13:00","13:30","14:00"];
//return horas;
}
$scope.updateHoras = function (hora){
$scope.resumen.hora = hora;
$scope.hora = hora;
};
$scope.issame = function (hora){
if ($scope.resumen.hora === hora){
return true;
}else{
return false;
}
}
$scope.updateGestiones = function(){
//alert($scope.idServicio);
citaPreviaServices.getGestiones($scope.idServicio).then(onFetchCompletedGestiones, onFetchError);
resetearHorasCitas();
// Ahora debo borrar los datos temporales de la Cita
$scope.resumen.oficina = "";
$scope.resumen.id_gestion = "";
$scope.resumen.gestion = "";
$scope.resumen.fecha = "";
$scope.resumen.hora = "";
// Borro datos generales
$scope.idGestion = "";
$scope.descOficina = "";
$scope.urlColaDesc = "";
$scope.max_dias_citas = 0;
var encontrado = false;
$scope.servicios.forEach( function (valor, indice, array){
if (array[indice].IdServicio == $scope.idServicio){
encontrado = true;
$scope.resumen.id_servicio = $scope.idServicio;
$scope.resumen.servicio = array[indice].Nombre;
$scope.resumen.oficina = array[indice].Direccion;
$scope.descOficina = array[indice].Direccion;
}
});
if (encontrado == false){
$scope.descOficina = "";
$scope.resumen.oficina = "";
$scope.resumen.id_servicio = "";
$scope.resumen.servicio = "";
$scope.resumen.id_gestion = "";
$scope.resumen.gestion = "";
$scope.resumen.fecha = "";
$scope.max_dias_citas = 0;
};
};
$scope.updateOficina = function(){
var encontrado = false;
// Al seleccionar Cola, borra Horas seleccionadas de anteriores Colas
resetearHorasCitas();
// Ahora debo borrar los datos temporales de la Cita
$scope.resumen.fecha = "";
$scope.resumen.hora = "";
//*****************************************************************
//*** Condiciones temporales para acceder al SAIC (A, B, E y F) ***
//*****************************************************************
getIpCliente();
if ((($scope.idServicio == "S") && ($scope.idGestion == "A")) ||
(($scope.idServicio == "S") && ($scope.idGestion == "B")) ||
(($scope.idServicio == "S") && ($scope.idGestion == "E")) ||
(($scope.idServicio == "S") && ($scope.idGestion == "F"))) {
if ((($scope.ip == "195.55.43.202") || ($scope.ip == "0.0.0.0") ||
($scope.ip == "217.127.49.149") || ($scope.ip == "80.35.23.0") ||
($scope.ip == "195.235.184.226") || ($scope.ip == "88.12.63.18") ||
($scope.ip == "88.12.63.19") || ($scope.ip == "217.125.90.59"))) {
// Permito el acceso
}else{
$scope.idGestion = "";
//alert("Pida Cita para esta Gestion llamando al 010 o al 966900886, de lunes a viernes, de 9:00 h. a 18:00 h.");
alert("Pida Cita para esta Gestion llamando al 010 o al 966900886, de lunes a viernes, de 9:00 h. a 18:00 h." + "\n[" + $scope.ip + "]");
return;
}
}
//*******************************************************
//*** Condiciones temporales para cola de Inmigracion ***
//*******************************************************
if ($scope.idServicio == "I") {
if ((($scope.ip == "195.55.43.202") || ($scope.ip == "0.0.0.0") ||
($scope.ip == "217.127.49.149") || ($scope.ip == "80.35.23.0") ||
($scope.ip == "195.235.184.226") || ($scope.ip == "88.12.63.18") ||
($scope.ip == "88.12.63.19") || ($scope.ip == "217.125.90.59"))) {
// Permito el acceso
}else{
$scope.idGestion = "";
//alert("La cita NO se ha gestionado. La CITA PREVIA para Inmigración, se realiza exclusivamente llamando al teléfono 965230267, de lunes a viernes, de 9:00 a 11:00");
alert("La cita NO se ha gestionado. La CITA PREVIA para Inmigración, se realiza exclusivamente llamando al teléfono 965230267, de lunes a viernes, de 9:00 a 11:00" + "\n[" + $scope.ip + "]");
return;
}
}
//************************************************************
$scope.max_dias_citas = 0;
$scope.gestiones.forEach( function (valor, indice, array){
if (array[indice].IdCola == $scope.idGestion){
encontrado = true;
$scope.resumen.id_gestion = $scope.idGestion;
$scope.resumen.gestion = array[indice].Nombre;
$scope.urlColaDesc = array[indice].Descripcion;
$scope.max_dias_citas = array[indice].MaxCita;
$scope.colaMotivoValor = array[indice].Motivo;
//alert($scope.max_dias_citas);
_buildMonth($scope.firstDay.startOf("isoWeek"), $scope.month);
}
});
if (encontrado == false){
$scope.resumen.id_gestion = "";
$scope.resumen.gestion = "";
$scope.resumen.fecha = "";
$scope.max_dias_citas = 0;
$scope.colaMotivoValor = 'N'
};
};
var onFetchError = function(message){
//alert("Error: "+message);
$scope.ip = "0.0.0.0";
$scope.resumen.ip = "0.0.0.0";
};
var onFetchCompletedServicios = function(data){
$scope.servicios = data.data.items;
};
var onFetchCompletedTiposDocumento = function (data){
$scope.tipos_doc = data.data.items;
}
var onFetchCompletedGestiones = function (data){
//$scope.gestiones;
$scope.gestiones = [];
elementos = data.data.items;
for (i=0; i<elementos.length; i++) {
//if (elementos[i].CitaPrevia == 'S'){
if ((elementos[i].CitaPrevia == 'S') && (elementos[i].Activa == 'S')) {
$scope.gestiones.push(elementos[i]);
}
}
};
var onFetchCompletedHorasCitas = function (data){
var horasCitasTodo = JSON.parse(data.data.result);
for (var k in horasCitasTodo){
$scope.horascitas.push(horasCitasTodo[k].hora);
};
}
var onFetchCompletedIp = function (response){
$scope.ip = response.data.ip;
$scope.resumen.ip = response.data.ip;
//alert($scope.ip);
}
var onFetchCompletedCitaPrevia = function (response){
alert(response.data.result);
if (response.data.result == 'Cita insertada'){
//$window.location.href = './#/verCita/'+$scope.resumen.num_documento+'/'+$scope.resumen.id_servicio+$scope.resumen.id_gestion+$scope.resumen.num_documento;
$window.location.href = './#/verCita/'+$scope.resumen.num_documento+'/'+$scope.resumen.id_servicio+$scope.resumen.id_gestion+$scope.resumen.num_documento+'/OLD';
}
/*var resultado = response.data.correcto;
var mensaje = response.data.mensaje;
var idCita = response.data.id_cita;
alert(resultado);
alert(mensaje);
alert(idCita);*/
};
var getServiciosController = function(){
citaPreviaServices.getServicios().then(onFetchCompletedServicios,onFetchError);
};
var getTiposDocumentoController = function (){
citaPreviaServices.obtenerTipoDocumento().then(onFetchCompletedTiposDocumento, onFetchError);
}
var getCitasDisponibles = function (servicio, cola, fecha){
citaPreviaServices.obtenerCitasDisponible(servicio, cola, fecha).then(onFetchCompletedHorasCitas,onFetchError);
}
var getIpCliente = function (){
citaPreviaServices.obtenerIp().then(onFetchCompletedIp,onFetchError)
}
var insertaCitaPreviaWeb = function (){
citaPreviaServices.insertarCitaPrevia($scope.resumen, $scope.colaMotivoValor, $scope.idProcedencia).then(onFetchCompletedCitaPrevia,onFetchError)
}
/*function validar_nif (value){
var validChars = 'TRWAGMYFPDXBNJZSQVHLCKET';
var nifRexp = /^[0-9]{8}[TRWAGMYFPDXBNJZSQVHLCKET]{1}$/i;
var nieRexp = /^[XYZ]{1}[0-9]{7}[TRWAGMYFPDXBNJZSQVHLCKET]{1}$/i;
var str = value.toString(
).toUpperCase();
if (!nifRexp.test(str) && !nieRexp.test(str)) return false;
var nie = str
.replace(/^[X]/, '0')
.replace(/^[Y]/, '1')
.replace(/^[Z]/, '2');
var letter = str.substr(-1);
var charIndex = parseInt(nie.substr(0, 8)) % 23;
if (validChars.charAt(charIndex) === letter) return true;
return false;
};*/
$scope.validarnif = function (value){
if (value == undefined || value == ''){
return true;
}else{
if (value.indexOf(' ')>0) return false;
if ($scope.resumen.tipo_documento=='1'){
return validateDNI(value);
}else{
if ($scope.resumen.tipo_documento=='2' || $scope.resumen.tipo_documento=='4'){
return validateCIF(value);
}else{
if ( $scope.resumen.tipo_documento=='3' ){
return true;
}else {
return false;
}
}
}
}
}
$scope.validarTuplaDocumento=function(){
if ($scope.resumen.num_documento != null && $scope.resumen.tipo_documento !=null){
return $scope.validarnif($scope.resumen.num_documento);
}else{
return true;
}
}
$scope.emailCorrecto=function (){
/*if ($scope.resumen.email != undefined && $scope.resumen.email!=''){
return false;
}else{
if ( $scope.idServicio == 'H' || $scope.idServicio == 'T'){
return false;
}else{
return true;
}
}*/
return false;
};
$scope.esBono=function (){
if ($scope.idServicio == 'L') {
return true;
}else{
return false;
}
};
$scope.colaMotivo=function (){
/*if ($scope.colaMotivoValor == 'S'){
return false;
}else{
return true;
}*/
return false;
};
$scope.getNombreOficina=function(IdServicio){
var nombreTraducido = '';
if (IdServicio!=undefined && IdServicio!=''){
$scope.servicios.forEach( function (valor, indice, array){
if (array[indice].IdServicio == IdServicio){
if ($rootScope.localizador == 'es') {
nombreTraducido = array[indice].Direccion;
}else{
nombreTraducido = array[indice].DireccionV;
}
};
});
}
return nombreTraducido;
}
$scope.getNombreServicio = function(IdServicio){
var nombreTraducido = '';
if (IdServicio!=undefined && IdServicio!='') {
$scope.servicios.forEach(function (valor, indice, array) {
if (array[indice].IdServicio == IdServicio) {
if ($rootScope.localizador == 'es') {
nombreTraducido = array[indice].Nombre;
} else {
nombreTraducido = array[indice].NombreV;
}
}
;
});
}
return nombreTraducido;
};
$scope.getNombreGestion = function(IdGestion){
var nombreTraducido = '';
if (IdGestion!=undefined && IdGestion!='') {
$scope.gestiones.forEach(function (valor, indice, array) {
if (array[indice].IdCola == IdGestion) {
if ($rootScope.localizador == 'es') {
nombreTraducido = array[indice].Nombre;
} else {
nombreTraducido = array[indice].NombreV;
}
}
;
});
}
return nombreTraducido;
};
$scope.pedirCita=function(event){
const button = (event.srcElement.disabled === undefined) ? event.srcElement.parentElement : event.srcElement;
button.setAttribute('disabled', true);
setTimeout(function () {
button.removeAttribute('disabled');
}, 3000);
if ($scope.formulario.$valid){
if ($scope.resumen.fecha == undefined || $scope.resumen.fecha == '' || $scope.resumen.hora == undefined || $scope.resumen.hora == ''){
alert($filter('translate')('PEDIR_ERROR_FECHA_HORA'));
}else {
if ($scope.colaMotivoValor == 'S' && ($scope.resumen.comentario == undefined || $scope.resumen.comentario == '')){
alert($filter('translate')('PEDIR_ERROR_CAMPOS'));
/*alert("Debe rellenar los campos obligatorios y/o corregir los datos erróneos.");*/
}else {
if ($scope.resumen.id_servicio == 'L' && $scope.resumen.impuestos != 'S') {
alert($filter('translate')('ERROR_LABEL_IMPUESTOS'));
}else {
insertaCitaPreviaWeb();
}
}
//alert("Consultando los datos de la cita: " + $scope.resumen.num_documento);
//$window.location.href = './#/verCita/'+$scope.consulta.nif+'/'+$scope.consulta.codigoCita;
}
}else {
//alert("Debe rellenar los campos obligatorios y/o corregir los datos erróneos.");
alert($filter('translate')('PEDIR_ERROR_CAMPOS'));
}
}
getServiciosController();
getTiposDocumentoController();
getIpCliente();
$scope.datosCita = {};
$scope.selected = undefined;
}).controller('verCitaController', function ($rootScope, $scope, $routeParams, citaPreviaServices, $translate, $filter){
$scope.changeLanguage = function (key) {
$translate.use(key);
};
$scope.registro_servicio;
$scope.registro_cola;
$scope.ocultarVentana = false;
$scope.cita = {
idCita:"",
idServicio:"",
servicio:"",
gestion:"",
oficina:"",
fecha:"",
hora:"",
codCita:"",
nombre:"",
apellidos:"",
nif:"",
telefono:"",
email:""
};
$scope.cita.nif = $routeParams.idNif;
$scope.getNombreServicio = function (){
if ($scope.registro_servicio!=undefined){
if ($rootScope.localizador == 'es') {
return $scope.registro_servicio.Nombre;
} else {
return $scope.registro_servicio.NombreV;
}
}else{
return '';
}
};
$scope.getNombreCola = function (){
//$scope.registro_cola = gestiones;
if ($scope.registro_cola!=undefined){
if ($rootScope.localizador == 'es') {
return $scope.registro_cola.Nombre;
}else{
return $scope.registro_cola.NombreV;
}
}else{
return '';
}
};
$scope.getOficina = function (){
if ($scope.registro_servicio!=undefined){
if ($rootScope.localizador == 'es') {
return $scope.registro_servicio.Direccion;
} else {
return $scope.registro_servicio.DireccionV;
}
}else{
return '';
}
};
//$scope.cita.codigoCita = $routeParams.idCita;
//citaPreviaServices.consultarCita('',$routeParams.idNif,$routeParams.idCita).success(function(response){
citaPreviaServices.consultarCita('',$routeParams.idNif,$routeParams.idCita,$routeParams.idTipoBusqueda).success(function(response){
var resultado = response.result;
resultado = JSON.stringify(eval("("+resultado.replace(/\'/g,'')+")"));
$scope.cita = JSON.parse(resultado);
if ($scope.cita.servicio == null){
$scope.ocultarVentana = true;
}else{
citaPreviaServices.obtenerServicio($scope.cita.servicio).success(function(response){
$scope.registro_servicio = response;
$scope.cita.idServicio = $scope.cita.servicio;
//$scope.cita.servicio = response.Nombre;
if ($rootScope.localizador == 'es') {
$scope.cita.servicio = response.Nombre;
$scope.cita.oficina = response.Direccion;
} else {
$scope.cita.servicio = response.NombreV;
$scope.cita.oficina = response.DireccionV;
}
citaPreviaServices.getGestiones($scope.cita.idServicio).success(function(response){
var gestiones = [];
gestiones = response.items;
gestiones.forEach( function (valor, indice, array){
if (array[indice].IdCola == $scope.cita.gestion){
$scope.registro_cola = array[indice];
if ($rootScope.localizador == 'es') {
$scope.cita.gestion = array[indice].Nombre;
}else{
$scope.cita.gestion = array[indice].NombreV;
}
}
});
});
});
}
/*$scope.cita.servicio = resultado.nif.replace(/\'/g,'');
$scope.cita.gestion = resultado.codCita.replace(/\'/g,'');;*/
});
function PrintElem(elem)
{
var mywindow = window.open('', 'PRINT', 'height=400,width=600');
mywindow.document.write('<html><head><title>' + document.title + '</title>');
mywindow.document.write('</head><body >');
mywindow.document.write('<h1>' + document.title + '</h1>');
mywindow.document.write(document.getElementById(elem).innerHTML);
mywindow.document.write('</body></html>');
mywindow.document.close(); // necessary for IE >= 10
mywindow.focus(); // necessary for IE >= 10*/
mywindow.print();
mywindow.close();
return true;
}
$scope.imprimirCita = function (){
//alert("Imprimir cita");
PrintElem("paginaImpresa");
}
}).
controller('anularVerCitaController', function ($rootScope, $scope, $routeParams,$window, citaPreviaServices, $translate, $filter){
$scope.changeLanguage = function (key) {
$translate.use(key);
};
$scope.ocultarVentana = false;
$scope.registro_servicio;
$scope.registro_cola;
$scope.cita = {
idCita:"",
idServicio:"",
servicio:"",
idGestion:"",
gestion:"",
oficina:"",
fecha:"",
hora:"",
codCita:"",
nombre:"",
apellidos:"",
nif:"",
telefono:"",
email:""
};
$scope.cita.nif = $routeParams.idNif;
$scope.getNombreServicio = function (){
if ($scope.registro_servicio!=undefined){
if ($rootScope.localizador == 'es') {
return $scope.registro_servicio.Nombre;
} else {
return $scope.registro_servicio.NombreV;
}
}else{
return '';
}
};
$scope.getNombreCola = function (){
//$scope.registro_cola = gestiones;
if ($scope.registro_cola!=undefined){
if ($rootScope.localizador == 'es') {
return $scope.registro_cola.Nombre;
}else{
return $scope.registro_cola.NombreV;
}
}else{
return '';
}
};
$scope.getOficina = function (){
if ($scope.registro_servicio!=undefined){
if ($rootScope.localizador == 'es') {
return $scope.registro_servicio.Direccion;
} else {
return $scope.registro_servicio.DireccionV;
}
}else{
return '';
}
};
//$scope.cita.codigoCita = $routeParams.idCita;
//citaPreviaServices.consultarCita('',$routeParams.idNif,$routeParams.idCita).success(function(response){
citaPreviaServices.consultarCita('',$routeParams.idNif,$routeParams.idCita,'NEW').success(function(response){
var resultado = response.result;
resultado = JSON.stringify(eval("("+resultado.replace(/\'/g,'')+")"));
$scope.cita = JSON.parse(resultado);
if ($scope.cita.servicio == null){
$scope.ocultarVentana = true;
}else{
citaPreviaServices.obtenerServicio($scope.cita.servicio).success(function(response){
$scope.registro_servicio = response;
$scope.cita.servicio = $scope.cita.servicio;
if ($rootScope.localizador == 'es') {
//$scope.cita.servicio = response.Nombre;
$scope.cita.oficina = response.Direccion;
} else {
//$scope.cita.servicio = response.NombreV;
$scope.cita.oficina = response.DireccionV;
}
citaPreviaServices.getGestiones($scope.cita.servicio).success(function(response){
var gestiones = [];
gestiones = response.items;
gestiones.forEach( function (valor, indice, array){
if (array[indice].IdCola == $scope.cita.gestion){
$scope.cita.idGestion = $scope.cita.gestion;
$scope.registro_cola = array[indice];
if ($rootScope.localizador == 'es') {
$scope.cita.gestion = array[indice].Nombre;
}else{
$scope.cita.gestion = array[indice].NombreV;
}
}
});
});
});
}
var onFetchError = function(message){
alert("Error: "+message);
};
var onFetchCompletedAnularCitaPrevia = function (response){
if (response.data.result == 'Cita anulada'){
alert($filter('translate')('ANULAR_ANULADA_OK'));
//alert("La cita ha sito anulada correctamente");
$window.location.href = './#/inicio';
}else{
alert($filter('translate')('ANULAR_ANULADA_ERROR'));
//alert("Error al anular la cita previa. Consulte ");
}
/*var resultado = response.data.correcto;
var mensaje = response.data.mensaje;
var idCita = response.data.id_cita;
alert(resultado);
alert(mensaje);
alert(idCita);*/
};
var anularCitaPreviaWeb = function (){
//citaPreviaServices.anularCita($scope.cita.servicio,$scope.cita.idGestion,$scope.cita.nif).then(onFetchCompletedAnularCitaPrevia,onFetchError)
citaPreviaServices.anularCita($scope.cita.servicio,$scope.cita.idGestion,$scope.cita.nif, $routeParams.idCita).then(onFetchCompletedAnularCitaPrevia,onFetchError)
}
$scope.anularCitaPrevia=function(){
anularCitaPreviaWeb();
}
/*$scope.cita.servicio = resultado.nif.replace(/\'/g,'');
$scope.cita.gestion = resultado.codCita.replace(/\'/g,'');;*/
});
});
angular.module('F1FeederApp.controllers', []).
/* Drivers controller */
controller('driversController', function($scope, ergastAPIservice) {
$scope.nameFilter = null;
$scope.driversList = [];
$scope.searchFilter = function (driver) {
var re = new RegExp($scope.nameFilter, 'i');
return !$scope.nameFilter || re.test(driver.Driver.givenName) || re.test(driver.Driver.familyName);
};
ergastAPIservice.getDrivers().success(function (response) {
//Digging into the response to get the relevant data
$scope.driversList = response.MRData.StandingsTable.StandingsLists[0].DriverStandings;
});
}).
/* Driver controller */
controller('driverController', function($scope, $routeParams, ergastAPIservice) {
$scope.id = $routeParams.id;
$scope.races = [];
$scope.driver = null;
ergastAPIservice.getDriverDetails($scope.id).success(function (response) {
$scope.driver = response.MRData.StandingsTable.StandingsLists[0].DriverStandings[0];
});
ergastAPIservice.getDriverRaces($scope.id).success(function (response) {
$scope.races = response.MRData.RaceTable.Races;
});
});