[ Index ]

PHP Cross Reference of Unnamed Project

title

Body

[close]

/grade/report/singleview/js/ -> singleview.js (source)

   1  M.gradereport_singleview = {};
   2  
   3  M.gradereport_singleview.init = function(Y) {
   4      var getColumnIndex = function(cell) {
   5          var rowNode = cell.ancestor('tr');
   6          if (!rowNode || !cell) {
   7              return;
   8          }
   9          var cells = rowNode.all('td, th');
  10          return cells.indexOf(cell);
  11      },
  12      getNextCell = function(cell) {
  13          var n = cell || document.activeElement,
  14              next = n.next('td.cell, th.cell');
  15          if (!next) {
  16              return null;
  17          }
  18          // Continue on until we find a navigable cell
  19          if (!next || !Y.one(next).one('input:not([type="hidden"]):not([disabled="DISABLED"]), select, a')) {
  20              return getNextCell(next);
  21          }
  22          return next;
  23      },
  24      getPrevCell = function(cell) {
  25          var n = cell || document.activeElement,
  26              next = n.previous('td.cell, th.cell');
  27          if (!next) {
  28              return null;
  29          }
  30          // Continue on until we find a navigable cell
  31          if (!Y.one(next).one('input:not([type="hidden"]):not([disabled="DISABLED"]), select, a')) {
  32              return getPrevCell(next);
  33          }
  34          return next;
  35      },
  36      getAboveCell = function(cell) {
  37          var n = cell || document.activeElement,
  38              tr = n.ancestor('tr').previous('tr'),
  39              columnIndex = getColumnIndex(n),
  40              next = null;
  41          if (tr) {
  42              next = tr.all('td, th').item(columnIndex);
  43          } else {
  44              return null;
  45          }
  46          // Continue on until we find a navigable cell
  47          if (!Y.one(next).one('input:not([type="hidden"]):not([disabled="DISABLED"]), select, a')) {
  48              return getAboveCell(next);
  49          }
  50          return next;
  51      },
  52      getBelowCell = function(cell) {
  53          var n = cell || document.activeElement,
  54              tr = n.ancestor('tr').next('tr'),
  55              columnIndex = getColumnIndex(n),
  56              next = null;
  57          if (tr) {
  58              next = tr.all('td, th').item(columnIndex);
  59          } else {
  60              return null;
  61          }
  62          // Continue on until we find a navigable cell
  63          if (!Y.one(next).one('input:not([type="hidden"]):not([disabled="DISABLED"]), select, a')) {
  64              return getBelowCell(next);
  65          }
  66          return next;
  67      };
  68  
  69      // Add ctrl+arrow controls for navigation
  70      Y.one(Y.config.doc.body).delegate('key', function(e) {
  71          e.preventDefault();
  72          e.stopPropagation();
  73          var next = null;
  74          switch (e.keyCode) {
  75              case 37:
  76                  next = getPrevCell(this.ancestor('td, th'));
  77                  break;
  78              case 38:
  79                  next = getAboveCell(this.ancestor('td, th'));
  80                  break;
  81              case 39:
  82                  next = getNextCell(this.ancestor('td, th'));
  83                  break;
  84              case 40:
  85                  next = getBelowCell(this.ancestor('td, th'));
  86                  break;
  87          }
  88          if (next) {
  89              Y.one(next).one('input:not([type="hidden"]):not([disabled="DISABLED"]), select, a').focus();
  90          }
  91          return;
  92      }, 'down:37,38,39,40+ctrl', 'table input, table select, table a');
  93  
  94      // Make toggle links
  95      Y.all('.include').each(function(link) {
  96          var type = link.getAttribute('class').split(" ")[2];
  97  
  98          var toggle = function(checked) {
  99              return function(input) {
 100                  input.getDOMNode().checked = checked;
 101                  Y.Event.simulate(input.getDOMNode(), 'change');
 102              };
 103          };
 104  
 105          link.on('click', function(e) {
 106              e.preventDefault();
 107              Y.all('input[name^=' + type + ']').each(toggle(link.hasClass('all')));
 108          });
 109      });
 110  
 111      // Override Toggle
 112      Y.all('input[name^=override_]').each(function(input) {
 113          input.on('change', function() {
 114              var checked = input.getDOMNode().checked;
 115              var names = input.getAttribute('name').split("_");
 116  
 117              var itemid = names[1];
 118              var userid = names[2];
 119  
 120              var interest = '_' + itemid + '_' + userid;
 121  
 122              Y.all('input[name$=' + interest + ']').filter('input[type=text]').each(function(text) {
 123                  text.getDOMNode().disabled = !checked;
 124              });
 125              // deal with scales that are not text... UCSB
 126              Y.all('select[name$=' + interest + ']').each(function(select) {
 127                  select.getDOMNode().disabled = !checked;
 128              });
 129          });
 130      });
 131  };


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