MDL-22951 - move the AJAX callback out into its own include, and tidy up
[moodle.git] / mod / scorm / datamodels / callback.js.php
2     this.connectPrereqCallback = {
4         success: function(o) {
5             scorm_tree_node = YAHOO.widget.TreeView.getTree('scorm_tree');
6             if (o.responseText !== undefined) {
7                 if (scorm_tree_node && o.responseText) {
8                     var hnode = scorm_tree_node.getHighlightedNode();
9                     var hidx = null;
10                     if (hnode) {
11                         hidx = hnode.index + scorm_tree_node.getNodeCount();
12                     }
13                     // all gone
14                     var root_node = scorm_tree_node.getRoot();
15                         scorm_tree_node.removeNode(root_node.children[0]);
16                     }
17                     // make sure the temporary tree element is not there
18                     var el_old_tree = document.getElementById('scormtree123');
19                     if (el_old_tree) {
20                         el_old_tree.parentNode.removeChild(el_old_tree);
21                     }
22                     var el_new_tree = document.createElement('div');
23                     var pagecontent = document.getElementById("page-content");
24                     el_new_tree.setAttribute('id','scormtree123');
25                     el_new_tree.innerHTML = o.responseText;
26                     // make sure it doesnt show
27                     el_new_tree.style.display = 'none';
28                     pagecontent.appendChild(el_new_tree)
29                     // ignore the first level element as this is the title
30                     scorm_tree_node.buildTreeFromMarkup(el_new_tree.firstChild.firstChild);
31                     var el = document.getElementById('scormtree123');
32                     el.parentNode.removeChild(el);
33                     scorm_tree_node.expandAll();
34                     scorm_tree_node.render();
35                     if (hidx != null) {
36                         hnode = scorm_tree_node.getNodeByIndex(hidx);
37                         if (hnode) {
38                             hnode.highlight();
39                             scorm_layout_widget = YAHOO.widget.Layout.getLayoutById('scorm_layout');
40                             var left = scorm_layout_widget.getUnitByPosition('left');
41                             if (left.expanded) {
42                                 hnode.focus();
43                             }
44                         }
45                     }
46                 }
47         },
49         failure: function(o) {
50             // do some sort of error handling
51             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(); ?>";
52             //TODO: Enable this error handing correctly - avoiding issues when closing player MDL-23470 
53             //alert('Prerequisites update failed - must restart SCORM player');
54             //window.location.href = sURL;
55         }
57     };