Commit 58852d4b authored by Dries's avatar Dries

- Patch #192736 by quicksketch et al: drag and drop for book module.

parent a960d4d6
......@@ -133,8 +133,8 @@ function cache_clear_all($cid = NULL, $table = NULL, $wildcard = FALSE) {
global $user;
if (!isset($cid) && !isset($table)) {
// Clear the block cache first, so stale data will
// not end up in the page cache.
// Clear the block cache first, so stale data will
// not end up in the page cache.
cache_clear_all(NULL, 'cache_block');
cache_clear_all(NULL, 'cache_page');
return;
......
......@@ -2028,10 +2028,12 @@ function drupal_get_js($scope = 'header', $javascript = NULL) {
* (optional) The column containing the field elements may be entirely hidden
* from view dynamically when the JavaScript is loaded. Set to FALSE if the
* column should not be hidden.
* @param $limit
* (optional) Limit the maximum amount of parenting in this table.
* @see block-admin-display-form.tpl.php
* @see theme_menu_overview_form()
*/
function drupal_add_tabledrag($table_id, $action, $relationship, $group, $subgroup = NULL, $source = NULL, $hidden = TRUE) {
function drupal_add_tabledrag($table_id, $action, $relationship, $group, $subgroup = NULL, $source = NULL, $hidden = TRUE, $limit = 0) {
static $js_added = FALSE;
if (!$js_added) {
drupal_add_js('misc/tabledrag.js', 'core');
......@@ -2047,6 +2049,7 @@ function drupal_add_tabledrag($table_id, $action, $relationship, $group, $subgro
'relationship' => $relationship,
'action' => $action,
'hidden' => $hidden,
'limit' => $limit,
);
drupal_add_js($settings, 'setting');
}
......
......@@ -1788,7 +1788,7 @@ function menu_link_save(&$item) {
function _menu_clear_page_cache() {
static $cache_cleared = 0;
// Clear the page and block caches, but at most twice, including at
// Clear the page and block caches, but at most twice, including at
// the end of the page load when there are multple links saved or deleted.
if (empty($cache_cleared)) {
cache_clear_all();
......@@ -1805,7 +1805,7 @@ function _menu_clear_page_cache() {
}
/**
* Helper function to update a list of menus with expanded items
* Helper function to update a list of menus with expanded items
*/
function _menu_set_expanded_menus() {
$names = array();
......
......@@ -46,6 +46,7 @@ Drupal.tableDrag = function(table, tableSettings) {
this.oldRowElement = null; // Remember the previous element.
this.oldY = 0; // Used to determine up or down direction from last mouse move.
this.changed = false; // Whether anything in the entire table has changed.
this.maxDepth = 0 // Maximum amount of allowed parenting.
// Configure the scroll settings.
this.scrollSettings = { amount: 4, interval: 50, trigger: 70 };
......@@ -62,6 +63,9 @@ Drupal.tableDrag = function(table, tableSettings) {
if (tableSettings[group][n]['relationship'] == 'parent') {
this.indentEnabled = true;
}
if (tableSettings[group][n]['limit'] > 0) {
this.maxDepth = tableSettings[group][n]['limit'];
}
}
}
if (this.indentEnabled) {
......@@ -190,7 +194,7 @@ Drupal.tableDrag.prototype.makeDraggable = function(item) {
}
// Create a new rowObject for manipulation of this row.
self.rowObject = new self.row(item, 'mouse', self.indentEnabled, true);
self.rowObject = new self.row(item, 'mouse', self.indentEnabled, self.maxDepth, true);
// Save the position of the table.
self.table.topY = self.getPosition(self.table).y;
......@@ -244,7 +248,7 @@ Drupal.tableDrag.prototype.makeDraggable = function(item) {
handle.keydown(function(event) {
// If a rowObject doesn't yet exist and this isn't the tab key.
if (event.keyCode != 9 && !self.rowObject) {
self.rowObject = new self.row(item, 'keyboard', self.indentEnabled, true);
self.rowObject = new self.row(item, 'keyboard', self.indentEnabled, self.maxDepth, true);
}
var keyChange = false;
......@@ -753,10 +757,12 @@ Drupal.tableDrag.prototype.onDrop = function() {
* The method in which this row is being moved. Either 'keyboard' or 'mouse'.
* @param indentEnabled
* Whether the containing table uses indentations. Used for optimizations.
* @param maxDepth
* The maximum amount of indentations this row may contain.
* @param addClasses
* Whether we want to add classes to this row to indicate child relationships.
*/
Drupal.tableDrag.prototype.row = function(tableRow, method, indentEnabled, addClasses) {
Drupal.tableDrag.prototype.row = function(tableRow, method, indentEnabled, maxDepth, addClasses) {
this.element = tableRow;
this.method = method;
this.group = new Array(tableRow);
......@@ -764,6 +770,7 @@ Drupal.tableDrag.prototype.row = function(tableRow, method, indentEnabled, addCl
this.changed = false;
this.table = $(tableRow).parents('table:first').get(0);
this.indentEnabled = indentEnabled;
this.maxDepth = maxDepth;
this.direction = ''; // Direction the row is being moved.
if (this.indentEnabled) {
......@@ -901,8 +908,8 @@ Drupal.tableDrag.prototype.row.prototype.indent = function(indentDiff) {
indentDiff = Math.max(nextIndent - this.indents, indentDiff);
}
// Never allow indentation greater than 8 parents (menu system limit).
if (indentDiff + this.groupDepth > 8) {
// Never allow indentation greater the set limit.
if (this.maxDepth && indentDiff + this.groupDepth > this.maxDepth) {
indentDiff = 0;
}
......
This diff is collapsed.
......@@ -28,6 +28,9 @@
display: block;
float: right;
}
#book-outline {
min-width: 56em;
}
.book-outline-form .form-item {
margin-top: 0;
margin-bottom: 0;
......
......@@ -143,13 +143,6 @@ function book_menu() {
'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;
}
......
......@@ -165,7 +165,7 @@ function menu_overview_form_submit($form, &$form_state) {
* Theme the menu overview form into a table.
*/
function theme_menu_overview_form($form) {
drupal_add_tabledrag('menu-overview', 'match', 'parent', 'menu-plid', 'menu-plid', 'menu-mlid');
drupal_add_tabledrag('menu-overview', 'match', 'parent', 'menu-plid', 'menu-plid', 'menu-mlid', TRUE, MENU_MAX_DEPTH - 1);
drupal_add_tabledrag('menu-overview', 'order', 'sibling', 'menu-weight');
$header = array(
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment