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 = ""
|
69
|
33 stt_prompt = ""
|
24
|
34 }
|
|
35 end
|
|
36 Io.stdout = Http.response.text_writer()
|
|
37 %>
|
|
38 <!doctype html>
|
|
39 <html lang="en">
|
|
40 <head>
|
|
41 <% head() %>
|
|
42 <style>
|
52
|
43 input[type=text],
|
24
|
44 textarea {
|
|
45 display: block;
|
27
|
46 width: 100%;
|
|
47 }
|
25
|
48 h4 {
|
|
49 margin-top: 22px;
|
|
50 margin-bottom: 4px;
|
|
51 }
|
|
52 input[type=submit] {
|
|
53 margin-top: 22px;
|
27
|
54 margin-bottom: 22px;
|
25
|
55 }
|
24
|
56 </style>
|
|
57 </head>
|
|
58 <body>
|
|
59 <% header() %>
|
|
60 <form content onsubmit="ajaxForm('/save_course.js',this)" action="javascript:">
|
25
|
61 <input type=hidden name=language value="<%=course.language%>">
|
24
|
62 <% if course_id ~= nil then %>
|
25
|
63 <input type=hidden name=course value="<%=course_id%>">
|
24
|
64 <% end %>
|
25
|
65 <h1>Edit Course</h1>
|
|
66 <h3><%= course.language_name() %></h3>
|
|
67
|
|
68 <h4>Course name</h4>
|
27
|
69 <input type=text required name=name value="<%=html_encode(course.name)%>">
|
25
|
70
|
67
|
71 <h4>Description</h4>
|
68
|
72 <textarea name=description oninput="fixTextarea(event.target)"><%=html_encode(course.description)%></textarea>
|
67
|
73
|
|
74 <br>
|
|
75
|
52
|
76 <p><label clickable><input type=checkbox name=has_ruby <%= course.has_ruby and "checked" or "" %> > Has pronunciation like {japanese|romaji}</label></p>
|
|
77
|
60
|
78 <h4>AI system prompt - chat instructions</h4>
|
42
|
79 <textarea required name=ai_system_prompt oninput="fixTextarea(event.target)"><%=html_encode(course.ai_system_prompt)%></textarea>
|
25
|
80
|
|
81 <h4>AI first message (optional)</h4>
|
52
|
82 <textarea name=ai_first_message oninput="fixTextarea(event.target)"><%=html_encode(course.ai_first_message)%></textarea>
|
25
|
83
|
46
|
84 <h4>Text to speech instructions</h4>
|
52
|
85 <textarea name=tts_instructions oninput="fixTextarea(event.target)"><%=html_encode(course.tts_instructions)%></textarea>
|
46
|
86
|
69
|
87 <h4>Speech to text prompt</h4>
|
|
88 <textarea name=stt_prompt oninput="fixTextarea(event.target)"><%=html_encode(course.stt_prompt)%></textarea>
|
|
89
|
25
|
90 <input type=submit>
|
27
|
91
|
|
92 <hr>
|
|
93
|
|
94 <p>Text areas take <a href="/tools/markdown.html">Markdown</a>. AI generally recognizes Markdown.</p>
|
24
|
95 </form>
|
42
|
96 <script>
|
|
97 'use strict';
|
|
98 let textareas = document.querySelectorAll('textarea');
|
|
99 for( let textarea of textareas ) {
|
|
100 fixTextarea(textarea);
|
|
101 }
|
48
|
102 scrollToTop();
|
42
|
103 </script>
|
24
|
104 </body>
|
|
105 </html>
|
|
106 <%
|
|
107 end
|