From 16e8f1308473e12ed2fcfabf35297ef050e39b09 Mon Sep 17 00:00:00 2001 From: Chris Scribner Date: Tue, 20 Sep 2011 10:54:31 -0400 Subject: [PATCH] Improving the experience of instructor managed tool types --- mod/lti/ajax.php | 1 + mod/lti/instructor_edit_tool_type.php | 11 ++- mod/lti/lang/en/lti.php | 7 +- mod/lti/locallib.php | 2 +- mod/lti/mod_form.js | 101 +++++++++++++++++++------- mod/lti/mod_form.php | 12 ++- 6 files changed, 98 insertions(+), 36 deletions(-) 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('