MDL-56564 mod_lti: External tool form fixes

* Revert disabling of the Preconfigured tool field on edit mode
* Reset LTI tool configuration fields when selecting a different
  preconfigured tool.
* Behat fixes for UI changes.
This commit is contained in:
Jun Pataleta 2016-10-24 17:07:50 +08:00
parent 0fbe41f4cd
commit 1b669ebeba
5 changed files with 69 additions and 61 deletions

View File

@ -49,10 +49,7 @@
self.updateAutomaticToolMatch(Y.one('#id_securetoolurl'));
};
var contentItemButton = Y.one('[name="selectcontent"]');
var contentItemUrl = contentItemButton.getAttribute('data-contentitemurl');
var typeSelector = Y.one('#id_typeid');
typeSelector.on('change', function(e){
updateToolMatches();
@ -69,8 +66,13 @@
allowgrades.set('checked', !self.getSelectedToolTypeOption().getAttribute('nogrades'));
self.toggleGradeSection();
}
// Reset configuration fields when another preconfigured tool is selected.
self.resetToolFields();
});
var contentItemButton = Y.one('[name="selectcontent"]');
var contentItemUrl = contentItemButton.getAttribute('data-contentitemurl');
// Handle configure from link button click.
contentItemButton.on('click', function() {
var contentItemId = self.getContentItemId();
@ -529,6 +531,18 @@
return selected.getAttribute('data-id');
}
return false;
},
/**
* Resets the values of fields related to the LTI tool settings.
*/
resetToolFields: function() {
// Reset values for all text fields.
var fields = Y.all('#id_toolurl, #id_securetoolurl, #id_instructorcustomparameters, #id_icon, #id_secureicon');
fields.set('value', null);
// Reset value for launch container select box.
Y.one('#id_launchcontainer').set('value', 1);
}
};
})();

View File

@ -95,14 +95,12 @@ class mod_lti_mod_form extends moodleform_mod {
$mform->addHelpButton('showdescriptionlaunch', 'display_description', 'lti');
// Tool settings.
$attributes = array();
if ($update = optional_param('update', false, PARAM_INT)) {
$attributes['disabled'] = 'disabled';
}
$attributes['class'] = 'lti_contentitem';
$tooltypes = $mform->addElement('select', 'typeid', get_string('external_tool_type', 'lti'), array(), $attributes);
$tooltypes = $mform->addElement('select', 'typeid', get_string('external_tool_type', 'lti'));
// Type ID parameter being passed when adding an preconfigured tool from activity chooser.
$typeid = optional_param('typeid', false, PARAM_INT);
$mform->getElement('typeid')->setValue($typeid);
if ($typeid) {
$mform->getElement('typeid')->setValue($typeid);
}
$mform->addHelpButton('typeid', 'external_tool_type', 'lti');
$toolproxy = array();
@ -131,7 +129,8 @@ class mod_lti_mod_form extends moodleform_mod {
} else {
$attributes = array();
}
if (!$update && $id) {
if ($id) {
$config = lti_get_type_config($id);
if (!empty($config['contentitem'])) {
$attributes['data-contentitem'] = 1;
@ -140,42 +139,32 @@ class mod_lti_mod_form extends moodleform_mod {
$noncontentitemtypes[] = $id;
}
}
$tooltypes->addOption($type->name, $id, $attributes);
}
// Add button that launches the content-item selection dialogue.
// Add button that launches the content-item selection dialogue.
// Set contentitem URL.
$contentitemurl = new moodle_url('/mod/lti/contentitem.php');
$contentbuttonattributes['data-contentitemurl'] = $contentitemurl->out(false);
$mform->addElement('button', 'selectcontent', get_string('selectcontent', 'lti'), $contentbuttonattributes);
if ($update) {
$mform->disabledIf('selectcontent', 'typeid', 'neq', 0);
} else {
// Disable select content button if the selected tool doesn't support content item or it's set to Automatic.
$allnoncontentitemtypes = $noncontentitemtypes;
$allnoncontentitemtypes[] = '0'; // Add option value for "Automatic, based on tool URL".
$mform->disabledIf('selectcontent', 'typeid', 'in', $allnoncontentitemtypes);
}
$contentbuttonattributes = [
'data-contentitemurl' => $contentitemurl->out(false)
];
$contentbuttonlabel = get_string('selectcontent', 'lti');
$contentbutton = $mform->addElement('button', 'selectcontent', $contentbuttonlabel, $contentbuttonattributes);
// Disable select content button if the selected tool doesn't support content item or it's set to Automatic.
$allnoncontentitemtypes = $noncontentitemtypes;
$allnoncontentitemtypes[] = '0'; // Add option value for "Automatic, based on tool URL".
$mform->disabledIf('selectcontent', 'typeid', 'in', $allnoncontentitemtypes);
$mform->addElement('text', 'toolurl', get_string('launch_url', 'lti'), array('size' => '64'));
$mform->setType('toolurl', PARAM_URL);
$mform->addHelpButton('toolurl', 'launch_url', 'lti');
if ($update) {
$mform->disabledIf('toolurl', 'typeid', 'neq', 0);
} else {
$mform->disabledIf('toolurl', 'typeid', 'in', $noncontentitemtypes);
}
$mform->disabledIf('toolurl', 'typeid', 'in', $noncontentitemtypes);
$mform->addElement('text', 'securetoolurl', get_string('secure_launch_url', 'lti'), array('size' => '64'));
$mform->setType('securetoolurl', PARAM_URL);
$mform->setAdvanced('securetoolurl');
$mform->addHelpButton('securetoolurl', 'secure_launch_url', 'lti');
if ($update) {
$mform->disabledIf('securetoolurl', 'typeid', 'neq', 0);
} else {
$mform->disabledIf('securetoolurl', 'typeid', 'in', $noncontentitemtypes);
}
$mform->disabledIf('securetoolurl', 'typeid', 'in', $noncontentitemtypes);
$mform->addElement('hidden', 'urlmatchedtypeid', '', array( 'id' => 'id_urlmatchedtypeid' ));
$mform->setType('urlmatchedtypeid', PARAM_INT);
@ -196,22 +185,14 @@ class mod_lti_mod_form extends moodleform_mod {
$mform->setType('resourcekey', PARAM_TEXT);
$mform->setAdvanced('resourcekey');
$mform->addHelpButton('resourcekey', 'resourcekey', 'lti');
if ($update) {
$mform->disabledIf('resourcekey', 'typeid', 'neq', 0);
} else {
$mform->disabledIf('resourcekey', 'typeid', 'in', $noncontentitemtypes);
}
$mform->setForceLtr('resourcekey');
$mform->disabledIf('resourcekey', 'typeid', 'in', $noncontentitemtypes);
$mform->addElement('passwordunmask', 'password', get_string('password', 'lti'));
$mform->setType('password', PARAM_TEXT);
$mform->setAdvanced('password');
$mform->addHelpButton('password', 'password', 'lti');
if ($update) {
$mform->disabledIf('password', 'typeid', 'neq', 0);
} else {
$mform->disabledIf('password', 'typeid', 'in', $noncontentitemtypes);
}
$mform->disabledIf('password', 'typeid', 'in', $noncontentitemtypes);
$mform->addElement('textarea', 'instructorcustomparameters', get_string('custom', 'lti'), array('rows' => 4, 'cols' => 60));
$mform->setType('instructorcustomparameters', PARAM_TEXT);
@ -223,21 +204,13 @@ class mod_lti_mod_form extends moodleform_mod {
$mform->setType('icon', PARAM_URL);
$mform->setAdvanced('icon');
$mform->addHelpButton('icon', 'icon_url', 'lti');
if ($update) {
$mform->disabledIf('icon', 'typeid', 'neq', 0);
} else {
$mform->disabledIf('icon', 'typeid', 'in', $noncontentitemtypes);
}
$mform->disabledIf('icon', 'typeid', 'in', $noncontentitemtypes);
$mform->addElement('text', 'secureicon', get_string('secure_icon_url', 'lti'), array('size' => '64'));
$mform->setType('secureicon', PARAM_URL);
$mform->setAdvanced('secureicon');
$mform->addHelpButton('secureicon', 'secure_icon_url', 'lti');
if ($update) {
$mform->disabledIf('secureicon', 'typeid', 'neq', 0);
} else {
$mform->disabledIf('secureicon', 'typeid', 'in', $noncontentitemtypes);
}
$mform->disabledIf('secureicon', 'typeid', 'in', $noncontentitemtypes);
// Add privacy preferences fieldset where users choose whether to send their data.
$mform->addElement('header', 'privacy', get_string('privacy', 'lti'));
@ -317,4 +290,3 @@ class mod_lti_mod_form extends moodleform_mod {
}
}

View File

@ -26,19 +26,19 @@ Feature: Add tools
And I log out
@javascript
Scenario: Add a tool via the acitivity picker
When I log in as "teacher1"
Scenario: Add a tool via the activity picker
Given I log in as "teacher1"
And I follow "Course 1"
And I turn editing mode on
And I add a "Teaching Tool 1" to section "1"
# For tool that does not support Content-Item message type, the Select content button must be disabled.
And I set the field "Activity name" to "Test tool activity 1"
And I click on "Show more..." "link"
And I expand all fieldsets
And I set the field "Launch container" to "Embed"
And the "Select content" "button" should be disabled
And I press "Save and return to course"
And I open "Test tool activity 1" actions menu
When I open "Test tool activity 1" actions menu
And I choose "Edit settings" in the open action menu
Then the field "Preconfigured tool" matches value "Teaching Tool 1"
# When editing settings, the Select content button should be disabled.
And the "Select content" "button" should be disabled
And the "Tool URL" "field" should be disabled

View File

@ -48,8 +48,7 @@ Feature: Content-Item support
And I open "Test tool activity 1" actions menu
And I choose "Edit settings" in the open action menu
Then the field "Preconfigured tool" matches value "Teaching Tool 1"
# When editing settings, the Select content button should be disabled.
And the "Select content" "button" should be disabled
And the "Select content" "button" should be enabled
@javascript
Scenario: Changing preconfigured tool selection
@ -86,3 +85,19 @@ Feature: Content-Item support
And I set the field "Activity name" to "Test tool activity 1"
And the "Select content" "button" should be disabled
And the "Tool URL" "field" should be enabled
@javascript
Scenario: Editing a manually configured external tool
Given I log in as "teacher1"
And I follow "Course 1"
And I turn editing mode on
And I add a "External tool" to section "1"
And the field "Preconfigured tool" matches value "Automatic, based on tool URL"
And I set the field "Activity name" to "Test tool activity 1"
And the "Select content" "button" should be disabled
And I set the field "Tool URL" to local url "/mod/lti/tests/fixtures/tool_provider.php"
And I press "Save and return to course"
When I open "Test tool activity 1" actions menu
And I choose "Edit settings" in the open action menu
Then the field "Preconfigured tool" matches value "Automatic, based on tool URL"
And the "Select content" "button" should be disabled

View File

@ -1,5 +1,12 @@
This files describes API changes in the lti code.
=== 3.2 ===
* Support for LTI ContentItem message type.
* New function lti_build_content_item_selection_request() for building an LTI ContentItemSelectionRequest.
* New Select content button in External tool configuration page that lets the user configure an external tool by fetching tool
configuration content from the preconfigured tool's content selection interface.
=== 3.1 ===
* When requesting a grade from the outcome service, and empty grade will now be returned as