MDL-22951 - move the AJAX callback out into its own include, and tidy up
authorPiers Harding <piers@ompka.net>
Sun, 25 Jul 2010 01:22:27 +0000 (01:22 +0000)
committerPiers Harding <piers@ompka.net>
Sun, 25 Jul 2010 01:22:27 +0000 (01:22 +0000)
mod/scorm/datamodels/aicc.js.php
mod/scorm/datamodels/callback.js.php [new file with mode: 0644]
mod/scorm/datamodels/scorm_12.js.php
mod/scorm/datamodels/scorm_13.js.php
mod/scorm/module.js
mod/scorm/prereqs.php

index c327898..7be7cd9 100644 (file)
@@ -202,62 +202,10 @@ function AICCapi() {
     }
 
 
-    this.connectPrereqCallback = {
-
-        success: function(o) {
-            scorm_tree_node = YAHOO.widget.TreeView.getTree('scorm_tree');
-            if (o.responseText !== undefined) {
-                if (scorm_tree_node && o.responseText) {
-                    var hnode = scorm_tree_node.getHighlightedNode();
-                    var hidx = null;
-                    if (hnode) {
-                        hidx = hnode.index + scorm_tree_node.getNodeCount();
-                    }
-                    // all gone
-                    var root_node = scorm_tree_node.getRoot();
-                        scorm_tree_node.removeNode(root_node.children[0]);
-                    }
-                    // make sure the temporary tree element is not there
-                    var el_old_tree = document.getElementById('scormtree123');
-                    if (el_old_tree) {
-                        el_old_tree.parentNode.removeChild(el_old_tree);
-                    }
-                    var el_new_tree = document.createElement('div');
-                    var pagecontent = document.getElementById("page-content");
-                    el_new_tree.setAttribute('id','scormtree123');
-                    el_new_tree.innerHTML = o.responseText;
-                    // make sure it doesnt show
-                    el_new_tree.style.display = 'none';
-                    pagecontent.appendChild(el_new_tree)
-                    // ignore the first level element as this is the title
-                    scorm_tree_node.buildTreeFromMarkup(el_new_tree.firstChild.firstChild);
-                    var el = document.getElementById('scormtree123');
-                    el.parentNode.removeChild(el);
-                    scorm_tree_node.expandAll();
-                    scorm_tree_node.render();
-                    if (hidx != null) {
-                        hnode = scorm_tree_node.getNodeByIndex(hidx);
-                        if (hnode) {
-                            hnode.highlight();
-                            scorm_layout_widget = YAHOO.widget.Layout.getLayoutById('scorm_layout');
-                            var left = scorm_layout_widget.getUnitByPosition('left');
-                            if (left.expanded) {
-                                hnode.focus();
-                            }
-                        }
-                    }
-                }
-        },
-
-        failure: function(o) {
-            // do some sort of error handling
-            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(); ?>";
-            //TODO: Enable this error handing correctly - avoiding issues when closing player MDL-23470 
-            //alert('Prerequisites update failed - must restart SCORM player');
-            //window.location.href = sURL;
-        }
-
-    };
+<?php
+    // pull in the TOC callback
+    include_once($CFG->dirroot.'/mod/scorm/datamodels/callback.js.php');
+ ?>
 
 
     function LMSFinish (param) {
diff --git a/mod/scorm/datamodels/callback.js.php b/mod/scorm/datamodels/callback.js.php
new file mode 100644 (file)
index 0000000..103bbaf
--- /dev/null
@@ -0,0 +1,59 @@
+
+    this.connectPrereqCallback = {
+
+        success: function(o) {
+            scorm_tree_node = YAHOO.widget.TreeView.getTree('scorm_tree');
+            if (o.responseText !== undefined) {
+                if (scorm_tree_node && o.responseText) {
+                    var hnode = scorm_tree_node.getHighlightedNode();
+                    var hidx = null;
+                    if (hnode) {
+                        hidx = hnode.index + scorm_tree_node.getNodeCount();
+                    }
+                    // all gone
+                    var root_node = scorm_tree_node.getRoot();
+                        scorm_tree_node.removeNode(root_node.children[0]);
+                    }
+                    // make sure the temporary tree element is not there
+                    var el_old_tree = document.getElementById('scormtree123');
+                    if (el_old_tree) {
+                        el_old_tree.parentNode.removeChild(el_old_tree);
+                    }
+                    var el_new_tree = document.createElement('div');
+                    var pagecontent = document.getElementById("page-content");
+                    el_new_tree.setAttribute('id','scormtree123');
+                    el_new_tree.innerHTML = o.responseText;
+                    // make sure it doesnt show
+                    el_new_tree.style.display = 'none';
+                    pagecontent.appendChild(el_new_tree)
+                    // ignore the first level element as this is the title
+                    scorm_tree_node.buildTreeFromMarkup(el_new_tree.firstChild.firstChild);
+                    var el = document.getElementById('scormtree123');
+                    el.parentNode.removeChild(el);
+                    scorm_tree_node.expandAll();
+                    scorm_tree_node.render();
+                    if (hidx != null) {
+                        hnode = scorm_tree_node.getNodeByIndex(hidx);
+                        if (hnode) {
+                            hnode.highlight();
+                            scorm_layout_widget = YAHOO.widget.Layout.getLayoutById('scorm_layout');
+                            var left = scorm_layout_widget.getUnitByPosition('left');
+                            if (left.expanded) {
+                                hnode.focus();
+                            }
+                        }
+                    }
+                }
+        },
+
+        failure: function(o) {
+            // do some sort of error handling
+            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(); ?>";
+            //TODO: Enable this error handing correctly - avoiding issues when closing player MDL-23470 
+            //alert('Prerequisites update failed - must restart SCORM player');
+            //window.location.href = sURL;
+        }
+
+    };
+
+
index 153beb5..2aa1f51 100644 (file)
@@ -184,64 +184,10 @@ function SCORMapi1_2() {
         return "false";
     }
 
-
-    this.connectPrereqCallback = {
-
-        success: function(o) {
-            scorm_tree_node = YAHOO.widget.TreeView.getTree('scorm_tree');
-            if (o.responseText !== undefined) {
-                if (scorm_tree_node && o.responseText) {
-                    var hnode = scorm_tree_node.getHighlightedNode();
-                    var hidx = null;
-                    if (hnode) {
-                        hidx = hnode.index + scorm_tree_node.getNodeCount();
-                    }
-                    // all gone
-                    var root_node = scorm_tree_node.getRoot();
-                        scorm_tree_node.removeNode(root_node.children[0]);
-                    }
-                    // make sure the temporary tree element is not there
-                    var el_old_tree = document.getElementById('scormtree123');
-                    if (el_old_tree) {
-                        el_old_tree.parentNode.removeChild(el_old_tree);
-                    }
-                    var el_new_tree = document.createElement('div');
-                    var pagecontent = document.getElementById("page-content");
-                    el_new_tree.setAttribute('id','scormtree123');
-                    el_new_tree.innerHTML = o.responseText;
-                    // make sure it doesnt show
-                    el_new_tree.style.display = 'none';
-                    pagecontent.appendChild(el_new_tree)
-                    // ignore the first level element as this is the title
-                    scorm_tree_node.buildTreeFromMarkup(el_new_tree.firstChild.firstChild);
-                    var el = document.getElementById('scormtree123');
-                    el.parentNode.removeChild(el);
-                    scorm_tree_node.expandAll();
-                    scorm_tree_node.render();
-                    if (hidx != null) {
-                        hnode = scorm_tree_node.getNodeByIndex(hidx);
-                        if (hnode) {
-                            hnode.highlight();
-                            scorm_layout_widget = YAHOO.widget.Layout.getLayoutById('scorm_layout');
-                            var left = scorm_layout_widget.getUnitByPosition('left');
-                            if (left.expanded) {
-                                hnode.focus();
-                            }
-                        }
-                    }
-                }
-        },
-
-        failure: function(o) {
-            // do some sort of error handling
-            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(); ?>";
-            //TODO: Enable this error handing correctly - avoiding issues when closing player MDL-23470 
-            //alert('Prerequisites update failed - must restart SCORM player');
-            //window.location.href = sURL;
-        }
-
-    };
-
+<?php
+    // pull in the TOC callback
+    include_once($CFG->dirroot.'/mod/scorm/datamodels/callback.js.php');
+ ?>
 
     function LMSFinish (param) {
         errorCode = "0";
index da02158..60f4730 100644 (file)
@@ -296,62 +296,11 @@ function SCORMapi1_3() {
         return "false";
     }
 
-    this.connectPrereqCallback = {
 
-        success: function(o) {
-            scorm_tree_node = YAHOO.widget.TreeView.getTree('scorm_tree');
-            if (o.responseText !== undefined) {
-                if (scorm_tree_node && o.responseText) {
-                    var hnode = scorm_tree_node.getHighlightedNode();
-                    var hidx = null;
-                    if (hnode) {
-                        hidx = hnode.index + scorm_tree_node.getNodeCount();
-                    }
-                    // all gone
-                    var root_node = scorm_tree_node.getRoot();
-                        scorm_tree_node.removeNode(root_node.children[0]);
-                    }
-                    // make sure the temporary tree element is not there
-                    var el_old_tree = document.getElementById('scormtree123');
-                    if (el_old_tree) {
-                        el_old_tree.parentNode.removeChild(el_old_tree);
-                    }
-                    var el_new_tree = document.createElement('div');
-                    var pagecontent = document.getElementById("page-content");
-                    el_new_tree.setAttribute('id','scormtree123');
-                    el_new_tree.innerHTML = o.responseText;
-                    // make sure it doesnt show
-                    el_new_tree.style.display = 'none';
-                    pagecontent.appendChild(el_new_tree)
-                    // ignore the first level element as this is the title
-                    scorm_tree_node.buildTreeFromMarkup(el_new_tree.firstChild.firstChild);
-                    var el = document.getElementById('scormtree123');
-                    el.parentNode.removeChild(el);
-                    scorm_tree_node.expandAll();
-                    scorm_tree_node.render();
-                    if (hidx != null) {
-                        hnode = scorm_tree_node.getNodeByIndex(hidx);
-                        if (hnode) {
-                            hnode.highlight();
-                            scorm_layout_widget = YAHOO.widget.Layout.getLayoutById('scorm_layout');
-                            var left = scorm_layout_widget.getUnitByPosition('left');
-                            if (left.expanded) {
-                                hnode.focus();
-                            }
-                        }
-                    }
-                }
-        },
-
-        failure: function(o) {
-            // do some sort of error handling
-            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(); ?>";
-            //TODO: Enable this error handing correctly - avoiding issues when closing player MDL-23470 
-            //alert('Prerequisites update failed - must restart SCORM player');
-            //window.location.href = sURL;
-        }
-
-    };
+<?php
+    // pull in the TOC callback
+    include_once($CFG->dirroot.'/mod/scorm/datamodels/callback.js.php');
+ ?>
 
 
     function Terminate (param) {
index 03b40df..32cdae3 100644 (file)
@@ -140,18 +140,13 @@ M.mod_scorm.init = function(Y, hide_nav, hide_toc, toc_title, window_name, windo
 
         var scorm_resize_layout = function(alsowidth) {
             if (window_name) {
-                //scorm_layout_widget.setStyle('width', '260px');
-                //scorm_layout_widget.render();
                 return;
             }
 
             if (alsowidth) {
-                //var layout = YAHOO.util.Dom.get('scorm_layout');
-                //layout.style.width = '600px';
                 scorm_layout_widget.setStyle('width', '');
                 var newwidth = scorm_get_htmlelement_size('content', 'width');
                 if (newwidth > 600) {
-                    //layout.style.width = newwidth+'px';
                     scorm_layout_widget.setStyle('width', newwidth+'px');
                 }
             }
@@ -241,14 +236,6 @@ M.mod_scorm.init = function(Y, hide_nav, hide_toc, toc_title, window_name, windo
         };
 
         var scorm_skipprev = function(node) {
-            /*
-            if (node == scorm_tree_node.getRoot().children[0]) {
-                return null;
-            }
-            else {
-                return scorm_tree_node.getRoot().children[0];
-            }
-            */
             if (node.previousSibling) {
                 return node.previousSibling;
             } else if (node.depth > 0) {
@@ -268,15 +255,6 @@ M.mod_scorm.init = function(Y, hide_nav, hide_toc, toc_title, window_name, windo
         };
 
         var scorm_skipnext = function(node) {
-            /*
-            var toc_children = scorm_tree_node.getRoot().children;
-            if (node == toc_children[toc_children.length - 1]) {
-                return null;
-            }
-            else {
-                return toc_children[toc_children.length - 1];
-            }
-            */
             if (node.nextSibling) {
                 return node.nextSibling;
             } else if (node.depth > 0) {
@@ -290,16 +268,6 @@ M.mod_scorm.init = function(Y, hide_nav, hide_toc, toc_title, window_name, windo
         YAHOO.widget.LayoutUnit.prototype.STR_COLLAPSE = M.str.moodle.hide;
         YAHOO.widget.LayoutUnit.prototype.STR_EXPAND = M.str.moodle.show;
 
-/*
-        scorm_layout_widget = new YAHOO.widget.Layout('scorm_layout', {
-            minWidth: 600,
-            minHeight: 400,
-            units: [
-                { position: 'left', body: 'scorm_toc', header: M.str.scorm.toc, width: 250, resize: true, gutter: '2px 5px 5px 2px', collapse: true, minWidth:150},
-                { position: 'center', body: '<div id="scorm_content"></div>', gutter: '2px 5px 5px 2px', scroll: true}
-            ]
-        });
-        */
         scorm_layout_widget = new YAHOO.widget.Layout('scorm_layout', {
             minWidth: 255,
             minHeight: 400,
@@ -360,8 +328,6 @@ M.mod_scorm.init = function(Y, hide_nav, hide_toc, toc_title, window_name, windo
 
         // navigation
         if (scorm_hide_nav == false) {
-            //scorm_nav_panel = new YAHOO.widget.Panel('scorm_navpanel', { visible:true, draggable:true, close:false,
-            //                                                       context: ['page', 'bl', 'bl', ["windowScroll", "textResize", "windowResize"]], constraintoviewport:true} );
             scorm_nav_panel = new YAHOO.widget.Panel('scorm_navpanel', { visible:true, draggable:true, close:false, xy: [250, 450],
                                                                     autofillheight: "body"} );
             scorm_nav_panel.setHeader(M.str.scorm.navigation);
index 6d25bbc..e1cddd5 100644 (file)
@@ -1,4 +1,7 @@
 <?php
+
+    // this page is called via AJAX to repopulte the TOC when LMSFinish() is called
+
     require_once('../../config.php');
     require_once($CFG->dirroot.'/mod/scorm/locallib.php');
 
@@ -52,9 +55,5 @@
             $result = scorm_get_toc($USER,$scorm,'structurelist',$currentorg,$scoid,$mode,$attempt,true, false);
             echo $result->toc;
         }
-        //echo "<ul><li>The Heading<ul>";
-        //echo "<li><a title='/moodledev/blah1'>Blah 1</a></li>";
-        //echo "<li><a title='/moodledev/blah2'>Blah 2</a></li>";
-        //echo "</ul></li></ul>";
     }