Merge branch 'm20_MDL-26176_cleanup' of github.com:danmarsden/moodle
[moodle.git] / mod / scorm / datamodels / callback.js.php
... / ...
CommitLineData
1
2 this.connectPrereqCallback = {
3
4 success: function(o) {
5 scorm_tree_node = YAHOO.widget.TreeView.getTree('scorm_tree');
6 if (o.responseText !== undefined) {
7 //alert('got a response: ' + o.responseText);
8 if (scorm_tree_node && o.responseText) {
9 var hnode = scorm_tree_node.getHighlightedNode();
10 var hidx = null;
11 if (hnode) {
12 hidx = hnode.index + scorm_tree_node.getNodeCount();
13 }
14 // all gone
15 var root_node = scorm_tree_node.getRoot();
16 while (root_node.children.length > 0) {
17 scorm_tree_node.removeNode(root_node.children[0]);
18 }
19 }
20 // make sure the temporary tree element is not there
21 var el_old_tree = document.getElementById('scormtree123');
22 if (el_old_tree) {
23 el_old_tree.parentNode.removeChild(el_old_tree);
24 }
25 var el_new_tree = document.createElement('div');
26 var pagecontent = document.getElementById("page-content");
27 el_new_tree.setAttribute('id','scormtree123');
28 el_new_tree.innerHTML = o.responseText;
29 // make sure it doesnt show
30 el_new_tree.style.display = 'none';
31 pagecontent.appendChild(el_new_tree)
32 // ignore the first level element as this is the title
33 var startNode = el_new_tree.firstChild.firstChild;
34 if (startNode.tagName == 'LI') {
35 // go back to the beginning
36 startNode = el_new_tree;
37 }
38 //var sXML = new XMLSerializer().serializeToString(startNode);
39 scorm_tree_node.buildTreeFromMarkup(startNode);
40 var el = document.getElementById('scormtree123');
41 el.parentNode.removeChild(el);
42 scorm_tree_node.expandAll();
43 scorm_tree_node.render();
44 if (hidx != null) {
45 hnode = scorm_tree_node.getNodeByIndex(hidx);
46 if (hnode) {
47 hnode.highlight();
48 scorm_layout_widget = YAHOO.widget.Layout.getLayoutById('scorm_layout');
49 var left = scorm_layout_widget.getUnitByPosition('left');
50 if (left.expanded) {
51 hnode.focus();
52 }
53 }
54 }
55 }
56 },
57
58 failure: function(o) {
59 // do some sort of error handling
60 var sURL = "<?php echo $CFG->wwwroot; ?>" + "/mod/scorm/prereqs.php?a=<?php echo $scorm->id ?>&scoid=<?php echo $scoid ?>&attempt=<?php echo $attempt ?>&mode=<?php echo $mode ?>&currentorg=<?php echo $currentorg ?>&sesskey=<?php echo sesskey(); ?>";
61 //TODO: Enable this error handing correctly - avoiding issues when closing player MDL-23470
62 //alert('Prerequisites update failed - must restart SCORM player');
63 //window.location.href = sURL;
64 }
65
66 };
67
68