horario_read.js 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282
  1. /*
  2. * Carga calendario sin permitir edicion
  3. */
  4. $(document).ready(function(){
  5. loadHorario();
  6. timer(_reloadTime);
  7. $('#modal_ver').on('hide.bs.modal', function (event) {//al cerrar verifica si se tiene que recargar
  8. if(_reloadOnClose){
  9. loadCalendario();
  10. _reloadOnClose = false;
  11. timer(_reloadTime);
  12. }
  13. });
  14. $(".date-picker" ).datepicker(datepickerOptions);
  15. $(".date-picker" ).datepicker( $.datepicker.regional[ "es" ] );
  16. $(".date-picker").blur(function(){
  17. var fechaObj = fechaObjeto($(this).val());
  18. if( fechaObj !== false ){
  19. if(Date.parse(fechaObj) < Date.parse(fechaObjeto(_periodo_fecha_inicial))){
  20. $(this).val(_periodo_fecha_inicial);
  21. }else if(Date.parse(fechaObj) > Date.parse(fechaObjeto(_periodo_fecha_final))){
  22. $(this).val(_periodo_fecha_final);
  23. }
  24. }
  25. });
  26. });
  27. function loadHorario(){
  28. $('.bloque-clase').remove();
  29. clasesObj = [];
  30. id_obj = 0;
  31. //carga horarios y crea bloques
  32. $.ajax({
  33. url: './action/horariogrupo_select.php',
  34. type: 'POST',
  35. dataType: 'json',
  36. data: { id: $('#filter_grupo').val(), puesto:false, editable: false},
  37. success: function(result) {
  38. if(result["error"]!= "" && result["error"] !== undefined){
  39. console.log("Ocurrió un error de load");
  40. $("#errorBox").collapse('show');
  41. $("#errorBox_text").html(result["error"]);
  42. $('#messageBox')[0].scrollIntoView({ block: "end" });
  43. }else{
  44. var i, j;
  45. for(i = 0; i< result["horario"].length; i++){
  46. var salon_nombre = "";
  47. var submateriaArr = [];
  48. var sinSalon_sub = false;
  49. var sinProfSubmateria = [];
  50. if(result["horario"][i]["submaterias"].length > 0){
  51. for(j = 0; j < result["horario"][i]["submaterias"].length; j++){
  52. var submateria = {
  53. submateria: result["horario"][i]["submaterias"][j]["submateria"],
  54. submateria_nombre: result["horario"][i]["submaterias"][j]["submateria_nombre"],
  55. fecha_inicial: result["horario"][i]["submaterias"][j]["fecha_inicial"],
  56. fecha_final: result["horario"][i]["submaterias"][j]["fecha_final"],
  57. /*salon: result["horario"][i]["submaterias"][j]["salon"],
  58. salon_nombre: result["horario"][i]["submaterias"][j]["salon_nombre"],
  59. salon_nombre_completo: result["horario"][i]["submaterias"][j]["salon_nombre_completo"]*/
  60. }
  61. sinProfSubmateria[submateria.submateria] = false;
  62. /*if(result["horario"][i]["submaterias"][j]["salon"] == ""){
  63. sinSalon_sub = true;
  64. }else{
  65. salon_nombre+= submateria.salon_nombre+", ";
  66. }*/
  67. if(submateria.submateria != "" && submateria != 0)
  68. submateriaArr.push(submateria);
  69. };
  70. /*if(salon_nombre.length > 2)
  71. salon_nombre = salon_nombre.substring(0, salon_nombre.length-2);*/
  72. }
  73. var profesorArr = [];
  74. for(j = 0; j < result["horario"][i]["profesores"].length; j++){
  75. var profesor = {
  76. profesor: result["horario"][i]["profesores"][j]["profesor"],
  77. profesor_nombre: result["horario"][i]["profesores"][j]["profesor_nombre"],
  78. submateria: result["horario"][i]["profesores"][j]["submateria"],
  79. }
  80. profesorArr.push(profesor);
  81. sinProfSubmateria[profesor.submateria] = true;
  82. }
  83. var vinculadasArr = [];
  84. for(j = 0; j < result["horario"][i]["vinculada"].length; j++){
  85. var vinculo = {
  86. id_db: result["horario"][i]["vinculada"][j]["id_db"],
  87. grupo: result["horario"][i]["vinculada"][j]["id_gpo"],
  88. //grupo_nombre: result["horario"][i]["vinculada"][j]["grupo_vinculo_nombre"],
  89. materia: result["horario"][i]["vinculada"][j]["id_mat"],
  90. materia_nombre: result["horario"][i]["vinculada"][j]["nombre"],
  91. }
  92. vinculadasArr.push(vinculo);
  93. };
  94. var clase = {
  95. id_obj: id_obj,
  96. dia: parseInt(result["horario"][i]["dia"]),
  97. dia_orig: parseInt(result["horario"][i]["dia"]),
  98. hora: result["horario"][i]["hora"],
  99. hora_orig: result["horario"][i]["hora"],
  100. duracion: parseInt(result["horario"][i]["duracion"]),
  101. materia: parseInt(result["horario"][i]["materia"]),
  102. materia_orig: parseInt(result["horario"][i]["materia"]),
  103. materia_nombre: result["horario"][i]["materia_nombre"],
  104. tipo: parseInt(result["horario"][i]["tipo"]),
  105. salon: parseInt(result["horario"][i]["salon"]),
  106. salon_nombre: result["horario"][i]["salon_nombre"],
  107. salon_nombre_completo: result["horario"][i]["salon_nombre_completo"],
  108. fecha_inicial: result["horario"][i]["fecha_inicial"],
  109. fecha_final: result["horario"][i]["fecha_final"],
  110. periodo_completo: result["horario"][i]["periodo_completo"],
  111. submaterias: submateriaArr,
  112. profesores: profesorArr,
  113. vinculos: vinculadasArr,
  114. color: result["horario"][i]["color"],
  115. colision: []
  116. };
  117. if(clase.tipo == 0){
  118. salon_nombre = clase.salon_nombre;
  119. if(clase.salon == 0 || clase.salon == "" || clase.salon == null || isNaN(clase.salon) || clase.salon == undefined){
  120. salon_nombre = "-Pendiente-";
  121. }
  122. }
  123. clasesObj.push(clase);
  124. creaHorarioHTML(id_obj, getX(clase.dia), getY(clase.hora), getAlto(clase.duracion) , clase.color, clase.materia_nombre, salon_nombre, clase.profesores.length, clase.periodo_completo, vinculadasArr.length, clase.fecha_inicial, clase.fecha_final);
  125. if(result["horario"][i]["alerta"]){
  126. if(clase.tipo == 0){
  127. if(clase.profesores.length == 0 || clase.salon == 0 || clase.salon == "" || clase.salon === null || isNaN(clase.salon) || clase.salon === undefined){
  128. $("#bloque_"+id_obj+" .alerta").removeClass("d-none");
  129. }
  130. }else{
  131. if(sinSalon_sub)
  132. $("#bloque_"+id_obj+" .alerta").removeClass("d-none");
  133. if(clase.profesores.length == 0){
  134. $("#bloque_"+id_obj+" .alerta").removeClass("d-none");
  135. }
  136. /*
  137. var prof_sub = true;
  138. sinProfSubmateria.forEach(function (arrayItem) {
  139. prof_sub = prof_sub && arrayItem;
  140. });
  141. if(!prof_sub)
  142. $("#bloque_"+id_obj+" .alerta").removeClass("d-none");*/
  143. }
  144. }
  145. id_obj++;
  146. //Actualiza horas asignadas
  147. actualizaHoras(clase.materia);
  148. }//fin for
  149. actualizaLista();
  150. //Checa colisiones
  151. for(var i=0; i< clasesObj.length; i++){
  152. var colision = colisionHorario(i, getX(clasesObj[i].dia), getY(clasesObj[i].hora), getAlto(clasesObj[i].duracion));
  153. clasesObj[i].colision = colision.slice();
  154. cambiaAncho(i, colision);
  155. }
  156. }
  157. _editable = true;
  158. },
  159. error: function(jqXHR, textStatus, errorThrown ){
  160. $("#errorBox").collapse('show');
  161. $("#errorBox_text").html("Error al cargar horario.<br>"+errorThrown);
  162. $('#messageBox')[0].scrollIntoView({ block: "end" });
  163. _editable = true;
  164. }
  165. });//ajax
  166. }
  167. function creaHorarioHTML(id, posX, posY, alto, color, texto, salon, numProf, completo, link, fini, ffin){//crea bloque HTML
  168. var completoClass = "";
  169. var linked = "";
  170. var fechaHTML = "";
  171. if(parseInt(completo) == 1){ completoClass = " d-none"; }//si está completo el horario no pone signo +
  172. else{ fechaHTML = '<br><span class="text-80"><span class="img-importante2 mr-1"></span> '+fini+' a '+ffin+'</span>'; }
  173. if(parseInt(link) == 0){linked = " d-none"; }
  174. var nuevoHorario = '<div class="bloque-clase overflow" id="bloque_'+id+'" data-id_obj="'+id+'"\
  175. style="top:'+posY+'px; left:'+posX+'px; background-color:'+color+'; height:'+alto+'px" >\
  176. <div class="menu-wrapper">\
  177. <p><span class="ing-importante ing-fw alerta d-none"></span> <span class="title">'+texto+'</span> <span class="ing-link ing-fw bloque-vinculada '+linked+'"></span> '+fechaHTML+'</p>\
  178. <div class="d-flex justify-content-between w-100">\
  179. <p class="salon my-0">'+salon+'</p> <p class="text-right my-0"><span class="ing-formacion ing-fw mx-1"></span> <span class="profesores">'+numProf+'</span></p>\
  180. </div>\
  181. <div class="menu-flotante d-none">\
  182. <span class="float-left iconos">\
  183. <span class="ing-mas ing-fw bloque-agrega mx-1 '+completoClass+'" aria-hidden="true" title="Agregar materia en mismo horario"></span>\
  184. </span>\
  185. <span class="float-right iconos" >\
  186. <span class="ing-buscar ing-fw bloque-ver mx-1" aria-hidden="true" title="Ver detalle"></span>\
  187. </span>\
  188. </div>\
  189. </div>\
  190. </div>';
  191. $(nuevoHorario).appendTo("#bloque-horarios");
  192. }
  193. function checaActualizaciones(){
  194. if(!_reloadOnClose && !(($("#modal_ver").data('bs.modal') || {_isShown: false})._isShown)){
  195. console.log("check");
  196. ordenaHorario();
  197. var strCheck = "";
  198. for(var i=0; i < clasesObj.length; i++){
  199. strCheck += clasesObj[i].dia+""+clasesObj[i].hora+""+clasesObj[i].materia+""+clasesObj[i].duracion+""+clasesObj[i].fecha_inicial+""+clasesObj[i].fecha_final+""+clasesObj[i].tipo;
  200. }
  201. strCheck = MD5(strCheck);
  202. $.ajax({
  203. url: './action/horariogrupo_validahash.php',
  204. type: 'POST',
  205. dataType: 'json',
  206. data: { id: _grupo_id, check: strCheck},
  207. success: function(result) {
  208. if(result["error"]!= "" && result["error"] !== undefined){
  209. $("#errorBox").collapse('show');
  210. $("#errorBox_text").html("Error al guardar el horario.<br>"+result["error"]);
  211. $('#messageBox')[0].scrollIntoView({ block: "end" });
  212. }else{
  213. var reload = result["reload"];
  214. if(reload){
  215. if(!(($("#modal_ver").data('bs.modal') || {_isShown: false})._isShown) ){//no están abiertos los modales{
  216. loadHorario();
  217. }else{
  218. _reloadOnClose = true;
  219. }
  220. }
  221. }
  222. },
  223. error: function(jqXHR, textStatus, errorThrown ){
  224. $("#errorBox").collapse('show');
  225. $("#errorBox_text").html(errorThrown);
  226. $('#messageBox')[0].scrollIntoView({ block: "end" });
  227. }
  228. });//ajax
  229. timer(_reloadTime);
  230. }else
  231. timer(2);
  232. }
  233. function traeAlFrente(index){
  234. var classI = getIndexClase(index);
  235. var posX = getX(clasesObj[classI].dia), posY = getY(clasesObj[classI].hora), alto = getAlto(clasesObj[classI].duracion);
  236. var i=0;
  237. for(i=0; i < clasesObj.length; i++){
  238. if(posX == getX(clasesObj[i].dia) && i != classI){//mismo día, no es el horario actual
  239. if((posY >= getY(clasesObj[i].hora) && posY <= getY(clasesObj[i].hora)+getAlto(clasesObj[i].duracion)) || (posY+alto >= getY(clasesObj[i].hora) && posY+alto <= getY(clasesObj[i].hora)+getAlto(clasesObj[i].duracion)) ){
  240. var id = (clasesObj[i].id_obj);
  241. $("#bloque_"+id).css({zIndex: i+10});
  242. }
  243. }
  244. }
  245. if(clasesObj.length > 0)//había otros
  246. $("#bloque_"+index).css({zIndex: i+15});
  247. }
  248. $(document).on( "click", ".bloque-clase", function(event){//manda al frente de todos
  249. var btn = $(event.target);
  250. //var thisIndex = getIndexClase(btn.parents('.bloque-clase').data("id_obj"));
  251. var thisIndex = btn.parents('.bloque-clase').data("id_obj");
  252. traeAlFrente(thisIndex);
  253. });
  254. function timer(tiempo = 0){
  255. if(tiempo > 0){
  256. setTimeout(checaActualizaciones, tiempo * 1000);
  257. }
  258. }