mirrored from git://git.moodle.org/moodle.git
/
contentitem.min.js
15 lines (14 loc) · 5.61 KB
/
contentitem.min.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
function asyncGeneratorStep(gen,resolve,reject,_next,_throw,key,arg){try{var info=gen[key](arg),value=info.value}catch(error){return void reject(error)}info.done?resolve(value):Promise.resolve(value).then(_next,_throw)}
/**
* 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
* @copyright 2016 Jun Pataleta <jun@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
* @since 3.2
*/
define("mod_lti/contentitem",["jquery","core/notification","core/str","core/templates","mod_lti/form-field","core/modal_factory","core/modal_events"],(function($,notification,str,templates,FormField,ModalFactory,ModalEvents){var dialogue,doneCallback,fn,_ref,contentItem={init:function(url,postData,cb){doneCallback=cb;var context={url:url,postData:postData},bodyPromise=templates.render("mod_lti/contentitem",context);if(dialogue)return dialogue.setBody(bodyPromise),void dialogue.show();str.get_string("selectcontent","lti").then((function(title){return ModalFactory.create({title:title,body:bodyPromise,large:!0})})).then((function(modal){dialogue=modal,modal.getRoot().on(ModalEvents.hidden,(function(){modal.setBody(""),notification.fetchNotifications()})),modal.show()})).catch(notification.exception)}},ltiFormFields=[new FormField("name",FormField.TYPES.TEXT,!1,""),new FormField("introeditor",FormField.TYPES.EDITOR,!1,""),new FormField("toolurl",FormField.TYPES.TEXT,!0,""),new FormField("securetoolurl",FormField.TYPES.TEXT,!0,""),new FormField("instructorchoiceacceptgrades",FormField.TYPES.CHECKBOX,!0,!0),new FormField("instructorchoicesendname",FormField.TYPES.CHECKBOX,!0,!0),new FormField("instructorchoicesendemailaddr",FormField.TYPES.CHECKBOX,!0,!0),new FormField("instructorcustomparameters",FormField.TYPES.TEXT,!0,""),new FormField("icon",FormField.TYPES.TEXT,!0,""),new FormField("secureicon",FormField.TYPES.TEXT,!0,""),new FormField("launchcontainer",FormField.TYPES.SELECT,!0,0),new FormField("grade_modgrade_point",FormField.TYPES.TEXT,!1,""),new FormField("lineitemresourceid",FormField.TYPES.TEXT,!0,""),new FormField("lineitemtag",FormField.TYPES.TEXT,!0,"")],hideElement=function(e){e.setAttribute("hidden","true"),e.setAttribute("aria-hidden","true"),e.setAttribute("tab-index","-1")},showElement=function(e){e.removeAttribute("hidden"),e.setAttribute("aria-hidden","false"),e.setAttribute("tab-index","1")},showMultipleSummaryAndHideForm=(fn=regeneratorRuntime.mark((function _callee(items){var form,toolArea,buttonGroup,submitAndLaunch,_yield$templates$rend,html,js;return regeneratorRuntime.wrap((function(_context){for(;;)switch(_context.prev=_context.next){case 0:return form=document.querySelector("#region-main-box form"),toolArea=form.querySelector('[data-attribute="dynamic-import"]'),buttonGroup=form.querySelector("#fgroup_id_buttonar"),submitAndLaunch=form.querySelector("#id_submitbutton"),Array.from(form.children).forEach(hideElement),hideElement(submitAndLaunch),_context.next=8,templates.renderForPromise("mod_lti/tool_deeplinking_results",{items:items});case 8:return _yield$templates$rend=_context.sent,html=_yield$templates$rend.html,js=_yield$templates$rend.js,_context.next=13,templates.replaceNodeContents(toolArea,html,js);case 13:showElement(toolArea),showElement(buttonGroup);case 15:case"end":return _context.stop()}}),_callee)})),_ref=function(){var self=this,args=arguments;return new Promise((function(resolve,reject){var gen=fn.apply(self,args);function _next(value){asyncGeneratorStep(gen,resolve,reject,_next,_throw,"next",value)}function _throw(err){asyncGeneratorStep(gen,resolve,reject,_next,_throw,"throw",err)}_next(void 0)}))},function(_x){return _ref.apply(this,arguments)});return window.processContentItemReturnData=function(returnData){var index;if(dialogue&&dialogue.hide(),returnData.multiple){for(index in ltiFormFields)ltiFormFields[index].setFieldValue("name"===ltiFormFields[index].name?"item":null);var variants=[];returnData.multiple.forEach((function(v){var config,variant;variants.push((config=v,variant={},["name","toolurl","securetoolurl","instructorcustomparameters","icon","secureicon","launchcontainer","lineitemresourceid","lineitemtag"].forEach((function(name){variant[name]=config[name]||""})),variant["introeditor[text]"]=config.introeditor?config.introeditor.text:"",variant["introeditor[format]"]=config.introeditor?config.introeditor.format:"",1===config.instructorchoiceacceptgrades?(variant.instructorchoiceacceptgrades="1",variant["grade[modgrade_point]"]=config.grade_modgrade_point||"100"):variant.instructorchoiceacceptgrades="0",variant))})),showMultipleSummaryAndHideForm(returnData.multiple);var submitAndCourse=document.querySelector("#id_submitbutton2");submitAndCourse.onclick=function(e){e.preventDefault(),submitAndCourse.disabled=!0;var fd=new FormData(document.querySelector("#region-main-box form")),backToCourse=function(){document.querySelector("#id_cancel").click()};variants.reduce((function(promise,variant){Object.entries(variant).forEach((function(entry){return fd.set(entry[0],entry[1])}));var body=new URLSearchParams(fd),doPost=function(){return fetch(document.location.pathname,{method:"post",body:body})};return promise.then(doPost).catch(doPost)}),Promise.resolve()).then(backToCourse).catch(backToCourse)}}else{for(index in ltiFormFields){var field=ltiFormFields[index],value=null;void 0!==returnData[field.name]&&(value=returnData[field.name]),field.setFieldValue(value)}field.setFieldValue(value)}doneCallback&&doneCallback(returnData)},contentItem}));
//# sourceMappingURL=contentitem.min.js.map