]> code.citadel.org Git - citadel.git/blobdiff - webcit-ng/static/js/views.js
Added stub renderers for Calendar and Contacts rooms
[citadel.git] / webcit-ng / static / js / views.js
index b5d7553377cc08adaf2831ce0dc9ba1ddf14e948..6c235fcdec530871dc93a42d059af2d23579a630 100644 (file)
+// Copyright (c) 2016-2023 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.
-//
-// This program is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-// GNU General Public License for more details.
+// This program is open source software.  Use, duplication, or
+// disclosure are subject to the GNU General Public License v3.
 
 
-// List of defined views shamelessly swiped from libcitadel headers
-//
-var views = {
-       VIEW_BBS                : 0,    /* Bulletin board view */
-       VIEW_MAILBOX            : 1,    /* Mailbox summary */
-       VIEW_ADDRESSBOOK        : 2,    /* Address book view */
-       VIEW_CALENDAR           : 3,    /* Calendar view */
-       VIEW_TASKS              : 4,    /* Tasks view */
-       VIEW_NOTES              : 5,    /* Notes view */
-       VIEW_WIKI               : 6,    /* Wiki view */
-       VIEW_CALBRIEF           : 7,    /* Brief Calendar view */
-       VIEW_JOURNAL            : 8,    /* Journal view */
-       VIEW_DRAFTS             : 9,    /* Drafts view */
-       VIEW_BLOG               : 10,   /* Blog view */
-       VIEW_QUEUE              : 11,   /* SMTP QUEUE rooms */
-       VIEW_WIKIMD             : 12,   /* Markdown Wiki view */
-};
-
-
-// This function is the dispatcher that determines the correct view for a room,
-// and calls the correct renderer.
-//
-function render_room_view(min_msg, max_msg)
-{
-       switch(current_view)
-       {
-               case views.VIEW_MAILBOX:                                                // FIXME view mail rooms as forums for now
+// Clear the sidebar buttons of any style indicating that one is selected
+function clear_sidebar_selection() {
+       var items = document.getElementById("ctdl-sidebar").getElementsByTagName("*");
+       for (var i = items.length; i--;) {
+               if (items[i].id.includes("ctdl-sidebar-button-")) {
+                       items[i].classList.remove("ctdl-sidebar-button-selected");
+               }
+       }
+       document.getElementById("ctdl_mail_folder_list").style.display = "none";
+}
+
+
+// Clear any drop handlers that might have been set by the previous view
+function clear_drop_handlers() {
+}
+
+
+// Clear the top bar navigation buttons.  The view renderer will set its own buttons.
+function clear_navigation_buttons() {
+       for (const d of ["ctdl-newmsg-button", "ctdl-ungoto-button", "ctdl-skip-button", "ctdl-goto-button", "ctdl-delete-button"]) {
+               document.getElementById(d).style.display = "none";
+       }
+}
+
+
+// This function is the dispatcher that determines the correct view for a room, and calls the correct renderer.
+function render_room_view() {
+
+       clear_navigation_buttons();
+       clear_sidebar_selection();
+       clear_drop_handlers();
+
+       document.getElementById("ctdl-main").innerHTML = 
+               "<div class=\"ctdl-middle\">"
+               + _("Loading messages from server, please wait")
+               + "</div>";
+
+       switch(current_view) {
+
+               // The "forum" module displays rooms with the "VIEW_BBS" view as classic style web forums.
                case views.VIEW_BBS:
-                       forum_readmessages("ctdl-main", min_msg, max_msg);
+                       document.getElementById("ctdl-sidebar-button-forums").classList.add("ctdl-sidebar-button-selected");
+                       view_render_forums();
+                       break;
+
+               // The "mail" module displays rooms with the VIEW_MAILBOX view as a webmail program.
+               case views.VIEW_MAILBOX:
+               case views.VIEW_DRAFTS:
+                       document.getElementById("ctdl-sidebar-button-mail").classList.add("ctdl-sidebar-button-selected");
+                       display_mail_folder_list("ctdl_mail_folder_list");
+                       view_render_mail();
+                       break;
+
+               // The "contacts" module displays rooms with the VIEW_ADDRESSBOOK view as a contacts manager.
+               case views.VIEW_ADDRESSBOOK:
+                       view_render_contacts();
+                       break;
+
+               case views.VIEW_CALENDAR:
+               case views.VIEW_CALBRIEF:
+                       view_render_calendar();
+                       break;
+
+               case views.VIEW_TASKS:
+                       document.getElementById("ctdl-main").innerHTML =
+                               `<div class="ctdl-middle">'${current_room}' is a task list but there is no renderer.</div>`;
+                       break;
+
+               case views.VIEW_NOTES:
+                       document.getElementById("ctdl-main").innerHTML =
+                               `<div class="ctdl-middle">'${current_room}' is a notes list but there is no renderer.</div>`;
+                       break;
+
+               case views.VIEW_WIKI:
+                       document.getElementById("ctdl-main").innerHTML =
+                               `<div class="ctdl-middle">'${current_room}' is a wiki but there is no renderer.</div>`;
+                       break;
+
+               case views.VIEW_JOURNAL:
+                       document.getElementById("ctdl-main").innerHTML =
+                               `<div class="ctdl-middle">'${current_room}' is a journal but there is no renderer.</div>`;
                        break;
+
+               case views.VIEW_BLOG:
+                       document.getElementById("ctdl-main").innerHTML =
+                               `<div class="ctdl-middle">'${current_room}' is a blog but there is no renderer.</div>`;
+                       break;
+
+               case views.VIEW_QUEUE:
+                       document.getElementById("ctdl-main").innerHTML =
+                               `<div class="ctdl-middle">'${current_room}' is the mail queue but there is no renderer.</div>`;
+                       break;
+
                default:
-                       document.getElementById("ctdl-main").innerHTML = "The view for " + current_room + " is " + current_view + " but there is no renderer." ;
+                       document.getElementById("ctdl-main").innerHTML =
+                               `<div class="ctdl-middle">The view for '${current_room}' is ${current_view} but there is no renderer.</div>`;
                        break;
        }
 
 }
 
 
-// Forum view (flat) -- let's have another go at this with the rendering done client-side
-//
-function forum_readmessages(target_div, min_msg, max_msg)
-{
-       var innerdivname = randomString(5);
-       document.getElementById(target_div).innerHTML = "<div id=\"" + innerdivname +
-               "\"><i class=\"fas fa-spinner fa-spin\"></i>&nbsp;&nbsp;"
-               + _("Loading messages from server, please wait") + "</div>" ;
-
-       var request = new XMLHttpRequest();
-       if (max_msg < 9999999999)
-       {
-               request.open("GET", "/ctdl/r/" + escapeHTMLURI(current_room) + "/msgs.lt|" + max_msg, true);
+// This gets called when the user clicks the "enter message" or "post message" or "add item" button etc.
+function entmsg_dispatcher() {
+       switch(current_view) {
+               case views.VIEW_BBS:
+                       forum_entmsg();
+                       break;
+               case views.VIEW_MAILBOX:
+                       mail_compose("", 0, [], [], "");
+                       break;
+               default:
+                       break;
        }
-       else
-       {
-               request.open("GET", "/ctdl/r/" + escapeHTMLURI(current_room) + "/msgs.gt|" + min_msg, true);
+}
+
+
+// This gets called when the user clicks the "delete" button etc.
+function delete_dispatcher() {
+       switch(current_view) {
+               case views.VIEW_MAILBOX:
+                       mail_delete_selected();
+                       break;
+               default:
+                       break;
        }
-       request.onreadystatechange = function()
-       {
-               if (this.readyState === 4)
-               {
-                       if ((this.status / 100) == 2)
-                       {
-                               msgs = JSON.parse(this.responseText);
-                               document.getElementById(innerdivname).innerHTML = "" ;
-
-                               // 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.
-                               if (min_msg > 0)
-                               {
-                                       msgs = msgs.slice(0, messages_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) | (max_msg < 9999999999))
-                               {
-                                       if (msgs.length > messages_per_page)
-                                       {
-                                               msgs = msgs.slice(msgs.length - messages_per_page);
-                                       }
-                                       new_old_div_name = randomString(5);
-                                       if (msgs.length < 1)
-                                       {
-                                               newlt = max_msg;
-                                       }
-                                       else
-                                       {
-                                               newlt = msgs[0];
-                                       }
-                                       document.getElementById(innerdivname).innerHTML +=
-                                               "<div id=\"" + new_old_div_name + "\">" +
-                                               "<a href=\"javascript:forum_readmessages('" + new_old_div_name + "', 0, " + newlt + ");\">" +
-                                               "link to msgs less than " + newlt + "</a></div>" ;
-                               }
-
-                               // Render the divs (we will fill them in later)
-                               for (var i in msgs)
-                               {
-                                       if ((msgs[i] > min_msg) && (msgs[i] < max_msg))
-                                       {
-                                               document.getElementById(innerdivname).innerHTML += "<div id=\"ctdl_msg_" + msgs[i] + "\">#" + msgs[i] + "</div>" ;
-                                       }
-                               }
-                               if (max_msg == 9999999999)
-                               {
-                                       new_new_div_name = randomString(5);
-                                       if (msgs.length <= 0)
-                                       {
-                                               newgt = min_msg;
-                                       }
-                                       else
-                                       {
-                                               newgt = msgs[msgs.length-1];
-                                       }
-                                       document.getElementById(innerdivname).innerHTML +=
-                                               "<div id=\"" + new_new_div_name + "\">" +
-                                               "<a href=\"javascript:forum_readmessages('" + new_new_div_name + "', " + newgt + ", 9999999999);\">" +
-                                               "link to msgs greater than " + newgt + "</a></div>" ;
-                               }
-
-                               // Render the individual messages in the divs
-                               for (var i in msgs)
-                               {
-                                       if ((msgs[i] > min_msg) && (msgs[i] < max_msg))
-                                       {
-                                               document.getElementById("ctdl_msg_" + msgs[i]).innerHTML = "<b>Message " + msgs[i] + " got rendered!!!</b>";
-                                       }
-                               }
-
-                       }
-                       else
-                       {
-                               document.getElementById(innerdivname).innerHTML = "ERROR " + this.status ;              // error message
-                       }
-               }
-       };
-       request.send();
-       request = null;
 }
+
+