mirror of
https://github.com/moodle/moodle.git
synced 2025-08-04 16:36:37 +02:00
MDL-21400 migrated roles JS to YUI3 and new modular structure
This commit is contained in:
parent
1b4e41af17
commit
9786fbfac4
5 changed files with 138 additions and 137 deletions
|
@ -256,8 +256,6 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Print the header and tabs
|
/// Print the header and tabs
|
||||||
$PAGE->requires->yui2_lib('dom-event');
|
|
||||||
$PAGE->requires->js('/admin/roles/roles.js');
|
|
||||||
if ($context->contextlevel == CONTEXT_USER) {
|
if ($context->contextlevel == CONTEXT_USER) {
|
||||||
$user = $DB->get_record('user', array('id'=>$userid));
|
$user = $DB->get_record('user', array('id'=>$userid));
|
||||||
$fullname = fullname($user, has_capability('moodle/site:viewfullnames', $context));
|
$fullname = fullname($user, has_capability('moodle/site:viewfullnames', $context));
|
||||||
|
@ -351,7 +349,7 @@
|
||||||
</div></form>
|
</div></form>
|
||||||
|
|
||||||
<?php
|
<?php
|
||||||
$PAGE->requires->js_function_call('init_add_assign_page');
|
$PAGE->requires->js_init_call('M.core_role.init_add_assign_page', null, 'core_role');
|
||||||
|
|
||||||
if (!empty($errors)) {
|
if (!empty($errors)) {
|
||||||
$msg = '<p>';
|
$msg = '<p>';
|
||||||
|
|
|
@ -121,11 +121,8 @@ abstract class capability_table_base {
|
||||||
/// End of the table.
|
/// End of the table.
|
||||||
echo "</tbody>\n</table>\n";
|
echo "</tbody>\n</table>\n";
|
||||||
if (count($this->capabilities) > capability_table_base::NUM_CAPS_FOR_SEARCH) {
|
if (count($this->capabilities) > capability_table_base::NUM_CAPS_FOR_SEARCH) {
|
||||||
global $CFG, $PAGE;
|
global $PAGE;
|
||||||
$PAGE->requires->yui2_lib('dom-event');
|
$PAGE->requires->js_init_call('M.core_role.init_cap_table_filter', array($this->id, get_string('filter'), get_string('clear')), 'core_role');
|
||||||
$PAGE->requires->js('/admin/roles/roles.js');
|
|
||||||
$PAGE->requires->js_function_call('cap_table_filter.init',
|
|
||||||
array($this->id, get_string('filter'), get_string('clear')));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
130
admin/roles/module.js
Normal file
130
admin/roles/module.js
Normal file
|
@ -0,0 +1,130 @@
|
||||||
|
/* 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. */
|
||||||
|
|
||||||
|
M.core_role = {};
|
||||||
|
|
||||||
|
M.core_role.CapTableFilter = function(Y, tableid, strsearch, strclear) {
|
||||||
|
this.delayhandle = -1,
|
||||||
|
this.searchdelay = 100, // milliseconds
|
||||||
|
|
||||||
|
this.Y = Y
|
||||||
|
// Find the form controls.
|
||||||
|
this.table = document.getElementById(tableid);
|
||||||
|
|
||||||
|
// Create a div to hold the search UI.
|
||||||
|
this.div = document.createElement('div');
|
||||||
|
this.div.className = 'capabilitysearchui';
|
||||||
|
this.div.style.width = this.table.offsetWidth + 'px';
|
||||||
|
|
||||||
|
// Create the capability search input.
|
||||||
|
this.input = document.createElement('input');
|
||||||
|
this.input.type = 'text';
|
||||||
|
this.input.id = tableid + 'capabilitysearch';
|
||||||
|
|
||||||
|
// Create a label for the search input.
|
||||||
|
this.label = document.createElement('label');
|
||||||
|
this.label.htmlFor = this.input.id;
|
||||||
|
this.label.appendChild(document.createTextNode(strsearch + ' '));
|
||||||
|
|
||||||
|
// Create a clear button to clear the input.
|
||||||
|
this.button = document.createElement('input');
|
||||||
|
this.button.value = strclear;
|
||||||
|
this.button.type = 'button';
|
||||||
|
this.button.disabled = true;
|
||||||
|
|
||||||
|
// Tie it all together
|
||||||
|
this.div.appendChild(this.label);
|
||||||
|
this.div.appendChild(this.input);
|
||||||
|
this.div.appendChild(this.button);
|
||||||
|
this.table.parentNode.insertBefore(this.div, this.table);
|
||||||
|
Y.on('keyup', this.change, this.input, this);
|
||||||
|
Y.on('click', this.clear, this.button, this);
|
||||||
|
|
||||||
|
// Horrible hack!
|
||||||
|
var hidden = document.createElement('input');
|
||||||
|
hidden.type = 'hidden';
|
||||||
|
hidden.disabled = true;
|
||||||
|
this.div.appendChild(hidden);
|
||||||
|
hidden = document.createElement('input');
|
||||||
|
hidden.type = 'hidden';
|
||||||
|
hidden.disabled = true;
|
||||||
|
this.div.appendChild(hidden);
|
||||||
|
};
|
||||||
|
|
||||||
|
M.core_role.CapTableFilter.prototype.clear = function () {
|
||||||
|
this.input.value = '';
|
||||||
|
if (this.delayhandle != -1) {
|
||||||
|
clearTimeout(this.delayhandle);
|
||||||
|
this.delayhandle = -1;
|
||||||
|
}
|
||||||
|
this.filter();
|
||||||
|
};
|
||||||
|
|
||||||
|
M.core_role.CapTableFilter.prototype.change = function() {
|
||||||
|
var self = this;
|
||||||
|
var handle = setTimeout(function(){self.filter();}, this.searchdelay);
|
||||||
|
if (this.delayhandle != -1) {
|
||||||
|
clearTimeout(this.delayhandle);
|
||||||
|
}
|
||||||
|
this.delayhandle = handle;
|
||||||
|
};
|
||||||
|
|
||||||
|
M.core_role.CapTableFilter.prototype.set_visible = function(row, visible) {
|
||||||
|
if (visible) {
|
||||||
|
this.Y.one(row).removeClass('hiddenrow');
|
||||||
|
} else {
|
||||||
|
this.Y.one(row).addClass('hiddenrow');
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
M.core_role.CapTableFilter.prototype.filter = function() {
|
||||||
|
var filtertext = this.input.value.toLowerCase();
|
||||||
|
this.button.disabled = (filtertext == '');
|
||||||
|
var lastheading = null;
|
||||||
|
var capssincelastheading = 0;
|
||||||
|
|
||||||
|
Y.all('#'+this.table.id+' tr').each(function(row, index, list) {
|
||||||
|
if (row.hasClass('rolecapheading')) {
|
||||||
|
if (lastheading) {
|
||||||
|
this.set_visible(lastheading, capssincelastheading > 0);
|
||||||
|
}
|
||||||
|
lastheading = row;
|
||||||
|
capssincelastheading = 0;
|
||||||
|
}
|
||||||
|
if (row.hasClass('rolecap')) {
|
||||||
|
var capname = row.one('.cap-name').get('text') + '|' + row.one('.cap-desc a').get('text').toLowerCase();
|
||||||
|
if (capname.indexOf(filtertext) >= 0) {
|
||||||
|
this.set_visible(row, true);
|
||||||
|
capssincelastheading += 1;
|
||||||
|
} else {
|
||||||
|
this.set_visible(row, false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}, this);
|
||||||
|
|
||||||
|
if (lastheading) {
|
||||||
|
this.set_visible(lastheading, capssincelastheading > 0);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
M.core_role.init_cap_table_filter = function(Y, tableid, strsearch, strclear) {
|
||||||
|
new M.core_role.CapTableFilter(Y, tableid, strsearch, strclear);
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
M.core_role.init_add_assign_page = function(Y) {
|
||||||
|
var addselect = user_selector.get('addselect');
|
||||||
|
document.getElementById('add').disabled = addselect.is_selection_empty();
|
||||||
|
addselect.subscribe('selectionchanged', function(isempty) {
|
||||||
|
document.getElementById('add').disabled = isempty;
|
||||||
|
});
|
||||||
|
|
||||||
|
var removeselect = user_selector.get('removeselect');
|
||||||
|
document.getElementById('remove').disabled = removeselect.is_selection_empty();
|
||||||
|
removeselect.subscribe('selectionchanged', function(isempty) {
|
||||||
|
document.getElementById('remove').disabled = isempty;
|
||||||
|
});
|
||||||
|
};
|
|
@ -1,127 +0,0 @@
|
||||||
/* 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.toLowerCase();
|
|
||||||
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', 'th', row)[0];
|
|
||||||
var capname = capcell.innerText || capcell.textContent;
|
|
||||||
if (capname.toLowerCase().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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
function init_add_assign_page() {
|
|
||||||
var addselect = user_selector.get('addselect');
|
|
||||||
document.getElementById('add').disabled = addselect.is_selection_empty();
|
|
||||||
addselect.subscribe('selectionchanged', function(isempty) {
|
|
||||||
document.getElementById('add').disabled = isempty;
|
|
||||||
});
|
|
||||||
|
|
||||||
var removeselect = user_selector.get('removeselect');
|
|
||||||
document.getElementById('remove').disabled = removeselect.is_selection_empty();
|
|
||||||
removeselect.subscribe('selectionchanged', function(isempty) {
|
|
||||||
document.getElementById('remove').disabled = isempty;
|
|
||||||
});
|
|
||||||
}
|
|
|
@ -353,6 +353,9 @@ class page_requirements_manager {
|
||||||
} else if($name === 'core_comment') {
|
} else if($name === 'core_comment') {
|
||||||
$pathtocomment = $CFG->httpswwwroot.'/comment/comment.js';
|
$pathtocomment = $CFG->httpswwwroot.'/comment/comment.js';
|
||||||
$module = array('fullpath'=>$pathtocomment, 'requires' => array('base', 'io', 'node', 'json', 'yui2-animation'));
|
$module = array('fullpath'=>$pathtocomment, 'requires' => array('base', 'io', 'node', 'json', 'yui2-animation'));
|
||||||
|
} else if($name === 'core_role') {
|
||||||
|
$pathtocomment = $CFG->httpswwwroot.'/'.$CFG->admin.'/roles/module.js';
|
||||||
|
$module = array('fullpath'=>$pathtocomment);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if ($dir = get_component_directory($name)) {
|
if ($dir = get_component_directory($name)) {
|
||||||
|
@ -472,7 +475,7 @@ class page_requirements_manager {
|
||||||
* {@link required_js_function_call::on_dom_ready()} or
|
* {@link required_js_function_call::on_dom_ready()} or
|
||||||
* {@link required_js_function_call::after_delay()} methods.
|
* {@link required_js_function_call::after_delay()} methods.
|
||||||
*/
|
*/
|
||||||
public function js_function_call($function, $arguments = array()) {
|
public function js_function_call($function, array $arguments = null) {
|
||||||
$requirement = new required_js_function_call($this, $function, $arguments);
|
$requirement = new required_js_function_call($this, $function, $arguments);
|
||||||
$this->requiredjscode[] = $requirement;
|
$this->requiredjscode[] = $requirement;
|
||||||
return $requirement;
|
return $requirement;
|
||||||
|
@ -492,7 +495,7 @@ class page_requirements_manager {
|
||||||
* @param bool $ondomready wait for dom ready (helps with some IE problems when modifying DOM)
|
* @param bool $ondomready wait for dom ready (helps with some IE problems when modifying DOM)
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function js_init_call($function, $extraarguments = array(), $module = null, $ondomready = false) {
|
public function js_init_call($function, array $extraarguments = null, $module = null, $ondomready = false) {
|
||||||
$jscode = js_writer::function_call_with_Y($function, $extraarguments);
|
$jscode = js_writer::function_call_with_Y($function, $extraarguments);
|
||||||
$this->js_init_code($jscode, $module, $ondomready);
|
$this->js_init_code($jscode, $module, $ondomready);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue