forked from moodle/moodle
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'MDL-49609-master-5' of git://github.com/junpataleta/moodle
- Loading branch information
Showing
22 changed files
with
1,318 additions
and
54 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
define([],function(){return{init:function(a){window!=top&&parent.processContentItemReturnData(a)}}}); |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,122 @@ | ||
// 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/>. | ||
|
||
/** | ||
* Launches the modal dialogue that contains the iframe that sends the Content-Item selection request to an | ||
* LTI tool provider that supports Content-Item type message. | ||
* | ||
* See template: mod_lti/contentitem | ||
* | ||
* @module mod_lti/contentitem | ||
* @class contentitem | ||
* @package mod_lti | ||
* @copyright 2016 Jun Pataleta <jun@moodle.com> | ||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later | ||
* @since 3.2 | ||
*/ | ||
define(['jquery', 'core/notification', 'core/str', 'core/templates', 'mod_lti/form-field', 'core/yui'], | ||
function($, notification, str, templates, FormField) { | ||
var dialogue; | ||
var contentItem = { | ||
/** | ||
* Init function. | ||
* | ||
* @param {string} url The URL for the content item selection. | ||
* @param {object} postData The data to be sent for the content item selection request. | ||
*/ | ||
init: function(url, postData) { | ||
var dialogueTitle = ''; | ||
str.get_string('selectcontent', 'lti').then(function(title) { | ||
dialogueTitle = title; | ||
var context = { | ||
url: url, | ||
postData: postData | ||
}; | ||
return templates.render('mod_lti/contentitem', context); | ||
|
||
}).then(function(html, js) { | ||
// Set dialog's body content. | ||
dialogue = new M.core.dialogue({ | ||
modal: true, | ||
headerContent: dialogueTitle, | ||
bodyContent: html, | ||
draggable: true, | ||
width: '800px', | ||
height: '600px' | ||
}); | ||
|
||
// Show dialog. | ||
dialogue.show(); | ||
|
||
// Destroy after hiding. | ||
dialogue.after('visibleChange', function(e) { | ||
// Going from visible to hidden. | ||
if (e.prevVal && !e.newVal) { | ||
this.destroy(); | ||
// Fetch notifications. | ||
notification.fetchNotifications(); | ||
} | ||
}, dialogue); | ||
|
||
templates.runTemplateJS(js); | ||
|
||
}).fail(notification.exception); | ||
} | ||
}; | ||
|
||
/** | ||
* Array of form fields for LTI tool configuration. | ||
* | ||
* @type {*[]} | ||
*/ | ||
var ltiFormFields = [ | ||
new FormField('name', FormField.TYPES.TEXT, false, ''), | ||
new FormField('introeditor', FormField.TYPES.EDITOR, false, ''), | ||
new FormField('toolurl', FormField.TYPES.TEXT, true, ''), | ||
new FormField('securetoolurl', FormField.TYPES.TEXT, true, ''), | ||
new FormField('instructorchoiceacceptgrades', FormField.TYPES.CHECKBOX, true, true), | ||
new FormField('instructorchoicesendname', FormField.TYPES.CHECKBOX, true, true), | ||
new FormField('instructorchoicesendemailaddr', FormField.TYPES.CHECKBOX, true, true), | ||
new FormField('instructorcustomparameters', FormField.TYPES.TEXT, true, ''), | ||
new FormField('icon', FormField.TYPES.TEXT, true, ''), | ||
new FormField('secureicon', FormField.TYPES.TEXT, true, ''), | ||
new FormField('launchcontainer', FormField.TYPES.SELECT, true, 0) | ||
]; | ||
|
||
/** | ||
* Window function that can be called from mod_lti/contentitem_return to close the dialogue and process the return data. | ||
* | ||
* @param {object} returnData The fetched configuration data from the Content-Item selection dialogue. | ||
*/ | ||
window.processContentItemReturnData = function(returnData) { | ||
if (dialogue) { | ||
dialogue.hide(); | ||
} | ||
|
||
// Populate LTI configuration fields from return data. | ||
var index; | ||
for (index in ltiFormFields) { | ||
var field = ltiFormFields[index]; | ||
var value = null; | ||
if ($.type(returnData[field.name]) !== 'undefined') { | ||
value = returnData[field.name]; | ||
} | ||
field.setFieldValue(value); | ||
} | ||
}; | ||
|
||
return contentItem; | ||
} | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
// 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/>. | ||
|
||
/** | ||
* Processes the result of LTI tool creation from a Content-Item message type. | ||
* | ||
* @module mod_lti/contentitem_return | ||
* @class contentitem_return | ||
* @package mod_lti | ||
* @copyright 2016 Jun Pataleta <jun@moodle.com> | ||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later | ||
* @since 3.2 | ||
*/ | ||
define([], function() { | ||
return { | ||
/** | ||
* Init function. | ||
* | ||
* @param {string} returnData The returned data. | ||
*/ | ||
init: function(returnData) { | ||
if (window != top) { | ||
// Send return data to be processed by the parent window. | ||
parent.processContentItemReturnData(returnData); | ||
} | ||
} | ||
}; | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
// 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/>. | ||
|
||
/** | ||
* A module that enables the setting of form field values on the client side. | ||
* | ||
* @module mod_lti/form-field | ||
* @class form-field | ||
* @package mod_lti | ||
* @copyright 2016 Jun Pataleta <jun@moodle.com> | ||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later | ||
* @since 3.2 | ||
*/ | ||
define(['jquery'], | ||
function($) { | ||
/** | ||
* Form field class. | ||
* | ||
* @param {string} name Field name. | ||
* @param {number} type The field type. | ||
* @param {boolean} resetIfUndefined Flag to reset the field to the default value if undefined in the return data. | ||
* @param {string|number|boolean} defaultValue The default value to use for the field. | ||
* @constructor | ||
*/ | ||
var FormField = function(name, type, resetIfUndefined, defaultValue) { | ||
this.name = name; | ||
this.id = 'id_' + this.name; | ||
this.selector = '#' + this.id; | ||
this.type = type; | ||
this.resetIfUndefined = resetIfUndefined; | ||
this.defaultValue = defaultValue; | ||
}; | ||
|
||
/** | ||
* Form field types. | ||
* | ||
* @type {{TEXT: number, SELECT: number, CHECKBOX: number, EDITOR: number}} | ||
*/ | ||
FormField.TYPES = { | ||
TEXT: 1, | ||
SELECT: 2, | ||
CHECKBOX: 3, | ||
EDITOR: 4 | ||
}; | ||
|
||
/** | ||
* Sets the values for a form field. | ||
* | ||
* @param {string|boolean|number} value The value to be set into the field. | ||
*/ | ||
FormField.prototype.setFieldValue = function(value) { | ||
if (value === null) { | ||
if (this.resetIfUndefined) { | ||
value = this.defaultValue; | ||
} else { | ||
// No need set the field value if value is null and there's no need to reset the field. | ||
return; | ||
} | ||
} | ||
|
||
switch (this.type) { | ||
case FormField.TYPES.CHECKBOX: | ||
if (value) { | ||
$(this.selector).prop('checked', true); | ||
} else { | ||
$(this.selector).prop('checked', false); | ||
} | ||
break; | ||
case FormField.TYPES.EDITOR: | ||
if ($.type(value.text) !== 'undefined') { | ||
/* global tinyMCE:false */ | ||
|
||
// Set text in editor's editable content, if applicable. | ||
// Check if it is an Atto editor. | ||
var attoEditor = $(this.selector + 'editable'); | ||
if (attoEditor.length) { | ||
attoEditor.html(value.text); | ||
} else if (typeof tinyMCE !== 'undefined') { | ||
// If the editor is not Atto, try to fallback to TinyMCE. | ||
tinyMCE.execInstanceCommand(this.id, 'mceInsertContent', false, value.text); | ||
} | ||
|
||
// Set text to actual editor text area. | ||
$(this.selector).val(value.text); | ||
} | ||
break; | ||
default: | ||
$(this.selector).val(value); | ||
break; | ||
} | ||
}; | ||
|
||
return FormField; | ||
} | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
<?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/>. | ||
|
||
/** | ||
* Handle sending a user to a tool provider to initiate a content-item selection. | ||
* | ||
* @package mod_lti | ||
* @copyright 2015 Vital Source Technologies http://vitalsource.com | ||
* @author Stephen Vickers | ||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later | ||
*/ | ||
|
||
require_once('../../config.php'); | ||
require_once($CFG->dirroot . '/mod/lti/lib.php'); | ||
require_once($CFG->dirroot . '/mod/lti/locallib.php'); | ||
|
||
$id = required_param('id', PARAM_INT); | ||
$courseid = required_param('course', PARAM_INT); | ||
$title = optional_param('title', '', PARAM_TEXT); | ||
$text = optional_param('text', '', PARAM_RAW); | ||
|
||
// Check access and capabilities. | ||
$course = $DB->get_record('course', array('id' => $courseid), '*', MUST_EXIST); | ||
require_login($course); | ||
$context = context_course::instance($courseid); | ||
require_capability('moodle/course:manageactivities', $context); | ||
require_capability('mod/lti:addcoursetool', $context); | ||
|
||
// Set the return URL. We send the launch container along to help us avoid frames-within-frames when the user returns. | ||
$returnurlparams = [ | ||
'course' => $course->id, | ||
'id' => $id, | ||
'sesskey' => sesskey() | ||
]; | ||
$returnurl = new \moodle_url('/mod/lti/contentitem_return.php', $returnurlparams); | ||
|
||
// Prepare the request. | ||
$request = lti_build_content_item_selection_request($id, $course, $returnurl, $title, $text, [], []); | ||
|
||
// Get the launch HTML. | ||
$content = lti_post_launch_html($request->params, $request->url, false); | ||
|
||
echo $content; |
Oops, something went wrong.