newLecture.html 5.0 KB

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