diff --git a/lib/amd/build/moodlenet/send_resource.min.js b/lib/amd/build/moodlenet/send_resource.min.js index 964d3e75d94..35129e6200f 100644 --- a/lib/amd/build/moodlenet/send_resource.min.js +++ b/lib/amd/build/moodlenet/send_resource.min.js @@ -6,6 +6,6 @@ define("core/moodlenet/send_resource",["exports","core/config","core/notificatio * @copyright 2023 Huong Nguyen * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later * @since 4.2 - */Object.defineProperty(_exports,"__esModule",{value:!0}),_exports.init=void 0,_config=_interopRequireDefault(_config),_prefetch=_interopRequireDefault(_prefetch),Templates=_interopRequireWildcard(Templates),MoodleNetService=_interopRequireWildcard(MoodleNetService),_send_activity_modal=_interopRequireDefault(_send_activity_modal);let siteSupportUrl,issuerId,courseId,resourceId,shareFormat,type,listenersRegistered=!1;const responseFromMoodleNet=function(status){let resourceUrl=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"";const $modal=undefined.getModal(),modal=$modal[0];modal.querySelector(".modal-header").classList.add("no-border"),undefined.setBody(Templates.render("core/moodlenet/send_activity_modal_done",{success:status,sitesupporturl:siteSupportUrl})),status&&(undefined.setFooter(Templates.render("core/moodlenet/send_activity_modal_footer_view",{resourseurl:resourceUrl})),undefined.showFooter())},handleAuthorization=issuerId=>MoodleNetService.authorizationCheck(issuerId,courseId).then((data=>data.status?((issuerId,resourceId,shareFormat)=>{const modal=(void 0).getModal()[0];let infoPromise;modal.querySelector(".modal-header").classList.remove("no-border"),modal.querySelector(".modal-header").classList.add("no-header-text"),(void 0).setBody(Templates.render("core/moodlenet/send_activity_modal_packaging",{})),(void 0).hideFooter(),"activity"===type?infoPromise=MoodleNetService.sendActivity(issuerId,resourceId,shareFormat):"course"===type&&(infoPromise=MoodleNetService.sendCourse(issuerId,resourceId,shareFormat)),infoPromise.then((async data=>{const status=data.status,resourceUrl=data.resourceurl;return responseFromMoodleNet(status,resourceUrl)})).catch(_notification.exception)})(issuerId,resourceId,shareFormat):(window.moodleNetAuthorize=(error,errorDescription)=>{""===error?handleAuthorization(issuerId):"access_denied"!==error&&(0,_notification.alert)("Authorization error","Error: "+error+"

Error description: "+errorDescription,"Cancel")},window.open(data.loginurl,"moodlenet_auth","location=0,status=0,width=".concat(550,",height=").concat(550,",scrollbars=yes"))))).catch(_notification.exception),registerEventListeners=()=>{document.addEventListener("click",(e=>{const shareAction=e.target.closest('[data-action="sendtomoodlenet"]'),sendAction=e.target.closest('.moodlenet-action-buttons [data-action="share"]');if(shareAction){e.preventDefault(),type=shareAction.getAttribute("data-type");const shareType=shareAction.getAttribute("data-sharetype");Promise.resolve(type).then((type=>{if("activity"===type)return MoodleNetService.getActivityInformation(_config.default.contextInstanceId);if("course"===type)return MoodleNetService.getCourseInformation(_config.default.contextInstanceId);throw new Error("Unknown type ".concat(type))})).then((data=>(async(data,shareType)=>data.status?(siteSupportUrl=data.supportpageurl,issuerId=data.issuerid,_send_activity_modal.default.create({templateContext:{activitytype:data.type,activityname:data.name,sharetype:await(0,_str.getString)("moodlenet:sharetype".concat(shareType),"moodle"),server:data.server}})):(0,_notification.addNotification)({message:data.warnings[0].message,type:"error"}))(data,shareType))).catch(_notification.exception)}sendAction&&(e.preventDefault(),courseId=_config.default.courseId,resourceId=_config.default.contextInstanceId,shareFormat=0,handleAuthorization(issuerId))}))};_exports.init=()=>{listenersRegistered||(_prefetch.default.prefetchTemplates(["core/moodlenet/send_activity_modal_base","core/moodlenet/send_activity_modal_packaging","core/moodlenet/send_activity_modal_done","core/moodlenet/send_activity_modal_footer_view"]),registerEventListeners(),listenersRegistered=!0)}})); + */Object.defineProperty(_exports,"__esModule",{value:!0}),_exports.init=void 0,_config=_interopRequireDefault(_config),_prefetch=_interopRequireDefault(_prefetch),Templates=_interopRequireWildcard(Templates),MoodleNetService=_interopRequireWildcard(MoodleNetService),_send_activity_modal=_interopRequireDefault(_send_activity_modal);let currentModal,siteSupportUrl,issuerId,courseId,resourceId,shareFormat,type,listenersRegistered=!1;const responseFromMoodleNet=function(status){let resourceUrl=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"";const $modal=currentModal.getModal(),modal=$modal[0];modal.querySelector(".modal-header").classList.add("no-border"),currentModal.setBody(Templates.render("core/moodlenet/send_activity_modal_done",{success:status,sitesupporturl:siteSupportUrl})),status&&(currentModal.setFooter(Templates.render("core/moodlenet/send_activity_modal_footer_view",{resourseurl:resourceUrl})),currentModal.showFooter())},handleAuthorization=issuerId=>MoodleNetService.authorizationCheck(issuerId,courseId).then((data=>data.status?((issuerId,resourceId,shareFormat)=>{const modal=currentModal.getModal()[0];let infoPromise;modal.querySelector(".modal-header").classList.remove("no-border"),modal.querySelector(".modal-header").classList.add("no-header-text"),currentModal.setBody(Templates.render("core/moodlenet/send_activity_modal_packaging",{})),currentModal.hideFooter(),"activity"===type?infoPromise=MoodleNetService.sendActivity(issuerId,resourceId,shareFormat):"course"===type&&(infoPromise=MoodleNetService.sendCourse(issuerId,resourceId,shareFormat)),infoPromise.then((async data=>{const status=data.status,resourceUrl=data.resourceurl;return responseFromMoodleNet(status,resourceUrl)})).catch(_notification.exception)})(issuerId,resourceId,shareFormat):(window.moodleNetAuthorize=(error,errorDescription)=>{""===error?handleAuthorization(issuerId):"access_denied"!==error&&(0,_notification.alert)("Authorization error","Error: "+error+"

Error description: "+errorDescription,"Cancel")},window.open(data.loginurl,"moodlenet_auth","location=0,status=0,width=".concat(550,",height=").concat(550,",scrollbars=yes"))))).catch(_notification.exception),registerEventListeners=()=>{document.addEventListener("click",(e=>{const shareAction=e.target.closest('[data-action="sendtomoodlenet"]'),sendAction=e.target.closest('.moodlenet-action-buttons [data-action="share"]');if(shareAction){e.preventDefault(),type=shareAction.getAttribute("data-type");const shareType=shareAction.getAttribute("data-sharetype");Promise.resolve(type).then((type=>{if("activity"===type)return MoodleNetService.getActivityInformation(_config.default.contextInstanceId);if("course"===type)return MoodleNetService.getCourseInformation(_config.default.contextInstanceId);throw new Error("Unknown type ".concat(type))})).then((data=>(async(data,shareType)=>data.status?(siteSupportUrl=data.supportpageurl,issuerId=data.issuerid,_send_activity_modal.default.create({templateContext:{activitytype:data.type,activityname:data.name,sharetype:await(0,_str.getString)("moodlenet:sharetype".concat(shareType),"moodle"),server:data.server}})):(0,_notification.addNotification)({message:data.warnings[0].message,type:"error"}))(data,shareType))).then((modal=>(currentModal=modal,currentModal))).catch(_notification.exception)}sendAction&&(e.preventDefault(),courseId=_config.default.courseId,resourceId=_config.default.contextInstanceId,shareFormat=0,handleAuthorization(issuerId))}))};_exports.init=()=>{listenersRegistered||(_prefetch.default.prefetchTemplates(["core/moodlenet/send_activity_modal_base","core/moodlenet/send_activity_modal_packaging","core/moodlenet/send_activity_modal_done","core/moodlenet/send_activity_modal_footer_view"]),registerEventListeners(),listenersRegistered=!0)}})); //# sourceMappingURL=send_resource.min.js.map \ No newline at end of file diff --git a/lib/amd/build/moodlenet/send_resource.min.js.map b/lib/amd/build/moodlenet/send_resource.min.js.map index 6d419666017..ddf0ffda330 100644 --- a/lib/amd/build/moodlenet/send_resource.min.js.map +++ b/lib/amd/build/moodlenet/send_resource.min.js.map @@ -1 +1 @@ -{"version":3,"file":"send_resource.min.js","sources":["../../src/moodlenet/send_resource.js"],"sourcesContent":["// This file is part of Moodle - http://moodle.org/\n//\n// Moodle is free software: you can redistribute it and/or modify\n// it under the terms of the GNU General Public License as published by\n// the Free Software Foundation, either version 3 of the License, or\n// (at your option) any later version.\n//\n// Moodle is distributed in the hope that it will be useful,\n// but WITHOUT ANY WARRANTY; without even the implied warranty of\n// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n// GNU General Public License for more details.\n//\n// You should have received a copy of the GNU General Public License\n// along with Moodle. If not, see .\n\n/**\n * A module to handle Share operations of the MoodleNet.\n *\n * @module core/moodlenet/send_resource\n * @copyright 2023 Huong Nguyen \n * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later\n * @since 4.2\n */\n\nimport Config from 'core/config';\nimport {alert as displayAlert, addNotification, exception as displayException} from 'core/notification';\nimport {getString} from 'core/str';\nimport Prefetch from \"core/prefetch\";\nimport * as Templates from 'core/templates';\nimport * as MoodleNetService from 'core/moodlenet/service';\nimport SendActivityModal from 'core/moodlenet/send_activity_modal';\n\nconst TYPE_ACTIVITY = \"activity\";\nconst TYPE_COURSE = \"course\";\n\nlet listenersRegistered = false;\nlet currentModal;\nlet siteSupportUrl;\nlet issuerId;\nlet courseId;\nlet resourceId;\nlet shareFormat;\nlet type;\n\n/**\n * Handle send to MoodleNet.\n *\n * @param {int} issuerId The OAuth 2 issuer ID.\n * @param {int} resourceId The resource ID, it can be a course or an activity.\n * @param {int} shareFormat The share format.\n */\nconst sendToMoodleNet = (issuerId, resourceId, shareFormat) => {\n const $modal = currentModal.getModal();\n const modal = $modal[0];\n modal.querySelector('.modal-header').classList.remove('no-border');\n modal.querySelector('.modal-header').classList.add('no-header-text');\n\n currentModal.setBody(Templates.render('core/moodlenet/send_activity_modal_packaging', {}));\n currentModal.hideFooter();\n\n let infoPromise;\n if (type === TYPE_ACTIVITY) {\n infoPromise = MoodleNetService.sendActivity(issuerId, resourceId, shareFormat);\n } else if (type === TYPE_COURSE) {\n infoPromise = MoodleNetService.sendCourse(issuerId, resourceId, shareFormat);\n }\n infoPromise.then(async(data) => {\n const status = data.status;\n const resourceUrl = data.resourceurl;\n return responseFromMoodleNet(status, resourceUrl);\n }).catch(displayException);\n};\n\n/**\n * Handle response from MoodleNet.\n *\n * @param {boolean} status Response status. True if successful.\n * @param {String} resourceUrl Resource URL.\n */\nconst responseFromMoodleNet = (status, resourceUrl = '') => {\n const $modal = currentModal.getModal();\n const modal = $modal[0];\n modal.querySelector('.modal-header').classList.add('no-border');\n currentModal.setBody(Templates.render('core/moodlenet/send_activity_modal_done', {\n success: status,\n sitesupporturl: siteSupportUrl,\n }));\n\n if (status) {\n currentModal.setFooter(Templates.render('core/moodlenet/send_activity_modal_footer_view', {\n resourseurl: resourceUrl,\n }));\n currentModal.showFooter();\n }\n};\n\n/**\n * Handle authorization with MoodleNet server.\n *\n * @param {Number} issuerId The OAuth 2 issuer ID.\n * @return {promise}\n */\nconst handleAuthorization = (issuerId) => {\n const windowsizewidth = 550;\n const windowsizeheight = 550;\n\n // Check if the user is authorized with MoodleNet or not.\n return MoodleNetService.authorizationCheck(issuerId, courseId).then((data) => {\n if (!data.status) {\n // Not yet authorized.\n // Declare moodleNetAuthorize variable, so we can call it later in the callback.\n window.moodleNetAuthorize = (error, errorDescription) => {\n // This will be called by the callback after the authorization is successful.\n if (error === '') {\n handleAuthorization(issuerId);\n } else if (error !== 'access_denied') {\n displayAlert(\n 'Authorization error',\n 'Error: ' + error + '

Error description: ' + errorDescription,\n 'Cancel'\n );\n }\n };\n // Open the login url of the OAuth 2 issuer for user to login into MoodleNet and authorize.\n return window.open(data.loginurl, 'moodlenet_auth',\n `location=0,status=0,width=${windowsizewidth},height=${windowsizeheight},scrollbars=yes`);\n } else {\n // Already authorized.\n return sendToMoodleNet(issuerId, resourceId, shareFormat);\n }\n }).catch(displayException);\n};\n\n/**\n * Render the modal to send resource to MoodleNet.\n *\n * @param {object} data The data of the resource to be shared.\n * @param {string} shareType The type of the resource to be shared.\n */\nconst renderModal = async(data, shareType) => {\n if (data.status) {\n siteSupportUrl = data.supportpageurl;\n issuerId = data.issuerid;\n return SendActivityModal.create({\n templateContext: {\n activitytype: data.type,\n activityname: data.name,\n sharetype: await getString(`moodlenet:sharetype${shareType}`, 'moodle'),\n server: data.server,\n }\n });\n } else {\n return addNotification({\n message: data.warnings[0].message,\n type: 'error'\n });\n }\n};\n\n/**\n * Register events.\n */\nconst registerEventListeners = () => {\n document.addEventListener('click', (e) => {\n const shareAction = e.target.closest('[data-action=\"sendtomoodlenet\"]');\n const sendAction = e.target.closest('.moodlenet-action-buttons [data-action=\"share\"]');\n if (shareAction) {\n e.preventDefault();\n type = shareAction.getAttribute('data-type');\n const shareType = shareAction.getAttribute('data-sharetype');\n Promise.resolve(type)\n .then((type) => {\n if (type === TYPE_ACTIVITY) {\n return MoodleNetService.getActivityInformation(Config.contextInstanceId);\n } else if (type === TYPE_COURSE) {\n return MoodleNetService.getCourseInformation(Config.contextInstanceId);\n }\n throw new Error(`Unknown type ${type}`);\n })\n .then((data) => renderModal(data, shareType))\n .catch(displayException);\n }\n\n if (sendAction) {\n e.preventDefault();\n courseId = Config.courseId;\n resourceId = Config.contextInstanceId;\n shareFormat = 0;\n handleAuthorization(issuerId);\n }\n });\n};\n\n\n/**\n * Initialize.\n */\nexport const init = () => {\n if (!listenersRegistered) {\n Prefetch.prefetchTemplates([\n 'core/moodlenet/send_activity_modal_base',\n 'core/moodlenet/send_activity_modal_packaging',\n 'core/moodlenet/send_activity_modal_done',\n 'core/moodlenet/send_activity_modal_footer_view',\n ]);\n registerEventListeners();\n listenersRegistered = true;\n }\n};\n"],"names":["siteSupportUrl","issuerId","courseId","resourceId","shareFormat","type","listenersRegistered","responseFromMoodleNet","status","resourceUrl","$modal","currentModal","getModal","modal","querySelector","classList","add","setBody","Templates","render","success","sitesupporturl","setFooter","resourseurl","showFooter","handleAuthorization","MoodleNetService","authorizationCheck","then","data","infoPromise","remove","hideFooter","sendActivity","sendCourse","async","resourceurl","catch","displayException","sendToMoodleNet","window","moodleNetAuthorize","error","errorDescription","open","loginurl","registerEventListeners","document","addEventListener","e","shareAction","target","closest","sendAction","preventDefault","getAttribute","shareType","Promise","resolve","getActivityInformation","Config","contextInstanceId","getCourseInformation","Error","supportpageurl","issuerid","SendActivityModal","create","templateContext","activitytype","activityname","name","sharetype","server","message","warnings","renderModal","prefetchTemplates"],"mappings":";;;;;;;;oVAqCIA,eACAC,SACAC,SACAC,WACAC,YACAC,KAPAC,qBAAsB,QA4CpBC,sBAAwB,SAACC,YAAQC,mEAAc,SAC3CC,OA5CNC,UA4C4BC,WACtBC,MAAQH,OAAO,GACrBG,MAAMC,cAAc,iBAAiBC,UAAUC,IAAI,aA9CnDL,UA+CaM,QAAQC,UAAUC,OAAO,0CAA2C,CAC7EC,QAASZ,OACTa,eAAg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iBoC,qBAAqBF,gBAAOC,yBAElD,IAAIE,6BAAsB1D,UAEnCuB,MAAMC,MAxCHM,OAAMN,KAAM2B,YACxB3B,KAAKrB,QACLR,eAAiB6B,KAAKmC,eACtB/D,SAAW4B,KAAKoC,SACTC,6BAAkBC,OAAO,CAC5BC,gBAAiB,CACbC,aAAcxC,KAAKxB,KACnBiE,aAAczC,KAAK0C,KACnBC,gBAAiB,+CAAgChB,WAAa,UAC9DiB,OAAQ5C,KAAK4C,YAId,iCAAgB,CACnBC,QAAS7C,KAAK8C,SAAS,GAAGD,QAC1BrE,KAAM,UAyBcuE,CAAY/C,KAAM2B,aACjCnB,MAAMC,yBAGXe,aACAJ,EAAEK,iBACFpD,SAAW0D,gBAAO1D,SAClBC,WAAayD,gBAAOC,kBACpBzD,YAAc,EACdqB,oBAAoBxB,6BASZ,KACXK,wCACQuE,kBAAkB,CACvB,0CACA,+CACA,0CACA,mDAEJ/B,yBACAxC,qBAAsB"} \ No newline at end of file +{"version":3,"file":"send_resource.min.js","sources":["../../src/moodlenet/send_resource.js"],"sourcesContent":["// This file is part of Moodle - http://moodle.org/\n//\n// Moodle is free software: you can redistribute it and/or modify\n// it under the terms of the GNU General Public License as published by\n// the Free Software Foundation, either version 3 of the License, or\n// (at your option) any later version.\n//\n// Moodle is distributed in the hope that it will be useful,\n// but WITHOUT ANY WARRANTY; without even the implied warranty of\n// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n// GNU General Public License for more details.\n//\n// You should have received a copy of the GNU General Public License\n// along with Moodle. If not, see .\n\n/**\n * A module to handle Share operations of the MoodleNet.\n *\n * @module core/moodlenet/send_resource\n * @copyright 2023 Huong Nguyen \n * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later\n * @since 4.2\n */\n\nimport Config from 'core/config';\nimport {alert as displayAlert, addNotification, exception as displayException} from 'core/notification';\nimport {getString} from 'core/str';\nimport Prefetch from \"core/prefetch\";\nimport * as Templates from 'core/templates';\nimport * as MoodleNetService from 'core/moodlenet/service';\nimport SendActivityModal from 'core/moodlenet/send_activity_modal';\n\nconst TYPE_ACTIVITY = \"activity\";\nconst TYPE_COURSE = \"course\";\n\nlet listenersRegistered = false;\nlet currentModal;\nlet siteSupportUrl;\nlet issuerId;\nlet courseId;\nlet resourceId;\nlet shareFormat;\nlet type;\n\n/**\n * Handle send to MoodleNet.\n *\n * @param {int} issuerId The OAuth 2 issuer ID.\n * @param {int} resourceId The resource ID, it can be a course or an activity.\n * @param {int} shareFormat The share format.\n */\nconst sendToMoodleNet = (issuerId, resourceId, shareFormat) => {\n const $modal = currentModal.getModal();\n const modal = $modal[0];\n modal.querySelector('.modal-header').classList.remove('no-border');\n modal.querySelector('.modal-header').classList.add('no-header-text');\n\n currentModal.setBody(Templates.render('core/moodlenet/send_activity_modal_packaging', {}));\n currentModal.hideFooter();\n\n let infoPromise;\n if (type === TYPE_ACTIVITY) {\n infoPromise = MoodleNetService.sendActivity(issuerId, resourceId, shareFormat);\n } else if (type === TYPE_COURSE) {\n infoPromise = MoodleNetService.sendCourse(issuerId, resourceId, shareFormat);\n }\n infoPromise.then(async(data) => {\n const status = data.status;\n const resourceUrl = data.resourceurl;\n return responseFromMoodleNet(status, resourceUrl);\n }).catch(displayException);\n};\n\n/**\n * Handle response from MoodleNet.\n *\n * @param {boolean} status Response status. True if successful.\n * @param {String} resourceUrl Resource URL.\n */\nconst responseFromMoodleNet = (status, resourceUrl = '') => {\n const $modal = currentModal.getModal();\n const modal = $modal[0];\n modal.querySelector('.modal-header').classList.add('no-border');\n currentModal.setBody(Templates.render('core/moodlenet/send_activity_modal_done', {\n success: status,\n sitesupporturl: siteSupportUrl,\n }));\n\n if (status) {\n currentModal.setFooter(Templates.render('core/moodlenet/send_activity_modal_footer_view', {\n resourseurl: resourceUrl,\n }));\n currentModal.showFooter();\n }\n};\n\n/**\n * Handle authorization with MoodleNet server.\n *\n * @param {Number} issuerId The OAuth 2 issuer ID.\n * @return {promise}\n */\nconst handleAuthorization = (issuerId) => {\n const windowsizewidth = 550;\n const windowsizeheight = 550;\n\n // Check if the user is authorized with MoodleNet or not.\n return MoodleNetService.authorizationCheck(issuerId, courseId).then((data) => {\n if (!data.status) {\n // Not yet authorized.\n // Declare moodleNetAuthorize variable, so we can call it later in the callback.\n window.moodleNetAuthorize = (error, errorDescription) => {\n // This will be called by the callback after the authorization is successful.\n if (error === '') {\n handleAuthorization(issuerId);\n } else if (error !== 'access_denied') {\n displayAlert(\n 'Authorization error',\n 'Error: ' + error + '

Error description: ' + errorDescription,\n 'Cancel'\n );\n }\n };\n // Open the login url of the OAuth 2 issuer for user to login into MoodleNet and authorize.\n return window.open(data.loginurl, 'moodlenet_auth',\n `location=0,status=0,width=${windowsizewidth},height=${windowsizeheight},scrollbars=yes`);\n } else {\n // Already authorized.\n return sendToMoodleNet(issuerId, resourceId, shareFormat);\n }\n }).catch(displayException);\n};\n\n/**\n * Render the modal to send resource to MoodleNet.\n *\n * @param {object} data The data of the resource to be shared.\n * @param {string} shareType The type of the resource to be shared.\n */\nconst renderModal = async(data, shareType) => {\n if (data.status) {\n siteSupportUrl = data.supportpageurl;\n issuerId = data.issuerid;\n return SendActivityModal.create({\n templateContext: {\n activitytype: data.type,\n activityname: data.name,\n sharetype: await getString(`moodlenet:sharetype${shareType}`, 'moodle'),\n server: data.server,\n }\n });\n } else {\n return addNotification({\n message: data.warnings[0].message,\n type: 'error'\n });\n }\n};\n\n/**\n * Register events.\n */\nconst registerEventListeners = () => {\n document.addEventListener('click', (e) => {\n const shareAction = e.target.closest('[data-action=\"sendtomoodlenet\"]');\n const sendAction = e.target.closest('.moodlenet-action-buttons [data-action=\"share\"]');\n if (shareAction) {\n e.preventDefault();\n type = shareAction.getAttribute('data-type');\n const shareType = shareAction.getAttribute('data-sharetype');\n Promise.resolve(type)\n .then((type) => {\n if (type === TYPE_ACTIVITY) {\n return MoodleNetService.getActivityInformation(Config.contextInstanceId);\n } else if (type === TYPE_COURSE) {\n return MoodleNetService.getCourseInformation(Config.contextInstanceId);\n }\n throw new Error(`Unknown type ${type}`);\n })\n .then((data) => {\n return renderModal(data, shareType);\n })\n .then((modal) => {\n currentModal = modal;\n return currentModal;\n })\n .catch(displayException);\n }\n\n if (sendAction) {\n e.preventDefault();\n courseId = Config.courseId;\n resourceId = Config.contextInstanceId;\n shareFormat = 0;\n handleAuthorization(issuerId);\n }\n });\n};\n\n\n/**\n * Initialize.\n */\nexport const init = () => {\n if (!listenersRegistered) {\n Prefetch.prefetchTemplates([\n 'core/moodlenet/send_activity_modal_base',\n 'core/moodlenet/send_activity_modal_packaging',\n 'core/moodlenet/send_activity_modal_done',\n 'core/moodlenet/send_activity_modal_footer_view',\n ]);\n registerEventListeners();\n listenersRegistered = true;\n }\n};\n"],"names":["currentModal","siteSupportUrl","issuerId","courseId","resourceId","shareFormat","type","listenersRegistered","responseFromMoodleNet","status","resourceUrl","$modal","getModal","modal","querySelector","classList","add","setBody","Templates","render","success","sitesupporturl","setFooter","resourseurl","showFooter","handleAuthorization","MoodleNetService","authorizationCheck","then","data","infoPromise","remove","hideFooter","sendActivity","sendCourse","async","resourceurl","catch","displayException","sendToMoodleNet","window","moodleNetAuthorize","error","errorDescription","open","loginurl","registerEventListeners","document","addEventListener","e","shareAction","target","closest","sendAction","preventDefault","getAttribute","shareType","Promise","resolve","getActivityInformation","Config","contextInstanceId","getCourseInformation","Error","supportpageurl","issuerid","SendActivityModal","create","templateContext","activitytype","activityname","name","sharetype","server","message","warnings","renderModal","prefetchTemplates"],"mappings":";;;;;;;;oVAoCIA,aACAC,eACAC,SACAC,SACAC,WACAC,YACAC,KAPAC,qBAAsB,QA4CpBC,sBAAwB,SAACC,YAAQC,mEAAc,SAC3CC,OAASX,aAAaY,WACtBC,MAAQF,OAAO,GACrBE,MAAMC,cAAc,iBAAiBC,UAAUC,IAAI,aACnDhB,aAAaiB,QAAQC,UAAUC,OAAO,0CAA2C,CAC7EC,QAASX,OACTY,eAAgBpB,kBAGhBQ,SACAT,aAAasB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6BAAsBzD,UAEnCsB,MAAMC,MAxCHM,OAAMN,KAAM2B,YACxB3B,KAAKpB,QACLR,eAAiB4B,KAAKmC,eACtB9D,SAAW2B,KAAKoC,SACTC,6BAAkBC,OAAO,CAC5BC,gBAAiB,CACbC,aAAcxC,KAAKvB,KACnBgE,aAAczC,KAAK0C,KACnBC,gBAAiB,+CAAgChB,WAAa,UAC9DiB,OAAQ5C,KAAK4C,YAId,iCAAgB,CACnBC,QAAS7C,KAAK8C,SAAS,GAAGD,QAC1BpE,KAAM,UA0BSsE,CAAY/C,KAAM2B,aAE5B5B,MAAMf,QACHb,aAAea,MACRb,gBAEVqC,MAAMC,yBAGXe,aACAJ,EAAEK,iBACFnD,SAAWyD,gBAAOzD,SAClBC,WAAawD,gBAAOC,kBACpBxD,YAAc,EACdoB,oBAAoBvB,6BASZ,KACXK,wCACQsE,kBAAkB,CACvB,0CACA,+CACA,0CACA,mDAEJ/B,yBACAvC,qBAAsB"} \ No newline at end of file diff --git a/lib/amd/src/moodlenet/send_resource.js b/lib/amd/src/moodlenet/send_resource.js index aa43e60b9f1..fff212152e9 100644 --- a/lib/amd/src/moodlenet/send_resource.js +++ b/lib/amd/src/moodlenet/send_resource.js @@ -177,7 +177,13 @@ const registerEventListeners = () => { } throw new Error(`Unknown type ${type}`); }) - .then((data) => renderModal(data, shareType)) + .then((data) => { + return renderModal(data, shareType); + }) + .then((modal) => { + currentModal = modal; + return currentModal; + }) .catch(displayException); }