File: /var/www/vhost/disk-apps/demo-telemedicina.teky.com.co/public/js/centers/centers.js
$(document).ready(function() {
$("#example2").DataTable({
paging: true,
lengthChange: true,
searching: true,
ordering: true,
info: true,
autoWidth: true,
language: {
url: Lang.get('messages.datatable.url_language')
},
buttons: ["copyHtml5", "excelHtml5", "csvHtml5", "pdfHtml5"]
});
});
/**Activar/Desactivar Hospitales usando switch*/
$(".chkcenter").change(function() {
var estado;
var id = $(this).attr("data-id");
if (this.checked) {
estado = 1;
} else {
estado = 0;
}
var info = {
id: id,
estado: estado
};
$.ajax({
url: "/centers/active",
type: "POST",
contentType: "application/json",
headers: {
"X-CSRF-TOKEN": $('meta[name="csrf-token"]').attr("content"),
"Content-Type": "application/json"
},
data: JSON.stringify(info),
success: function(r) {
if (r[0]["respuesta"]) {
swal("Ok", Lang.get('messages.centers.update_ok'));
} else {
swal("Ok", Lang.get('messages.centers.error_update'), "error");
}
}
});
});
$('#country_id').change(function () {
valor = $(this).val();
if(!valor){
$('#department_id').empty();
$('#city_id').empty();
return;
}
$('#modalLoader').modal('show');
$.ajax({
url: "/states/get/" + valor,
type: "GET",
contentType: 'application/json',
headers: {
'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content'),
'Content-Type': 'application/json'
},
success: function (r) {
if (r[0]["respuesta"]) {
$('#modalLoader').modal('hide');
var states = r[0]["states"];
$('#department_id').empty();
var sel = '<option value="">' + Lang.get('messages.select') + '</option>';
$('#department_id').append(sel);
for (var i in states) {
var row = '<option value="' + states[i].id + '">' + states[i].name + '</option>';
$('#department_id').append(row);
}
} else {
$('#department_id').empty();
$('#city_id').empty();
}
},
error: function(err){
$('#modalLoader').modal('hide');
}
});
});
$("#department_id").change(function() {
var department_id = $("#department_id").val();
if (!department_id) {
$("#city_id").empty();
var sel = '<option value="">' + Lang.get('messages.centers.select') + '</option>';
$("#city_id").append(sel);
return;
}
$.ajax({
url: "/city/get/" + department_id,
type: "GET",
contentType: "application/json",
headers: {
"X-CSRF-TOKEN": $('meta[name="csrf-token"]').attr("content"),
"Content-Type": "application/json"
},
success: function(res) {
var cities = res[0]["cities"];
$("#city_id").empty();
var sel = '<option value="">' + Lang.get('messages.centers.select') + '</option>';
$("#city_id").append(sel);
for (var i in cities) {
var row = '<option value="' + cities[i].id + '">' + cities[i].name + "</option>";
$("#city_id").append(row);
}
}
});
});