diff --git a/mod/lti/ajax.php b/mod/lti/ajax.php
index 54eac007929..cd05a5cf179 100644
--- a/mod/lti/ajax.php
+++ b/mod/lti/ajax.php
@@ -20,6 +20,7 @@ switch($action){
if(!empty($tool)){
$response->toolid = $tool->id;
$response->toolname = htmlspecialchars($tool->name);
+ $response->tooldomain = htmlspecialchars($tool->tooldomain);
}
break;
diff --git a/mod/lti/instructor_edit_tool_type.php b/mod/lti/instructor_edit_tool_type.php
index 7680a4856be..530f0ce4e3d 100644
--- a/mod/lti/instructor_edit_tool_type.php
+++ b/mod/lti/instructor_edit_tool_type.php
@@ -34,10 +34,13 @@ if (confirm_sesskey() && isset($data->submitbutton)) {
lti_update_type($type, $data);
+ $fromdb = lti_get_type($typeid);
+ $json = json_encode($fromdb);
+
//Output script to update the calling window.
$script = <<
@@ -51,12 +54,14 @@ SCRIPT;
$type->course = $COURSE->id;
$id = lti_add_type($type, $data);
- $name = json_encode($type->name);
+
+ $fromdb = lti_get_type($id);
+ $json = json_encode($fromdb);
//Output script to update the calling window.
$script = <<
diff --git a/mod/lti/lang/en/lti.php b/mod/lti/lang/en/lti.php
index b949b38761d..67950ff15c7 100644
--- a/mod/lti/lang/en/lti.php
+++ b/mod/lti/lang/en/lti.php
@@ -201,4 +201,9 @@ $string['delete_confirmation'] = 'Are you sure you want to delete this external
$string['cannot_edit'] = 'You may not edit this tool configuration.';
$string['cannot_delete'] = 'You may not delete this tool configuration.';
$string['global_tool_types'] = 'Global tool types';
-$string['course_tool_types'] = 'Course tool types';
\ No newline at end of file
+$string['course_tool_types'] = 'Course tool types';
+
+$string['using_tool_configuration'] = 'Using tool configuration: ';
+$string['domain_mismatch'] = 'Launch URL\'s domain does not match tool configuration.';
+$string['custom_config'] = 'Using custom tool configuration.';
+$string['tool_config_not_found'] = 'Tool configuration not found for this URL.';
\ No newline at end of file
diff --git a/mod/lti/locallib.php b/mod/lti/locallib.php
index c4790e99643..3dca134e163 100644
--- a/mod/lti/locallib.php
+++ b/mod/lti/locallib.php
@@ -410,7 +410,7 @@ QUERY;
$types[0] = (object)array('name' => get_string('automatic', 'lti'), 'course' => $SITE->id);
foreach($admintypes as $type) {
- $types[$type->id] = (object)array('name' => $type->name, 'course' => $type->course);
+ $types[$type->id] = $type;
}
return $types;
diff --git a/mod/lti/mod_form.js b/mod/lti/mod_form.js
index 7569629f880..edd394d525b 100644
--- a/mod/lti/mod_form.js
+++ b/mod/lti/mod_form.js
@@ -1,6 +1,5 @@
(function(){
var Y;
- var self;
M.mod_lti = M.mod_lti || {};
@@ -10,7 +9,7 @@
Y = yui3;
}
- self = this;
+ var self = this;
this.settings = Y.JSON.parse(settings);
this.urlCache = {};
@@ -47,7 +46,13 @@
self.updateAutomaticToolMatch();
},
+ clearToolCache: function(){
+ this.urlCache = {};
+ },
+
updateAutomaticToolMatch: function(){
+ var self = this;
+
var toolurl = Y.one('#id_toolurl');
var typeSelector = Y.one('#id_typeid');
var automatchToolDisplay = Y.one('#lti_automatch_tool');
@@ -62,8 +67,29 @@
var url = toolurl.get('value');
- if(!url || typeSelector.get('value') > 0){
+ //Hide the display if the url box is empty
+ if(!url){
automatchToolDisplay.setStyle('display', 'none');
+ } else {
+ automatchToolDisplay.set('innerHTML', '');
+ automatchToolDisplay.setStyle('display', '');
+ }
+
+ var selectedToolType = typeSelector.get('value');
+ var selectedOption = typeSelector.one('option[value=' + selectedToolType + ']');
+
+ //A specific tool type is selected (not "auto")"
+ if(selectedToolType > 0){
+ //If the entered domain matches the domain of the tool configuration...
+ var domainRegex = /(?:https?:\/\/)?(?:www\.)?([^\/]+)(?:\/|$)/i;
+ var match = domainRegex.exec(url);
+ if(match && match[1] && match[1].toLowerCase() === selectedOption.getAttribute('domain').toLowerCase()){
+ automatchToolDisplay.set('innerHTML', '
' + M.str.lti.using_tool_configuration + selectedOption.get('text'));
+ } else {
+ //The entered URL does not match the domain of the tool configuration
+ automatchToolDisplay.set('innerHTML', '
' + M.str.lti.domain_mismatch);
+ }
+
return;
}
@@ -72,17 +98,15 @@
//We don't care what tool type this tool is associated with if it's manually configured'
if(key.get('value') !== '' && secret.get('value') !== ''){
- automatchToolDisplay.set('innerHTML', '
Using custom tool configuration.');
+ automatchToolDisplay.set('innerHTML', '
' + M.str.lti.custom_config);
} else {
var continuation = function(toolInfo){
- automatchToolDisplay.setStyle('display', '');
-
if(toolInfo.toolname){
- automatchToolDisplay.set('innerHTML', '
Using tool configuration: ' + toolInfo.toolname);
+ automatchToolDisplay.set('innerHTML', '
' + M.str.lti.using_tool_configuration + toolInfo.toolname);
} else {
//Inform them custom configuration is in use
if(key.get('value') === '' || secret.get('value') === ''){
- automatchToolDisplay.set('innerHTML', '
Tool configuration not found for this URL.');
+ automatchToolDisplay.set('innerHTML', '
' + M.str.lti.tool_config_not_found);
}
}
};
@@ -147,6 +171,8 @@
* Javascript is a requirement to edit course level tools at this point.
*/
createTypeEditorButtons: function(){
+ var self = this;
+
var typeSelector = Y.one('#id_typeid');
var createIcon = function(id, tooltip, iconUrl){
@@ -181,17 +207,7 @@
if(self.getSelectedToolTypeOption().getAttribute('editable')){
if(confirm(M.str.lti.delete_confirmation)){
-
- Y.io(self.settings.instructor_tool_type_edit_url + '&action=delete&typeid=' + toolTypeId, {
- on: {
- success: function(){
- self.getSelectedToolTypeOption().remove();
- },
- failure: function(){
-
- }
- }
- });
+ self.deleteTool(toolTypeId);
}
} else {
alert(M.str.lti.cannot_delete);
@@ -218,34 +234,65 @@
}
},
- addToolType: function(text, value){
+ addToolType: function(toolType){
var typeSelector = Y.one('#id_typeid');
var course_tool_group = Y.one('#course_tool_group');
var option = Y.Node.create('')
- .set('text', text)
- .set('value', value)
+ .set('text', toolType.name)
+ .set('value', toolType.id)
.set('selected', 'selected')
.setAttribute('editable', '1')
- .setAttribute('courseTool', '1');
+ .setAttribute('courseTool', '1')
+ .setAttribute('domain', toolType.tooldomain);
if(course_tool_group){
course_tool_group.append(option);
} else {
typeSelector.append(option);
}
+
+ //Adding the new tool may affect which tool gets matched automatically
+ this.clearToolCache();
+ this.updateAutomaticToolMatch();
},
- updateToolType: function(text, value){
+ updateToolType: function(toolType){
var typeSelector = Y.one('#id_typeid');
- var option = typeSelector.one('option[value=' + value + ']');
- option.set('text', text);
+ var option = typeSelector.one('option[value=' + toolType.id + ']');
+ option.set('text', toolType.name)
+ .set('domain', toolType.tooldomain);
+
+ //Editing the tool may affect which tool gets matched automatically
+ this.clearToolCache();
+ this.updateAutomaticToolMatch();
+ },
+
+ deleteTool: function(toolTypeId){
+ var self = this;
+
+ Y.io(self.settings.instructor_tool_type_edit_url + '&action=delete&typeid=' + toolTypeId, {
+ on: {
+ success: function(){
+ self.getSelectedToolTypeOption().remove();
+
+ //Editing the tool may affect which tool gets matched automatically
+ self.clearToolCache();
+ self.updateAutomaticToolMatch();
+ },
+ failure: function(){
+
+ }
+ }
+ });
},
findToolByUrl: function(url, callback){
+ var self = this;
+
Y.io(self.settings.ajax_url, {
- data: { action: 'find_tool_config',
+ data: {action: 'find_tool_config',
course: self.settings.courseId,
toolurl: url
},
diff --git a/mod/lti/mod_form.php b/mod/lti/mod_form.php
index c9d37143368..7f2a0edf867 100644
--- a/mod/lti/mod_form.php
+++ b/mod/lti/mod_form.php
@@ -80,9 +80,9 @@ class mod_lti_mod_form extends moodleform_mod {
foreach(lti_get_types_for_add_instance() as $id => $type){
if($type->course == $COURSE->id) {
- $attributes = array( 'editable' => 1, 'courseTool' => 1 );
+ $attributes = array( 'editable' => 1, 'courseTool' => 1, 'domain' => $type->tooldomain );
} else if($id != 0) {
- $attributes = array( 'globalTool' => 1);
+ $attributes = array( 'globalTool' => 1, 'domain' => $type->tooldomain);
} else {
$attributes = array();
}
@@ -169,7 +169,7 @@ class mod_lti_mod_form extends moodleform_mod {
'add_icon_url' => (string)$OUTPUT->pix_url('t/add'),
'delete_icon_url' => (string)$OUTPUT->pix_url('t/delete'),
'green_check_icon_url' => (string)$OUTPUT->pix_url('i/tick_green_small'),
- 'yellow_check_icon_url' => (string)$OUTPUT->pix_url('i/tick_amber_small'),
+ 'warning_icon_url' => (string)$OUTPUT->pix_url('warning', 'lti'),
'instructor_tool_type_edit_url' => $editurl->out(false),
'ajax_url' => $ajaxurl->out(true),
'courseId' => $COURSE->id
@@ -187,7 +187,11 @@ class mod_lti_mod_form extends moodleform_mod {
array('cannot_edit', 'lti'),
array('cannot_delete', 'lti'),
array('global_tool_types', 'lti'),
- array('course_tool_types', 'lti')
+ array('course_tool_types', 'lti'),
+ array('using_tool_configuration', 'lti'),
+ array('domain_mismatch', 'lti'),
+ array('custom_config', 'lti'),
+ array('tool_config_not_found', 'lti')
),
);