X-Git-Url: https://code.citadel.org/?a=blobdiff_plain;f=webcit-ng%2Fstatic%2Fjs%2Fviews.js;h=7ad2a6b921600ef2d12cd44d3f4337bd75584b26;hb=d62e89645b97e92bfec2bc71995530ac732ebd63;hp=3df8843153a9944bb78130de89f6bcd6e72e96b0;hpb=a2e2b0eab5e29c1bd61ec21737d28d3cb70ee364;p=citadel.git
diff --git a/webcit-ng/static/js/views.js b/webcit-ng/static/js/views.js
index 3df884315..7ad2a6b92 100644
--- a/webcit-ng/static/js/views.js
+++ b/webcit-ng/static/js/views.js
@@ -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,38 +32,80 @@ 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(min_msg, max_msg)
+{
+ switch(current_view)
+ {
case views.VIEW_MAILBOX: // FIXME view mail rooms as forums for now
case views.VIEW_BBS:
- forum_readmessages("flat");
+ forum_readmessages("ctdl-main", min_msg, max_msg);
break;
default:
- document.getElementById("main").innerHTML = "The view for " + current_room + " is " + current_view + " but there is no renderer." ;
+ document.getElementById("ctdl-main").innerHTML = "The view for " + current_room + " is " + current_view + " but there is no renderer." ;
break;
}
}
-// Forum view -- flat or threaded
-// 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
+// Forum view (flat) -- let's have another go at this with the rendering done client-side
//
-function forum_readmessages(flat_or_threads) {
+function forum_readmessages(target_div, min_msg, max_msg)
+{
var innerdivname = randomString(5);
- document.getElementById("main").innerHTML = "
" + _("Loading messages from server, please wait") + "
" ;
+ document.getElementById(target_div).innerHTML = "
"
+ + _("Loading messages from server, please wait") + "
" ;
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) {
- document.getElementById(innerdivname).outerHTML = this.responseText;
+ request.open("GET", "/ctdl/r/" + escapeHTMLURI(current_room) + "/msgs.gt|" + min_msg, true);
+ request.onreadystatechange = function()
+ {
+ if (this.readyState === 4)
+ {
+ if ((this.status / 100) == 2)
+ {
+ msgs = JSON.parse(this.responseText);
+
+ document.getElementById(innerdivname).innerHTML =
+ "Are we logged in? " + logged_in + "
"
+ + "Last seen: " + last_seen + "
"
+ + "Number of messages: " + msgs.length + "
"
+ + "min_msg=" + min_msg + "
"
+ + "max_msg=" + max_msg + "
" ;
+
+ if (msgs.length == 0)
+ {
+ document.getElementById(innerdivname).innerHTML += "FIXME no msgs" ;
+ }
+
+ // If we were given an explicit starting point, by all means start there.
+ // Note that we don't have to remove them from the array because we did a 'msgs gt|xxx' command to Citadel.
+ else if (min_msg > 0)
+ {
+ msgs = msgs.slice(0, msgs_per_page);
+ }
+
+ // show us the last 20 messages and scroll to the bottom (this will become the not-logged-in behavior)
+ else if ((logged_in) | (!logged_in))
+ {
+ if (msgs.length > messages_per_page)
+ {
+ msgs = msgs.slice(msgs.length - messages_per_page);
+ document.getElementById(innerdivname).innerHTML += "link to msgs less than " + msgs[0] + "
" ;
+ }
+ }
+
+ for (var i in msgs)
+ {
+ document.getElementById(innerdivname).innerHTML +=
+ "message #" + msgs[i] + "
" ;
+ }
+ document.getElementById(innerdivname).innerHTML += "link to msgs greater than " + msgs[msgs.length-1] + "
" ;
}
- else {
- document.getElementById(innerdivname).outerHTML = "ERROR " + this.status ;
+ else
+ {
+ document.getElementById(innerdivname).innerHTML = this.status ; // error message
}
}
};