]> code.citadel.org Git - citadel.git/blobdiff - webcit-ng/static/js/view_forum.js
Revert previous commit because it didn't work. Furthermore, remove the content-lengt...
[citadel.git] / webcit-ng / static / js / view_forum.js
index 464e59a4a69090730a1f2a1a347fce1c47b9e000..56b6a589b1e100fa73b3bdc8704d40170ff0cb63 100644 (file)
@@ -216,8 +216,8 @@ function open_reply_box(prefix, msgnum, is_quoted) {
          "</div><br>"                                                  // end header
 
 
-       + "<div class=\"ctdl-msg-body\" style=\"height:30vh;\">"        // begin body
-       + "This is where the reply text will go."
+       + "<div class=\"ctdl-msg-body\" id=\"ctdl-editor-body\" style=\"padding:5px;\" contenteditable=\"true\">"       // begin body
+       + "\n"                                                          // empty initial content
        + "</div>"                                                      // end body
 
 
@@ -227,23 +227,18 @@ function open_reply_box(prefix, msgnum, is_quoted) {
        + "</span>"                                                     // end footer info on left side
        + "<span class=\"ctdl-msg-header-buttons\">"                    // begin buttons on right side
 
-       + "<span class=\"ctdl-msg-button\"><a href=\"#\">"              // FIXME save and cancel buttons
-       + "<i class=\"fa fa-trash\"></i> " 
+       + "<span class=\"ctdl-msg-button\"><a href=\"javascript:save_message('" +  new_div_name + "', '" + msgnum + "');\">"
+       + "<i class=\"fa fa-check\" style=\"color:green\"></i> "        // save button
        + _("Post message")
        + "</a></span>"
 
-       + "<span class=\"ctdl-msg-button\"><a href=\"#\">"              // FIXME save and cancel buttons
-       + "<i class=\"fa fa-trash\"></i> " 
+       + "<span class=\"ctdl-msg-button\"><a href=\"javascript:cancel_post('" +  new_div_name + "');\">"
+       + "<i class=\"fa fa-trash\" style=\"color:red\"></i> "          // cancel button
        + _("Cancel")
        + "</a></span>"
 
-       + "</span>";                                                    // end buttons on right side
-       if (msg.subj) {
-               replybox +=
-               "<br><span class=\"ctdl-msgsubject\">" + "FIXME subject" + "</span>";
-       }
-       replybox +=
-         "</div><br>"                                                  // end footer
+       + "</span>"                                                     // end buttons on right side
+       + "</div><br>"                                                  // end footer
 
 
        + "</div>"                                                      // end content
@@ -252,4 +247,44 @@ function open_reply_box(prefix, msgnum, is_quoted) {
 
        document.getElementById(new_div_name).innerHTML = replybox;
        document.getElementById(new_div_name).scrollIntoView({behavior: "smooth", block: "end", inline: "nearest"});
+
+       // These actions must happen *after* the initial render loop completes.
+       setTimeout(function() {
+               var tag = document.getElementById("ctdl-editor-body");
+               tag.focus();                                            // sets the focus
+               window.getSelection().collapse(tag.firstChild, 0);      // positions the cursor
+       }, 0);
+}
+
+
+// Abort a message post (it simply destroys the div)
+function cancel_post(div_name) {
+       document.getElementById(div_name).outerHTML = "";               // make it cease to exist
+}
+
+
+// Save the posted message to the server
+function save_message(div_name, reply_to_msgnum) {
+       msg_text = "<html><body>" + document.getElementById("ctdl-editor-body").innerHTML + "</body></html>\n";
+       url = "/ctdl/r/" + escapeHTMLURI(current_room) + "/dummy_name_for_new_message";
+
+       var request = new XMLHttpRequest();
+       request.open("PUT", url, true);
+       request.setRequestHeader("Content-type", "text/html");
+       request.onreadystatechange = function() {
+               if (request.readyState == 4) {
+                       if (Math.trunc(request.status / 100) == 2) {
+                               alert("headers: " + request.getAllResponseHeaders());
+                               document.getElementById(div_name).outerHTML = "";               // close the editor
+                       }
+                       else {
+                               error_message = request.responseText;
+                               if (error_message.length == 0) {
+                                       error_message = _("An error has occurred.");
+                               }
+                               alert(error_message);                                           // FIXME make this pretty
+                       }
+               }
+       };
+       request.send(msg_text);
 }