[ Index ] |
PHP Cross Reference of moodle-2.8 |
[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) { helper(e, true, '_included', mod); }); 95 Y.one('#backup-none-mod_' + mod).on('click', function(e) { helper(e, false, '_included', mod); }); 96 if (withuserdata) { 97 Y.one('#backup-all-userdata-mod_' + mod).on('click', function(e) { helper(e, true, withuserdata, mod); }); 98 Y.one('#backup-none-userdata-mod_' + mod).on('click', function(e) { helper(e, false, withuserdata, mod); }); 99 } 100 }; 101 102 // For each module type on the course, add hidden select all/none options. 103 var modlist = Y.Node.create('<div id="mod_select_links">'); 104 modlist.hide(); 105 modlist.currentlyshown = false; 106 links.appendChild(modlist); 107 for (var mod in modnames) { 108 // Only include actual values from the list. 109 if (!modnames.hasOwnProperty(mod)) { 110 continue; 111 } 112 html = html_generator('include_setting section_level', 'mod_' + mod, modnames[mod]); 113 if (withuserdata) { 114 html += html_generator('normal_setting', 'userdata-mod_' + mod, modnames[mod]); 115 } 116 var modlinks = Y.Node.create( 117 '<div class="grouped_settings section_level">' + html + '</div>'); 118 modlist.appendChild(modlinks); 119 initlinks(modlinks, mod); 120 } 121 122 // Toggles the display of the hidden module select all/none links. 123 var toggletypes = function() { 124 // Change text of type toggle link. 125 var link = Y.one('#backup-bytype'); 126 if (modlist.currentlyshown) { 127 link.setHTML(M.util.get_string('showtypes', 'backup')); 128 } else { 129 link.setHTML(M.util.get_string('hidetypes', 'backup')); 130 } 131 132 // The link has now been toggled (from show to hide, or vice-versa). 133 modlist.currentlyshown = !modlist.currentlyshown; 134 135 // Either hide or show the links. 136 var animcfg = { node: modlist, duration: 0.2 }, 137 anim; 138 if (modlist.currentlyshown) { 139 // Animate reveal of the module links. 140 modlist.show(); 141 animcfg.to = { maxHeight: modlist.get('clientHeight') + 'px' }; 142 modlist.setStyle('maxHeight', '0px'); 143 anim = new Y.Anim(animcfg); 144 anim.on('end', function() { modlist.setStyle('maxHeight', 'none'); }); 145 anim.run(); 146 } else { 147 // Animate hide of the module links. 148 animcfg.to = { maxHeight: '0px' }; 149 modlist.setStyle('maxHeight', modlist.get('clientHeight') + 'px'); 150 anim = new Y.Anim(animcfg); 151 anim.on('end', function() { modlist.hide(); modlist.setStyle('maxHeight', 'none'); }); 152 anim.run(); 153 } 154 155 }; 156 Y.one('#backup-bytype').on('click', function() { toggletypes(); }); 157 158 Y.one('#backup-all-included').on('click', function(e) { helper(e, true, '_included'); }); 159 Y.one('#backup-none-included').on('click', function(e) { helper(e, false, '_included'); }); 160 if (withuserdata) { 161 Y.one('#backup-all-userdata').on('click', function(e) { helper(e, true, withuserdata); }); 162 Y.one('#backup-none-userdata').on('click', function(e) { helper(e, false, withuserdata); }); 163 } 164 };
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Fri Nov 28 20:29:05 2014 | Cross-referenced by PHPXref 0.7.1 |