diff src/thread.html.luan @ 34:c8d47981c74f

upload using ajax
author Franklin Schmidt <fschmidt@gmail.com>
date Tue, 02 Aug 2022 20:46:02 -0600
parents 4fdc4ec0050b
children 1ce75c5ab0f7
line wrap: on
line diff
--- a/src/thread.html.luan	Mon Aug 01 22:50:16 2022 -0600
+++ b/src/thread.html.luan	Tue Aug 02 20:46:02 2022 -0600
@@ -9,7 +9,6 @@
 local head = Shared.head or error()
 local header = Shared.header or error()
 local footer = Shared.footer or error()
-local get_url_from_file = Shared.get_url_from_file or error()
 local Forum = require "site:/lib/Forum.luan"
 local forum_title = Forum.title or error()
 local Db = require "site:/lib/Db.luan"
@@ -82,14 +81,17 @@
 				let post = postDiv.getAttribute('post');
 				let text = postDiv.querySelector('textarea').value;
 				let postData = 'post=' + post + '&text=' + encodeURIComponent(text);
-				ajax("save_edit.js",postData);
+				ajax('save_edit.js',postData);
 			}
 
-			function upload(input) {
-				let postDiv = getPostDiv(input);
-				let post = postDiv.getAttribute('post');
-				let file = input.files[0];
-				ajax("/upload_bbcode.js?post="+post,file);
+			function gotFile(input) {
+				function uploaded(url,filename) {
+					let postDiv = getPostDiv(input);
+					let textarea = postDiv.querySelector('textarea');
+					textarea.focus();
+					textarea.setRangeText(url,textarea.selectionStart,textarea.selectionEnd,'select');
+				}
+				upload(input,uploaded);
 			}
 
 			function deletePost(span) {
@@ -150,10 +152,8 @@
 		<div hidden edit>
 			<textarea></textarea>
 			<p>
-				<label clickable
-					><input type=file onchange="upload(this)"
-					><span inline_button>upload</span>
-				</label>
+				<input type=file onchange="gotFile(this)">
+				<button onclick="fileButtonClick(this)">Upload File</button>
 				<button onclick="saveEdit(this)">save</button>
 				<button onclick="cancelEdit(this)">cancel</button>
 			</p>