Adding a button for toggling nested items in activecollab

This is a follow up to Bookmarklets for expanding, collapsing items in activeCollab.

I hacked the activeCollab Checklist module last night. Specifically the ChecklistsController.class.php file, adding the links to toggle the nested items.

Here’s the new button:

Here it is expanded:

I briefly looked at creating a module to override the checklist controller module but wasn’t able to make any headway there so I created a patch: ChecklistsController.class.php_toggle_nested_items_5-5-11_v0.2.patch.

At this point it only shows up on checklist pages if we find other nested items elsewhere then we can apply the idea to other files or look closer at a custom module again.

There is a simple way to use a custom module to add breadcrumbs or navigation menu items but I didn’t see a simple way to add the button to the wireframe.

Here’s the code:

wireframe->addPageAction($text, $url, $subitems, $additional);
       * Hack Author: Vid
       * Date: 5-4-11
       * Version 0.2
       **/
       $text = "Toggle Nested Items";
       $url = "#";
       $subitems = array(
          array(
            'text'     => "Open All",
            'url'      => "javascript:$('a.collapsed').click();void(0);",
            'id'       => "toggle_nested_items_open_all"
          ),
          array(
            'text'     => "Close All",
            'url'      => "javascript:$('a.expanded').not('a.collapsed').click();void(0);",
            'id'       => "toggle_nested_items_close_all"
          ),
          array(
            'text'     => "Toggle All",
            'url'      => "javascript:$('.expander%20a').click();void(0);",
            'id'       => "toggle_nested_items_toggle_all"
          )
        );
       $additional = array(
          'id'     => "toggle_nested_items"
        );

       $this->wireframe->addPageAction($text, $url, $subitems, $additional);
       ################################################ End hack for nested checklists ################################################

Ideally a module performing this function would

  • Stand alone
  • Operate on the relevant pages (using some unknown function or old-school php to determine the current page)
    • Then a case could be added for the checklist index page
  • Ensure non-js compatibility:
    • The urls of each action would reload the page and trigger some undetermined code that would act on the default classes of the li tags with php
    • If js is enabled then the static code in those links would be replaced with the jQuery
      • To support that, each item has been given an ID
    • The module would need to include a js file replacing the link content with the js

    OR

    • The entire nested set could be hidden with style of display:none; in a stylesheet
      #toggle_nested_items {display:none;}

      and then js could be used to display it.

      $('#toggle_nested_items').show();

      This messes with the pretty formatting a bit but could work.

  • Some look at these js code bits may be in order:
    javascript: void(0);

    They are usually considered extra cruft, but may be needed here without full access to the link object.
    The ‘method’ option in the ‘additional’ array warrants more investigation. I don’t know if it calls a js or php method

Comments
Leave a Comment