Guest User

Untitled

a guest
Jan 22nd, 2019
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.19 KB | None | 0 0
  1. function DayClick(dayNum, obj) {
  2. if ($(obj).hasClass('selected') && ($('#Schedule tbody tr td.d' + dayNum + ' div.selected').length)) {
  3. $('#Schedule tbody tr td.d' + dayNum + ' div').removeClass('selected');
  4. $(obj).removeClass('selected');
  5. }
  6. else {
  7. $('#Schedule tbody tr td.d' + dayNum + ' div').addClass('selected');
  8. $(obj).addClass('selected');
  9. };
  10. }
  11. $(document).ready(function() {
  12. $('#Schedule tbody tr .d0').hover(
  13. function() { $('#Schedule thead tr td.d0').addClass('hovered') },
  14. function() { $('#Schedule thead tr td.d0').removeClass('hovered') });
  15. $('#Schedule thead tr .d0').hover(
  16. function() { $('#Schedule td.d0').addClass('hovered') },
  17. function() { $('#Schedule td.d0').removeClass('hovered') })
  18. .click(function() { DayClick('0', this) });
  19.  
  20. $('#Schedule tbody tr .d1').hover(
  21. function() { $('#Schedule thead tr td.d1').addClass('hovered') },
  22. function() { $('#Schedule thead tr td.d1').removeClass('hovered') });
  23. $('#Schedule thead tr .d1').hover(
  24. function() { $('#Schedule td.d1').addClass('hovered') },
  25. function() { $('#Schedule td.d1').removeClass('hovered') })
  26. .click(function() { DayClick('1', this) });
  27.  
  28. $('#Schedule tbody tr .d2').hover(
  29. function() { $('#Schedule thead tr td.d2').addClass('hovered') },
  30. function() { $('#Schedule thead tr td.d2').removeClass('hovered') });
  31. $('#Schedule thead tr .d2').hover(
  32. function() { $('#Schedule td.d2').addClass('hovered') },
  33. function() { $('#Schedule td.d2').removeClass('hovered') })
  34. .click(function() { DayClick('2', this) });
  35.  
  36. $('#Schedule tbody tr .d3').hover(
  37. function() { $('#Schedule thead tr td.d3').addClass('hovered') },
  38. function() { $('#Schedule thead tr td.d3').removeClass('hovered') });
  39. $('#Schedule thead tr .d3').hover(
  40. function() { $('#Schedule td.d3').addClass('hovered') },
  41. function() { $('#Schedule td.d3').removeClass('hovered') })
  42. .click(function() { DayClick('3', this) });
  43.  
  44. $('#Schedule tbody tr .d4').hover(
  45. function() { $('#Schedule thead tr td.d4').addClass('hovered') },
  46. function() { $('#Schedule thead tr td.d4').removeClass('hovered') });
  47. $('#Schedule thead tr .d4').hover(
  48. function() { $('#Schedule td.d4').addClass('hovered') },
  49. function() { $('#Schedule td.d4').removeClass('hovered') })
  50. .click(function() { DayClick('4', this) });
  51.  
  52. $('#Schedule tbody tr .d5').hover(
  53. function() { $('#Schedule thead tr td.d5').addClass('hovered') },
  54. function() { $('#Schedule thead tr td.d5').removeClass('hovered') });
  55. $('#Schedule thead tr .d5').hover(
  56. function() { $('#Schedule td.d5').addClass('hovered') },
  57. function() { $('#Schedule td.d5').removeClass('hovered') })
  58. .click(function() { DayClick('5', this) });
  59.  
  60. $('#Schedule tbody tr .d6').hover(
  61. function() { $('#Schedule thead tr td.d6').addClass('hovered') },
  62. function() { $('#Schedule thead tr td.d6').removeClass('hovered') });
  63. $('#Schedule thead tr .d6').hover(
  64. function() { $('#Schedule td.d6').addClass('hovered') },
  65. function() { $('#Schedule td.d6').removeClass('hovered') })
  66. .click(function() { DayClick('6', this) });
  67.  
  68. $('#Schedule tr').hover(
  69. function() { $(this).addClass('hovered') },
  70. function() { $(this).removeClass('hovered') });
  71. $('#Schedule tbody tr td div').click(
  72. function() { $(this).toggleClass('selected') });
  73. });
  74. $(function(){
  75. const table = document.querySelector('#Schedule');
  76. const cells = document.querySelectorAll('.cell');
  77. document.querySelector("#btn").addEventListener('click', sendHandler);
  78.  
  79. function sendHandler(e) {
  80. let resultArray = [];
  81. cells.forEach(cell => {
  82. let {day, month, year, time} = cell.dataset;
  83. let employees = cell.querySelectorAll('.employee');
  84. let employeesIDs = [...employees].map(employeeElement => employeeElement.dataset.employeeId);
  85. resultArray.push({day, month, year, time, employeesIDs});
  86. });
  87. resultJson = JSON.stringify(resultArray);
  88. console.log(resultJson);
  89. }
  90. });
Add Comment
Please, Sign In to add comment