tolerancia_masiva.js 3.75 KB
Newer Older
Billy Larru committed
1 2 3 4
const listarPersonal = (selectorName) => {
	initSelect2(selectorName, baseURLRest + URI_TRABAJADORES, {title: "nombresapellidos", subtitle: "documentoidentidad"});
};

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
const listarCargos = () => {
	$(`#cboCargoFiltro`).select2({
		containerCssClass: 'select-xs',
		ajax: {
			url: baseURLRest + URI_CARGOS,
			dataType: `json`,
			delay: 1000,
			data: function (params) {
				return {
					q: params.term, // search term
					page: params.page
				};
			},
			processResults: function (data, params) {
				// parse the results into the format expected by Select2
				// since we are using custom formatting functions we do not need to
				// alter the remote JSON data, except to indicate that infinite
				// scrolling can be used
				params.page = params.page || 1;

				return {
					results: data,
					pagination: {
						more: (params.page * 30) < data.length
					}
				};
			},
			cache: true
		},
		placeholder: `Buscar`,
		allowClear: true,
		escapeMarkup: function (markup) {
			return markup;
		}, // let our custom formatter work
		minimumInputLength: 1,
		templateResult: formatRepo,
		templateSelection: formatRepoSelection
	});

	function formatRepo(repo) {
		if (repo.loading) {
			return repo.text;
		}

		var markup = `
			<div class='select2-result-repository clearfix'>
				<div class='select2-result-repository__title'>${repo.nombre}</div>
			</div>`;

		return markup;
	}

	function formatRepoSelection(repo) {
		if (repo.id) {
			return repo.nombre;
		} else {
			return repo.text;
		}
	}
Billy Larru committed
64
};
65

66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81
const filtrarPersonalPorCargo = () => {
	let cargo = $("#cboCargoFiltro").select2('data')[0];
	let puestolaboral_id = cargo.id;

	let params = {
		puestolaboral_id
	};


	ajaxWebService.get(URI_TRABAJADORES, {params}).then((response) => {
		debugger
		let html = "";
		let trabajadores = response.data;
		html = trabajadores.map((trabajador) => `<option value="${trabajador.id}">${trabajador.apellidos} ${trabajador.nombres}</option>`);
		$("#lista").append(html);
		$("#lista").trigger('bootstrapDualListbox.refresh', true);
82

83 84 85 86 87
	});
};


const initDualListbox = (nodeIdentifier) => {
Billy Larru committed
88 89 90 91 92 93 94 95 96 97
	let options = {
		moveOnSelect: false,
		infoText: 'Mostrando todos {0}',
		infoTextFiltered: '<span class="label label-warning">Filtrado</span> {0} de {1}',
		infoTextEmpty: `<span class="text-danger">La lista está vacía</span>`,
		filterPlaceHolder: 'Buscar por nombre',
		filterTextClear: 'Mostrar todos',
		preserveSelectionOnMove: 'moved',
		moveOnSelect: false
	}
98 99 100
	$(nodeIdentifier).bootstrapDualListbox(options);
};

101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141
const inicializarInputsModalToleranciaMasiva = () => {
	initDatePicker("#dpFecha");
	listarSedes("#cboSedes");
};

const registrarToleranciaMasiva = () => {
	swal({
		type: 'success',
		title: '¡Se registró la tolerancia masiva!',
		showConfirmButton: false,
		timer: 1500
	})
};


const mostrarModalAsignarTolerancia = () => {
	ajaxModal.get("administrativos/tolerancia/masiva/registroTolerancia.jsp").then((response) => {
		swal({
			title: '<strong>Registro de Tolerancia Masiva</strong>',
//            type: 'info',
			html: response.data,
			showCloseButton: true,
			showCancelButton: true,
			focusConfirm: false,
			confirmButtonText: '<i class="icon-checkmark2"></i> Registrar tolerancia',
			confirmButtonAriaLabel: 'Registrar tolerancia',
			cancelButtonText: '<i class="icon-cross3"></i>Cancelar',
			cancelButtonAriaLabel: 'Thumbs down',
			width: '30%',
			customClass: 'swal2-overflow',
			onOpen: () => {
				inicializarInputsModalToleranciaMasiva();
			}
		}).then((result) => {
			if (result.value) {
				registrarToleranciaMasiva();
			}
		});
	});
};

142 143
$(() => {
	initDualListbox("#lista");
Billy Larru committed
144 145
	listarPersonal("#cboPersonalFiltro");
	listarCargos("#cboCargoFiltro");
146
	$("#btnAplicarFiltro").click(filtrarPersonalPorCargo);
147
	$("#btnAsignarTolerancia").click(mostrarModalAsignarTolerancia);
148
});