]> git.mjollnir.org Git - moodle.git/commitdiff
MDL-16605 Add an ajaxy search box on the define/override roles screen to help find...
authortjhunt <tjhunt>
Fri, 26 Sep 2008 06:50:31 +0000 (06:50 +0000)
committertjhunt <tjhunt>
Fri, 26 Sep 2008 06:50:31 +0000 (06:50 +0000)
admin/roles/manage.html
admin/roles/manage.php
admin/roles/override.html
admin/roles/override.php
admin/roles/roles.js [new file with mode: 0644]
lang/en_utf8/moodle.php
theme/standard/styles_layout.css

index 5d6845359d85fd4c5a8c65d36a9a50679b9d9a2c..930d417b1cc6e2a4a64fb5f28d1551293f0adb29 100755 (executable)
@@ -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>
index 1ed02410acdf67535aa3099bab6cc7676774835b..dba2f525bee181274147084eed0e901115369fe7 100755 (executable)
     }
 
 /// 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';
index 74d0eafd75a3c851022ce4272b8335b5b03e67a2..a36672303493c3d2a240cbddac243e0ecab3a592 100755 (executable)
@@ -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>
     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>
index fbb45ca6f06a5ae351ddaff126e4a0ee2a6117d5..34c99232f46eb27211a4bcde5cbdf66104a4afc1 100755 (executable)
 
 
 /// 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
diff --git a/admin/roles/roles.js b/admin/roles/roles.js
new file mode 100644 (file)
index 0000000..2f85336
--- /dev/null
@@ -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);
+        }
+    }
+};
index 95558b41a38ff6fa21f722d39bdfe5744144ee95..6afbed3bb17a5fb98c8d25ab677bd6fff55f56d2 100644 (file)
@@ -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';
index a020494dd6e1a0a55ef1b6619e62bbf676afd8cc..4649a7e5630b28ee41fa1eda9503ad512e8e5b03 100644 (file)
@@ -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,