disabled server-side message sequencing code
[citadel.git] / webcit-ng / static / js / views.js
1 //
2 // Copyright (c) 2016-2018 by the citadel.org team
3 //
4 // This program is open source software; you can redistribute it and/or modify
5 // it under the terms of the GNU General Public License version 3.
6 //
7 // This program is distributed in the hope that it will be useful,
8 // but WITHOUT ANY WARRANTY; without even the implied warranty of
9 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
10 // GNU General Public License for more details.
11
12
13 // List of defined views shamelessly swiped from libcitadel headers
14 //
15 var views = {
16         VIEW_BBS                : 0,    /* Bulletin board view */
17         VIEW_MAILBOX            : 1,    /* Mailbox summary */
18         VIEW_ADDRESSBOOK        : 2,    /* Address book view */
19         VIEW_CALENDAR           : 3,    /* Calendar view */
20         VIEW_TASKS              : 4,    /* Tasks view */
21         VIEW_NOTES              : 5,    /* Notes view */
22         VIEW_WIKI               : 6,    /* Wiki view */
23         VIEW_CALBRIEF           : 7,    /* Brief Calendar view */
24         VIEW_JOURNAL            : 8,    /* Journal view */
25         VIEW_DRAFTS             : 9,    /* Drafts view */
26         VIEW_BLOG               : 10,   /* Blog view */
27         VIEW_QUEUE              : 11,   /* SMTP QUEUE rooms */
28         VIEW_WIKIMD             : 12,   /* Markdown Wiki view */
29 };
30
31
32 // This function is the dispatcher that determines the correct view for a room,
33 // and calls the correct renderer.
34 //
35 function render_room_view()
36 {
37         switch(current_view)
38         {
39                 case views.VIEW_MAILBOX:                                                // FIXME view mail rooms as forums for now
40                 case views.VIEW_BBS:
41                         forum_readmessages();
42                         break;
43                 default:
44                         document.getElementById("main").innerHTML = "The view for " + current_room + " is " + current_view + " but there is no renderer." ;
45                         break;
46         }
47
48 }
49
50
51 // Forum view -- flat or threaded
52 // The inner div exists so that if the user clicks away early, the main div doesn't get clobbered when the load completes.
53 // The parameter can be set to "flat" or "threads" which is passed directly to the API
54 //
55 function XX_forum_readmessages(flat_or_threads)
56 {
57         var innerdivname = randomString(5);
58         document.getElementById("main").innerHTML = "<div id=\"" + innerdivname +
59                 "\"><br><br><br><center><h5><i class=\"fas fa-spinner fa-spin\"></i>&nbsp;&nbsp;"
60                 + _("Loading messages from server, please wait") + "</h5></center></div>" ;
61
62         var request = new XMLHttpRequest();
63         request.open("GET", "/ctdl/r/" + escapeHTMLURI(current_room) + "/" + flat_or_threads, true);
64         request.onreadystatechange = function()
65         {
66                 if (this.readyState === 4)
67                 {
68                         if ((this.status / 100) == 2)
69                         {
70                                 document.getElementById(innerdivname).outerHTML = this.responseText;
71                         }
72                         else
73                         {
74                                 document.getElementById(innerdivname).outerHTML = "ERROR " + this.status ;
75                         }
76                 }
77         };
78         request.send();
79         request = null;
80 }
81
82
83 // Forum view (flat) -- let's have another go at this with the rendering done client-side
84 //
85 function forum_readmessages()
86 {
87         var innerdivname = randomString(5);
88         document.getElementById("main").innerHTML = "<div id=\"" + innerdivname +
89                 "\"><br><br><br><center><h5><i class=\"fas fa-spinner fa-spin\"></i>&nbsp;&nbsp;"
90                 + _("Loading messages from server, please wait") + "</h5></center></div>" ;
91
92         var request = new XMLHttpRequest();
93         request.open("GET", "/ctdl/r/" + escapeHTMLURI(current_room) + "/msgs.all", true);
94         request.onreadystatechange = function()
95         {
96                 if (this.readyState === 4)
97                 {
98                         if ((this.status / 100) == 2)
99                         {
100                                 msgs = JSON.parse(this.responseText);
101                                 document.getElementById(innerdivname).innerHTML =
102                                         "Are we logged in? " + logged_in + "<br>"
103                                         + "Last seen: " + last_seen + "<br>"
104                                         + "Number of messages: " + msgs.length + "<br>" ;
105
106                                 if (msgs.length == 0)
107                                 {
108                                                 document.getElementById(innerdivname).innerHTML += "FIXME no msgs" ;
109                                 }
110
111                                 // show us the last 20 messages and scroll to the bottom (this will become the not-logged-in behavior)
112                                 else if ((logged_in) | (!logged_in))
113                                 {
114                                         if (msgs.length > messages_per_page)
115                                         {
116                                                 msgs = msgs.slice(msgs.length - messages_per_page);
117                                                 document.getElementById(innerdivname).innerHTML += "link to msgs less than " + msgs[0] + "<br>" ;
118                                         }
119                                 }
120
121                                 for (var i in msgs)
122                                 {
123                                         document.getElementById(innerdivname).innerHTML += "message # " + msgs[i] + "<br>" ;
124                                 }
125                         }
126                         else
127                         {
128                                 document.getElementById(innerdivname).innerHTML = this.status ;         // error message
129                         }
130                 }
131         };
132         request.send();
133         request = null;
134 }