[ Index ] |
PHP Cross Reference of Unnamed Project |
[Summary view] [Print] [Text view]
1 /** 2 * Adds select all/none links to the top of the backup/restore/import schema page. 3 * 4 * @module moodle-backup-backupselectall 5 */ 6 7 // Namespace for the backup 8 M.core_backup = M.core_backup || {}; 9 10 /** 11 * Adds select all/none links to the top of the backup/restore/import schema page. 12 * 13 * @class M.core_backup.backupselectall 14 */ 15 M.core_backup.backupselectall = function(modnames) { 16 var formid = null; 17 18 var helper = function(e, check, type, mod) { 19 e.preventDefault(); 20 var prefix = ''; 21 if (typeof mod !== 'undefined') { 22 prefix = 'setting_activity_' + mod + '_'; 23 } 24 25 var len = type.length; 26 Y.all('input[type="checkbox"]').each(function(checkbox) { 27 var name = checkbox.get('name'); 28 // If a prefix has been set, ignore checkboxes which don't have that prefix. 29 if (prefix && name.substring(0, prefix.length) !== prefix) { 30 return; 31 } 32 if (name.substring(name.length - len) === type) { 33 checkbox.set('checked', check); 34 } 35 }); 36 37 // At this point, we really need to persuade the form we are part of to 38 // update all of its disabledIf rules. However, as far as I can see, 39 // given the way that lib/form/form.js is written, that is impossible. 40 if (formid && M.form) { 41 M.form.updateFormState(formid); 42 } 43 }; 44 45 var html_generator = function(classname, idtype, heading, extra) { 46 if (typeof extra === 'undefined') { 47 extra = ''; 48 } 49 return '<div class="' + classname + '">' + 50 '<div class="fitem fitem_fcheckbox backup_selector">' + 51 '<div class="fitemtitle">' + heading + '</div>' + 52 '<div class="felement">' + 53 '<a id="backup-all-' + idtype + '" href="#">' + M.util.get_string('all', 'moodle') + '</a> / ' + 54 '<a id="backup-none-' + idtype + '" href="#">' + M.util.get_string('none', 'moodle') + '</a>' + 55 extra + 56 '</div>' + 57 '</div>' + 58 '</div>'; 59 }; 60 61 var firstsection = Y.one('fieldset#id_coursesettings .fcontainer.clearfix .grouped_settings.section_level'); 62 if (!firstsection) { 63 // This is not a relevant page. 64 return; 65 } 66 if (!firstsection.one('.felement.fcheckbox')) { 67 // No checkboxes. 68 return; 69 } 70 71 formid = firstsection.ancestor('form').getAttribute('id'); 72 73 var withuserdata = false; 74 Y.all('input[type="checkbox"]').each(function(checkbox) { 75 var name = checkbox.get('name'); 76 if (name.substring(name.length - 9) === '_userdata') { 77 withuserdata = '_userdata'; 78 } else if (name.substring(name.length - 9) === '_userinfo') { 79 withuserdata = '_userinfo'; 80 } 81 }); 82 83 // Add global select all/none options. 84 var html = html_generator('include_setting section_level', 'included', M.util.get_string('select', 'moodle'), 85 ' (<a id="backup-bytype" href="#">' + M.util.get_string('showtypes', 'backup') + '</a>)'); 86 if (withuserdata) { 87 html += html_generator('normal_setting', 'userdata', M.util.get_string('select', 'moodle')); 88 } 89 var links = Y.Node.create('<div class="grouped_settings section_level">' + html + '</div>'); 90 firstsection.insert(links, 'before'); 91 92 // Add select all/none for each module type. 93 var initlinks = function(links, mod) { 94 Y.one('#backup-all-mod_' + mod).on('click', function(e) { 95 helper(e, true, '_included', mod); 96 }); 97 Y.one('#backup-none-mod_' + mod).on('click', function(e) { 98 helper(e, false, '_included', mod); 99 }); 100 if (withuserdata) { 101 Y.one('#backup-all-userdata-mod_' + mod).on('click', function(e) { 102 helper(e, true, withuserdata, mod); 103 }); 104 Y.one('#backup-none-userdata-mod_' + mod).on('click', function(e) { 105 helper(e, false, withuserdata, mod); 106 }); 107 } 108 }; 109 110 // For each module type on the course, add hidden select all/none options. 111 var modlist = Y.Node.create('<div id="mod_select_links">'); 112 modlist.hide(); 113 modlist.currentlyshown = false; 114 links.appendChild(modlist); 115 for (var mod in modnames) { 116 // Only include actual values from the list. 117 if (!modnames.hasOwnProperty(mod)) { 118 continue; 119 } 120 html = html_generator('include_setting section_level', 'mod_' + mod, modnames[mod]); 121 if (withuserdata) { 122 html += html_generator('normal_setting', 'userdata-mod_' + mod, modnames[mod]); 123 } 124 var modlinks = Y.Node.create( 125 '<div class="grouped_settings section_level">' + html + '</div>'); 126 modlist.appendChild(modlinks); 127 initlinks(modlinks, mod); 128 } 129 130 // Toggles the display of the hidden module select all/none links. 131 var toggletypes = function() { 132 // Change text of type toggle link. 133 var link = Y.one('#backup-bytype'); 134 if (modlist.currentlyshown) { 135 link.setHTML(M.util.get_string('showtypes', 'backup')); 136 } else { 137 link.setHTML(M.util.get_string('hidetypes', 'backup')); 138 } 139 140 // The link has now been toggled (from show to hide, or vice-versa). 141 modlist.currentlyshown = !modlist.currentlyshown; 142 143 // Either hide or show the links. 144 var animcfg = {node: modlist, duration: 0.2}, 145 anim; 146 if (modlist.currentlyshown) { 147 // Animate reveal of the module links. 148 modlist.show(); 149 animcfg.to = {maxHeight: modlist.get('clientHeight') + 'px'}; 150 modlist.setStyle('maxHeight', '0px'); 151 anim = new Y.Anim(animcfg); 152 anim.on('end', function() { 153 modlist.setStyle('maxHeight', 'none'); 154 }); 155 anim.run(); 156 } else { 157 // Animate hide of the module links. 158 animcfg.to = {maxHeight: '0px'}; 159 modlist.setStyle('maxHeight', modlist.get('clientHeight') + 'px'); 160 anim = new Y.Anim(animcfg); 161 anim.on('end', function() { 162 modlist.hide(); 163 modlist.setStyle('maxHeight', 'none'); 164 }); 165 anim.run(); 166 } 167 168 }; 169 Y.one('#backup-bytype').on('click', function() { 170 toggletypes(); 171 }); 172 173 Y.one('#backup-all-included').on('click', function(e) { 174 helper(e, true, '_included'); 175 }); 176 Y.one('#backup-none-included').on('click', function(e) { 177 helper(e, false, '_included'); 178 }); 179 if (withuserdata) { 180 Y.one('#backup-all-userdata').on('click', function(e) { 181 helper(e, true, withuserdata); 182 }); 183 Y.one('#backup-none-userdata').on('click', function(e) { 184 helper(e, false, withuserdata); 185 }); 186 } 187 };
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Thu Aug 11 10:00:09 2016 | Cross-referenced by PHPXref 0.7.1 |