1 YUI.add('moodle-backup-backupselectall', function(Y) {
3 // Namespace for the backup
4 M.core_backup = M.core_backup || {};
7 * Adds select all/none links to the top of the backup/restore/import schema page.
9 M.core_backup.select_all_init = function(str) {
12 var helper = function(e, check, type) {
15 var len = type.length;
16 Y.all('input[type="checkbox"]').each(function(checkbox) {
17 var name = checkbox.get('name');
18 if (name.substring(name.length - len) == type) {
19 checkbox.set('checked', check);
23 // At this point, we really need to persuade the form we are part of to
24 // update all of its disabledIf rules. However, as far as I can see,
25 // given the way that lib/form/form.js is written, that is impossible.
26 if (formid && M.form) {
27 M.form.updateFormState(formid);
31 var html_generator = function(classname, idtype) {
32 return '<div class="' + classname + '">' +
33 '<div class="fitem fitem_fcheckbox">' +
34 '<div class="fitemtitle">' + str.select + '</div>' +
35 '<div class="felement">' +
36 '<a id="backup-all-' + idtype + '" href="#">' + str.all + '</a> / ' +
37 '<a id="backup-none-' + idtype + '" href="#">' + str.none + '</a>' +
43 var firstsection = Y.one('fieldset#coursesettings .fcontainer.clearfix .grouped_settings.section_level');
45 // This is not a relevant page.
48 if (!firstsection.one('.felement.fcheckbox')) {
53 formid = firstsection.ancestor('form').getAttribute('id');
55 var withuserdata = false;
56 Y.all('input[type="checkbox"]').each(function(checkbox) {
57 var name = checkbox.get('name');
58 if (name.substring(name.length - 9) == '_userdata') {
59 withuserdata = '_userdata';
60 } else if (name.substring(name.length - 9) == '_userinfo') {
61 withuserdata = '_userinfo';
65 var html = html_generator('include_setting section_level', 'included');
67 html += html_generator('normal_setting', 'userdata');
69 var links = Y.Node.create('<div class="grouped_settings section_level">' + html + '</div>');
70 firstsection.insert(links, 'before');
72 Y.one('#backup-all-included').on('click', function(e) { helper(e, true, '_included'); });
73 Y.one('#backup-none-included').on('click', function(e) { helper(e, false, '_included'); });
75 Y.one('#backup-all-userdata').on('click', function(e) { helper(e, true, withuserdata); });
76 Y.one('#backup-none-userdata').on('click', function(e) { helper(e, false, withuserdata); });
80 }, '@VERSION@', {'requires':['base','node','event', 'node-event-simulate']});