annotate src/index.html.luan @ 65:6cfef9850520

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