I just thought it would be nice and it wouldn't require much effort to implement. just a simple tree view of the TOC from a drupal collaborative book page hierarchy,
I honestly don't know if it's present and being just a drupal newbie is what my wondering is all about. so if so please be kind and let me know.
TIA

CommentFileSizeAuthor
#10 dynbooktoc.tar_.gz3.16 KBnatuk
#7 book_1.module41.58 KBtwohills
#6 book_0.module41.81 KBtwohills
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

moshe weitzman’s picture

see #3558

puregin’s picture

Version: 4.2.0 » x.y.z

I'm marking this as active again, since the other issue referred to was set to 'won't fix'.

I think that there may be some interest in this from the AJAX experts :)

puregin’s picture

Status: Closed (duplicate) » Active

OK, this time I really will mark it as active :)

twohills’s picture

+1 to that. I'm building a single "omnibus" book across a big chunk of content and it will have about 400 pages. I really need a tree view that is manageable, i.e. where branches can be expanded or collapsed Explorer style.

nedjo’s picture

The activemenu component of the Javascript Tools package provides relevant methods and could be adapted for this, http://drupal.org/node/57285.

twohills’s picture

FileSize
41.81 KB

I hacked books.module to give me an expand/collapse ToC. Sorry there are multiple changes in here so i can't be sure to disentangle just the ToC ones but here goes. In book_menu add:

    $items[] = array('path' => 'book/toc', 'title' => t('table of contents'),
      'callback' => 'book_page_toc',
      'access' => user_access('access content'),
      'type' => MENU_CALLBACK);
//WARNING: "toc" is used in two separate contexts in this pgm: toc for toc-in-block and page_toc for toc-in-page
  }

make this change to book_link:

  $links = array();

  if ($type == 'node' && isset($node->parent)) {
    if (!$main) {
      if ($node->parent) {
         $nodes = book_location($node);
         $nid = $nodes[0]->nid;
      } else {
         $nid = $node->nid;
      }
      $links[] = l(t('Contents'), "book/toc/$nid");

      if (book_access('create', $node)) {
        $links[] = l(t('add child page'), "node/add/book/parent/$node->nid");
      }

new function:

//WARNING: "toc" is used in two separate contexts in this pgm: toc for toc-in-block and page_toc for toc-in-page
function book_page_toc($nid) {
  $view = !user_access('administer nodes');
  print theme('page', book_admin_view($nid, 0, $view));
}

and replace these three functions:

function book_admin_view_line($node, $depth = 0, $view = FALSE) { 
  if ($view) {
    $output = array('<div style="padding-left: '. (25 * $depth) .'px;">'
                    . l( $node->title, 'node/'. $node->nid )
                    .'</div>'
                   );
  } else {  
    $output = array(
                 '<div style="padding-left: '. (25 * $depth) .'px;">'
                . form_textfield(NULL, $node->nid .'][title', $node->title, 64, 255) 
                .'</div>'
                , form_weight(NULL, $node->nid .'][weight', $node->weight, 15)
                , l(t('view'), 'node/'. $node->nid)
                , l(t('edit'), 'node/'. $node->nid .'/edit')
                , l(t('delete'), 'node/'.$node->nid.'/delete')
              );
  }
  return $output;
}

function book_admin_view_book($nid, $depth = 1, $view = FALSE) {
  $result = db_query('SELECT n.nid, b.weight, n.title, 
                             (SELECT count(x.nid) FROM book x WHERE x.parent = n.nid) AS kids 
                      FROM node n INNER JOIN book b ON n.nid = b.nid 
                      WHERE b.parent = %d ORDER BY b.weight, n.title', $nid);

  $rows = array();
  $edit = $_POST['edit'];   
  while ($node = db_fetch_object($result)) {
//    $node = node_load(array('nid' => $node->nid));               //###### see http://drupal.org/node/57846
    $row = book_admin_view_line($node, $depth, $view);
    if ( $edit[$node->nid]['expand'] == 1) {                     
      $down = book_admin_view_book($node->nid, $depth + 1, $view);
      if ($down) {
        $rows[] = array_merge( $row, array(form_checkbox(NULL, $node->nid .'][expand', 1, 1)));
        $rows = array_merge($rows, $down );
      } else {
        $rows[] = $row;
      }
    } else {
      if ($node->kids > 0) {
        $rows[] = array_merge( $row, array(form_checkbox(NULL, $node->nid .'][expand', 1, 0)));
      } else {
        $rows[] = $row;
      }
    }
  }

  return $rows;
}

/**
 * Display an administrative view of the hierarchy of a book.
 */
function book_admin_view($nid, $depth = 0, $view = FALSE) {
  if ($nid) {
    $node = node_load(array('nid' => $nid));

    $output .= '<h3>'. check_plain($node->title) .'</h3>';
    if ($view) {
      $header = array(t('Title') , t('Expand'));
    } else {
      $header = array(t('Title'), t('Weight'), array('data' => t('Operations'), 'colspan' => '3'), t('Expand'));
    }

    $rows[] = book_admin_view_line($node, $depth, $view);
    $rows = array_merge($rows, book_admin_view_book($nid, $depth+1, $view));

    $output .= theme('table', $header, $rows);
    if (!$view) {
      $output .= form_submit(t('Save updates'));
    }
    $output .= form_submit(t('Refresh'));                                   

    return form($output);
  }
}

I think I got it all. As I say there are multiple changes intermingled in this module, so this is not a tested patch, just a helping hand to anyone who wants to write their own mods. Good luck!

twohills’s picture

FileSize
41.58 KB

wish i could edit the previous post :-)
see the attached module for a better version that actually works

Crell’s picture

Version: x.y.z » 6.x-dev
Status: Active » Fixed

Book module is now all javascripty. :-)

webchick’s picture

Version: 6.x-dev » 7.x-dev
Status: Fixed » Active

javaScripty it may be, but it doesn't actually do this, afaik.

Bumping to 7.x, as it's a new feature.

natuk’s picture

FileSize
3.16 KB

My dynbooktoc module demonstrated here:

http://www.ligatus.org.uk/glossary/?q=en/dynbooktoc

is something that I have been working on for D5. I have been unable to transfer it to D6 because the D6 version of the book module does not allow more than 9 generations (see here: http://drupal.org/node/274270). However, in the hope that this limitation will be lifted, or with some changes for D7, this might prove useful.

Note the cookies functionality: i.e. if you delve into the hierarchy, navigate away from the page and then come back to it, it will remember which nodes have been opened.

Needless to say that the code needs reviewing...

natuk

bomarmonk’s picture

This looks good. I would very much like to have this kind of book navigation on my site. It would be great if a TOC could be expanded on each book page, showing the active page and the ordered list of children under the parent book.

BetaTheta’s picture

subscribing

webchick’s picture

Version: 7.x-dev » 8.x-dev
colan’s picture

Doesn't Advanced Book Blocks do this already?

colan’s picture

Actually, I think we should probably drop the Book module from core entirely, and forget about this issue. Book uses its own custom table. There are now more generic ways of doing this, such as the recipe over at http://drupal.org/node/1176828#comment-4818914. Using that approach, the corresponding issue to this one would be #1048442: Collapsible blocks using Tree View.

jhedstrom’s picture

Version: 8.0.x-dev » 8.1.x-dev
Issue summary: View changes
Status: Active » Postponed (maintainer needs more info)
Issue tags: +Needs issue summary update

Version: 8.1.x-dev » 8.2.x-dev

Drupal 8.1.0-beta1 was released on March 2, 2016, which means new developments and disruptive changes should now be targeted against the 8.2.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle

Version: 8.2.x-dev » 8.3.x-dev

Drupal 8.2.0-beta1 was released on August 3, 2016, which means new developments and disruptive changes should now be targeted against the 8.3.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

sarmiliboyz’s picture

Version: 8.3.x-dev » 8.4.x-dev

Version: 8.4.x-dev » 8.5.x-dev

Drupal 8.4.0-alpha1 was released July 28, 2017, which means new developments and disruptive changes should now be targeted against the 8.5.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.5.x-dev » 8.6.x-dev

Drupal 8.5.0-alpha1 will be released the week of January 17, 2018, which means new developments and disruptive changes should now be targeted against the 8.6.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

andypost’s picture

Status: Postponed (maintainer needs more info) » Needs work

NW for summary update

Version: 8.6.x-dev » 8.7.x-dev

Drupal 8.6.0-alpha1 will be released the week of July 16, 2018, which means new developments and disruptive changes should now be targeted against the 8.7.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.7.x-dev » 8.8.x-dev

Drupal 8.7.0-alpha1 will be released the week of March 11, 2019, which means new developments and disruptive changes should now be targeted against the 8.8.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

jhedstrom’s picture

Status: Needs work » Closed (outdated)

Closing as outdated since no updates of any substance have happened in some time.

colan’s picture