Index: modules/book/book.module
===================================================================
RCS file: /cvs/drupal/drupal/modules/book/book.module,v
retrieving revision 1.445
diff -u -r1.445 book.module
--- modules/book/book.module 4 Nov 2007 14:28:35 -0000 1.445
+++ modules/book/book.module 16 Nov 2007 10:28:47 -0000
@@ -143,13 +143,6 @@
'type' => MENU_CALLBACK,
'file' => 'book.pages.inc',
);
- $items['book/js/admin/%node'] = array(
- 'page callback' => 'book_admin_js_update',
- 'access callback' => '_book_outline_access',
- 'access arguments' => array(3),
- 'type' => MENU_CALLBACK,
- 'file' => 'book.admin.inc',
- );
return $items;
}
Index: modules/book/book.admin.inc
===================================================================
RCS file: /cvs/drupal/drupal/modules/book/book.admin.inc,v
retrieving revision 1.5
diff -u -r1.5 book.admin.inc
--- modules/book/book.admin.inc 17 Oct 2007 12:34:16 -0000 1.5
+++ modules/book/book.admin.inc 16 Nov 2007 10:28:47 -0000
@@ -70,24 +70,12 @@
*/
function book_admin_edit($form_state, $node) {
drupal_set_title(check_plain($node->title));
- $form = array(
- '#cache' => TRUE,
- '#prefix' => '
',
- '#suffix' => '
',
- );
-
+ $form = array();
$form['#node'] = $node;
$form['table'] = _book_admin_table($node);
$form['save'] = array(
'#type' => 'submit',
'#value' => t('Save book pages'),
- '#ahah' => array(
- 'path' => 'book/js/admin/'. $node->nid,
- 'selector' => '#book-admin-edit select',
- 'wrapper' => 'book-admin-edit-wrapper',
- 'event' => 'change',
- 'effect' => 'fade',
- ),
);
return $form;
}
@@ -100,9 +88,7 @@
function book_admin_edit_submit($form, &$form_state) {
foreach ($form_state['values']['table'] as $row) {
$node = node_load($row['nid'], FALSE);
-
- if ($row['title'] != $node->title || $row['weight'] != $node->book['weight']) {
-
+ if ($row['title'] != $node->title || $row['plid'] != $node->book['plid'] || $row['weight'] != $node->book['weight']) {
// Record changes in node's log message.
$log_messages = array();
if ($row['title'] != $node->title) {
@@ -115,6 +101,7 @@
$node->title = $row['title'];
$node->book['link_title'] = $row['title'];
$node->book['weight'] = $row['weight'];
+ $node->book['plid'] = $row['plid'];
$node->revision = 1;
$node->log = implode(' ', $log_messages);
@@ -139,7 +126,10 @@
);
$tree = book_menu_subtree_data($node->book);
- _book_admin_table_tree($tree, $form);
+ $tree = array_shift($tree); // Do not include the book item itself.
+ if ($tree['below']) {
+ _book_admin_table_tree($tree['below'], $form);
+ }
return $form;
}
@@ -164,6 +154,15 @@
'#default_value' => $data['link']['weight'],
'#delta' => 15,
),
+ 'plid' => array(
+ '#type' => 'textfield',
+ '#default_value' => $data['link']['plid'],
+ '#size' => 6,
+ ),
+ 'mlid' => array(
+ '#type' => 'hidden',
+ '#default_value' => $data['link']['mlid'],
+ ),
);
if ($data['below']) {
_book_admin_table_tree($data['below'], $form);
@@ -179,7 +178,10 @@
* @ingroup themeable
*/
function theme_book_admin_table($form) {
- $header = array(t('Title'), t('Weight'), array('data' => t('Operations'), 'colspan' => '3'));
+ drupal_add_tabledrag('book-outline', 'match', 'parent', 'book-plid', 'book-plid', 'book-mlid', FALSE);
+ drupal_add_tabledrag('book-outline', 'order', 'sibling', 'book-weight', NULL, NULL, FALSE);
+
+ $header = array(t('Title'), t('Weight'), t('Parent'), array('data' => t('Operations'), 'colspan' => '3'));
$rows = array();
$destination = drupal_get_destination();
@@ -187,10 +189,16 @@
foreach (element_children($form) as $key) {
$nid = $form[$key]['nid']['#value'];
$href = $form[$key]['href']['#value'];
- $asterisk = (isset($form[$key]['#attributes']['class']) && strpos($form[$key]['#attributes']['class'], 'book-changed') !== FALSE) ? '*' : '';
+
+ // Add special classes to be used for tabledrag.js.
+ $form[$key]['plid']['#attributes']['class'] = 'book-plid';
+ $form[$key]['mlid']['#attributes']['class'] = 'book-mlid';
+ $form[$key]['weight']['#attributes']['class'] = 'book-weight';
+
$data = array(
- ''. drupal_render($form[$key]['title']) . $asterisk .'
',
+ theme('indentation', $form[$key]['depth']['#value'] - 2) . drupal_render($form[$key]['title']),
drupal_render($form[$key]['weight']),
+ drupal_render($form[$key]['plid']) . drupal_render($form[$key]['mlid']),
l(t('view'), $href),
$access ? l(t('edit'), 'node/'. $nid .'/edit', array('query' => $destination)) : ' ',
$access ? l(t('delete'), 'node/'. $nid .'/delete', array('query' => $destination) ) : ' ',
@@ -199,77 +207,11 @@
if (isset($form[$key]['#attributes'])) {
$row = array_merge($row, $form[$key]['#attributes']);
}
+ $row['class'] = empty($row['class']) ? 'draggable' : $row['class'] .' draggable';
$rows[] = $row;
}
- return theme('status_messages') . theme('table', $header, $rows);
-}
-
-/**
- * Menu callback for updating the book outline form.
- */
-function book_admin_js_update() {
- $cid = 'form_'. $_POST['form_build_id'];
- $cache = cache_get($cid, 'cache_form');
- if ($cache) {
- $form = $cache->data;
-
- $tree = book_menu_subtree_data($form['#node']->book);
- _book_admin_js_update_tree($tree);
- _book_admin_sort_tree($tree);
-
- // Create the form in the new order.
- $table_form = array();
- _book_admin_table_tree($tree, $table_form);
-
- // Find the changed element on this request and save the current classes.
- foreach (element_children($form['table']) as $key) {
- if (isset($form['table'][$key]['#attributes'])) {
- $table_form[$key]['#attributes'] = $form['table'][$key]['#attributes'];
- }
- if ($form['table'][$key]['weight']['#default_value'] != $_POST['table'][$key]['weight']) {
- $changed_key = $key;
- }
- }
-
- // Preserve the order of the new form while merging the previous data.
- $form_order = array_flip(array_keys($table_form)); // Save the form order.
- $form['table'] = array_merge($form['table'], $table_form); // Merge the data.
- $form['table'] = array_merge($form_order, $form['table']); // Put back into the correct order.
- $form['table'][$changed_key]['#attributes']['class'] = 'book-changed';
-
- cache_set($cid, $form, 'cache_form', $cache->expire);
-
- // Add the special AHAH class for new content.
- $form['table'][$changed_key]['#attributes']['class'] = isset($form['table'][$changed_key]['#attributes']['class']) ? $form['table'][$changed_key]['#attributes']['class'] .' ahah-new-content' : 'ahah-new-content';
-
- // Set a message for the user to save the form.
- drupal_set_message(t('Your changes will not be saved until you click the Save book pages button.'), 'warning');
-
- // Prevent duplicate wrappers.
- unset($form['#prefix'], $form['#suffix']);
-
- // Render the form.
- $form['#post'] = $_POST;
- $form_state = array('submitted' => FALSE);
- $form = form_builder('book_admin_edit', $form, $form_state);
- $output = drupal_render($form);
-
- drupal_json(array('status' => TRUE, 'data' => $output));
- }
-}
-
-/**
- * Recursive helper to set new form weights to the tree.
- */
-function _book_admin_js_update_tree(&$tree) {
- foreach($tree as $key => $subtree) {
- $tree[$key]['link']['weight'] = $_POST['table'][$key]['weight'];
- $tree[$key]['link']['title'] = $_POST['table'][$key]['title'];
- if (!empty($subtree['below'])) {
- _book_admin_js_update_tree($tree[$key]['below']);
- }
- }
+ return theme('table', $header, $rows, array('id' => 'book-outline'));
}
/**