Mercurial Hosting > lang
changeset 53:6c78fd83518f
add delete course
author | Franklin Schmidt <fschmidt@gmail.com> |
---|---|
date | Sun, 17 Aug 2025 16:59:37 +0900 |
parents | 27758f3b2d69 |
children | 16e5c14eb800 |
files | courses/j1.txt src/course.js src/delete_course.js.luan src/lib/Course.luan src/view_course.html.luan |
diffstat | 5 files changed, 47 insertions(+), 1 deletions(-) [+] |
line wrap: on
line diff
--- a/courses/j1.txt Sat Aug 16 09:56:10 2025 +0900 +++ b/courses/j1.txt Sun Aug 17 16:59:37 2025 +0900 @@ -1,4 +1,4 @@ -j1 +Beginner Listening # CRITICAL RULES - CHECK EVERY RESPONSE
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/course.js Sun Aug 17 16:59:37 2025 +0900 @@ -0,0 +1,11 @@ +'use strict'; + +function deleteCourse() { + let dialog = document.querySelector('dialog[delete]'); + dialog.showModal(); +} + +function doDeleteCourse(el,courseId) { + closeModal(el); + ajax(`delete_course.js?course=${courseId}`); +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/delete_course.js.luan Sun Aug 17 16:59:37 2025 +0900 @@ -0,0 +1,20 @@ +local Luan = require "luan:Luan.luan" +local error = Luan.error +local Io = require "luan:Io.luan" +local Http = require "luan:http/Http.luan" +local User = require "site:/lib/User.luan" +local current_user = User.current or error() +local Course = require "site:/lib/Course.luan" +local get_course_by_id = Course.get_by_id or error() + + +return function() + local course = Http.request.parameters.course or error() + course = get_course_by_id(course) or error() + course.user_id == current_user().id or error() + course.delete() + Io.stdout = Http.response.text_writer() +%> + location = '/your_courses.html'; +<% +end
--- a/src/lib/Course.luan Sat Aug 16 09:56:10 2025 +0900 +++ b/src/lib/Course.luan Sun Aug 17 16:59:37 2025 +0900 @@ -50,6 +50,10 @@ course.id = doc.id end + function course.delete() + Db.delete("id:"..course.id) + end + function course.name_html() return html_encode(course.name) end
--- a/src/view_course.html.luan Sat Aug 16 09:56:10 2025 +0900 +++ b/src/view_course.html.luan Sun Aug 17 16:59:37 2025 +0900 @@ -7,6 +7,7 @@ local Shared = require "site:/lib/Shared.luan" local head = Shared.head or error() local header = Shared.header or error() +local started = Shared.started or error() local Course = require "site:/lib/Course.luan" local get_course_by_id = Course.get_by_id or error() local User = require "site:/lib/User.luan" @@ -30,6 +31,7 @@ margin-bottom: 4px; } </style> + <script src="/course.js?s=<%=started%>"></script> </head> <body> <% header() %> @@ -48,6 +50,7 @@ <a href="new_chat.red?course=<%=course.id%>">New chat</a> <% if is_owner then %> - <a href="edit_course.html?course=<%=course.id%>">Edit</a> + - <a href="javascript:deleteCourse()">Delete</a> <% end %> </p> @@ -63,6 +66,14 @@ <pre><%=html_encode(course.tts_instructions)%></pre> </div> + <dialog delete> + <h2>Delete Course</h2> + <p>Are you sure that you want to delete this course?</p> + <div buttons> + <button onclick="closeModal(this)">Cancel</button> + <button onclick="doDeleteCourse(this,<%=course_id%>)">Delete</button> + </div> + </dialog> </body> </html> <%