123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220 |
- //alumnosObj.push({id: <?php echo $cve;?>, nombre:"", plan:"", matArr:[{id, desc, clave, plan, sem, grupo_id, grupo, califArr{calif, fecha, calif_tipo, revalidada}}]});
- //carga las materias en el objeto alumnosObj
- function loadMaterias(){
- if(idArr.length > 0){
- $.ajax({
- url: './action/calificamaterias_select.php',
- type: 'POST',
- dataType: 'json',
- data: { idArr: idArr, plan: _plan, tipo_calif:_tipo_calif},
- success: function(result) {
- if(result["error"]!= "" && result["error"] !== undefined){
- $("#errorBox").collapse('show');
- $("#errorBox_text").html(result["error"]);
- $('#messageBox')[0].scrollIntoView({ block: "end" });
- }else{
- //cargar datos de materias
- if(result["alumnos"].length > 0){//hay materias
- alumnosObj = result["alumnos"];
- }//hay materias
-
- printAlumnosDataHTML();//imprime datos de alumnos
- printMateriasHTML();//imprime listado
-
- $(document).find(".calif:enabled:visible:first").focus();
- }
- },
- error: function(jqXHR, textStatus, errorThrown ){
- $("#errorBox").collapse('show');
- $("#errorBox_text").html(errorThrown);
- $('#messageBox')[0].scrollIntoView({ block: "end" });
- }
- });//
-
- }//fin hay semestre
- }
- function buscaAlumno(clave){
- var i;
- for(i = 0; i<alumnosObj.length; i++){
- if(alumnosObj[i].id == clave)
- return i;
- }
- return -1;
- }
- function buscaMateria(index, id){
- var i;
- for(i = 0; i<alumnosObj[index].matArr.length; i++){
- if(alumnosObj[index].matArr[i].id == id)
- return i;
- }
- return -1;
- }
- function buscaCalif(arr, tipo){
- for(i = 0; i<arr.length; i++){
- if(arr[i]["calif_tipo"] == tipo){
- return i;
- }
- }
- return -1;
- }
- function printAlumnosDataHTML(){
- for(var index=0; index < alumnosObj.length; index++){
- var alumno = alumnosObj[index].id;
- $("#tab"+alumno+" .nombre").text(alumnosObj[index].nombre);
- $("#tab"+alumno+" .plan").text(alumnosObj[index].plan);
- }
- }
- function datosMateriaHTML(desc, grupo, clave, plan){
- var grupo_html="";
- if(!(grupo === null || grupo == ""))
- grupo_html = '<span class="mr-2 badge badge-secondary text-monospace">'+grupo+'</span>';
- return '<td><b class="text-uppercase">'+grupo_html+' '+desc+'</b><br>['+clave+'] '+plan+'</td>';
- }
- function calificaciones(clase, calif){
- var texto
- texto = '<select class="form-control '+clase+' check-modificada">';
- for(var i=10; i>=5; i--){
- if(i==10){
- texto+='<option value="">-</option>';
- }
- texto+='<option value="'+i+'"';
- if(calif == i)
- texto+=' selected="selected"';
- texto +='>'+i+'</option>';
- }
-
- texto+='<option value="0"';
- if(calif <= 0)
- texto+=' selected="selected"';
- if(_tipo_calif != 2)
- texto +='>NP</option>';
- else
- texto +='>SD</option>';
- texto+='</select>';
-
- return texto;
- }
- //Para materias cargdas. Ya pueden tener Calificación
- function printMateriasHTML(){
- for(var index=0; index < alumnosObj.length; index++){
- var alumno = alumnosObj[index].id;
-
- for(var m = 0; m < alumnosObj[index].matArr.length; m++){
- //{id, desc, clave, plan, calif, fecha, extra, revalidada}
- var id_mat = alumnosObj[index].matArr[m].id;
- var desc = alumnosObj[index].matArr[m].desc;
- var clave = alumnosObj[index].matArr[m].clave;
- var plan = alumnosObj[index].matArr[m].plan;
- var calif = alumnosObj[index].matArr[m].calif;
- var grupo = alumnosObj[index].matArr[m].grupo;
-
-
- var nuevaMateria ="";
- nuevaMateria = '<tr class="materia" id="mat_'+alumno+'_'+id_mat+'" data-al="'+alumno+'" data-mat="'+id_mat+'">';
- nuevaMateria += datosMateriaHTML(desc, grupo, clave, plan);
- nuevaMateria += '<td style="width:120px;" class="text-center">';
- nuevaMateria += calificaciones("calif", calif)+'</td>';
- nuevaMateria += '</tr>';
- $(nuevaMateria).appendTo("#tab"+alumno+" .table-asignadas tbody");
- }
- }
- }
- function preguntarAntesDeSalir(){
- if (_modificado)
- return "¿Deseas abandonar la página? Los últimos cambios que realizaste no se guardarán";
- }
- window.onbeforeunload = preguntarAntesDeSalir;
- $(document).on("change", ".check-modificada", function(e){
- _modificado = true;
- });
- $(document).ready(function(){
- loadMaterias();
- _selected = $(".nav-pills .active").data("id");
-
- //cambia tab, cambia variable de activo
- $(".nav-pills .nav-link").click(function(){
- _selected = $(this).data("id");
- });
-
- $('a[data-toggle="tab"]').on('shown.bs.tab', function (e) {
- //e.target // newly activated tab
- //e.relatedTarget // previous active tab
- var clave = $(e.target).data("id");
- $("#tab"+clave).find(".calif:enabled:visible:first").focus();
- })
-
- $(".btn-next").click(function(){
- var next = $('.nav-pills .active').parent().next('li');
- if(next.length){
- next.find('a').trigger('click');
- }else{
- $('#tablist a:first').tab('show');
- }
- });
-
- //alumnosObj.push({id: <?php echo $cve;?>, nombre:"", plan:"", matArr:[{id, desc, clave, plan, sem, grupo_id, grupo, califArr{calif, fecha, calif_tipo, revalidada}}]});
- $("#btn-guardar").click(function(){
- //guarda valores en objeto
-
- $(".table-asignadas .materia").each(function(index) {//cada renglón
- var pos = buscaAlumno($(this).data("al"));
- var matPos = buscaMateria(pos, $(this).data("mat"));
- //if($(this).find(".calif").val() != ""){
- alumnosObj[pos].matArr[matPos]["calif"] = $(this).find(".calif").val();
- alumnosObj[pos].matArr[matPos]["calif_tipo"] = _tipo_calif;
- //}
- });
-
- $.ajax({
- url: './action/calificamaterias_update.php',
- type: 'POST',
- dataType: 'json',
- async: false,
- data: { json: JSON.stringify(alumnosObj), tipo:_tipo_calif},
- beforeSend: function(x) {
- if (x && x.overrideMimeType) {
- x.overrideMimeType("application/j-son;charset=UTF-8");
- }
- },
- success: function(result) {
- if(result["error"]!= "" && result["error"] !== undefined){
- $("#errorBox").collapse('show');
- $("#errorBox_text").html(result["error"]);
- }else{
- $("#errorBox").collapse('hide');
- _modificado = false;
- $("#successBox").collapse('show');
- $("#successBox_text").html(result["ok"]);
- }
- $('#messageBox')[0].scrollIntoView({ block: "end" });
- },
- error: function(jqXHR, textStatus, errorThrown ){
- $("#errorBox").collapse('show');
- $("#errorBox_text").html(errorThrown);
- $('#messageBox')[0].scrollIntoView({ block: "end" });
- }
- });//ajax
- });
-
- });
|