From 847e1098dadfabdbafb82197747bb1ce1790a0ba Mon Sep 17 00:00:00 2001 From: Andrew Nicols Date: Thu, 6 Jun 2024 00:10:02 +0800 Subject: [PATCH] MDL-82045 course: Destroy copy course modal instead of hiding it --- course/amd/build/copy_modal.min.js | 2 +- course/amd/build/copy_modal.min.js.map | 2 +- course/amd/src/copy_modal.js | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/course/amd/build/copy_modal.min.js b/course/amd/build/copy_modal.min.js index 9e5e5cb8147..2572eb66f7d 100644 --- a/course/amd/build/copy_modal.min.js +++ b/course/amd/build/copy_modal.min.js @@ -8,6 +8,6 @@ define("core_course/copy_modal",["exports","core/str","core/modal","core/ajax"," * @author Matt Porritt * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later * @since 3.9 - */Object.defineProperty(_exports,"__esModule",{value:!0}),_exports.default=void 0,_modal=_interopRequireDefault(_modal),ajax=_interopRequireWildcard(ajax),Fragment=_interopRequireWildcard(Fragment),_notification=_interopRequireDefault(_notification),Config=_interopRequireWildcard(Config);class CopyModal{static init(context){return new CopyModal(context)}constructor(context){this.contextid=context,this.registerEventListeners()}registerEventListeners(){document.addEventListener("click",(e=>{const copyAction=e.target.closest(".action-copy");if(!copyAction)return;e.preventDefault();const url=new URL(copyAction.href),params=new URLSearchParams(url.search);this.fetchCourseData(params.get("id")).then((_ref=>{let[course]=_ref;return this.createModal(course)})).catch((error=>_notification.default.exception(error)))}))}fetchCourseData(courseid){return ajax.call([{methodname:"core_course_get_courses",args:{options:{ids:[courseid]}}}])[0]}submitBackupRequest(jsonformdata){return ajax.call([{methodname:"core_backup_submit_copy_form",args:{jsonformdata:jsonformdata}}])[0]}createModal(course){let formdata=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};const params={jsonformdata:JSON.stringify(formdata),courseid:course.id};return _modal.default.create({title:(0,_str.get_string)("copycoursetitle","backup",course.shortname),body:Fragment.loadFragment("course","new_base_form",this.contextid,params),large:!0,show:!0,removeOnClose:!0}).then((modal=>(modal.getRoot().on("click","#id_submitreturn",(e=>{this.processModalForm(course,modal,e)})),modal.getRoot().on("click","#id_cancel",(e=>{e.preventDefault(),modal.hide()})),modal.getRoot().on("click","#id_submitdisplay",(e=>{e.formredirect=!0,this.processModalForm(course,modal,e)})),modal)))}processModalForm(course,modal,e){e.preventDefault();const copyform=modal.getRoot().find("form").serialize(),formjson=JSON.stringify(copyform),invalid=modal.getRoot()[0].querySelectorAll('[aria-invalid="true"], .error');invalid.length?invalid[0].focus():(modal.hide(),this.submitBackupRequest(formjson).then((()=>{if(1==e.formredirect){const redirect="".concat(Config.wwwroot,"/backup/copyprogress.php?id=").concat(course.id);window.location.assign(redirect)}})).catch((()=>{this.createModal(course,copyform)})))}}return _exports.default=CopyModal,_exports.default})); + */Object.defineProperty(_exports,"__esModule",{value:!0}),_exports.default=void 0,_modal=_interopRequireDefault(_modal),ajax=_interopRequireWildcard(ajax),Fragment=_interopRequireWildcard(Fragment),_notification=_interopRequireDefault(_notification),Config=_interopRequireWildcard(Config);class CopyModal{static init(context){return new CopyModal(context)}constructor(context){this.contextid=context,this.registerEventListeners()}registerEventListeners(){document.addEventListener("click",(e=>{const copyAction=e.target.closest(".action-copy");if(!copyAction)return;e.preventDefault();const url=new URL(copyAction.href),params=new URLSearchParams(url.search);this.fetchCourseData(params.get("id")).then((_ref=>{let[course]=_ref;return this.createModal(course)})).catch((error=>_notification.default.exception(error)))}))}fetchCourseData(courseid){return ajax.call([{methodname:"core_course_get_courses",args:{options:{ids:[courseid]}}}])[0]}submitBackupRequest(jsonformdata){return ajax.call([{methodname:"core_backup_submit_copy_form",args:{jsonformdata:jsonformdata}}])[0]}createModal(course){let formdata=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};const params={jsonformdata:JSON.stringify(formdata),courseid:course.id};return _modal.default.create({title:(0,_str.get_string)("copycoursetitle","backup",course.shortname),body:Fragment.loadFragment("course","new_base_form",this.contextid,params),large:!0,show:!0,removeOnClose:!0}).then((modal=>(modal.getRoot().on("click","#id_submitreturn",(e=>{this.processModalForm(course,modal,e)})),modal.getRoot().on("click","#id_cancel",(e=>{e.preventDefault(),modal.destroy()})),modal.getRoot().on("click","#id_submitdisplay",(e=>{e.formredirect=!0,this.processModalForm(course,modal,e)})),modal)))}processModalForm(course,modal,e){e.preventDefault();const copyform=modal.getRoot().find("form").serialize(),formjson=JSON.stringify(copyform),invalid=modal.getRoot()[0].querySelectorAll('[aria-invalid="true"], .error');invalid.length?invalid[0].focus():(modal.destroy(),this.submitBackupRequest(formjson).then((()=>{if(1==e.formredirect){const redirect="".concat(Config.wwwroot,"/backup/copyprogress.php?id=").concat(course.id);window.location.assign(redirect)}})).catch((()=>{this.createModal(course,copyform)})))}}return _exports.default=CopyModal,_exports.default})); //# sourceMappingURL=copy_modal.min.js.map \ No newline at end of file diff --git a/course/amd/build/copy_modal.min.js.map b/course/amd/build/copy_modal.min.js.map index 079fc925a3c..67e6a32b851 100644 --- a/course/amd/build/copy_modal.min.js.map +++ b/course/amd/build/copy_modal.min.js.map @@ -1 +1 @@ -{"version":3,"file":"copy_modal.min.js","sources":["../src/copy_modal.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 * This module provides the course copy modal from the course and\n * category management screen.\n *\n * @module core_course/copy_modal\n * @copyright 2020 onward The Moodle Users Association \n * @author Matt Porritt \n * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later\n * @since 3.9\n */\n\nimport {get_string as getString} from 'core/str';\nimport Modal from 'core/modal';\nimport * as ajax from 'core/ajax';\nimport * as Fragment from 'core/fragment';\nimport Notification from 'core/notification';\nimport * as Config from 'core/config';\n\nexport default class CopyModal {\n static init(context) {\n return new CopyModal(context);\n }\n\n constructor(context) {\n this.contextid = context;\n\n this.registerEventListeners();\n }\n\n registerEventListeners() {\n document.addEventListener('click', (e) => {\n const copyAction = e.target.closest('.action-copy');\n if (!copyAction) {\n return;\n }\n e.preventDefault(); // Stop. Hammer time.\n\n const url = new URL(copyAction.href);\n const params = new URLSearchParams(url.search);\n\n this.fetchCourseData(params.get('id'))\n .then(([course]) => this.createModal(course))\n .catch((error) => Notification.exception(error));\n });\n }\n\n fetchCourseData(courseid) {\n return ajax.call([{\n methodname: 'core_course_get_courses',\n args: {\n options: {\n ids: [courseid],\n },\n },\n }])[0];\n }\n\n submitBackupRequest(jsonformdata) {\n return ajax.call([{\n methodname: 'core_backup_submit_copy_form',\n args: {\n jsonformdata,\n },\n }])[0];\n }\n\n createModal(\n course,\n formdata = {},\n ) {\n const params = {\n jsonformdata: JSON.stringify(formdata),\n courseid: course.id,\n };\n\n // Create the Modal.\n return Modal.create({\n title: getString('copycoursetitle', 'backup', course.shortname),\n body: Fragment.loadFragment('course', 'new_base_form', this.contextid, params),\n large: true,\n show: true,\n removeOnClose: true,\n })\n .then((modal) => {\n // Explicitly handle form click events.\n modal.getRoot().on('click', '#id_submitreturn', (e) => {\n this.processModalForm(course, modal, e);\n });\n modal.getRoot().on('click', '#id_cancel', (e) => {\n e.preventDefault();\n modal.hide();\n });\n modal.getRoot().on('click', '#id_submitdisplay', (e) => {\n e.formredirect = true;\n this.processModalForm(course, modal, e);\n\n });\n\n return modal;\n });\n }\n\n processModalForm(course, modal, e) {\n e.preventDefault(); // Stop modal from closing.\n\n // Form data.\n const copyform = modal.getRoot().find('form').serialize();\n const formjson = JSON.stringify(copyform);\n\n // Handle invalid form fields for better UX.\n const invalid = modal.getRoot()[0].querySelectorAll('[aria-invalid=\"true\"], .error');\n if (invalid.length) {\n invalid[0].focus();\n return;\n }\n\n modal.hide();\n\n // Submit form via ajax.\n this.submitBackupRequest(formjson)\n .then(() => {\n if (e.formredirect == true) {\n // We are redirecting to copy progress display.\n const redirect = `${Config.wwwroot}/backup/copyprogress.php?id=${course.id}`;\n window.location.assign(redirect);\n }\n\n return;\n })\n .catch(() => {\n // Form submission failed server side, redisplay with errors.\n this.createModal(course, copyform);\n });\n }\n}\n"],"names":["CopyModal","context","constructor","contextid","registerEventListeners","document","addEventListener","e","copyAction","target","closest","preventDefault","url","URL","href","params","URLSearchParams","search","fetchCourseData","get","then","_ref","course","this","createModal","catch","error","Notification","exception","courseid","ajax","call","methodname","args","options","ids","submitBackupRequest","jsonformdata","formdata","JSON","stringify","id","Modal","create","title","shortname","body","Fragment","loadFragment","large","show","removeOnClose","modal","getRoot","on","processModalForm","hide","formredirect","copyform","find","serialize","formjson","invalid","querySelectorAll","length","focus","redirect","Config","wwwroot","window","location","assign"],"mappings":";;;;;;;;;;0SAiCqBA,sBACLC,gBACD,IAAID,UAAUC,SAGzBC,YAAYD,cACHE,UAAYF,aAEZG,yBAGTA,yBACIC,SAASC,iBAAiB,SAAUC,UAC1BC,WAAaD,EAAEE,OAAOC,QAAQ,oBAC/BF,kBAGLD,EAAEI,uBAEIC,IAAM,IAAIC,IAAIL,WAAWM,MACzBC,OAAS,IAAIC,gBAAgBJ,IAAIK,aAElCC,gBAAgBH,OAAOI,IAAI,OAC/BC,MAAKC,WAAEC,oBAAYC,KAAKC,YAAYF,WACpCG,OAAOC,OAAUC,sBAAaC,UAAUF,YAIjDR,gBAAgBW,iBACLC,KAAKC,KAAK,CAAC,CACdC,WAAY,0BACZC,KAAM,CACFC,QAAS,CACLC,IAAK,CAACN,eAGd,GAGRO,oBAAoBC,qBACTP,KAAKC,KAAK,CAAC,CACdC,WAAY,+BACZC,KAAM,CACFI,aAAAA,iBAEJ,GAGRb,YACIF,YACAgB,gEAAW,SAELvB,OAAS,CACXsB,aAAcE,KAAKC,UAAUF,UAC7BT,SAAUP,OAAOmB,WAIdC,eAAMC,OAAO,CAChBC,OAAO,mBAAU,kBAAmB,SAAUtB,OAAOuB,WACrDC,KAAMC,SAASC,aAAa,SAAU,gBAAiBzB,KAAKpB,UAAWY,QACvEkC,OAAO,EACPC,MAAM,EACNC,eAAe,IAElB/B,MAAMgC,QAEHA,MAAMC,UAAUC,GAAG,QAAS,oBAAqB/C,SACxCgD,iBAAiBjC,OAAQ8B,MAAO7C,MAEzC6C,MAAMC,UAAUC,GAAG,QAAS,cAAe/C,IACvCA,EAAEI,iBACFyC,MAAMI,UAEVJ,MAAMC,UAAUC,GAAG,QAAS,qBAAsB/C,IAC9CA,EAAEkD,cAAe,OACZF,iBAAiBjC,OAAQ8B,MAAO7C,MAIlC6C,SAIfG,iBAAiBjC,OAAQ8B,MAAO7C,GAC5BA,EAAEI,uBAGI+C,SAAWN,MAAMC,UAAUM,KAAK,QAAQC,YACxCC,SAAWtB,KAAKC,UAAUkB,UAG1BI,QAAUV,MAAMC,UAAU,GAAGU,iBAAiB,iCAChDD,QAAQE,OACRF,QAAQ,GAAGG,SAIfb,MAAMI,YAGDpB,oBAAoByB,UACxBzC,MAAK,QACoB,GAAlBb,EAAEkD,aAAsB,OAElBS,mBAAcC,OAAOC,+CAAsC9C,OAAOmB,IACxE4B,OAAOC,SAASC,OAAOL,cAK9BzC,OAAM,UAEED,YAAYF,OAAQoC"} \ No newline at end of file +{"version":3,"file":"copy_modal.min.js","sources":["../src/copy_modal.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 * This module provides the course copy modal from the course and\n * category management screen.\n *\n * @module core_course/copy_modal\n * @copyright 2020 onward The Moodle Users Association \n * @author Matt Porritt \n * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later\n * @since 3.9\n */\n\nimport {get_string as getString} from 'core/str';\nimport Modal from 'core/modal';\nimport * as ajax from 'core/ajax';\nimport * as Fragment from 'core/fragment';\nimport Notification from 'core/notification';\nimport * as Config from 'core/config';\n\nexport default class CopyModal {\n static init(context) {\n return new CopyModal(context);\n }\n\n constructor(context) {\n this.contextid = context;\n\n this.registerEventListeners();\n }\n\n registerEventListeners() {\n document.addEventListener('click', (e) => {\n const copyAction = e.target.closest('.action-copy');\n if (!copyAction) {\n return;\n }\n e.preventDefault(); // Stop. Hammer time.\n\n const url = new URL(copyAction.href);\n const params = new URLSearchParams(url.search);\n\n this.fetchCourseData(params.get('id'))\n .then(([course]) => this.createModal(course))\n .catch((error) => Notification.exception(error));\n });\n }\n\n fetchCourseData(courseid) {\n return ajax.call([{\n methodname: 'core_course_get_courses',\n args: {\n options: {\n ids: [courseid],\n },\n },\n }])[0];\n }\n\n submitBackupRequest(jsonformdata) {\n return ajax.call([{\n methodname: 'core_backup_submit_copy_form',\n args: {\n jsonformdata,\n },\n }])[0];\n }\n\n createModal(\n course,\n formdata = {},\n ) {\n const params = {\n jsonformdata: JSON.stringify(formdata),\n courseid: course.id,\n };\n\n // Create the Modal.\n return Modal.create({\n title: getString('copycoursetitle', 'backup', course.shortname),\n body: Fragment.loadFragment('course', 'new_base_form', this.contextid, params),\n large: true,\n show: true,\n removeOnClose: true,\n })\n .then((modal) => {\n // Explicitly handle form click events.\n modal.getRoot().on('click', '#id_submitreturn', (e) => {\n this.processModalForm(course, modal, e);\n });\n modal.getRoot().on('click', '#id_cancel', (e) => {\n e.preventDefault();\n modal.destroy();\n });\n modal.getRoot().on('click', '#id_submitdisplay', (e) => {\n e.formredirect = true;\n this.processModalForm(course, modal, e);\n\n });\n\n return modal;\n });\n }\n\n processModalForm(course, modal, e) {\n e.preventDefault(); // Stop modal from closing.\n\n // Form data.\n const copyform = modal.getRoot().find('form').serialize();\n const formjson = JSON.stringify(copyform);\n\n // Handle invalid form fields for better UX.\n const invalid = modal.getRoot()[0].querySelectorAll('[aria-invalid=\"true\"], .error');\n if (invalid.length) {\n invalid[0].focus();\n return;\n }\n\n modal.destroy();\n\n // Submit form via ajax.\n this.submitBackupRequest(formjson)\n .then(() => {\n if (e.formredirect == true) {\n // We are redirecting to copy progress display.\n const redirect = `${Config.wwwroot}/backup/copyprogress.php?id=${course.id}`;\n window.location.assign(redirect);\n }\n\n return;\n })\n .catch(() => {\n // Form submission failed server side, redisplay with errors.\n this.createModal(course, copyform);\n });\n }\n}\n"],"names":["CopyModal","context","constructor","contextid","registerEventListeners","document","addEventListener","e","copyAction","target","closest","preventDefault","url","URL","href","params","URLSearchParams","search","fetchCourseData","get","then","_ref","course","this","createModal","catch","error","Notification","exception","courseid","ajax","call","methodname","args","options","ids","submitBackupRequest","jsonformdata","formdata","JSON","stringify","id","Modal","create","title","shortname","body","Fragment","loadFragment","large","show","removeOnClose","modal","getRoot","on","processModalForm","destroy","formredirect","copyform","find","serialize","formjson","invalid","querySelectorAll","length","focus","redirect","Config","wwwroot","window","location","assign"],"mappings":";;;;;;;;;;0SAiCqBA,sBACLC,gBACD,IAAID,UAAUC,SAGzBC,YAAYD,cACHE,UAAYF,aAEZG,yBAGTA,yBACIC,SAASC,iBAAiB,SAAUC,UAC1BC,WAAaD,EAAEE,OAAOC,QAAQ,oBAC/BF,kBAGLD,EAAEI,uBAEIC,IAAM,IAAIC,IAAIL,WAAWM,MACzBC,OAAS,IAAIC,gBAAgBJ,IAAIK,aAElCC,gBAAgBH,OAAOI,IAAI,OAC/BC,MAAKC,WAAEC,oBAAYC,KAAKC,YAAYF,WACpCG,OAAOC,OAAUC,sBAAaC,UAAUF,YAIjDR,gBAAgBW,iBACLC,KAAKC,KAAK,CAAC,CACdC,WAAY,0BACZC,KAAM,CACFC,QAAS,CACLC,IAAK,CAACN,eAGd,GAGRO,oBAAoBC,qBACTP,KAAKC,KAAK,CAAC,CACdC,WAAY,+BACZC,KAAM,CACFI,aAAAA,iBAEJ,GAGRb,YACIF,YACAgB,gEAAW,SAELvB,OAAS,CACXsB,aAAcE,KAAKC,UAAUF,UAC7BT,SAAUP,OAAOmB,WAIdC,eAAMC,OAAO,CAChBC,OAAO,mBAAU,kBAAmB,SAAUtB,OAAOuB,WACrDC,KAAMC,SAASC,aAAa,SAAU,gBAAiBzB,KAAKpB,UAAWY,QACvEkC,OAAO,EACPC,MAAM,EACNC,eAAe,IAElB/B,MAAMgC,QAEHA,MAAMC,UAAUC,GAAG,QAAS,oBAAqB/C,SACxCgD,iBAAiBjC,OAAQ8B,MAAO7C,MAEzC6C,MAAMC,UAAUC,GAAG,QAAS,cAAe/C,IACvCA,EAAEI,iBACFyC,MAAMI,aAEVJ,MAAMC,UAAUC,GAAG,QAAS,qBAAsB/C,IAC9CA,EAAEkD,cAAe,OACZF,iBAAiBjC,OAAQ8B,MAAO7C,MAIlC6C,SAIfG,iBAAiBjC,OAAQ8B,MAAO7C,GAC5BA,EAAEI,uBAGI+C,SAAWN,MAAMC,UAAUM,KAAK,QAAQC,YACxCC,SAAWtB,KAAKC,UAAUkB,UAG1BI,QAAUV,MAAMC,UAAU,GAAGU,iBAAiB,iCAChDD,QAAQE,OACRF,QAAQ,GAAGG,SAIfb,MAAMI,eAGDpB,oBAAoByB,UACxBzC,MAAK,QACoB,GAAlBb,EAAEkD,aAAsB,OAElBS,mBAAcC,OAAOC,+CAAsC9C,OAAOmB,IACxE4B,OAAOC,SAASC,OAAOL,cAK9BzC,OAAM,UAEED,YAAYF,OAAQoC"} \ No newline at end of file diff --git a/course/amd/src/copy_modal.js b/course/amd/src/copy_modal.js index 04b7f11b64f..b79d297662e 100644 --- a/course/amd/src/copy_modal.js +++ b/course/amd/src/copy_modal.js @@ -103,7 +103,7 @@ export default class CopyModal { }); modal.getRoot().on('click', '#id_cancel', (e) => { e.preventDefault(); - modal.hide(); + modal.destroy(); }); modal.getRoot().on('click', '#id_submitdisplay', (e) => { e.formredirect = true; @@ -129,7 +129,7 @@ export default class CopyModal { return; } - modal.hide(); + modal.destroy(); // Submit form via ajax. this.submitBackupRequest(formjson)