[ Index ]

PHP Cross Reference of Unnamed Project

title

Body

[close]

/backup/util/ui/yui/build/moodle-backup-backupselectall/ -> moodle-backup-backupselectall-debug.js (source)

   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) {
  97              helper(e, true, '_included', mod);
  98          });
  99          Y.one('#backup-none-mod_' + mod).on('click', function(e) {
 100              helper(e, false, '_included', mod);
 101          });
 102          if (withuserdata) {
 103              Y.one('#backup-all-userdata-mod_' + mod).on('click', function(e) {
 104                  helper(e, true, withuserdata, mod);
 105              });
 106              Y.one('#backup-none-userdata-mod_' + mod).on('click', function(e) {
 107                  helper(e, false, withuserdata, mod);
 108              });
 109          }
 110      };
 111  
 112      // For each module type on the course, add hidden select all/none options.
 113      var modlist = Y.Node.create('<div id="mod_select_links">');
 114      modlist.hide();
 115      modlist.currentlyshown = false;
 116      links.appendChild(modlist);
 117      for (var mod in modnames) {
 118          // Only include actual values from the list.
 119          if (!modnames.hasOwnProperty(mod)) {
 120              continue;
 121          }
 122          html = html_generator('include_setting section_level', 'mod_' + mod, modnames[mod]);
 123          if (withuserdata) {
 124              html += html_generator('normal_setting', 'userdata-mod_' + mod, modnames[mod]);
 125          }
 126          var modlinks = Y.Node.create(
 127              '<div class="grouped_settings section_level">' + html + '</div>');
 128          modlist.appendChild(modlinks);
 129          initlinks(modlinks, mod);
 130      }
 131  
 132      // Toggles the display of the hidden module select all/none links.
 133      var toggletypes = function() {
 134          // Change text of type toggle link.
 135          var link = Y.one('#backup-bytype');
 136          if (modlist.currentlyshown) {
 137              link.setHTML(M.util.get_string('showtypes', 'backup'));
 138          } else {
 139              link.setHTML(M.util.get_string('hidetypes', 'backup'));
 140          }
 141  
 142          // The link has now been toggled (from show to hide, or vice-versa).
 143          modlist.currentlyshown = !modlist.currentlyshown;
 144  
 145          // Either hide or show the links.
 146          var animcfg = {node: modlist, duration: 0.2},
 147              anim;
 148          if (modlist.currentlyshown) {
 149              // Animate reveal of the module links.
 150              modlist.show();
 151              animcfg.to = {maxHeight: modlist.get('clientHeight') + 'px'};
 152              modlist.setStyle('maxHeight', '0px');
 153              anim = new Y.Anim(animcfg);
 154              anim.on('end', function() {
 155                  modlist.setStyle('maxHeight', 'none');
 156              });
 157              anim.run();
 158          } else {
 159              // Animate hide of the module links.
 160              animcfg.to = {maxHeight: '0px'};
 161              modlist.setStyle('maxHeight', modlist.get('clientHeight') + 'px');
 162              anim = new Y.Anim(animcfg);
 163              anim.on('end', function() {
 164                  modlist.hide();
 165                  modlist.setStyle('maxHeight', 'none');
 166              });
 167              anim.run();
 168          }
 169  
 170      };
 171      Y.one('#backup-bytype').on('click', function() {
 172          toggletypes();
 173      });
 174  
 175      Y.one('#backup-all-included').on('click', function(e) {
 176          helper(e, true, '_included');
 177      });
 178      Y.one('#backup-none-included').on('click', function(e) {
 179          helper(e, false, '_included');
 180      });
 181      if (withuserdata) {
 182          Y.one('#backup-all-userdata').on('click', function(e) {
 183              helper(e, true, withuserdata);
 184          });
 185          Y.one('#backup-none-userdata').on('click', function(e) {
 186              helper(e, false, withuserdata);
 187          });
 188      }
 189  };
 190  
 191  
 192  }, '@VERSION@', {"requires": ["node", "event", "node-event-simulate", "anim"]});


Generated: Thu Aug 11 10:00:09 2016 Cross-referenced by PHPXref 0.7.1