The in-iconbar wholist is now expandable and collapsible.
authorArt Cancro <ajc@uncensored.citadel.org>
Thu, 12 May 2011 21:14:07 +0000 (17:14 -0400)
committerWilfried Goesgens <dothebart@citadel.org>
Sun, 4 Sep 2011 20:32:37 +0000 (20:32 +0000)
It also maintains its state across page reloads.  I *may* move it into the ib-vector
to make it persistent across logins.  TODO: same for the in-inconbar roomlist.

webcit/iconbar.c
webcit/static/t/iconbar.html
webcit/static/wclib.js

index 3b4b17554782199881e2a44d43c8d127a81f0036..60e421bd34fe635d4f4699b7e1de2d7d7893f95c 100644 (file)
@@ -261,8 +261,10 @@ ServerStartModule_ICONBAR
 
 int ConditionalWholistExpanded(StrBuf *Target, WCTemplputParams *TP)
 {
-       if (WC) return(WC->ib_wholist_expanded);
-       return(0);
+       int r = 0;
+       if (WC) r = WC->ib_wholist_expanded;
+       syslog(LOG_DEBUG, "ConditionalWholistExpanded() returns %d", r);
+       return(r);
 }
 
 
@@ -273,6 +275,24 @@ int ConditionalRoomlistExpanded(StrBuf *Target, WCTemplputParams *TP)
 }
 
 
+
+/*
+ * Toggle the wholist expanded state in session memory
+ */
+void toggle_wholist_expanded_state(void) {
+       wcsession *WCC = WC;
+
+       if (!WCC) {
+               wc_printf("no session");
+               return;
+       }
+
+       WCC->ib_wholist_expanded = IBSTR("wstate");
+       wc_printf("%d", WCC->ib_wholist_expanded);
+       syslog(LOG_DEBUG, "ib_wholist_expanded set to %d", WCC->ib_wholist_expanded);
+}
+
+
 void 
 InitModule_ICONBAR
 (void)
@@ -281,6 +301,7 @@ InitModule_ICONBAR
 
        /*WebcitAddUrlHandler(HKEY("user_iconbar"), "", 0, doUserIconStylesheet, 0); */
        WebcitAddUrlHandler(HKEY("commit_iconbar"), "", 0, commit_iconbar, 0);
+       WebcitAddUrlHandler(HKEY("toggle_wholist_expanded_state"), "", 0, toggle_wholist_expanded_state, AJAX);
        RegisterConditional(HKEY("COND:ICONBAR:ACTIVE"), 3, ConditionalIsActiveStylesheet, CTX_NONE);
        RegisterNamespace("ICONBAR", 0, 0, tmplput_iconbar, NULL, CTX_NONE);
        RegisterConditional(HKEY("COND:ICONBAR:WHOLISTEXPANDED"), 0, ConditionalWholistExpanded, CTX_NONE);
@@ -306,3 +327,4 @@ SessionDestroyModule_ICONBAR
        if (sess->IBSettingsVec != NULL)
                free(sess->IBSettingsVec);
 }
+
index 038d0d8d4c8418085b0249be664f21f38a2ed932..bc4c2952b15598fa993872ecc5e29ca17b3685a5 100644 (file)
@@ -50,7 +50,9 @@
 </li>
 <li id="ib_users" class="ib_button">
 <a class="ib_button_link" href="do_template?template=who" title="<?_("See who is online right now")>">
-<img src="static/expand.gif" onClick="$('online_users').style.display='block'; return false;">
+<img id="expand_wholist"
+src=<?%("COND:ICONBAR:WHOLISTEXPANDED", 1, 1, 1, "static/collapse.gif", "static/expand.gif")>
+onClick="return toggle_wholist();">
 <span><?_("Online users")></span>
 </a>
 <ul id="online_users">
index 6fddde5c814f11e7b156b6c941c0f0875e4a40f9..01057a82b3672fed3c1509bbd8e5cc436220ae65 100644 (file)
@@ -144,6 +144,11 @@ function activate_entmsg_autocompleters() {
        new Ajax.Autocompleter('recp_id', 'recp_name_choices', 'recp_autocomplete', {} );
 }
 
+function activate_iconbar_wholist_populat0r() 
+{
+       new Ajax.PeriodicalUpdater('online_users', 'do_template?template=who_iconbar', {method: 'get', frequency: 30});
+}
+
 function setupIconBar() {
   if (!document.getElementById("switch")) {
       return;
@@ -163,8 +168,16 @@ function setupIconBar() {
     }
   }
   var online_users = document.getElementById("online_users");
-  /* FIXME is there a way to not update this div when it is not showing? */
-  new Ajax.PeriodicalUpdater('online_users', 'do_template?template=who_iconbar', {method: 'get', frequency: 30});
+
+       /* WARNING: VILE, SLEAZY HACK.  We determine the state of the box based on the image loaded. */
+       if ( $('expand_wholist').src.substring($('expand_wholist').src.length - 12) == "collapse.gif" ) {
+               $('online_users').style.display = 'block';
+               activate_iconbar_wholist_populat0r();
+       }
+       else {
+               $('online_users').style.display = 'none';
+       }
+
 }
 function changeIconBarEvent(event) {
   changeIconBar(event.target);
@@ -867,18 +880,44 @@ function ConfirmLogoff() {
        new Ajax.Updater(
                'md-content',
                'do_template?template=confirmlogoff',
-                {
-                        method: 'get',
+               {
+                       method: 'get',
                        onSuccess: function(cl_success) {
                                toggleModal(1);
                        }
-                }
-        );
+               }
+       );
 }
 
 
 function switch_to_lang(new_lang) {
-        p = 'push?url=' + encodeURI(window.location);
-        new Ajax.Request(p, { method: 'get' } );
+       p = 'push?url=' + encodeURI(window.location);
+       new Ajax.Request(p, { method: 'get' } );
        window.location = 'switch_language?lang=' + new_lang ;
 }
+
+
+function toggle_wholist() 
+{
+       d = $('online_users').style.display;
+
+       if (d == 'block') {
+               $('online_users').style.display = 'none';
+               $('expand_wholist').src = 'static/expand.gif';
+               wstate=0;
+       }
+
+       else {
+               $('online_users').style.display = 'block';
+               $('expand_wholist').src = 'static/collapse.gif';
+               activate_iconbar_wholist_populat0r();
+               wstate=1;
+       }
+
+       // tell the server what I did
+       p = 'toggle_wholist_expanded_state?wstate=' + wstate + '?rand=' + Math.random() ;
+       new Ajax.Request(p, { method: 'get' } );
+
+       return false;   /* this prevents the click from registering as a wholist button press */
+
+}