annotate src/index.html.luan @ 63:afd5ab5b02a2

file upload
author Franklin Schmidt <fschmidt@gmail.com>
date Wed, 05 Mar 2025 18:43:06 -0700
parents 3521166513b3
children 6cfef9850520
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
1 local Luan = require "luan:Luan.luan"
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
2 local error = Luan.error
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
3 local Io = require "luan:Io.luan"
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
4 local Http = require "luan:http/Http.luan"
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
5 local Shared = require "site:/lib/Shared.luan"
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
6 local head = Shared.head or error()
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
7 local header = Shared.header or error()
10
f9e6a4cc4f7d add Post
Franklin Schmidt <fschmidt@gmail.com>
parents: 9
diff changeset
8 local started = Shared.started or error()
15
8b8905f63d80 add get_chats
Franklin Schmidt <fschmidt@gmail.com>
parents: 10
diff changeset
9 local chats_html = Shared.chats_html or error()
4
2da10ece826f add Chat
Franklin Schmidt <fschmidt@gmail.com>
parents: 3
diff changeset
10 local User = require "site:/lib/User.luan"
5
a49866b52cc2 login to chat
Franklin Schmidt <fschmidt@gmail.com>
parents: 4
diff changeset
11 local current_user = User.current or error()
4
2da10ece826f add Chat
Franklin Schmidt <fschmidt@gmail.com>
parents: 3
diff changeset
12 local Chat = require "site:/lib/Chat.luan"
59
8270106644db add chat.luan
Franklin Schmidt <fschmidt@gmail.com>
parents: 58
diff changeset
13 local get_chat_by_id = Chat.get_by_id or error()
8
Franklin Schmidt <fschmidt@gmail.com>
parents: 7
diff changeset
14 local Logging = require "luan:logging/Logging.luan"
21
5a56297713a3 move chat to home
Franklin Schmidt <fschmidt@gmail.com>
parents: 20
diff changeset
15 local logger = Logging.logger "index.html"
0
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
16
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
17
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
18 return function()
4
2da10ece826f add Chat
Franklin Schmidt <fschmidt@gmail.com>
parents: 3
diff changeset
19 local user = current_user()
2da10ece826f add Chat
Franklin Schmidt <fschmidt@gmail.com>
parents: 3
diff changeset
20 if user == nil then
59
8270106644db add chat.luan
Franklin Schmidt <fschmidt@gmail.com>
parents: 58
diff changeset
21 Http.response.send_redirect("/login.html")
4
2da10ece826f add Chat
Franklin Schmidt <fschmidt@gmail.com>
parents: 3
diff changeset
22 return
2da10ece826f add Chat
Franklin Schmidt <fschmidt@gmail.com>
parents: 3
diff changeset
23 end
59
8270106644db add chat.luan
Franklin Schmidt <fschmidt@gmail.com>
parents: 58
diff changeset
24 local user_id = user.id
8270106644db add chat.luan
Franklin Schmidt <fschmidt@gmail.com>
parents: 58
diff changeset
25 local chat = Http.request.parameters.chat
8
Franklin Schmidt <fschmidt@gmail.com>
parents: 7
diff changeset
26 local selected = nil
59
8270106644db add chat.luan
Franklin Schmidt <fschmidt@gmail.com>
parents: 58
diff changeset
27 if chat ~= nil then
8270106644db add chat.luan
Franklin Schmidt <fschmidt@gmail.com>
parents: 58
diff changeset
28 selected = get_chat_by_id(chat)
4
2da10ece826f add Chat
Franklin Schmidt <fschmidt@gmail.com>
parents: 3
diff changeset
29 end
0
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
30 Io.stdout = Http.response.text_writer()
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
31 %>
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
32 <!doctype html>
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
33 <html>
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
34 <head>
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
35 <% head() %>
7
41d35b72c774 chat page
Franklin Schmidt <fschmidt@gmail.com>
parents: 5
diff changeset
36 <style>
10
f9e6a4cc4f7d add Post
Franklin Schmidt <fschmidt@gmail.com>
parents: 9
diff changeset
37 @import "chat.css?s=<%=started%>";
7
41d35b72c774 chat page
Franklin Schmidt <fschmidt@gmail.com>
parents: 5
diff changeset
38 </style>
33
e2b7f6393dab add online
Franklin Schmidt <fschmidt@gmail.com>
parents: 30
diff changeset
39 <style online></style>
10
f9e6a4cc4f7d add Post
Franklin Schmidt <fschmidt@gmail.com>
parents: 9
diff changeset
40 <script src="chat.js?s=<%=started%>"></script>
0
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
41 </head>
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
42 <body>
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
43 <% header() %>
60
3521166513b3 finish invite
Franklin Schmidt <fschmidt@gmail.com>
parents: 59
diff changeset
44 <div chat_content show="intro">
7
41d35b72c774 chat page
Franklin Schmidt <fschmidt@gmail.com>
parents: 5
diff changeset
45 <div chats>
15
8b8905f63d80 add get_chats
Franklin Schmidt <fschmidt@gmail.com>
parents: 10
diff changeset
46 <% chats_html() %>
7
41d35b72c774 chat page
Franklin Schmidt <fschmidt@gmail.com>
parents: 5
diff changeset
47 </div>
60
3521166513b3 finish invite
Franklin Schmidt <fschmidt@gmail.com>
parents: 59
diff changeset
48 <div intro>
3521166513b3 finish invite
Franklin Schmidt <fschmidt@gmail.com>
parents: 59
diff changeset
49 <h3 or>Choose a chat on the left</h3>
3521166513b3 finish invite
Franklin Schmidt <fschmidt@gmail.com>
parents: 59
diff changeset
50 <p or>or</p>
3521166513b3 finish invite
Franklin Schmidt <fschmidt@gmail.com>
parents: 59
diff changeset
51 <h3>Chat with another person</h3>
3521166513b3 finish invite
Franklin Schmidt <fschmidt@gmail.com>
parents: 59
diff changeset
52 <form action="javascript:invite()">
3521166513b3 finish invite
Franklin Schmidt <fschmidt@gmail.com>
parents: 59
diff changeset
53 <p>
3521166513b3 finish invite
Franklin Schmidt <fschmidt@gmail.com>
parents: 59
diff changeset
54 <label>Person's email</label><br>
3521166513b3 finish invite
Franklin Schmidt <fschmidt@gmail.com>
parents: 59
diff changeset
55 <input type=email name=email required><br>
3521166513b3 finish invite
Franklin Schmidt <fschmidt@gmail.com>
parents: 59
diff changeset
56 </p>
3521166513b3 finish invite
Franklin Schmidt <fschmidt@gmail.com>
parents: 59
diff changeset
57 <p>
3521166513b3 finish invite
Franklin Schmidt <fschmidt@gmail.com>
parents: 59
diff changeset
58 <input type=submit>
3521166513b3 finish invite
Franklin Schmidt <fschmidt@gmail.com>
parents: 59
diff changeset
59 </p>
3521166513b3 finish invite
Franklin Schmidt <fschmidt@gmail.com>
parents: 59
diff changeset
60 </form>
34
Franklin Schmidt <fschmidt@gmail.com>
parents: 33
diff changeset
61 </div>
60
3521166513b3 finish invite
Franklin Schmidt <fschmidt@gmail.com>
parents: 59
diff changeset
62 <div posts></div>
0
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
63 </div>
35
27c41f22d2a9 improve fixPosts
Franklin Schmidt <fschmidt@gmail.com>
parents: 34
diff changeset
64 <div hidden>
27c41f22d2a9 improve fixPosts
Franklin Schmidt <fschmidt@gmail.com>
parents: 34
diff changeset
65 <span pulldown>
27c41f22d2a9 improve fixPosts
Franklin Schmidt <fschmidt@gmail.com>
parents: 34
diff changeset
66 <img onclick="clickMenu(this)" src="/images/more_vert.svg">
27c41f22d2a9 improve fixPosts
Franklin Schmidt <fschmidt@gmail.com>
parents: 34
diff changeset
67 <div>
38
436216d17a1b fix edit and delete
Franklin Schmidt <fschmidt@gmail.com>
parents: 35
diff changeset
68 <span onclick="editPost(this)">Edit</span>
436216d17a1b fix edit and delete
Franklin Schmidt <fschmidt@gmail.com>
parents: 35
diff changeset
69 <span onclick="deletePost(this)">Delete</span>
35
27c41f22d2a9 improve fixPosts
Franklin Schmidt <fschmidt@gmail.com>
parents: 34
diff changeset
70 </div>
27c41f22d2a9 improve fixPosts
Franklin Schmidt <fschmidt@gmail.com>
parents: 34
diff changeset
71 </span>
27c41f22d2a9 improve fixPosts
Franklin Schmidt <fschmidt@gmail.com>
parents: 34
diff changeset
72 </div>
20
dade6a560494 add dialogs
Franklin Schmidt <fschmidt@gmail.com>
parents: 17
diff changeset
73 <dialog delete_chat>
dade6a560494 add dialogs
Franklin Schmidt <fschmidt@gmail.com>
parents: 17
diff changeset
74 <h2>Delete Chat</h2>
dade6a560494 add dialogs
Franklin Schmidt <fschmidt@gmail.com>
parents: 17
diff changeset
75 <p>Are you sure that you want to delete this chat?</p>
dade6a560494 add dialogs
Franklin Schmidt <fschmidt@gmail.com>
parents: 17
diff changeset
76 <div buttons>
60
3521166513b3 finish invite
Franklin Schmidt <fschmidt@gmail.com>
parents: 59
diff changeset
77 <button onclick="closeModal(this)">Cancel</button>
3521166513b3 finish invite
Franklin Schmidt <fschmidt@gmail.com>
parents: 59
diff changeset
78 <button onclick="doDeleteChat(this)">Delete</button>
20
dade6a560494 add dialogs
Franklin Schmidt <fschmidt@gmail.com>
parents: 17
diff changeset
79 </div>
dade6a560494 add dialogs
Franklin Schmidt <fschmidt@gmail.com>
parents: 17
diff changeset
80 </dialog>
23
c54c806fcc6e add delete_post
Franklin Schmidt <fschmidt@gmail.com>
parents: 21
diff changeset
81 <dialog delete_post>
c54c806fcc6e add delete_post
Franklin Schmidt <fschmidt@gmail.com>
parents: 21
diff changeset
82 <h2>Delete Message</h2>
c54c806fcc6e add delete_post
Franklin Schmidt <fschmidt@gmail.com>
parents: 21
diff changeset
83 <p>Are you sure that you want to delete this message?</p>
c54c806fcc6e add delete_post
Franklin Schmidt <fschmidt@gmail.com>
parents: 21
diff changeset
84 <div buttons>
60
3521166513b3 finish invite
Franklin Schmidt <fschmidt@gmail.com>
parents: 59
diff changeset
85 <button onclick="closeModal(this)">Cancel</button>
3521166513b3 finish invite
Franklin Schmidt <fschmidt@gmail.com>
parents: 59
diff changeset
86 <button onclick="doDeletePost(this)">Delete</button>
23
c54c806fcc6e add delete_post
Franklin Schmidt <fschmidt@gmail.com>
parents: 21
diff changeset
87 </div>
c54c806fcc6e add delete_post
Franklin Schmidt <fschmidt@gmail.com>
parents: 21
diff changeset
88 </dialog>
24
af41be2dcdec add edit_post
Franklin Schmidt <fschmidt@gmail.com>
parents: 23
diff changeset
89 <dialog edit_post>
af41be2dcdec add edit_post
Franklin Schmidt <fschmidt@gmail.com>
parents: 23
diff changeset
90 <h2>Edit Message</h2>
af41be2dcdec add edit_post
Franklin Schmidt <fschmidt@gmail.com>
parents: 23
diff changeset
91 <p><textarea onfocus="fixTextarea(event)" oninput="fixTextarea(event)"></textarea></p>
af41be2dcdec add edit_post
Franklin Schmidt <fschmidt@gmail.com>
parents: 23
diff changeset
92 <div buttons>
60
3521166513b3 finish invite
Franklin Schmidt <fschmidt@gmail.com>
parents: 59
diff changeset
93 <button onclick="closeModal(this)">Cancel</button>
3521166513b3 finish invite
Franklin Schmidt <fschmidt@gmail.com>
parents: 59
diff changeset
94 <button onclick="savePost(this)">Save</button>
24
af41be2dcdec add edit_post
Franklin Schmidt <fschmidt@gmail.com>
parents: 23
diff changeset
95 </div>
af41be2dcdec add edit_post
Franklin Schmidt <fschmidt@gmail.com>
parents: 23
diff changeset
96 </dialog>
56
323ddacc1593 start invite
Franklin Schmidt <fschmidt@gmail.com>
parents: 48
diff changeset
97 <dialog invite>
323ddacc1593 start invite
Franklin Schmidt <fschmidt@gmail.com>
parents: 48
diff changeset
98 <h2>Chat with another person</h2>
323ddacc1593 start invite
Franklin Schmidt <fschmidt@gmail.com>
parents: 48
diff changeset
99 <p>We have sent an invite to <span email></span></p>
323ddacc1593 start invite
Franklin Schmidt <fschmidt@gmail.com>
parents: 48
diff changeset
100 <div buttons>
60
3521166513b3 finish invite
Franklin Schmidt <fschmidt@gmail.com>
parents: 59
diff changeset
101 <button onclick="gotoInvite(this)">Close</button>
56
323ddacc1593 start invite
Franklin Schmidt <fschmidt@gmail.com>
parents: 48
diff changeset
102 </div>
323ddacc1593 start invite
Franklin Schmidt <fschmidt@gmail.com>
parents: 48
diff changeset
103 </dialog>
63
afd5ab5b02a2 file upload
Franklin Schmidt <fschmidt@gmail.com>
parents: 60
diff changeset
104 <input type="file" required onchange="loadedFile(this)">
15
8b8905f63d80 add get_chats
Franklin Schmidt <fschmidt@gmail.com>
parents: 10
diff changeset
105 <script>
35
27c41f22d2a9 improve fixPosts
Franklin Schmidt <fschmidt@gmail.com>
parents: 34
diff changeset
106 'use strict';
27c41f22d2a9 improve fixPosts
Franklin Schmidt <fschmidt@gmail.com>
parents: 34
diff changeset
107
8
Franklin Schmidt <fschmidt@gmail.com>
parents: 7
diff changeset
108 <%
Franklin Schmidt <fschmidt@gmail.com>
parents: 7
diff changeset
109 if selected ~= nil then
Franklin Schmidt <fschmidt@gmail.com>
parents: 7
diff changeset
110 %>
59
8270106644db add chat.luan
Franklin Schmidt <fschmidt@gmail.com>
parents: 58
diff changeset
111 selectChat('<%=selected.id%>');
8
Franklin Schmidt <fschmidt@gmail.com>
parents: 7
diff changeset
112 <%
Franklin Schmidt <fschmidt@gmail.com>
parents: 7
diff changeset
113 end
Franklin Schmidt <fschmidt@gmail.com>
parents: 7
diff changeset
114 %>
35
27c41f22d2a9 improve fixPosts
Franklin Schmidt <fschmidt@gmail.com>
parents: 34
diff changeset
115 setUserEventSource(<%=user_id%>);
30
f4708943f29e add heartbeat
Franklin Schmidt <fschmidt@gmail.com>
parents: 27
diff changeset
116 lastUpdate = <%=user.last_update()%>;
35
27c41f22d2a9 improve fixPosts
Franklin Schmidt <fschmidt@gmail.com>
parents: 34
diff changeset
117 userId = '<%=user_id%>';
15
8b8905f63d80 add get_chats
Franklin Schmidt <fschmidt@gmail.com>
parents: 10
diff changeset
118 </script>
8b8905f63d80 add get_chats
Franklin Schmidt <fschmidt@gmail.com>
parents: 10
diff changeset
119 </body>
0
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
120 </html>
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
121 <%
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
122 end