Starting to pull some rendering out of the C code and put it back in JS
[citadel.git] / webcit-ng / static / js / views.js
index 3df8843153a9944bb78130de89f6bcd6e72e96b0..cf975ba0417442e0bb57fa609ccbc8d753cd14dc 100644 (file)
@@ -1,5 +1,5 @@
 //
-// Copyright (c) 2016-2017 by the citadel.org team
+// Copyright (c) 2016-2018 by the citadel.org team
 //
 // This program is open source software; you can redistribute it and/or modify
 // it under the terms of the GNU General Public License version 3.
@@ -32,9 +32,10 @@ var views = {
 // This function is the dispatcher that determines the correct view for a room,
 // and calls the correct renderer.
 //
-function render_room_view() {
-
-       switch(current_view) {
+function render_room_view()
+{
+       switch(current_view)
+       {
                case views.VIEW_MAILBOX:                                                // FIXME view mail rooms as forums for now
                case views.VIEW_BBS:
                        forum_readmessages("flat");
@@ -51,18 +52,25 @@ function render_room_view() {
 // The inner div exists so that if the user clicks away early, the main div doesn't get clobbered when the load completes.
 // The parameter can be set to "flat" or "threads" which is passed directly to the API
 //
-function forum_readmessages(flat_or_threads) {
+function XX_forum_readmessages(flat_or_threads)
+{
        var innerdivname = randomString(5);
-       document.getElementById("main").innerHTML = "<div id=\"" + innerdivname + "\"><img src=\"/ctdl/s/throbber.gif\" />" + _("Loading messages from server, please wait") + "</div>" ;
+       document.getElementById("main").innerHTML = "<div id=\"" + innerdivname +
+               "\"><br><br><br><center><h5><i class=\"fas fa-spinner fa-spin\"></i>&nbsp;&nbsp;"
+               + _("Loading messages from server, please wait") + "</h5></center></div>" ;
 
        var request = new XMLHttpRequest();
        request.open("GET", "/ctdl/r/" + escapeHTMLURI(current_room) + "/" + flat_or_threads, true);
-       request.onreadystatechange = function() {
-               if (this.readyState === 4) {
-                       if ((this.status / 100) == 2) {
+       request.onreadystatechange = function()
+       {
+               if (this.readyState === 4)
+               {
+                       if ((this.status / 100) == 2)
+                       {
                                document.getElementById(innerdivname).outerHTML = this.responseText;
                        }
-                       else {
+                       else
+                       {
                                document.getElementById(innerdivname).outerHTML = "ERROR " + this.status ;
                        }
                }
@@ -70,3 +78,39 @@ function forum_readmessages(flat_or_threads) {
        request.send();
        request = null;
 }
+
+
+// Forum view -- let's have another go at this with the rendering done client-side
+//
+function forum_readmessages(flat_or_threads)
+{
+       var innerdivname = randomString(5);
+       document.getElementById("main").innerHTML = "<div id=\"" + innerdivname +
+               "\"><br><br><br><center><h5><i class=\"fas fa-spinner fa-spin\"></i>&nbsp;&nbsp;"
+               + _("Loading messages from server, please wait") + "</h5></center></div>" ;
+
+       var request = new XMLHttpRequest();
+       request.open("GET", "/ctdl/r/" + escapeHTMLURI(current_room) + "/msgs.all", true);
+       request.onreadystatechange = function()
+       {
+               if (this.readyState === 4)
+               {
+                       if ((this.status / 100) == 2)
+                       {
+                               document.getElementById(innerdivname).innerHTML = "Are we logged in? " + logged_in + "<ul>" ;
+                               msgs = JSON.parse(this.responseText);
+                               for (var i in msgs)
+                               {
+                                       document.getElementById(innerdivname).innerHTML += "<li>" + msgs[i] + "</li>" ;
+                               }
+                               document.getElementById(innerdivname).innerHTML += "</ul>" ;
+                       }
+                       else
+                       {
+                               document.getElementById(innerdivname).innerHTML = this.status ;         // error message
+                       }
+               }
+       };
+       request.send();
+       request = null;
+}