Issue #1848064 by sun, Wim Leers, bleen18, nod_, tstoeckler: Added Allow to filter modules by arbitrary search strings on the Modules page.

8.0.x
webchick 2013-02-08 16:41:02 -08:00
parent 5b6c981231
commit bf2bbbe931
4 changed files with 89 additions and 3 deletions

View File

@ -815,6 +815,26 @@ function system_modules($form, $form_state = array()) {
return system_modules_confirm_form($visible_files, $form_state['storage']);
}
// JS-only table filters.
$form['filters'] = array(
'#type' => 'container',
'#attributes' => array(
'class' => array('table-filter', 'js-show'),
),
);
$form['filters']['text'] = array(
'#type' => 'search',
'#title' => t('Search'),
'#size' => 30,
'#placeholder' => t('Enter module name…'),
'#attributes' => array(
'class' => array('table-filter-text'),
'data-table' => '#system-modules',
'autocomplete' => 'off',
'title' => t('Enter a part of the module name or description to filter by.'),
),
);
$modules = array();
$form['modules'] = array('#tree' => TRUE);
@ -2363,11 +2383,11 @@ function theme_system_modules_details($variables) {
$row[] = array('class' => array('checkbox'), 'data' => drupal_render($module['enable']));
// Add the module label and expand/collapse functionalty.
$col2 = '<label id="' . $key . '" for="' . $module['enable']['#id'] . '" class="module-name">' . drupal_render($module['name']) . '</label>';
$col2 = '<label id="' . $key . '" for="' . $module['enable']['#id'] . '" class="module-name table-filter-text-source">' . drupal_render($module['name']) . '</label>';
$row[] = array('class' => array('module'), 'data' => $col2);
// Add the description, along with any modules it requires.
$description = '<span class="details"><span class="text">' . drupal_render($module['description']) . '</span></span>';
$description = '<span class="details"><span class="text table-filter-text-source">' . drupal_render($module['description']) . '</span></span>';
if ($version || $requires || $required_by) {
$description .= ' <div class="requirements">';
if ($version) {

View File

@ -203,6 +203,16 @@ tr .ajax-progress-throbber .throbber {
display: none;
}
/**
* For anything you want to show on page load only when JS is enabled.
*/
.js-show {
display: none;
}
.js .js-show {
display: block;
}
/**
* Hide elements from all users.
*

View File

@ -2133,7 +2133,7 @@ function system_library_info() {
),
);
$libraries['drupal.system.modules'] = array(
'title' => 'System cron',
'title' => 'System modules',
'version' => VERSION,
'js' => array(
drupal_get_path('module', 'system') . '/system.modules.js' => array(),

View File

@ -64,4 +64,60 @@ Drupal.behaviors.hideModuleInformation = {
}
};
/**
* Filters the module list table by a text input search string.
*
* Additionally accounts for multiple tables being wrapped in "package" details
* elements.
*
* Text search input: input.table-filter-text
* Target table: input.table-filter-text[data-table]
* Source text: .table-filter-text-source
*/
Drupal.behaviors.tableFilterByText = {
attach: function (context, settings) {
var $input = $('input.table-filter-text').once('table-filter-text');
var $table = $($input.attr('data-table'));
var $rowsAndDetails, $rows, $details;
function hidePackageDetails(index, element) {
var $details = $(element);
var $visibleRows = $details.find('table:not(.sticky-header)').find('tbody tr:visible');
$details.toggle($visibleRows.length > 0);
}
function filterModuleList (e) {
var query = $(e.target).val().toLowerCase();
function showModuleRow (index, row) {
var $row = $(row);
var $sources = $row.find('.table-filter-text-source');
var textMatch = $sources.text().toLowerCase().indexOf(query) !== -1;
$row.closest('tr').toggle(textMatch);
}
// Filter if the length of the query is at least 2 characters.
if (query.length >= 2) {
$rows.each(showModuleRow);
// Hide the package <details> if they don't have any visible rows.
// Note that we first show() all <details> to be able to use ':visible'.
$details.show().each(hidePackageDetails);
}
else {
$rowsAndDetails.show();
}
}
if ($table.length) {
$rowsAndDetails = $table.find('tr, details');
$rows = $table.find('tbody tr');
$details = $table.find('details');
// @todo Use autofocus attribute when possible.
$input.focus().on('keyup', filterModuleList);
}
}
};
}(jQuery, Drupal));