//------------------------------------------------------------------------------------------------------------------------------- // Variables globales //------------------------------------------------------------------------------------------------------------------------------- var TipoNIFCIFPASS = JSON.parse('{"NIF":0,"CIF":1,"PASS":2}'); /* Gonzalo */ var getUrlParameter = function getUrlParameter(sParam) { var sPageURL = decodeURIComponent(window.location.search.substring(1)), sURLVariables = sPageURL.split('&'), sParameterName, i; for (i = 0; i < sURLVariables.length; i++) { sParameterName = sURLVariables[i].split('='); if (sParameterName[0] === sParam) { return sParameterName[1] === undefined ? true : sParameterName[1]; } } }; /*fin Gonzalo*/ //------------------------------------------------------------------------------------------------------------------------------- // INICIALIZA los componentes: Tooltip, Tab seleccionado ... //------------------------------------------------------------------------------------------------------------------------------- $(function () { //Es lo mismo que document ready //Inicializo los tooltip, ojo, los que se cargan en los template hay que hacerlos en cada template $('[rel="tooltip"]').tooltip();//Inicializo tooltip //Soluciona el fallo de bootstrap de cuando abro una modal sobre otra que es muy grande y necesita scroll y cierro la primera deja de funcionar el scroll. $(document).on('hidden.bs.modal', '.modal', function () { $('.modal:visible').length && $(document.body).addClass('modal-open'); }); //JODER Abro la primera pestaña del tab //$('#Menu a:first').click();//no dispara el handler del evento click sino lo meto dentro del document ready $('#tabInicio').click(); }); //Para backgrid (CONTRATOS) var FechaFormatter= _.extend({}, Backgrid.CellFormatter.prototype, { fromRaw: function (rawValue, model) { return BDDateToUserDate(rawValue); } }); var FechaCell = Backgrid.DateCell.extend({ formatter: FechaFormatter }); var HtmlCell = Backgrid.HtmlCell = Backgrid.Cell.extend({ /** @property */ className: "html-cell", initialize: function () { Backgrid.Cell.prototype.initialize.apply(this, arguments); }, render: function () { this.$el.empty(); var rawValue = this.model.get(this.column.get("name")); var formattedValue = this.formatter.fromRaw(rawValue, this.model); this.$el.append(formattedValue); this.delegateEvents(); return this; } }); //Para editar/borrar contratos var ButtonCellContratos = Backgrid.Cell.extend({ template: _.template(''), events: { "click .contratobotoneditar": "editRow", "click .contratobotonborrar": "deleteRow" }, editRow: function (e) { e.preventDefault(); $('#ModalEditarGrabarContratoTitle').html('Editar datos de contrato'); var template = _.template($('#Template-Editar-Grabar-Contrato').html(), {contrato : this.model}); $('#ModalEditarGrabarContratoMensaje').html(template); contratosListaView.PrepararFormulario(); $('#ModalEditarGrabarContrato').modal('show'); }, deleteRow: function (e) { e.preventDefault(); var idcontrato=this.model.get('idcontrato'); bootbox.dialog({message: "¿Está seguro de que quiere borrar definitivamente el contrato?",title: "Borrar Contrato", buttons: { success: { label: "Borrar", className: "btn-danger", callback: function() { $.ajax({ url: 'https://eternity.online/patrocinadores/naturpellet-futsal-oficina-virtual/rest/data.php/borrarcontrato/'+idcontrato, type: 'POST', }). always(function( msg ) { CargaContratos(); }); } }, danger: { label: "Cancelar", className: "btn", callback: function() { //Example.show("uh oh, look out!"); } } } }); //this.model.collection.remove(this.model); }, render: function () { this.$el.html(this.template()); this.delegateEvents(); return this; } }); //Generales, funciones específicas de apoyo a ciertas zonas de la aplicación var lista_citas=[]; function pintaGridCitasInicio(idusuario,cita) { //PARA EL USUARIO NO REGISTRADO if (cita) { lista_citas.push(cita); } var template = _.template($('#Template-Grid-Citas').html(), {citas: lista_citas}); $('#contenedor_inicio_citas').html(template); $('#BodyTablaCitas').html(RellenaTablaCitas()); } //CONTROL DE EVENTOS //Evento de carga de tabs (disparo lectura de datos) cuando se pulsa sobre ellos //Cuando pulsa en un tab, busca su funcion asociada en data y la ejecuta $('body').on('click','a[data-toggle="tab"]', function (e) { //e.target // activated tab //e.relatedTarget // previous tab window[$(e.target).data('funcionCarga')](); //Llama a la funcion de disparo especificada en el tab }); //------------------------------------------------------------------------------------------------------------------------------- //FUNCIONES DE DISPARO //------------------------------------------------------------------------------------------------------------------------------- function CargaInicio(){ inicioListaContratosView.render({idusuario:""}); } function CargaMisDatos() { //Si ha hecho login son sus datos y si no hace las labores de registro //Ahora renderizo la vista misDatosView.render({idusuario:""}); } function CargaContratos() { //Ahora renderizo la vista contratosListaView.render(); } function CargaListados () { $('#lc_fecha_alta_desde').datetimepicker({ lang:'es', timepicker:false, format:'d/m/Y', closeOnDateSelect: true }); $('#lc_fecha_alta_hasta').datetimepicker({ lang:'es', timepicker:false, format:'d/m/Y', closeOnDateSelect: true }); $('#la_fecha_desde').datetimepicker({ lang:'es', timepicker:false, format:'d/m/Y', closeOnDateSelect: true }); $('#la_fecha_hasta').datetimepicker({ lang:'es', timepicker:false, format:'d/m/Y', closeOnDateSelect: true }); //Paises var O = $.getJSON( "rest/data.php/paises", function(ListaPaises) { $('#lc_idpais').empty();//Limpio el contenido del select paises _.each(ListaPaises, function(pais) { $('#lc_idpais').append($('