MDL-29207: SCORM prereq callback is pure js - move it to module.js so it can be cached better.

This commit is contained in:
Dan Marsden 2013-02-03 20:00:18 +13:00
parent 5f03868a53
commit 361069cbbb
5 changed files with 86 additions and 127 deletions

View File

@ -219,13 +219,6 @@ if ($count > 0) {
return "false";
}
<?php
// pull in the TOC callback
require_once($CFG->dirroot.'/mod/scorm/datamodels/callback.js.php');
?>
function LMSFinish (param) {
errorCode = "0";
if (param == "") {
@ -245,7 +238,7 @@ require_once($CFG->dirroot.'/mod/scorm/datamodels/callback.js.php');
}
// trigger TOC update
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(); ?>";
var callback = this.connectPrereqCallback;
var callback = M.mod_scorm.connectPrereqCallback;
YUI().use('yui2-connection', function(Y) {
Y.YUI2.util.Connect.asyncRequest('GET', sURL, callback, null);
});

View File

@ -1,104 +0,0 @@
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
?>
this.connectPrereqCallback = {
success: function(o) {
YUI().use('yui2-treeview', 'yui2-layout', function(Y) {
// MDL-29159 The core version of getContentHtml doesn't escape text properly.
Y.YUI2.widget.TextNode.prototype.getContentHtml = function() {
var sb = [];
sb[sb.length] = this.href ? '<a' : '<span';
sb[sb.length] = ' id="' + Y.YUI2.lang.escapeHTML(this.labelElId) + '"';
sb[sb.length] = ' class="' + Y.YUI2.lang.escapeHTML(this.labelStyle) + '"';
if (this.href) {
sb[sb.length] = ' href="' + Y.YUI2.lang.escapeHTML(this.href) + '"';
sb[sb.length] = ' target="' + Y.YUI2.lang.escapeHTML(this.target) + '"';
}
if (this.title) {
sb[sb.length] = ' title="' + Y.YUI2.lang.escapeHTML(this.title) + '"';
}
sb[sb.length] = ' >';
sb[sb.length] = this.label;
sb[sb.length] = this.href?'</a>':'</span>';
return sb.join("");
};
if (o.responseText !== undefined) {
var tree = new Y.YUI2.widget.TreeView('scorm_tree');
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();
while (root_node.children.length > 0) {
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
var startNode = el_new_tree.firstChild.firstChild;
if (startNode.tagName == 'LI') {
// go back to the beginning
startNode = el_new_tree;
}
//var sXML = new XMLSerializer().serializeToString(startNode);
scorm_tree_node.buildTreeFromMarkup('scormtree123');
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 = Y.YUI2.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;
}
};

View File

@ -198,11 +198,6 @@ function SCORMapi1_2() {
return "false";
}
<?php
// pull in the TOC callback
require_once($CFG->dirroot.'/mod/scorm/datamodels/callback.js.php');
?>
function LMSFinish (param) {
errorCode = "0";
if (param == "") {
@ -235,7 +230,7 @@ function SCORMapi1_2() {
?>
// trigger TOC update
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(); ?>";
var callback = this.connectPrereqCallback;
var callback = M.mod_scorm.connectPrereqCallback;
YUI().use('yui2-connection', function(Y) {
Y.YUI2.util.Connect.asyncRequest('GET', sURL, callback, null);
});

View File

@ -313,13 +313,6 @@ function SCORMapi1_3() {
return "false";
}
<?php
// pull in the TOC callback
include_once($CFG->dirroot.'/mod/scorm/datamodels/callback.js.php');
?>
function Terminate (param) {
errorCode = "0";
if (param == "") {
@ -366,7 +359,7 @@ function SCORMapi1_3() {
}
// trigger TOC update
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(); ?>";
var callback = this.connectPrereqCallback;
var callback = M.mod_scorm.connectPrereqCallback;
YUI().use('yui2-connection', function(Y) {
Y.YUI2.util.Connect.asyncRequest('GET', sURL, callback, null);
});

View File

@ -14,7 +14,7 @@
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* Javascript helper function for IMS Content Package module.
* Javascript helper function for SCORM module.
*
* @package mod-scorm
* @copyright 2009 Petr Skoda (http://skodak.org)
@ -541,4 +541,86 @@ M.mod_scorm.init = function(Y, hide_nav, hide_toc, toc_title, window_name, launc
scorm_resize_layout(true);
};
});
};
M.mod_scorm.connectPrereqCallback = {
success: function(o) {
YUI().use('yui2-treeview', 'yui2-layout', function(Y) {
// MDL-29159 The core version of getContentHtml doesn't escape text properly.
Y.YUI2.widget.TextNode.prototype.getContentHtml = function() {
var sb = [];
sb[sb.length] = this.href ? '<a' : '<span';
sb[sb.length] = ' id="' + Y.YUI2.lang.escapeHTML(this.labelElId) + '"';
sb[sb.length] = ' class="' + Y.YUI2.lang.escapeHTML(this.labelStyle) + '"';
if (this.href) {
sb[sb.length] = ' href="' + Y.YUI2.lang.escapeHTML(this.href) + '"';
sb[sb.length] = ' target="' + Y.YUI2.lang.escapeHTML(this.target) + '"';
}
if (this.title) {
sb[sb.length] = ' title="' + Y.YUI2.lang.escapeHTML(this.title) + '"';
}
sb[sb.length] = ' >';
sb[sb.length] = this.label;
sb[sb.length] = this.href?'</a>':'</span>';
return sb.join("");
};
if (o.responseText !== undefined) {
var tree = new Y.YUI2.widget.TreeView('scorm_tree');
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();
while (root_node.children.length > 0) {
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
var startNode = el_new_tree.firstChild.firstChild;
if (startNode.tagName == 'LI') {
// go back to the beginning
startNode = el_new_tree;
}
//var sXML = new XMLSerializer().serializeToString(startNode);
scorm_tree_node.buildTreeFromMarkup('scormtree123');
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 = Y.YUI2.widget.Layout.getLayoutById('scorm_layout');
var left = scorm_layout_widget.getUnitByPosition('left');
if (left.expanded) {
hnode.focus();
}
}
}
}
});
},
failure: function(o) {
// TODO: do some sort of error handling.
}
};