[ Index ]

PHP Cross Reference of moodle-2.8

title

Body

[close]

/grade/edit/tree/ -> functions.js (source)

   1  /**
   2   * Toggles the selection checkboxes of all grade items children of the given eid (a category id)
   3   */
   4  function togglecheckboxes(event, args) {
   5  YUI().use('yui2-dom', 'yui2-element', function (Y) {
   6  
   7      var rows = Y.YUI2.util.Dom.getElementsByClassName(args.eid);
   8  
   9      for (var i = 0; i < rows.length; i++) {
  10          var element = new Y.YUI2.util.Element(rows[i]);
  11          var checkboxes = element.getElementsByClassName('itemselect');
  12          if (checkboxes[0]) {
  13              checkboxes[0].checked=args.check;
  14          }
  15      }
  16  
  17      toggleCategorySelector();
  18  
  19  });
  20  }
  21  
  22  function toggle_advanced_columns() {
  23  YUI().use('yui2-dom', function (Y) {
  24  
  25      var advEls = Y.YUI2.util.Dom.getElementsByClassName("advanced");
  26      var shownAdvEls = Y.YUI2.util.Dom.getElementsByClassName("advancedshown");
  27  
  28      for (var i = 0; i < advEls.length; i++) {
  29          Y.YUI2.util.Dom.replaceClass(advEls[i], "advanced", "advancedshown");
  30      }
  31  
  32      for (var i = 0; i < shownAdvEls.length; i++) {
  33          Y.YUI2.util.Dom.replaceClass(shownAdvEls[i], "advancedshown", "advanced");
  34      }
  35  
  36  });
  37  }
  38  
  39  /**
  40   * Check if any of the grade item checkboxes is ticked. If yes, enable the dropdown. Otherwise, disable it
  41   */
  42  function toggleCategorySelector() {
  43  YUI().use('yui2-dom', function (Y) {
  44  
  45      var menumoveafter = document.getElementById('menumoveafter');
  46      if (!menumoveafter) {
  47          return;
  48      }
  49  
  50      var itemboxes = Y.YUI2.util.Dom.getElementsByClassName('itemselect');
  51      for (var i = 0; i < itemboxes.length; i++) {
  52          if (itemboxes[i].checked) {
  53              menumoveafter.disabled = false;
  54              return true;
  55          }
  56      }
  57      menumoveafter.disabled = 'disabled';
  58  
  59  });
  60  }
  61  
  62  function submit_bulk_move(e, args) {
  63      document.getElementById('bulkmoveinput').value = 1;
  64      document.getElementById('gradetreeform').submit();
  65  }
  66  
  67  function update_category_aggregation(e, args) {
  68      var selectmenu = e.target;
  69      window.location = 'index.php?id='+args.courseid+'&category='+args.category+'&aggregationtype='+selectmenu.get('value')+'&sesskey='+args.sesskey;
  70  }
  71  
  72  /**
  73   * The weight override checkboxes toggle the disabled status of their associated weight fields.
  74   */
  75  YUI().use('node', 'delegate', function(Y) {
  76      Y.on('domready', function() {
  77          Y.delegate('click', function(e) {
  78              var t = e.currentTarget,
  79                  itemid = t.get('id').split('_')[1];
  80              Y.one('input[name=weight_' + itemid + ']').set('disabled', t.get('checked') ? false : true);
  81          }, Y.config.doc.body, 'input.weightoverride');
  82      });
  83  });
  84  
  85  /* TODO: finish and rewrite for YUI3...
  86  Y.YUI2.namespace('grade_edit_tree');
  87  
  88  (function() {
  89      var Dom = Y.YUI2.util.Dom;
  90      var DDM = Y.YUI2.util.DragDropMgr;
  91      var Event = Y.YUI2.util.Event;
  92      var gretree = Y.YUI2.grade_edit_tree;
  93  
  94      gretree.DDApp = {
  95  
  96          init: function() {
  97  
  98              var edit_tree_table = Dom.get('grade_edit_tree_table');
  99              var i;
 100              var item_rows = edit_tree_table.getElementsByClassName('item', 'tr');
 101              var category_rows = edit_tree_table.getElementsByClassName('category', 'tr');
 102  
 103              new Y.YUI2.util.DDTarget('grade_edit_tree_table');
 104  
 105              for (i = 0; i < item_rows.length; i++) {
 106                  if (!Dom.hasClass(item_rows[i],'categoryitem')) {
 107                      new gretree.DDList(item_rows[i]);
 108                  }
 109              }
 110  
 111              for (i = 0; i < category_rows.length; i++) {
 112                  if (!Dom.hasClass(category_rows[i],'coursecategory')) {
 113                      // Find the cell that spans rows for this category
 114                      var rowspancell = category_rows[i].getElementsByClassName('name', 'td');
 115                      var rowspan = parseInt(rowspancell[0].previousSibling.rowSpan) + 1;
 116                      var rows = Array(rowspan);
 117                      var lastRow = category_rows[i];
 118  
 119                      for (var j = 0; j < rowspan; j++) {
 120                          rows[j] = lastRow;
 121                          lastRow = lastRow.nextSibling;
 122                      }
 123  
 124                      new gretree.DDList(rows);
 125                  }
 126              }
 127  
 128              Y.YUI2.util.Event.on("showButton", "click", this.showOrder);
 129              Y.YUI2.util.Event.on("switchButton", "click", this.switchStyles);
 130          },
 131  
 132          showOrder: function() {
 133              var parseTable = function(table, title) {
 134                  var items = table.getElementsByTagName('tr');
 135                  var out = title + ": ";
 136  
 137                  for (i = 0; i < items.length; i++) {
 138                      out += items[i].id + ' ';
 139                  }
 140                  return out;
 141              };
 142  
 143              var table = Dom.get('grade_edit_tree_table');
 144              alert(parseTable(table, "Grade edit tree table"));
 145          },
 146  
 147          switchStyles: function() {
 148              Dom.get('grade_edit_tree_table').className = 'draglist_alt';
 149          }
 150      };
 151  
 152      gretree.DDList = function(id, sGroup, config) {
 153  
 154          gretree.DDList.superclass.constructor.call(this, id, sGroup, config);
 155          this.logger =  this.logger || Y.YUI2;
 156          var el = this.getDragEl();
 157          Dom.setStyle(el, 'opacity', 0.67);
 158  
 159          this.goingUp = false;
 160          this.lastY = 0;
 161      };
 162  
 163      Y.YUI2.extend(gretree.DDList, Y.YUI2.util.DDProxy, {
 164  
 165          startDrag: function(x, y) {
 166              this.logger.log(this.id + ' startDrag');
 167  
 168              // Make the proxy look like the source element
 169              var dragEl = this.getDragEl();
 170              var clickEl = this.getEl();
 171  
 172              Dom.setStyle(clickEl, 'visibility', 'hidden');
 173  
 174              dragEl.innerHTML = clickEl.innerHTML;
 175  
 176              Dom.setStyle(dragEl, 'color', Dom.getStyle(clickEl, 'color'));
 177              Dom.setStyle(dragEl, 'backgroundColor', Dom.getStyle(clickEl, 'backgroundColor'));
 178              Dom.setStyle(dragEl, 'border', '2px solid gray');
 179          },
 180  
 181          endDrag: function(e) {
 182              this.logger.log(this.id + ' endDrag');
 183              var srcEl = this.getEl();
 184              var proxy = this.getDragEl();
 185  
 186              // Show the proxy element and adnimate it to the src element's location
 187              Dom.setStyle(proxy, 'visibility', '');
 188              var a = new Y.YUI2.util.Motion(proxy, { points: { to: Dom.getXY(srcEl) } }, 0.2, Y.YUI2.util.Easing.easeOut);
 189              var proxyid = proxy.id;
 190              var thisid = this.id;
 191  
 192              // Hide the proxy and show the source element when finished with the animation
 193              a.onComplete.subscribe(function() {
 194                  Dom.setStyle(proxyid, 'visibility', 'hidden');
 195                  Dom.setStyle(thisid, 'visibility', '');
 196              });
 197  
 198              a.animate();
 199          },
 200  
 201          onDragDrop: function(e, id) {
 202              this.logger.log(this.id + ' dragDrop');
 203  
 204              // If there is one drop interaction, the tr was dropped either on the table, or it was dropped on the current location of the source element
 205  
 206              if (DDM.interactionInfo.drop.length === 1) {
 207                  // The position of the cursor at the time of the drop (Y.YUI2.util.Point)
 208                  var pt = DDM.interactionInfo.point;
 209  
 210                  // The region occupied by the source element at the time of the drop
 211                  var region = DDM.interactionInfo.sourceRegion;
 212  
 213                  // Check to see if we are over the source element's location. We will append to the bottom of the list once we are sure it was a drop in the negative space
 214                  if (!region.intersect(pt)) {
 215                      var destEl = Dom.get(id);
 216                      var destDD = DDM.getDDById(id);
 217                      destEl.appendChild(this.getEl());
 218                      destDD.isEmpty = false;
 219                      DDM.refreshCache();
 220                  }
 221              }
 222          },
 223  
 224          onDrag: function(e) {
 225  
 226              // Keep track of the direction of the drag for use during onDragOver
 227              var y = Event.getPageY(e);
 228  
 229              if (y < this.lastY) {
 230                  this.goingUp = true;
 231              } else if (y > this.lastY) {
 232                  this.goingUp = false;
 233              }
 234  
 235              this.lastY = y;
 236          },
 237  
 238          onDragOver: function(e, id) {
 239              var srcEl = this.getEl();
 240              var destEl = Dom.get(id);
 241  
 242              // We are only concerned with tr items, we ignore the dragover notifications for the table
 243              if (destEl.nodeName.toLowerCase() == 'tr') {
 244                  var orig_p = srcEl.parentNode;
 245                  var p = destEl.parentNode;
 246  
 247                  if (this.goingup) {
 248                      p.insertBefore(srcEl, destEl); // insert above
 249                  } else {
 250                      p.insertBefore(srcEl, destEl.nextSibling); // insert below
 251                  }
 252  
 253                  DDM.refreshCache();
 254              }
 255          }
 256      });
 257      // Y.YUI2.util.Event.onDOMReady(gretree.DDApp.init, gretree.DDApp, true); // Uncomment this line when dragdrop is fully implemented
 258  })();
 259  */


Generated: Fri Nov 28 20:29:05 2014 Cross-referenced by PHPXref 0.7.1