説明なし

dashboard.js 3.2KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. // import {MDCDialog} from '@material/dialog';
  2. // import {MDCSelect} from '@material/select';
  3. // import {MDCTextField} from '@material/textfield';
  4. // const dialog = new MDCDialog(document.querySelector('.mdc-dialog'));
  5. // const select = new MDCSelect(document.querySelector('.mdc-select'));
  6. // const textfield = new MDCSelect(document.querySelector('.mdc-textfield'));
  7. // var fonts = {
  8. // Roboto: {
  9. // normal: 'fonts/Roboto-Regular.ttf',
  10. // bold: 'fonts/Roboto-Medium.ttf',
  11. // italics: 'fonts/Roboto-Italic.ttf',
  12. // bolditalics: 'fonts/Roboto-.ttf',
  13. // }
  14. // };
  15. var pdfMake = require('pdfmake/build/pdfmake.js');
  16. var pdfFonts = require('pdfmake/build/vfs_fonts.js');
  17. pdfMake.vfs = pdfFonts.pdfMake.vfs;
  18. function table(course) {
  19. return {
  20. widths: [100, 300],
  21. headerRows: 2,
  22. body: [
  23. [{text: `${course.code} ${course.title}`, bold: true, colSpan: 2, alignment: 'center'}, {}],
  24. ['Seccion', 'Profesor'],
  25. ].concat( course.sections.map( function(section) {
  26. if (section.hasOwnProperty('professors')) {
  27. return [section.code, section.professors.map( function (professor) {
  28. return professor.first_name + ' ' + professor.last_name;
  29. })];
  30. } else {
  31. return [section.code, ''];
  32. }
  33. }))
  34. }
  35. }
  36. $(document).ready( function() {
  37. // $('#button-semester-load').on('click', function (event) {
  38. // dialog.open();
  39. // });
  40. $('#button-load').on('show.bs.modal', function (event) {
  41. // const select = new MDCSelect(document.querySelector('.mdc-select'));
  42. var button = $(event.relatedTarget);
  43. var action = button.data('action');
  44. $('#select-semester').change( function() {
  45. $('#modal-semester-form').submit( function(event) {
  46. event.preventDefault();
  47. $.ajax({
  48. url: `/dashboard/${action}/${select.value}`,
  49. type: 'get',
  50. success: function(data) {
  51. var docDef = {
  52. content: [
  53. {text: `Horario BIOL ${data.alpha}`, style: 'header'},
  54. {text: 'sujeto a cambios', style: 'header', fontSize: 18},
  55. ].concat( data.courses.map( function(course) {
  56. return {
  57. style: 'tableStyle',
  58. alignment: 'center',
  59. table: table(course)
  60. }
  61. })),
  62. styles: {
  63. header: {
  64. fontSize: 22,
  65. bold: true,
  66. alignment: 'center',
  67. },
  68. tableStyle: {
  69. margin: [50,10,0,15]
  70. },
  71. }
  72. };
  73. pdfMake.createPdf(docDef).download();
  74. }
  75. })
  76. });
  77. });
  78. });
  79. });
  80. window.mdc.autoInit();