newLecture.html 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="utf-8">
  5. <title>Lee Morgan -create lecture-</title>
  6. <style>
  7. form{
  8. display: flex;
  9. flex-direction: column;
  10. }
  11. form > *{
  12. margin: 10px 0;
  13. }
  14. input[type=submit]{
  15. max-width: 250px;
  16. }
  17. button{
  18. max-width: 250px;
  19. }
  20. #exercises{
  21. display: flex;
  22. flex-direction: column;
  23. }
  24. #exercises > *{
  25. margin: 10px 0;
  26. }
  27. #exercises input{
  28. margin-left: 5px;
  29. }
  30. </style>
  31. </head>
  32. <body>
  33. <h1>Create New Lecture</h1>
  34. <form
  35. id="form"
  36. action="/learn/lecture/new"
  37. method="post"
  38. encType="multipart/form-data"
  39. >
  40. <label>Uploader ID
  41. <input name="uploader" type="text" required>
  42. </label>
  43. <label>Uploader Password
  44. <input name="password" type="password" required>
  45. </label>
  46. <label>Course
  47. <select id="course" name="course" required></select>
  48. </label>
  49. <label>Title
  50. <input name="title" type="text" required>
  51. </label>
  52. <label>Video (Rumble link)
  53. <input name="video" type="text" required>
  54. </label>
  55. <label>Description
  56. <input name="description" type="text" required>
  57. </label>
  58. <label>Documents
  59. <input name="documents" type="file" multiple>
  60. </label>
  61. <h2>Exercises</h2>
  62. <button id="exerciseButton" type="button">Add Exercise</button>
  63. <div id="exercises">
  64. <label>Exercise 1<input type="text"></label>
  65. </div>
  66. <input id="hidden" name="exercises" type="hidden">
  67. <input type="submit" value="Submit">
  68. </form>
  69. <script>
  70. //Get Available Courses
  71. fetch("/learn/courses")
  72. .then(response => response.json())
  73. .then((response)=>{
  74. let select = document.getElementById("course");
  75. for(let i = 0; i < response.length; i++){
  76. let option = document.createElement("option");
  77. option.innerText = response[i].title;
  78. option.value = response[i]._id;
  79. select.appendChild(option);
  80. }
  81. })
  82. .catch((err)=>{});
  83. //Add exercises
  84. let count = 1;
  85. let div = document.getElementById("exercises");
  86. document.getElementById("exerciseButton").onclick = ()=>{
  87. count++;
  88. let label = document.createElement("label");
  89. label.innerText = `Exercise ${count}`;
  90. div.appendChild(label);
  91. let input = document.createElement("input");
  92. input.type = "text";
  93. label.appendChild(input);
  94. }
  95. //Submit
  96. let form = document.getElementById("form");
  97. form.onsubmit = ()=>{
  98. event.preventDefault();
  99. let exercises = "";
  100. for(let i = 0; i < div.children.length; i++){
  101. exercises += `${div.children[i].children[0].value}~`;
  102. }
  103. document.getElementById("hidden").value = exercises;
  104. form.submit();
  105. }
  106. </script>
  107. </body>
  108. </html>