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