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