YUI.add('moodle-backup-backupselectall', function (Y, NAME) { /** * Adds select all/none links to the top of the backup/restore/import schema page. * * @module moodle-backup-backupselectall */ // Namespace for the backup M.core_backup = M.core_backup || {}; /** * Adds select all/none links to the top of the backup/restore/import schema page. * * @class M.core_backup.backupselectall */ M.core_backup.backupselectall = function(modnames) { var formid = null; var helper = function(e, check, type, mod) { e.preventDefault(); var prefix = ''; if (typeof mod !== 'undefined') { prefix = 'setting_activity_' + mod + '_'; } var len = type.length; Y.all('input[type="checkbox"]').each(function(checkbox) { var name = checkbox.get('name'); // If a prefix has been set, ignore checkboxes which don't have that prefix. if (prefix && name.substring(0, prefix.length) !== prefix) { return; } if (name.substring(name.length - len) === type) { checkbox.set('checked', check); } }); // At this point, we really need to persuade the form we are part of to // update all of its disabledIf rules. However, as far as I can see, // given the way that lib/form/form.js is written, that is impossible. if (formid && M.form) { M.form.updateFormState(formid); } }; var html_generator = function(classname, idtype, heading, extra) { if (typeof extra === 'undefined') { extra = ''; } return '
' + '
' + '
' + heading + '
' + '' + '
' + '
'; }; var firstsection = Y.one('fieldset#id_coursesettings .fcontainer.clearfix .grouped_settings.section_level'); if (!firstsection) { // This is not a relevant page. return; } if (!firstsection.one('input[type="checkbox"]')) { // No checkboxes. return; } formid = firstsection.ancestor('form').getAttribute('id'); var withuserdata = false; Y.all('input[type="checkbox"]').each(function(checkbox) { var name = checkbox.get('name'); if (name.substring(name.length - 9) === '_userdata') { withuserdata = '_userdata'; } else if (name.substring(name.length - 9) === '_userinfo') { withuserdata = '_userinfo'; } }); // Add global select all/none options. var html = html_generator('include_setting section_level', 'included', M.util.get_string('select', 'moodle'), ' (' + M.util.get_string('showtypes', 'backup') + ')'); if (withuserdata) { html += html_generator('normal_setting', 'userdata', M.util.get_string('select', 'moodle')); } var links = Y.Node.create('
' + html + '
'); firstsection.insert(links, 'before'); // Add select all/none for each module type. var initlinks = function(links, mod) { Y.one('#backup-all-mod_' + mod).on('click', function(e) { helper(e, true, '_included', mod); }); Y.one('#backup-none-mod_' + mod).on('click', function(e) { helper(e, false, '_included', mod); }); if (withuserdata) { Y.one('#backup-all-userdata-mod_' + mod).on('click', function(e) { helper(e, true, withuserdata, mod); }); Y.one('#backup-none-userdata-mod_' + mod).on('click', function(e) { helper(e, false, withuserdata, mod); }); } }; // For each module type on the course, add hidden select all/none options. var modlist = Y.Node.create('