Commit 40566af6 authored by Andrew Nicols's avatar Andrew Nicols
Browse files

Merge branch 'MDL-57490-master' of git://github.com/danpoltawski/moodle

parents 3dc33059 f8abbbe2
......@@ -896,96 +896,53 @@ M.util.add_spinner = function(Y, node) {
return spinner;
}
//=== old legacy JS code, hopefully to be replaced soon by M.xx.yy and YUI3 code ===
/**
* @deprecated since Moodle 3.3.
*/
function checkall() {
var inputs = document.getElementsByTagName('input');
for (var i = 0; i < inputs.length; i++) {
if (inputs[i].type == 'checkbox') {
if (inputs[i].disabled || inputs[i].readOnly) {
continue;
}
inputs[i].checked = true;
}
}
throw new Error('checkall can not be used any more. Please use jQuery instead.');
}
/**
* @deprecated since Moodle 3.3.
*/
function checknone() {
var inputs = document.getElementsByTagName('input');
for (var i = 0; i < inputs.length; i++) {
if (inputs[i].type == 'checkbox') {
if (inputs[i].disabled || inputs[i].readOnly) {
continue;
}
inputs[i].checked = false;
}
}
throw new Error('checknone can not be used any more. Please use jQuery instead.');
}
/**
* Either check, or uncheck, all checkboxes inside the element with id is
* @param id the id of the container
* @param checked the new state, either '' or 'checked'.
* @deprecated since Moodle 3.3.
*/
function select_all_in_element_with_id(id, checked) {
var container = document.getElementById(id);
if (!container) {
return;
}
var inputs = container.getElementsByTagName('input');
for (var i = 0; i < inputs.length; ++i) {
if (inputs[i].type == 'checkbox' || inputs[i].type == 'radio') {
inputs[i].checked = checked;
}
}
throw new Error('select_all_in_element_with_id can not be used any more. Please use jQuery instead.');
}
/**
* @deprecated since Moodle 3.3.
*/
function select_all_in(elTagName, elClass, elId) {
var inputs = document.getElementsByTagName('input');
inputs = filterByParent(inputs, function(el) {return findParentNode(el, elTagName, elClass, elId);});
for(var i = 0; i < inputs.length; ++i) {
if(inputs[i].type == 'checkbox' || inputs[i].type == 'radio') {
inputs[i].checked = 'checked';
}
}
throw new Error('select_all_in can not be used any more. Please use jQuery instead.');
}
/**
* @deprecated since Moodle 3.3.
*/
function deselect_all_in(elTagName, elClass, elId) {
var inputs = document.getElementsByTagName('INPUT');
inputs = filterByParent(inputs, function(el) {return findParentNode(el, elTagName, elClass, elId);});
for(var i = 0; i < inputs.length; ++i) {
if(inputs[i].type == 'checkbox' || inputs[i].type == 'radio') {
inputs[i].checked = '';
}
}
throw new Error('deselect_all_in can not be used any more. Please use jQuery instead.');
}
/**
* @deprecated since Moodle 3.3.
*/
function confirm_if(expr, message) {
if(!expr) {
return true;
}
return confirm(message);
throw new Error('confirm_if can not be used any more.');
}
/*
findParentNode (start, elementName, elementClass, elementID)
Travels up the DOM hierarchy to find a parent element with the
specified tag name, class, and id. All conditions must be met,
but any can be ommitted. Returns the BODY element if no match
found.
*/
/**
* @deprecated since Moodle 3.3.
*/
function findParentNode(el, elName, elClass, elId) {
while (el.nodeName.toUpperCase() != 'BODY') {
if ((!elName || el.nodeName.toUpperCase() == elName) &&
(!elClass || el.className.indexOf(elClass) != -1) &&
(!elId || el.id == elId)) {
break;
}
el = el.parentNode;
}
return el;
throw new Error('findParentNode can not be used any more. Please use jQuery instead.');
}
function unmaskPassword(id) {
......@@ -1031,15 +988,11 @@ function unmaskPassword(id) {
}
}
/**
* @deprecated since Moodle 3.3.
*/
function filterByParent(elCollection, parentFinder) {
var filteredCollection = [];
for (var i = 0; i < elCollection.length; ++i) {
var findParent = parentFinder(elCollection[i]);
if (findParent.nodeName.toUpperCase() != 'BODY') {
filteredCollection.push(elCollection[i]);
}
}
return filteredCollection;
throw new Error('filterByParent can not be used any more. Please use jQuery instead.');
}
/**
......@@ -1253,10 +1206,11 @@ function convert_object_to_string(obj, separator) {
return list.join(separator);
}
/**
* @deprecated since Moodle 3.3.
*/
function stripHTML(str) {
var re = /<\S[^><]*>/g;
var ret = str.replace(re, "");
return ret;
throw new Error('stripHTML can not be used any more. Please use jQuery instead.');
}
function updateProgressBar(id, percent, msg, estimate) {
......@@ -1290,64 +1244,6 @@ function updateProgressBar(id, percent, msg, estimate) {
el.dispatchEvent(event);
}
// ===== Deprecated core Javascript functions for Moodle ====
// DO NOT USE!!!!!!!
// Do not put this stuff in separate file because it only adds extra load on servers!
/**
* @method show_item
* @deprecated since Moodle 2.7.
* @see Y.Node.show
*/
function show_item() {
throw new Error('show_item can not be used any more. Please use Y.Node.show.');
}
/**
* @method destroy_item
* @deprecated since Moodle 2.7.
* @see Y.Node.destroy
*/
function destroy_item() {
throw new Error('destroy_item can not be used any more. Please use Y.Node.destroy.');
}
/**
* @method hide_item
* @deprecated since Moodle 2.7.
* @see Y.Node.hide
*/
function hide_item() {
throw new Error('hide_item can not be used any more. Please use Y.Node.hide.');
}
/**
* @method addonload
* @deprecated since Moodle 2.7 - please do not use this function any more.
*/
function addonload() {
throw new Error('addonload can not be used any more.');
}
/**
* @method getElementsByClassName
* @deprecated Since Moodle 2.7 - please do not use this function any more.
* @see Y.one
* @see Y.all
*/
function getElementsByClassName() {
throw new Error('getElementsByClassName can not be used any more. Please use Y.one or Y.all.');
}
/**
* @method findChildNodes
* @deprecated since Moodle 2.7 - please do not use this function any more.
* @see Y.all
*/
function findChildNodes() {
throw new Error('findChildNodes can not be used any more. Please use Y.all.');
}
M.util.help_popups = {
setup : function(Y) {
Y.one('body').delegate('click', this.open_popup, 'a.helplinkpopup', this);
......
......@@ -10,6 +10,9 @@ information provided here is intended especially for developers.
* Return value of the validate_email() is now proper boolean as documented. Previously the function could return 1, 0 or false.
* M.util.focus_login_form and M.util.focus_login_error no longer do anything. Please use jquery instead. See
lib/templates/login.mustache for an example.
* Some outdated global JS functions have been removed and should be replaced with calls to jquery or alternative approaches:
checkall, checknone, select_all_in_element_with_id, select_all_in, deselect_all_in, confirm_if, findParentNode,
filterByParent, stripHTML
=== 3.2 ===
......
......@@ -448,8 +448,8 @@ if ($action === 'delete') {
}
echo html_writer::table($table);
if (has_capability('mod/lesson:edit', $context)) {
$checklinks = '<a href="javascript: checkall();">'.get_string('selectall').'</a> / ';
$checklinks .= '<a href="javascript: checknone();">'.get_string('deselectall').'</a>';
$checklinks = '<a id="checkall" href="#">'.get_string('selectall').'</a> / ';
$checklinks .= '<a id="checknone" href="#">'.get_string('deselectall').'</a>';
$checklinks .= html_writer::label('action', 'menuaction', false, array('class' => 'accesshide'));
$options = array('delete' => get_string('deleteselected'));
$attributes = array('id' => 'actionid', 'class' => 'custom-select m-l-1');
......@@ -459,6 +459,14 @@ if ($action === 'delete') {
$('#actionid').change(function() {
$('#mod-lesson-report-form').submit();
});
$('#checkall').click(function(e) {
$('#mod-lesson-report-form').find('input:checkbox').prop('checked', true);
e.preventDefault();
});
$('#checknone').click(function(e) {
$('#mod-lesson-report-form').find('input:checkbox').prop('checked', false);
e.preventDefault();
});
});");
echo $OUTPUT->box($checklinks, 'center');
echo '</form>';
......
......@@ -569,15 +569,27 @@ abstract class quiz_attempts_report_table extends table_sql {
}
public function wrap_html_finish() {
global $PAGE;
if ($this->is_downloading() || !$this->includecheckboxes) {
return;
}
echo '<div id="commands">';
echo '<a href="javascript:select_all_in(\'DIV\', null, \'tablecontainer\');">' .
echo '<a id="checkattempts" href="#">' .
get_string('selectall', 'quiz') . '</a> / ';
echo '<a href="javascript:deselect_all_in(\'DIV\', null, \'tablecontainer\');">' .
echo '<a id="uncheckattempts" href="#">' .
get_string('selectnone', 'quiz') . '</a> ';
$PAGE->requires->js_amd_inline("
require(['jquery'], function($) {
$('#checkattempts').click(function(e) {
$('#attemptsform').find('input:checkbox').prop('checked', true);
e.preventDefault();
});
$('#uncheckattempts').click(function(e) {
$('#attemptsform').find('input:checkbox').prop('checked', false);
e.preventDefault();
});
});");
echo '&nbsp;&nbsp;';
$this->submit_buttons();
echo '</div>';
......
......@@ -492,10 +492,20 @@ class report extends \mod_scorm\report {
if ($candelete) {
echo \html_writer::start_tag('table', array('id' => 'commands'));
echo \html_writer::start_tag('tr').\html_writer::start_tag('td');
echo \html_writer::link('javascript:select_all_in(\'DIV\', null, \'scormtablecontainer\');',
get_string('selectall', 'scorm')).' / ';
echo \html_writer::link('javascript:deselect_all_in(\'DIV\', null, \'scormtablecontainer\');',
get_string('selectnone', 'scorm'));
echo \html_writer::link('#', get_string('selectall', 'scorm'), array('id' => 'checkattempts'));
echo ' / ';
echo \html_writer::link('#', get_string('selectnone', 'scorm'), array('id' => 'uncheckattempts'));
$PAGE->requires->js_amd_inline("
require(['jquery'], function($) {
$('#checkattempts').click(function(e) {
$('#attemptsform').find('input:checkbox').prop('checked', true);
e.preventDefault();
});
$('#uncheckattempts').click(function(e) {
$('#attemptsform').find('input:checkbox').prop('checked', false);
e.preventDefault();
});
});");
echo '&nbsp;&nbsp;';
echo \html_writer::empty_tag('input', array('type' => 'submit',
'value' => get_string('deleteselected', 'scorm'),
......
......@@ -582,10 +582,20 @@ class report extends \mod_scorm\report {
if ($candelete) {
echo \html_writer::start_tag('table', array('id' => 'commands'));
echo \html_writer::start_tag('tr').\html_writer::start_tag('td');
echo \html_writer::link('javascript:select_all_in(\'DIV\', null, \'scormtablecontainer\');',
get_string('selectall', 'scorm')).' / ';
echo \html_writer::link('javascript:deselect_all_in(\'DIV\', null, \'scormtablecontainer\');',
get_string('selectnone', 'scorm'));
echo \html_writer::link('#', get_string('selectall', 'scorm'), array('id' => 'checkattempts'));
echo ' / ';
echo \html_writer::link('#', get_string('selectnone', 'scorm'), array('id' => 'uncheckattempts'));
$PAGE->requires->js_amd_inline("
require(['jquery'], function($) {
$('#checkattempts').click(function(e) {
$('#attemptsform').find('input:checkbox').prop('checked', true);
e.preventDefault();
});
$('#uncheckattempts').click(function(e) {
$('#attemptsform').find('input:checkbox').prop('checked', false);
e.preventDefault();
});
});");
echo '&nbsp;&nbsp;';
echo \html_writer::empty_tag('input', array('type' => 'submit',
'value' => get_string('deleteselected', 'scorm'),
......
......@@ -582,10 +582,20 @@ class report extends \mod_scorm\report {
if ($candelete) {
echo \html_writer::start_tag('table', array('id' => 'commands'));
echo \html_writer::start_tag('tr').\html_writer::start_tag('td');
echo \html_writer::link('javascript:select_all_in(\'DIV\', null, \'scormtablecontainer\');',
get_string('selectall', 'scorm')).' / ';
echo \html_writer::link('javascript:deselect_all_in(\'DIV\', null, \'scormtablecontainer\');',
get_string('selectnone', 'scorm'));
echo \html_writer::link('#', get_string('selectall', 'scorm'), array('id' => 'checkattempts'));
echo ' / ';
echo \html_writer::link('#', get_string('selectnone', 'scorm'), array('id' => 'uncheckattempts'));
$PAGE->requires->js_amd_inline("
require(['jquery'], function($) {
$('#checkattempts').click(function(e) {
$('#attemptsform').find('input:checkbox').prop('checked', true);
e.preventDefault();
});
$('#uncheckattempts').click(function(e) {
$('#attemptsform').find('input:checkbox').prop('checked', false);
e.preventDefault();
});
});");
echo '&nbsp;&nbsp;';
echo \html_writer::empty_tag('input', array('type' => 'submit',
'value' => get_string('deleteselected', 'scorm'),
......
Supports Markdown
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