MDL-16605 Add an ajaxy search box on the define/override roles screen to help find the capability you want
This commit is contained in:
@@ -95,7 +95,7 @@
|
||||
$strprohibit = get_string('prohibit','role');
|
||||
?>
|
||||
|
||||
<table class="rolecap">
|
||||
<table class="rolecap" id="managerolestable">
|
||||
|
||||
<tr>
|
||||
<th class="name" align="left" scope="col"><?php print_string('capability','role') ?></th>
|
||||
@@ -214,6 +214,10 @@ foreach ($capabilities as $capability) {
|
||||
<input type="submit" value="<?php p($submitlabel) ?>" />
|
||||
<input type="submit" name="cancel" value="<?php print_string('cancel') ?>" />
|
||||
</div>
|
||||
<?php } ?>
|
||||
<?php }
|
||||
|
||||
print_js_call('cap_table_filter.init',
|
||||
array('managerolestable', get_string('search'), get_string('clear')));
|
||||
?>
|
||||
|
||||
</form>
|
||||
|
||||
@@ -417,7 +417,8 @@
|
||||
}
|
||||
|
||||
/// print UI now
|
||||
|
||||
require_js(array('yui_yahoo', 'yui_dom', 'yui_event'));
|
||||
require_js($CFG->admin . '/roles/roles.js');
|
||||
admin_externalpage_print_header();
|
||||
|
||||
$currenttab = 'manage';
|
||||
|
||||
@@ -15,7 +15,7 @@
|
||||
<input type="hidden" name="courseid" value="<?php p($courseid) ?>" />
|
||||
</fieldset>
|
||||
|
||||
<table class="rolecap">
|
||||
<table class="rolecap" id="overriderolestable">
|
||||
<tr>
|
||||
<th class="name" align="left" scope="col"><?php print_string('capability','role') ?></th>
|
||||
<th class="inherit" scope="col"><?php p($strinherit); ?></th>
|
||||
@@ -150,6 +150,11 @@
|
||||
if ($safeoverridenotice) {
|
||||
echo '<div class="sefeoverridenotice">'.$strsafewarning.'</div>';
|
||||
}
|
||||
|
||||
if (count($capabilities) > 12) {
|
||||
print_js_call('cap_table_filter.init',
|
||||
array('overriderolestable', get_string('search'), get_string('clear')));
|
||||
}
|
||||
?>
|
||||
|
||||
</form>
|
||||
|
||||
@@ -146,7 +146,8 @@
|
||||
|
||||
|
||||
/// Print the header and tabs
|
||||
|
||||
require_js(array('yui_yahoo', 'yui_dom', 'yui_event'));
|
||||
require_js($CFG->admin . '/roles/roles.js');
|
||||
if ($context->contextlevel == CONTEXT_USER) {
|
||||
$navlinks = array();
|
||||
/// course header
|
||||
|
||||
@@ -0,0 +1,113 @@
|
||||
/* This class filters the rows of a table like the one on the define or
|
||||
override roles pages. It adds a search box just above the table, and if
|
||||
content is typed into that box, it hides any rows in the table where the
|
||||
capability name does not contain that text. */
|
||||
cap_table_filter = {
|
||||
input: null,
|
||||
table: null,
|
||||
button: null,
|
||||
delayhandle: -1,
|
||||
searchdelay: 100, // milliseconds
|
||||
|
||||
init: function(tableid, strsearch, strclear) {
|
||||
// Find the form controls.
|
||||
cap_table_filter.table = document.getElementById(tableid);
|
||||
|
||||
// Create a div to hold the search UI.
|
||||
var div = document.createElement('div');
|
||||
div.className = 'capabilitysearchui';
|
||||
div.style.width = cap_table_filter.table.offsetWidth + 'px';
|
||||
|
||||
// Create the capability search input.
|
||||
var input = document.createElement('input');
|
||||
input.type = 'text';
|
||||
input.id = tableid + 'capabilitysearch';
|
||||
cap_table_filter.input = input;
|
||||
|
||||
// Create a label for the search input.
|
||||
var label = document.createElement('label');
|
||||
label.htmlFor = input.id;
|
||||
label.appendChild(document.createTextNode(strsearch + ' '));
|
||||
|
||||
// Create a clear button to clear the input.
|
||||
var button = document.createElement('input');
|
||||
button.value = strclear;
|
||||
button.type = 'button';
|
||||
button.disabled = true;
|
||||
cap_table_filter.button = button;
|
||||
|
||||
// Tie it all together
|
||||
div.appendChild(label);
|
||||
div.appendChild(input);
|
||||
div.appendChild(button);
|
||||
cap_table_filter.table.parentNode.insertBefore(div, cap_table_filter.table);
|
||||
YAHOO.util.Event.addListener(input, 'keyup', cap_table_filter.change);
|
||||
YAHOO.util.Event.addListener(button, 'click', cap_table_filter.clear);
|
||||
|
||||
// Horrible hack!
|
||||
var hidden = document.createElement('input');
|
||||
hidden.type = 'hidden';
|
||||
hidden.disabled = true;
|
||||
div.appendChild(hidden);
|
||||
hidden = document.createElement('input');
|
||||
hidden.type = 'hidden';
|
||||
hidden.disabled = true;
|
||||
div.appendChild(hidden);
|
||||
},
|
||||
|
||||
clear: function () {
|
||||
cap_table_filter.input.value = '';
|
||||
if(cap_table_filter.delayhandle != -1) {
|
||||
clearTimeout(cap_table_filter.delayhandle);
|
||||
cap_table_filter.delayhandle = -1;
|
||||
}
|
||||
cap_table_filter.filter();
|
||||
},
|
||||
|
||||
change: function() {
|
||||
var handle = setTimeout(function(){cap_table_filter.filter();}, cap_table_filter.searchdelay);
|
||||
if(cap_table_filter.delayhandle != -1) {
|
||||
clearTimeout(cap_table_filter.delayhandle);
|
||||
}
|
||||
cap_table_filter.delayhandle = handle;
|
||||
},
|
||||
|
||||
set_visible: function(row, visible) {
|
||||
if (visible) {
|
||||
YAHOO.util.Dom.removeClass(row, 'hiddenrow');
|
||||
} else {
|
||||
YAHOO.util.Dom.addClass(row, 'hiddenrow');
|
||||
}
|
||||
},
|
||||
|
||||
filter: function() {
|
||||
var filtertext = cap_table_filter.input.value;
|
||||
cap_table_filter.button.disabled = filtertext == '';
|
||||
var rows = cap_table_filter.table.getElementsByTagName('tr');
|
||||
var lastheading = null;
|
||||
var capssincelastheading = 0;
|
||||
for (var i = 1; i < rows.length; i++) {
|
||||
var row = rows[i];
|
||||
if (YAHOO.util.Dom.hasClass(row, 'rolecapheading')) {
|
||||
if (lastheading) {
|
||||
cap_table_filter.set_visible(lastheading, capssincelastheading > 0);
|
||||
}
|
||||
lastheading = row;
|
||||
capssincelastheading = 0;
|
||||
}
|
||||
if (YAHOO.util.Dom.hasClass(row, 'rolecap')) {
|
||||
var capcell = YAHOO.util.Dom.getElementsByClassName('name', 'td', row)[0];
|
||||
var capname = capcell.innerText || capcell.textContent;
|
||||
if (capname.indexOf(filtertext) >= 0) {
|
||||
cap_table_filter.set_visible(row, true);
|
||||
capssincelastheading += 1;
|
||||
} else {
|
||||
cap_table_filter.set_visible(row, false);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (lastheading) {
|
||||
cap_table_filter.set_visible(lastheading, capssincelastheading > 0);
|
||||
}
|
||||
}
|
||||
};
|
||||
@@ -232,6 +232,7 @@ $string['clammovedfilebasic'] = 'The file has been moved to a quarantine directo
|
||||
$string['clamquarantinedirfailed'] = 'Could not move the file into your specified quarantine directory, $a. You need to fix this as files are being deleted if they\'re found to be infected.';
|
||||
$string['clamunknownerror'] = 'There was an unknown error with clam.';
|
||||
$string['cleaningtempdata'] = 'Cleaning temp data';
|
||||
$string['clear'] = 'Clear';
|
||||
$string['clicktochange'] = 'Click to change';
|
||||
$string['clickhere'] = 'Click here ...';
|
||||
$string['closewindow'] = 'Close this window';
|
||||
|
||||
@@ -1009,6 +1009,14 @@ body#admin-modules table.generaltable td.c0
|
||||
margin-left:auto;
|
||||
margin-right:auto;
|
||||
}
|
||||
.capabilitysearchui {
|
||||
text-align: left;
|
||||
margin-left: auto;
|
||||
margin-right: auto;
|
||||
}
|
||||
table.rolecap .hiddenrow {
|
||||
display: none;
|
||||
}
|
||||
|
||||
.rolecap .inherit,
|
||||
.rolecap .allow,
|
||||
|
||||
Reference in New Issue
Block a user