24
|
1 local Luan = require "luan:Luan.luan"
|
|
2 local error = Luan.error
|
|
3 local Html = require "luan:Html.luan"
|
|
4 local html_encode = Html.encode or error()
|
|
5 local Io = require "luan:Io.luan"
|
|
6 local Http = require "luan:http/Http.luan"
|
|
7 local Shared = require "site:/lib/Shared.luan"
|
|
8 local head = Shared.head or error()
|
|
9 local header = Shared.header or error()
|
|
10 local User = require "site:/lib/User.luan"
|
|
11 local current_user = User.current_required or error()
|
|
12 local Course = require "site:/lib/Course.luan"
|
|
13 local get_course_by_id = Course.get_by_id or error()
|
|
14
|
|
15
|
|
16 return function()
|
|
17 local user = current_user()
|
|
18 if user == nil then return end
|
|
19 local course_id = Http.request.parameters.course
|
|
20 local course
|
|
21 if course_id ~= nil then
|
|
22 course = get_course_by_id(course_id) or error()
|
|
23 course.user_id == user.id or error()
|
|
24 else
|
|
25 course = Course.new{
|
|
26 language = Http.request.parameters.language or error()
|
|
27 name = ""
|
|
28 ai_system_prompt = ""
|
52
|
29 ai_first_message = ""
|
|
30 tts_instructions = ""
|
|
31 has_ruby = false
|
67
|
32 description = ""
|
24
|
33 }
|
|
34 end
|
|
35 Io.stdout = Http.response.text_writer()
|
|
36 %>
|
|
37 <!doctype html>
|
|
38 <html lang="en">
|
|
39 <head>
|
|
40 <% head() %>
|
|
41 <style>
|
52
|
42 input[type=text],
|
24
|
43 textarea {
|
|
44 display: block;
|
27
|
45 width: 100%;
|
|
46 }
|
25
|
47 h4 {
|
|
48 margin-top: 22px;
|
|
49 margin-bottom: 4px;
|
|
50 }
|
|
51 input[type=submit] {
|
|
52 margin-top: 22px;
|
27
|
53 margin-bottom: 22px;
|
25
|
54 }
|
24
|
55 </style>
|
|
56 </head>
|
|
57 <body>
|
|
58 <% header() %>
|
|
59 <form content onsubmit="ajaxForm('/save_course.js',this)" action="javascript:">
|
25
|
60 <input type=hidden name=language value="<%=course.language%>">
|
24
|
61 <% if course_id ~= nil then %>
|
25
|
62 <input type=hidden name=course value="<%=course_id%>">
|
24
|
63 <% end %>
|
25
|
64 <h1>Edit Course</h1>
|
|
65 <h3><%= course.language_name() %></h3>
|
|
66
|
|
67 <h4>Course name</h4>
|
27
|
68 <input type=text required name=name value="<%=html_encode(course.name)%>">
|
25
|
69
|
67
|
70 <h4>Description</h4>
|
|
71 <textarea required name=description oninput="fixTextarea(event.target)"><%=html_encode(course.description)%></textarea>
|
|
72
|
|
73 <br>
|
|
74
|
52
|
75 <p><label clickable><input type=checkbox name=has_ruby <%= course.has_ruby and "checked" or "" %> > Has pronunciation like {japanese|romaji}</label></p>
|
|
76
|
60
|
77 <h4>AI system prompt - chat instructions</h4>
|
42
|
78 <textarea required name=ai_system_prompt oninput="fixTextarea(event.target)"><%=html_encode(course.ai_system_prompt)%></textarea>
|
25
|
79
|
|
80 <h4>AI first message (optional)</h4>
|
52
|
81 <textarea name=ai_first_message oninput="fixTextarea(event.target)"><%=html_encode(course.ai_first_message)%></textarea>
|
25
|
82
|
46
|
83 <h4>Text to speech instructions</h4>
|
52
|
84 <textarea name=tts_instructions oninput="fixTextarea(event.target)"><%=html_encode(course.tts_instructions)%></textarea>
|
46
|
85
|
25
|
86 <input type=submit>
|
27
|
87
|
|
88 <hr>
|
|
89
|
|
90 <p>Text areas take <a href="/tools/markdown.html">Markdown</a>. AI generally recognizes Markdown.</p>
|
24
|
91 </form>
|
42
|
92 <script>
|
|
93 'use strict';
|
|
94 let textareas = document.querySelectorAll('textarea');
|
|
95 for( let textarea of textareas ) {
|
|
96 fixTextarea(textarea);
|
|
97 }
|
48
|
98 scrollToTop();
|
42
|
99 </script>
|
24
|
100 </body>
|
|
101 </html>
|
|
102 <%
|
|
103 end
|