newLecture.html 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  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, #furtherReading{
  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/lectures/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 Link
  53. <input name="video" type="text" required>
  54. </label>
  55. <label>Description
  56. <textarea name="description" required></textarea>
  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"></div>
  64. <h2>Further Reading</h2>
  65. <button id="furtherButton" type="button">Add Link</button>
  66. <div id="furtherReading"></div>
  67. <input id="hidden" name="exercises" type="hidden">
  68. <input id="readingsHidden" name="furtherReading" type="hidden">
  69. <input id="date" name="date" type="hidden">
  70. <input type="submit" value="Submit">
  71. </form>
  72. <script>
  73. //Get Available Courses
  74. fetch("/learn/courses/json")
  75. .then(response => response.json())
  76. .then((response)=>{
  77. let select = document.getElementById("course");
  78. for(let i = 0; i < response.length; i++){
  79. let option = document.createElement("option");
  80. option.innerText = response[i].title;
  81. option.value = response[i]._id;
  82. select.appendChild(option);
  83. }
  84. })
  85. .catch((err)=>{});
  86. //Add exercises
  87. let count = 0;
  88. let div = document.getElementById("exercises");
  89. document.getElementById("exerciseButton").onclick = ()=>{
  90. count++;
  91. let label = document.createElement("label");
  92. label.innerText = `Exercise ${count}`;
  93. div.appendChild(label);
  94. let input = document.createElement("textarea");
  95. label.appendChild(input);
  96. }
  97. //Add further reading
  98. let furtherCount = 0;
  99. let furtherDiv = document.getElementById("furtherReading");
  100. document.getElementById("furtherButton").onclick = ()=>{
  101. furtherCount++;
  102. let label = document.createElement("label");
  103. label.innerText = `Link ${furtherCount}`;
  104. furtherDiv.appendChild(label);
  105. let inputText = document.createElement("input");
  106. inputText.type = "text";
  107. label.appendChild(inputText);
  108. let inputLink = document.createElement("input");
  109. inputLink.type = "text";
  110. label.appendChild(inputLink);
  111. }
  112. //Submit
  113. let form = document.getElementById("form");
  114. form.onsubmit = ()=>{
  115. event.preventDefault();
  116. let exercises = "";
  117. for(let i = 0; i < div.children.length; i++){
  118. exercises += `${div.children[i].children[0].value}\n`;
  119. }
  120. let readings = ""
  121. for(let i = 0; i < furtherDiv.children.length; i++){
  122. readings += `${furtherDiv.children[i].children[0].value}\n${furtherDiv.children[i].children[1].value}\n`;
  123. }
  124. document.getElementById("hidden").value = exercises;
  125. document.getElementById("readingsHidden").value = readings;
  126. document.getElementById("date").value = new Date();
  127. form.submit();
  128. }
  129. </script>
  130. </body>
  131. </html>