\n * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later\n */\n\n\"use strict\";\n\nimport ContentItem from 'mod_lti/contentitem';\n\n/**\n * Initialise module.\n *\n * @param {int} courseId the course id.\n * @param {string} toolUrl the external tool url.\n */\nconst init = (courseId, toolUrl) => {\n const contentItemButton = document.querySelector('[name=\"selectcontent\"]');\n\n if (!contentItemButton) {\n return;\n }\n\n contentItemButton.addEventListener('click', () => {\n const contentItemUrl = contentItemButton.getAttribute('data-contentitemurl');\n const contentItemId = document.querySelector('#hidden_typeid').value;\n if (contentItemId) {\n const title = document.querySelector('#id_name').value.trim();\n const text = document.querySelector('#id_introeditor').value.trim();\n const postData = {\n id: contentItemId,\n course: courseId,\n title: title,\n text: text\n };\n\n // The callback below is called after the content item has been returned and processed.\n ContentItem.init(contentItemUrl, toolUrl, postData, (returnData) => {\n if (!returnData.multiple) {\n // The state of the grade checkbox has already been set by processContentItemReturnData() but that\n // hasn't fired the click/change event required by formslib to show/hide the dependent grade fields.\n // Fire it now.\n const allowGrades = document.querySelector('#id_instructorchoiceacceptgrades');\n let allowGradesChangeEvent = new Event('change');\n allowGrades.dispatchEvent(allowGradesChangeEvent);\n\n // If the tool is set to accept grades, make sure \"Point\" is selected.\n if (allowGrades.checked) {\n const gradeType = document.querySelector('#id_grade_modgrade_type');\n gradeType.value = \"point\";\n let gradeTypeChangeEvent = new Event('change');\n gradeType.dispatchEvent(gradeTypeChangeEvent);\n }\n }\n });\n }\n });\n};\n\nexport default {\n init: init\n};\n"],"names":["init","courseId","toolUrl","contentItemButton","document","querySelector","addEventListener","contentItemUrl","getAttribute","contentItemId","value","title","trim","text","postData","id","course","returnData","multiple","allowGrades","allowGradesChangeEvent","Event","dispatchEvent","checked","gradeType","gradeTypeChangeEvent"],"mappings":"oQA4Ee,CACXA,KA5CS,CAACC,SAAUC,iBACdC,kBAAoBC,SAASC,cAAc,0BAE5CF,mBAILA,kBAAkBG,iBAAiB,SAAS,WAClCC,eAAiBJ,kBAAkBK,aAAa,uBAChDC,cAAgBL,SAASC,cAAc,kBAAkBK,SAC3DD,cAAe,OACTE,MAAQP,SAASC,cAAc,YAAYK,MAAME,OACjDC,KAAOT,SAASC,cAAc,mBAAmBK,MAAME,OACvDE,SAAW,CACbC,GAAIN,cACJO,OAAQf,SACRU,MAAOA,MACPE,KAAMA,2BAIEb,KAAKO,eAAgBL,QAASY,UAAWG,iBAC5CA,WAAWC,SAAU,OAIhBC,YAAcf,SAASC,cAAc,wCACvCe,uBAAyB,IAAIC,MAAM,aACvCF,YAAYG,cAAcF,wBAGtBD,YAAYI,QAAS,OACfC,UAAYpB,SAASC,cAAc,2BACzCmB,UAAUd,MAAQ,YACde,qBAAuB,IAAIJ,MAAM,UACrCG,UAAUF,cAAcG"}
\ No newline at end of file
diff --git a/mod/lti/amd/src/contentitem.js b/mod/lti/amd/src/contentitem.js
index 96d4d905932..bb0ac1c94eb 100644
--- a/mod/lti/amd/src/contentitem.js
+++ b/mod/lti/amd/src/contentitem.js
@@ -42,13 +42,15 @@ define(
* Init function.
*
* @param {string} url The URL for the content item selection.
+ * @param {string} toolUrl The URL of the LTI tool.
* @param {object} postData The data to be sent for the content item selection request.
* @param {Function} cb The callback to run once the content item has been processed.
*/
- init: function(url, postData, cb) {
+ init: function(url, toolUrl, postData, cb) {
doneCallback = cb;
var context = {
url: url,
+ toolUrl: toolUrl,
postData: postData
};
var bodyPromise = templates.render('mod_lti/contentitem', context);
diff --git a/mod/lti/amd/src/mod_form.js b/mod/lti/amd/src/mod_form.js
index dcf77b1c8c9..a074f97c303 100644
--- a/mod/lti/amd/src/mod_form.js
+++ b/mod/lti/amd/src/mod_form.js
@@ -29,8 +29,9 @@ import ContentItem from 'mod_lti/contentitem';
* Initialise module.
*
* @param {int} courseId the course id.
+ * @param {string} toolUrl the external tool url.
*/
-const init = (courseId) => {
+const init = (courseId, toolUrl) => {
const contentItemButton = document.querySelector('[name="selectcontent"]');
if (!contentItemButton) {
@@ -51,7 +52,7 @@ const init = (courseId) => {
};
// The callback below is called after the content item has been returned and processed.
- ContentItem.init(contentItemUrl, postData, (returnData) => {
+ ContentItem.init(contentItemUrl, toolUrl, postData, (returnData) => {
if (!returnData.multiple) {
// The state of the grade checkbox has already been set by processContentItemReturnData() but that
// hasn't fired the click/change event required by formslib to show/hide the dependent grade fields.
diff --git a/mod/lti/mod_form.php b/mod/lti/mod_form.php
index d6ac4da0dc2..ca9b70bb3a5 100644
--- a/mod/lti/mod_form.php
+++ b/mod/lti/mod_form.php
@@ -309,7 +309,7 @@ class mod_lti_mod_form extends moodleform_mod {
}
public function definition() {
- global $PAGE, $OUTPUT, $COURSE;
+ global $CFG, $PAGE, $OUTPUT, $COURSE;
if ($this->type) {
component_callback("ltisource_$this->type", 'add_instance_hook');
@@ -517,7 +517,11 @@ class mod_lti_mod_form extends moodleform_mod {
$this->add_action_buttons();
if ($supportscontentitemselection) {
- $PAGE->requires->js_call_amd('mod_lti/mod_form', 'init', [$COURSE->id]);
+ $jsparams = [$COURSE->id];
+ // If local-network-access is enabled, pass the tool URL as well.
+ $jsparams[] = (isset($CFG->ltiallowlocalnetwork) && $CFG->ltiallowlocalnetwork) ? $tooltype->baseurl : '';
+
+ $PAGE->requires->js_call_amd('mod_lti/mod_form', 'init', $jsparams);
}
}
diff --git a/mod/lti/templates/contentitem.mustache b/mod/lti/templates/contentitem.mustache
index eab9868d949..58162e1a671 100644
--- a/mod/lti/templates/contentitem.mustache
+++ b/mod/lti/templates/contentitem.mustache
@@ -32,6 +32,7 @@
Example context (json):
{
"url": "/",
+ "toolUrl": "http://external.tool.url",
"postData": {
"id": "1",
"course": "1",
@@ -48,7 +49,7 @@
{{#str}} register_warning, mod_lti {{/str}}
-