horario.js 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. /*
  2. * Funciones generales de horario
  3. * Necesita variables globales: _w, _h, _hora_min, _frac
  4. */
  5. function getX(dia){//lunes = 1 devuelve pos en X
  6. return (parseInt(dia)-1) * _w;
  7. }
  8. function getY(hora){//recibe hh:mm devuelve pos en Y
  9. var horaNuevaArr = hora.split(':');
  10. return ((parseInt(horaNuevaArr[0]) - _hora_min) * (_h * _frac)) + (parseInt(horaNuevaArr[1]) / (60/_frac) * _h);
  11. }
  12. function getDia(x){//recibe coordenada y devuelve día
  13. return parseInt(x / _w)+1;
  14. }
  15. function getHora(y){//recibe coordenada y devuelve hora
  16. var hora = parseInt(y / (_h * _frac)) + _hora_min;
  17. if(hora < 10)
  18. return "0"+hora;
  19. return hora;
  20. }
  21. function getMinutos(y){//recibe coordenada y devuelve minutos de la hora
  22. var base = parseInt(y / (_h * _frac));
  23. var min = (y - (base * _h * _frac)) * 60 / (_h * _frac);
  24. if(min < 10)
  25. return "0"+min;
  26. return min;
  27. }
  28. function getAlto(alto){//calcula alto del bloque html
  29. return alto * _h / (60/_frac);
  30. }
  31. $(document).on( "mouseenter", ".menu-wrapper", function(){
  32. $(this).find('.menu-flotante').removeClass('d-none');
  33. });
  34. $(document).on( "mouseleave", ".menu-wrapper", function(){
  35. $(this).find('.menu-flotante').addClass('d-none');
  36. });
  37. function getIndexClase(idobj){//busca en qué posición del arreglo está el id del horario
  38. for(var i=0; i < clasesObj.length; i++){
  39. if(clasesObj[i].id_obj == idobj){
  40. return i;
  41. }
  42. }
  43. return -1;
  44. }
  45. //devuelve arreglo de pos de colisiones, necesita arreglo global clasesObj
  46. function colisionHorario(max, posX, posY, alto){
  47. var colArr = [];
  48. for(var i=0; i < max; i++){
  49. if(posX == getX(clasesObj[i].dia)){//mismo día
  50. 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))) ){
  51. //console.log("["+clasesObj.length+" vs i= "+i+"]( ["+clasesObj[i].dia+"]"+posX+" == "+getX(clasesObj[i].dia)+")("+posY +" >= "+getY(clasesObj[i].hora)+" && <"+(getY(clasesObj[i].hora)+getAlto(clasesObj[i].duracion))+") || ("+(posY+alto)+" >= "+getY(clasesObj[i].hora)+" && <= "+(getY(clasesObj[i].hora)+getAlto(clasesObj[i].duracion))+")");
  52. colArr.push(clasesObj[i].id_obj);
  53. }
  54. }
  55. }
  56. return colArr;
  57. }
  58. function getColisionAll(colArr, total){//revisa todas las colisiones
  59. for(var i=0; i<colArr.length; i++){
  60. total++;
  61. total = getColisionAll(clasesObj[colArr[i]].colision, total);
  62. }
  63. return total;
  64. }
  65. function cambiaAnchoAll(colArr, offset, index){//revisa todas las colisiones
  66. for(var i=0; i<colArr.length; i++){
  67. if((offset * _tab_size) < _w) {
  68. $("#bloque_"+colArr[i]).css({width: (_w - (offset * _tab_size))+"px", marginLeft: ((index * _tab_size)%_w)+"px"});
  69. console.log("w< ["+(_w - (offset * _tab_size))+"] mL ["+((index * _tab_size)%_w)+"]");
  70. }else{
  71. $("#bloque_"+colArr[i]).css({width: _tab_size+"px", marginLeft: ((index * _tab_size)%_w)+"px"});
  72. console.log("w> ["+_tab_size+"] mL ["+((index * _tab_size)%_w)+"]");
  73. }
  74. $("#bloque_"+colArr[i]).addClass("pointer");
  75. index++;
  76. index = cambiaAnchoAll(clasesObj[colArr[i]].colision, offset, index);
  77. }
  78. return index;
  79. }
  80. //recibe arreglo de ids de colisiones de colisionHorario
  81. function cambiaAncho(idCurr, colArr){
  82. var id;
  83. var offset = getColisionAll(colArr, 0);
  84. var index = cambiaAnchoAll(colArr, offset, 0);
  85. if(offset > 0){//había otros
  86. //console.log("("+idCurr+") Cambia ancho Last ["+i+"] de ["+offset+"] -> width["+(_w - (offset * _tab_size))+"] mL["+i* _tab_size+"]");
  87. //$("#bloque_"+idCurr).css({width: _w - (offset * _tab_size), marginLeft: index*_tab_size});
  88. if((offset * _tab_size) < _w) {
  89. $("#bloque_"+idCurr).css({width: (_w - (offset * _tab_size))+"px", marginLeft: ((index * _tab_size)%_w)+"px"});
  90. console.log("* w< ["+(_w - (offset * _tab_size))+"] mL ["+((index * _tab_size)%_w)+"]");
  91. }else{
  92. $("#bloque_"+idCurr).css({width: _tab_size+"px", marginLeft: (((index +1) * _tab_size)%_w)+"px"});
  93. console.log("w> ["+_tab_size+"] mL ["+((index * _tab_size)%_w)+"]");
  94. }
  95. $("#bloque_"+idCurr).addClass("pointer");
  96. }
  97. }