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. <link rel="icon" type="img/ico" href="/images/favicon">
  7. <style>
  8. form{
  9. display: flex;
  10. flex-direction: column;
  11. }
  12. form > *{
  13. margin: 10px 0;
  14. }
  15. input[type=submit]{
  16. max-width: 250px;
  17. }
  18. button{
  19. max-width: 250px;
  20. }
  21. #exercises, #furtherReading{
  22. display: flex;
  23. flex-direction: column;
  24. }
  25. #exercises > *{
  26. margin: 10px 0;
  27. }
  28. #exercises input{
  29. margin-left: 5px;
  30. }
  31. </style>
  32. </head>
  33. <body>
  34. <h1>Create New Lecture</h1>
  35. <form
  36. id="form"
  37. action="/learn/lectures/new"
  38. method="post"
  39. encType="multipart/form-data"
  40. >
  41. <label>Uploader ID
  42. <input name="uploader" type="text" required>
  43. </label>
  44. <label>Uploader Password
  45. <input name="password" type="password" required>
  46. </label>
  47. <label>Course
  48. <select id="course" name="course" required></select>
  49. </label>
  50. <label>Title
  51. <input name="title" type="text" required>
  52. </label>
  53. <label>Video Link
  54. <input name="video" type="text" required>
  55. </label>
  56. <label>Description
  57. <textarea name="description" required></textarea>
  58. </label>
  59. <label>Documents
  60. <input name="documents" type="file" multiple>
  61. </label>
  62. <h2>Exercises</h2>
  63. <button id="exerciseButton" type="button">Add Exercise</button>
  64. <div id="exercises"></div>
  65. <h2>Further Reading</h2>
  66. <button id="furtherButton" type="button">Add Link</button>
  67. <div id="furtherReading"></div>
  68. <input id="hidden" name="exercises" type="hidden">
  69. <input id="readingsHidden" name="furtherReading" type="hidden">
  70. <input id="date" name="date" 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 = 0;
  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("textarea");
  96. label.appendChild(input);
  97. }
  98. //Add further reading
  99. let furtherCount = 0;
  100. let furtherDiv = document.getElementById("furtherReading");
  101. document.getElementById("furtherButton").onclick = ()=>{
  102. furtherCount++;
  103. let label = document.createElement("label");
  104. label.innerText = `Link ${furtherCount}`;
  105. furtherDiv.appendChild(label);
  106. let inputText = document.createElement("input");
  107. inputText.type = "text";
  108. label.appendChild(inputText);
  109. let inputLink = document.createElement("input");
  110. inputLink.type = "text";
  111. label.appendChild(inputLink);
  112. }
  113. //Submit
  114. let form = document.getElementById("form");
  115. form.onsubmit = ()=>{
  116. event.preventDefault();
  117. let exercises = "";
  118. for(let i = 0; i < div.children.length; i++){
  119. exercises += `${div.children[i].children[0].value}\n`;
  120. }
  121. let readings = ""
  122. for(let i = 0; i < furtherDiv.children.length; i++){
  123. readings += `${furtherDiv.children[i].children[0].value}\n${furtherDiv.children[i].children[1].value}\n`;
  124. }
  125. document.getElementById("hidden").value = exercises;
  126. document.getElementById("readingsHidden").value = readings;
  127. document.getElementById("date").value = new Date();
  128. form.submit();
  129. }
  130. </script>
  131. </body>
  132. </html>