function MaterialsFilePicker(callback) {
  this.doneCallback = callback;
  this.selectedMaterials = {};
  this.treeElement = $('#file-picker-tree');
  
  var courseId = gon.course;
  var that = this;
  $.ajax({
    url: '/courses/' + courseId + '/materials.json',
    success: that.onWorkbinStructureReceived
  });
}

MaterialsFilePicker.prototype.onSelectionCompleted = function() {
  var selectedItems = [];
  for (var id in selectedMaterials) {
    var currentTuple = selectedMaterials[id];
    selectedItems.push(currentTuple);
  }
  
  this.doneCallback(selectedItems);
};

MaterialsFilePicker.prototype.onWorkbinStructureReceived = function(rootNode) {
  var shouldIncludeFiles = true;
  var treeData = parseFileJsonForJqTree(rootNode, shouldIncludeFiles);
  
  treeElement.tree({
    data: treeData,
    autoOpen: true,
    keyboardSupport: false    
  });
};

MaterialsFilePicker.prototype.onNodeClicked = function(event) {
  // Disable single selection: click to select for everything.
  event.preventDefault();
  
  var selectedNode = event.node;
  var nodeId = selectedNode.id;
  
  var isNodeSelected = treeElement.tree('isNodeSelected', selectedNode);
  var isNodeAFile = nodeId.indexOf("file") !== -1;
  
  // We don't bother with folders - only individual files.
  if (isNodeAFile) {
    var indexAfterPrefix = nodeId.indexOf("_") + 1;
    var id = nodeId.slice(indexAfterPrefix);
    
    // <ID, Type, Name, URL>
    if (isNodeSelected) {
      treeElement.tree('removeFromSelection', selectedNode);
      
      var tuple = [id, "Material", selectedNode.label, selectedNode.url];
      selectedMaterials[id] = tuple;
    } else {
      treeElement.tree('addToSelection', selectedNode);
      delete selectedMaterials[id];
    }
  }
};
@@ -420,16 +420,21 @@
 r id in 
+this.
 selected
@@ -469,16 +469,21 @@
 Tuple = 
+this.
 selected
@@ -771,16 +771,21 @@
 );%0A  %0A  
+this.
 treeElem
@@ -1123,16 +1123,21 @@
 ected = 
+this.
 treeElem
@@ -1467,32 +1467,37 @@
 lected) %7B%0A      
+this.
 treeElement.tree
@@ -1618,24 +1618,29 @@
 url%5D;%0A      
+this.
 selectedMate
@@ -1677,16 +1677,21 @@
 %7B%0A      
+this.
 treeElem
@@ -1745,16 +1745,21 @@
  delete 
+this.
 selected

Fix reference issues with "this".