first commit

This commit is contained in:
CHIEFSOFT\ameye
2024-09-30 18:11:26 -04:00
commit e592ca6823
27270 changed files with 5002257 additions and 0 deletions
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
+10
View File
@@ -0,0 +1,10 @@
define("core_user/edit_profile_fields",["exports","core_form/modalform","core/str"],(function(_exports,_modalform,_str){var obj;
/**
* User profile fields editor
*
* @module core_user/edit_profile_fields
* @copyright 2021 Marina Glancy
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/Object.defineProperty(_exports,"__esModule",{value:!0}),_exports.init=void 0,_modalform=(obj=_modalform)&&obj.__esModule?obj:{default:obj};const Selectors_actions={editCategory:'[data-action="editcategory"]',editField:'[data-action="editfield"]',createField:'[data-action="createfield"]'};_exports.init=()=>{document.addEventListener("click",(function(e){let element=e.target.closest(Selectors_actions.editCategory);if(element){e.preventDefault();const title=element.getAttribute("data-id")?(0,_str.getString)("profileeditcategory","admin",element.getAttribute("data-name")):(0,_str.getString)("profilecreatenewcategory","admin"),form=new _modalform.default({formClass:"core_user\\form\\profile_category_form",args:{id:element.getAttribute("data-id")},modalConfig:{title:title},returnFocus:element});form.addEventListener(form.events.FORM_SUBMITTED,(()=>window.location.reload())),form.show()}if(element=e.target.closest(Selectors_actions.editField),element){e.preventDefault();const form=new _modalform.default({formClass:"core_user\\form\\profile_field_form",args:{id:element.getAttribute("data-id")},modalConfig:{title:(0,_str.getString)("profileeditfield","admin",element.getAttribute("data-name"))},returnFocus:element});form.addEventListener(form.events.FORM_SUBMITTED,(()=>window.location.reload())),form.show()}if(element=e.target.closest(Selectors_actions.createField),element){e.preventDefault();const form=new _modalform.default({formClass:"core_user\\form\\profile_field_form",args:{datatype:element.getAttribute("data-datatype"),categoryid:element.getAttribute("data-categoryid")},modalConfig:{title:(0,_str.getString)("profilecreatenewfield","admin",element.getAttribute("data-datatypename"))},returnFocus:element});form.addEventListener(form.events.FORM_SUBMITTED,(()=>window.location.reload())),form.show()}}))}}));
//# sourceMappingURL=edit_profile_fields.min.js.map
@@ -0,0 +1 @@
{"version":3,"file":"edit_profile_fields.min.js","sources":["../src/edit_profile_fields.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 <http://www.gnu.org/licenses/>.\n\nimport ModalForm from 'core_form/modalform';\nimport {getString} from 'core/str';\n\n/**\n * User profile fields editor\n *\n * @module core_user/edit_profile_fields\n * @copyright 2021 Marina Glancy\n * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later\n */\n\nconst Selectors = {\n actions: {\n editCategory: '[data-action=\"editcategory\"]',\n editField: '[data-action=\"editfield\"]',\n createField: '[data-action=\"createfield\"]',\n },\n};\n\nexport const init = () => {\n document.addEventListener('click', function(e) {\n let element = e.target.closest(Selectors.actions.editCategory);\n if (element) {\n e.preventDefault();\n const title = element.getAttribute('data-id') ?\n getString('profileeditcategory', 'admin', element.getAttribute('data-name')) :\n getString('profilecreatenewcategory', 'admin');\n const form = new ModalForm({\n formClass: 'core_user\\\\form\\\\profile_category_form',\n args: {id: element.getAttribute('data-id')},\n modalConfig: {title},\n returnFocus: element,\n });\n form.addEventListener(form.events.FORM_SUBMITTED, () => window.location.reload());\n form.show();\n }\n\n element = e.target.closest(Selectors.actions.editField);\n if (element) {\n e.preventDefault();\n const form = new ModalForm({\n formClass: 'core_user\\\\form\\\\profile_field_form',\n args: {id: element.getAttribute('data-id')},\n modalConfig: {title: getString('profileeditfield', 'admin', element.getAttribute('data-name'))},\n returnFocus: element,\n });\n form.addEventListener(form.events.FORM_SUBMITTED, () => window.location.reload());\n form.show();\n }\n\n element = e.target.closest(Selectors.actions.createField);\n if (element) {\n e.preventDefault();\n const form = new ModalForm({\n formClass: 'core_user\\\\form\\\\profile_field_form',\n args: {datatype: element.getAttribute('data-datatype'), categoryid: element.getAttribute('data-categoryid')},\n modalConfig: {title: getString('profilecreatenewfield', 'admin', element.getAttribute('data-datatypename'))},\n returnFocus: element,\n });\n form.addEventListener(form.events.FORM_SUBMITTED, () => window.location.reload());\n form.show();\n }\n });\n};\n"],"names":["Selectors","editCategory","editField","createField","document","addEventListener","e","element","target","closest","preventDefault","title","getAttribute","form","ModalForm","formClass","args","id","modalConfig","returnFocus","events","FORM_SUBMITTED","window","location","reload","show","datatype","categoryid"],"mappings":";;;;;;;sJA0BMA,kBACO,CACLC,aAAc,+BACdC,UAAW,4BACXC,YAAa,6CAID,KAChBC,SAASC,iBAAiB,SAAS,SAASC,OACpCC,QAAUD,EAAEE,OAAOC,QAAQT,kBAAkBC,iBAC7CM,QAAS,CACTD,EAAEI,uBACIC,MAAQJ,QAAQK,aAAa,YAC/B,kBAAU,sBAAuB,QAASL,QAAQK,aAAa,eAC/D,kBAAU,2BAA4B,SACpCC,KAAO,IAAIC,mBAAU,CACvBC,UAAW,yCACXC,KAAM,CAACC,GAAIV,QAAQK,aAAa,YAChCM,YAAa,CAACP,MAAAA,OACdQ,YAAaZ,UAEjBM,KAAKR,iBAAiBQ,KAAKO,OAAOC,gBAAgB,IAAMC,OAAOC,SAASC,WACxEX,KAAKY,UAGTlB,QAAUD,EAAEE,OAAOC,QAAQT,kBAAkBE,WACzCK,QAAS,CACTD,EAAEI,uBACIG,KAAO,IAAIC,mBAAU,CACvBC,UAAW,sCACXC,KAAM,CAACC,GAAIV,QAAQK,aAAa,YAChCM,YAAa,CAACP,OAAO,kBAAU,mBAAoB,QAASJ,QAAQK,aAAa,eACjFO,YAAaZ,UAEjBM,KAAKR,iBAAiBQ,KAAKO,OAAOC,gBAAgB,IAAMC,OAAOC,SAASC,WACxEX,KAAKY,UAGTlB,QAAUD,EAAEE,OAAOC,QAAQT,kBAAkBG,aACzCI,QAAS,CACTD,EAAEI,uBACIG,KAAO,IAAIC,mBAAU,CACvBC,UAAW,sCACXC,KAAM,CAACU,SAAUnB,QAAQK,aAAa,iBAAkBe,WAAYpB,QAAQK,aAAa,oBACzFM,YAAa,CAACP,OAAO,kBAAU,wBAAyB,QAASJ,QAAQK,aAAa,uBACtFO,YAAaZ,UAEjBM,KAAKR,iBAAiBQ,KAAKO,OAAOC,gBAAgB,IAAMC,OAAOC,SAASC,WACxEX,KAAKY"}
+10
View File
@@ -0,0 +1,10 @@
define("core_user/form_user_selector",["exports","core/ajax","core/templates","core/str"],(function(_exports,_ajax,_templates,_str){var obj;
/**
* Provides the required functionality for an autocomplete element to select a user.
*
* @module core_user/form_user_selector
* @copyright 2020 David Mudrák <david@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/Object.defineProperty(_exports,"__esModule",{value:!0}),_exports.processResults=function(selector,results){return Array.isArray(results)?results.map((result=>({value:result.id,label:result.label}))):results},_exports.transport=async function(selector,query,callback,failure){const request={methodname:"core_user_search_identity",args:{query:query}};try{const response=await _ajax.default.call([request])[0];if(response.overflow){const msg=await(0,_str.getString)("toomanyuserstoshow","core",">"+response.maxusersperpage);callback(msg)}else{let labels=[];response.list.forEach((user=>{labels.push((0,_templates.render)("core_user/form_user_selector_suggestion",user))})),labels=await Promise.all(labels),response.list.forEach(((user,index)=>{user.label=labels[index]})),callback(response.list)}}catch(e){failure(e)}},_ajax=(obj=_ajax)&&obj.__esModule?obj:{default:obj}}));
//# sourceMappingURL=form_user_selector.min.js.map
@@ -0,0 +1 @@
{"version":3,"file":"form_user_selector.min.js","sources":["../src/form_user_selector.js"],"sourcesContent":["// This file is part of Moodle - https://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 <http://www.gnu.org/licenses/>.\n\n/**\n * Provides the required functionality for an autocomplete element to select a user.\n *\n * @module core_user/form_user_selector\n * @copyright 2020 David Mudrák <david@moodle.com>\n * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later\n */\n\nimport Ajax from 'core/ajax';\nimport {render as renderTemplate} from 'core/templates';\nimport {getString} from 'core/str';\n\n/**\n * Load the list of users matching the query and render the selector labels for them.\n *\n * @param {String} selector The selector of the auto complete element.\n * @param {String} query The query string.\n * @param {Function} callback A callback function receiving an array of results.\n * @param {Function} failure A function to call in case of failure, receiving the error message.\n */\nexport async function transport(selector, query, callback, failure) {\n\n const request = {\n methodname: 'core_user_search_identity',\n args: {\n query: query\n }\n };\n\n try {\n const response = await Ajax.call([request])[0];\n\n if (response.overflow) {\n const msg = await getString('toomanyuserstoshow', 'core', '>' + response.maxusersperpage);\n callback(msg);\n\n } else {\n let labels = [];\n response.list.forEach(user => {\n labels.push(renderTemplate('core_user/form_user_selector_suggestion', user));\n });\n labels = await Promise.all(labels);\n\n response.list.forEach((user, index) => {\n user.label = labels[index];\n });\n\n callback(response.list);\n }\n\n } catch (e) {\n failure(e);\n }\n}\n\n/**\n * Process the results for auto complete elements.\n *\n * @param {String} selector The selector of the auto complete element.\n * @param {Array} results An array or results returned by {@see transport()}.\n * @return {Array} New array of the selector options.\n */\nexport function processResults(selector, results) {\n\n if (!Array.isArray(results)) {\n return results;\n\n } else {\n return results.map(result => ({value: result.id, label: result.label}));\n }\n}\n"],"names":["selector","results","Array","isArray","map","result","value","id","label","query","callback","failure","request","methodname","args","response","Ajax","call","overflow","msg","maxusersperpage","labels","list","forEach","user","push","Promise","all","index","e"],"mappings":";;;;;;;8FA6E+BA,SAAUC,gBAEhCC,MAAMC,QAAQF,SAIRA,QAAQG,KAAIC,UAAYC,MAAOD,OAAOE,GAAIC,MAAOH,OAAOG,UAHxDP,2CA7CiBD,SAAUS,MAAOC,SAAUC,eAEjDC,QAAU,CACZC,WAAY,4BACZC,KAAM,CACFL,MAAOA,kBAKLM,eAAiBC,cAAKC,KAAK,CAACL,UAAU,MAExCG,SAASG,SAAU,OACbC,UAAY,kBAAU,qBAAsB,OAAQ,IAAMJ,SAASK,iBACzEV,SAASS,SAEN,KACCE,OAAS,GACbN,SAASO,KAAKC,SAAQC,OAClBH,OAAOI,MAAK,qBAAe,0CAA2CD,UAE1EH,aAAeK,QAAQC,IAAIN,QAE3BN,SAASO,KAAKC,SAAQ,CAACC,KAAMI,SACzBJ,KAAKhB,MAAQa,OAAOO,UAGxBlB,SAASK,SAASO,OAGxB,MAAOO,GACLlB,QAAQkB"}
+10
View File
@@ -0,0 +1,10 @@
define("core_user/local/participants/bulkactions",["exports","core_user/repository","core/str","core/modal_events","core/modal_save_cancel","core/notification","core/templates","core/toast"],(function(_exports,Repository,Str,_modal_events,_modal_save_cancel,_notification,_templates,_toast){function _interopRequireDefault(obj){return obj&&obj.__esModule?obj:{default:obj}}function _getRequireWildcardCache(nodeInterop){if("function"!=typeof WeakMap)return null;var cacheBabelInterop=new WeakMap,cacheNodeInterop=new WeakMap;return(_getRequireWildcardCache=function(nodeInterop){return nodeInterop?cacheNodeInterop:cacheBabelInterop})(nodeInterop)}function _interopRequireWildcard(obj,nodeInterop){if(!nodeInterop&&obj&&obj.__esModule)return obj;if(null===obj||"object"!=typeof obj&&"function"!=typeof obj)return{default:obj};var cache=_getRequireWildcardCache(nodeInterop);if(cache&&cache.has(obj))return cache.get(obj);var newObj={},hasPropertyDescriptor=Object.defineProperty&&Object.getOwnPropertyDescriptor;for(var key in obj)if("default"!==key&&Object.prototype.hasOwnProperty.call(obj,key)){var desc=hasPropertyDescriptor?Object.getOwnPropertyDescriptor(obj,key):null;desc&&(desc.get||desc.set)?Object.defineProperty(newObj,key,desc):newObj[key]=obj[key]}return newObj.default=obj,cache&&cache.set(obj,newObj),newObj}
/**
* Bulk actions for lists of participants.
*
* @module core_user/local/participants/bulkactions
* @copyright 2020 Andrew Nicols <andrew@nicols.co.uk>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/Object.defineProperty(_exports,"__esModule",{value:!0}),_exports.showSendMessage=_exports.showAddNote=void 0,Repository=_interopRequireWildcard(Repository),Str=_interopRequireWildcard(Str),_modal_events=_interopRequireDefault(_modal_events),_modal_save_cancel=_interopRequireDefault(_modal_save_cancel),_notification=_interopRequireDefault(_notification),_templates=_interopRequireDefault(_templates);_exports.showAddNote=(courseid,users,noteStateNames,stateHelpIcon)=>{if(!users.length)return Promise.resolve();const states=[];for(let key in noteStateNames)switch(key){case"draft":states.push({value:"personal",label:noteStateNames[key]});break;case"public":states.push({value:"course",label:noteStateNames[key],selected:1});break;case"site":states.push({value:key,label:noteStateNames[key]})}const context={stateNames:states,stateHelpIcon:stateHelpIcon.innerHTML};let titlePromise=null;return titlePromise=1===users.length?Str.get_string("addbulknotesingle","core_notes"):Str.get_string("addbulknote","core_notes",users.length),_modal_save_cancel.default.create({body:_templates.default.render("core_user/add_bulk_note",context),title:titlePromise,buttons:{save:titlePromise},removeOnClose:!0,show:!0}).then((modal=>(modal.getRoot().on(_modal_events.default.save,(()=>submitAddNote(courseid,users,modal))),modal)))};const submitAddNote=(courseid,users,modal)=>{const text=modal.getRoot().find("form textarea").val(),publishstate=modal.getRoot().find("form select").val(),notes=users.map((userid=>({userid:userid,text:text,courseid:courseid,publishstate:publishstate})));return Repository.createNotesForUsers(notes).then((noteIds=>1===noteIds.length?Str.get_string("addbulknotedonesingle","core_notes"):Str.get_string("addbulknotedone","core_notes",noteIds.length))).then((msg=>(0,_toast.add)(msg))).catch(_notification.default.exception)};_exports.showSendMessage=users=>{if(!users.length)return Promise.resolve();let titlePromise;return titlePromise=1===users.length?Str.get_string("sendbulkmessagesingle","core_message"):Str.get_string("sendbulkmessage","core_message",users.length),_modal_save_cancel.default.create({body:_templates.default.render("core_user/send_bulk_message",{}),title:titlePromise,buttons:{save:titlePromise},removeOnClose:!0,show:!0}).then((modal=>(modal.getRoot().on(_modal_events.default.save,(e=>{const text=modal.getRoot().find("form textarea").val();if(""===text.trim())return modal.getRoot().find('[data-role="messagetextrequired"]').removeAttr("hidden"),void e.preventDefault();submitSendMessage(modal,users,text)})),modal)))};const submitSendMessage=(modal,users,text)=>{const messages=users.map((touserid=>({touserid:touserid,text:text})));return Repository.sendMessagesToUsers(messages).then((messageIds=>1==messageIds.length?Str.get_string("sendbulkmessagesentsingle","core_message"):Str.get_string("sendbulkmessagesent","core_message",messageIds.length))).then((msg=>(0,_toast.add)(msg))).catch(_notification.default.exception)}}));
//# sourceMappingURL=bulkactions.min.js.map
File diff suppressed because one or more lines are too long
+11
View File
@@ -0,0 +1,11 @@
define("core_user/participants",["exports","core_table/dynamic","core/str","core/checkbox-toggleall","core/custom_interaction_events","core_table/local/dynamic/selectors","core/modal_events","core/notification","core/pending","jquery","core_user/local/participants/bulkactions","core/inplace_editable"],(function(_exports,DynamicTable,Str,_checkboxToggleall,_custom_interaction_events,_selectors,_modal_events,_notification,_pending,_jquery,_bulkactions,_inplace_editable){function _interopRequireDefault(obj){return obj&&obj.__esModule?obj:{default:obj}}function _getRequireWildcardCache(nodeInterop){if("function"!=typeof WeakMap)return null;var cacheBabelInterop=new WeakMap,cacheNodeInterop=new WeakMap;return(_getRequireWildcardCache=function(nodeInterop){return nodeInterop?cacheNodeInterop:cacheBabelInterop})(nodeInterop)}function _interopRequireWildcard(obj,nodeInterop){if(!nodeInterop&&obj&&obj.__esModule)return obj;if(null===obj||"object"!=typeof obj&&"function"!=typeof obj)return{default:obj};var cache=_getRequireWildcardCache(nodeInterop);if(cache&&cache.has(obj))return cache.get(obj);var newObj={},hasPropertyDescriptor=Object.defineProperty&&Object.getOwnPropertyDescriptor;for(var key in obj)if("default"!==key&&Object.prototype.hasOwnProperty.call(obj,key)){var desc=hasPropertyDescriptor?Object.getOwnPropertyDescriptor(obj,key):null;desc&&(desc.get||desc.set)?Object.defineProperty(newObj,key,desc):newObj[key]=obj[key]}return newObj.default=obj,cache&&cache.set(obj,newObj),newObj}
/**
* Some UI stuff for participants page.
* This is also used by the report/participants/index.php because it has the same functionality.
*
* @module core_user/participants
* @copyright 2017 Damyon Wiese
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/Object.defineProperty(_exports,"__esModule",{value:!0}),_exports.init=void 0,DynamicTable=_interopRequireWildcard(DynamicTable),Str=_interopRequireWildcard(Str),_checkboxToggleall=_interopRequireDefault(_checkboxToggleall),_custom_interaction_events=_interopRequireDefault(_custom_interaction_events),_selectors=_interopRequireDefault(_selectors),_modal_events=_interopRequireDefault(_modal_events),_notification=_interopRequireDefault(_notification),_pending=_interopRequireDefault(_pending),_jquery=_interopRequireDefault(_jquery);const Selectors_bulkActionSelect="#formactionid",Selectors_bulkUserSelectedCheckBoxes="input[data-togglegroup='participants-table'][data-toggle='slave']:checked",Selectors_checkCountButton="#checkall",Selectors_showCountText='[data-region="participant-count"]',Selectors_stateHelpIcon='[data-region="state-help-icon"]',Selectors_tableForm=uniqueId=>'form[data-table-unique-id="'.concat(uniqueId,'"]');_exports.init=_ref=>{let{uniqueid:uniqueid,noteStateNames:noteStateNames={}}=_ref;const root=document.querySelector(Selectors_tableForm(uniqueid)),getTableFromUniqueId=uniqueId=>root.querySelector(_selectors.default.main.fromRegionId(uniqueId)),resetBulkAction=bulkActionSelect=>{bulkActionSelect.value=""};_custom_interaction_events.default.define(Selectors_bulkActionSelect,[_custom_interaction_events.default.events.accessibleChange]),(0,_jquery.default)(Selectors_bulkActionSelect).on(_custom_interaction_events.default.events.accessibleChange,(e=>{const bulkActionSelect=e.target.closest("select"),action=bulkActionSelect.value,checkboxes=getTableFromUniqueId(uniqueid).querySelectorAll(Selectors_bulkUserSelectedCheckBoxes),pendingPromise=new _pending.default("core_user/participants:bulkActionSelect");if(-1!==action.indexOf("#")){e.preventDefault();const ids=[];let bulkAction;if(checkboxes.forEach((checkbox=>{ids.push(checkbox.getAttribute("name").replace("user",""))})),"#messageselect"===action?bulkAction=(0,_bulkactions.showSendMessage)(ids):"#addgroupnote"===action&&(bulkAction=(0,_bulkactions.showAddNote)(root.dataset.courseId,ids,noteStateNames,root.querySelector(Selectors_stateHelpIcon))),bulkAction){const pendingBulkAction=new _pending.default("core_user/participants:bulkActionSelected");bulkAction.then((modal=>(modal.getRoot().on(_modal_events.default.hidden,(()=>{bulkActionSelect.focus()})),pendingBulkAction.resolve(),modal))).catch(_notification.default.exception)}}else""!==action&&checkboxes.length&&bulkActionSelect.form.submit();resetBulkAction(bulkActionSelect),pendingPromise.resolve()})),root.addEventListener("click",(e=>{const checkCountButton=root.querySelector(Selectors_checkCountButton);if(checkCountButton&&checkCountButton.contains(e.target)){e.preventDefault();const tableRoot=getTableFromUniqueId(uniqueid);DynamicTable.setPageSize(tableRoot,checkCountButton.dataset.targetPageSize).then((tableRoot=>(_checkboxToggleall.default.setGroupState(root,"participants-table",!0),tableRoot))).catch(_notification.default.exception)}})),root.addEventListener(DynamicTable.Events.tableContentRefreshed,(e=>{const checkCountButton=root.querySelector(Selectors_checkCountButton),tableRoot=e.target,defaultPageSize=parseInt(tableRoot.dataset.tableDefaultPerPage,10),currentPageSize=parseInt(tableRoot.dataset.tablePageSize,10),totalRowCount=parseInt(tableRoot.dataset.tableTotalRows,10);_checkboxToggleall.default.updateSlavesFromMasterState(root,"participants-table");const pageCountStrings=[{key:"countparticipantsfound",component:"core_user",param:totalRowCount}];totalRowCount<=defaultPageSize?checkCountButton&&checkCountButton.classList.add("hidden"):totalRowCount<=currentPageSize?(pageCountStrings.push({key:"selectalluserswithcount",component:"core",param:defaultPageSize}),checkCountButton&&checkCountButton.classList.add("hidden")):(pageCountStrings.push({key:"selectalluserswithcount",component:"core",param:totalRowCount}),checkCountButton&&checkCountButton.classList.remove("hidden")),Str.get_strings(pageCountStrings).then((_ref2=>{let[showingParticipantCountString,selectCountString]=_ref2;root.querySelector(Selectors_showCountText).innerHTML=showingParticipantCountString,selectCountString&&checkCountButton&&(checkCountButton.value=selectCountString)})).catch(_notification.default.exception)}))}}));
//# sourceMappingURL=participants.min.js.map
File diff suppressed because one or more lines are too long
+10
View File
@@ -0,0 +1,10 @@
define("core_user/participants_filter",["exports","core/datafilter","core_table/dynamic","core/datafilter/selectors","core/notification","core/pending"],(function(_exports,_datafilter,DynamicTable,_selectors,_notification,_pending){function _getRequireWildcardCache(nodeInterop){if("function"!=typeof WeakMap)return null;var cacheBabelInterop=new WeakMap,cacheNodeInterop=new WeakMap;return(_getRequireWildcardCache=function(nodeInterop){return nodeInterop?cacheNodeInterop:cacheBabelInterop})(nodeInterop)}function _interopRequireDefault(obj){return obj&&obj.__esModule?obj:{default:obj}}
/**
* Participants filter management.
*
* @module core_user/participants_filter
* @copyright 2021 Tomo Tsuyuki <tomotsuyuki@catalyst-au.net>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/Object.defineProperty(_exports,"__esModule",{value:!0}),_exports.init=void 0,_datafilter=_interopRequireDefault(_datafilter),DynamicTable=function(obj,nodeInterop){if(!nodeInterop&&obj&&obj.__esModule)return obj;if(null===obj||"object"!=typeof obj&&"function"!=typeof obj)return{default:obj};var cache=_getRequireWildcardCache(nodeInterop);if(cache&&cache.has(obj))return cache.get(obj);var newObj={},hasPropertyDescriptor=Object.defineProperty&&Object.getOwnPropertyDescriptor;for(var key in obj)if("default"!==key&&Object.prototype.hasOwnProperty.call(obj,key)){var desc=hasPropertyDescriptor?Object.getOwnPropertyDescriptor(obj,key):null;desc&&(desc.get||desc.set)?Object.defineProperty(newObj,key,desc):newObj[key]=obj[key]}newObj.default=obj,cache&&cache.set(obj,newObj);return newObj}(DynamicTable),_selectors=_interopRequireDefault(_selectors),_notification=_interopRequireDefault(_notification),_pending=_interopRequireDefault(_pending);_exports.init=filterRegionId=>{const filterSet=document.getElementById(filterRegionId),coreFilter=new _datafilter.default(filterSet,(function(filters,pendingPromise){DynamicTable.setFilters(DynamicTable.getTableFromId(filterSet.dataset.tableRegion),{jointype:parseInt(filterSet.querySelector(_selectors.default.filterset.fields.join).value,10),filters:filters}).then((result=>(pendingPromise.resolve(),result))).catch(_notification.default.exception)}));coreFilter.init();const tableRoot=DynamicTable.getTableFromId(filterSet.dataset.tableRegion),initialFilters=DynamicTable.getFilters(tableRoot);if(initialFilters){const initialFilterPromise=new _pending.default("core/filter:setFilterFromConfig");(config=>{const filterConfig=Object.entries(config.filters);if(!filterConfig.length)return Promise.resolve();filterSet.querySelector(_selectors.default.filterset.fields.join).value=config.jointype;const filterPromises=filterConfig.map((_ref=>{let[filterType,filterData]=_ref;if("courseid"===filterType)return!1;const filterValues=filterData.values;return!!filterValues.length&&coreFilter.addFilterRow().then((_ref2=>{let[filterRow]=_ref2;coreFilter.addFilter(filterRow,filterType,filterValues)}))})).filter((promise=>promise));return filterPromises.length?Promise.all(filterPromises).then((()=>coreFilter.removeEmptyFilters())).then((()=>{coreFilter.updateFiltersOptions()})).then((()=>{coreFilter.updateTableFromFilter()})):Promise.resolve()})(initialFilters).then((()=>initialFilterPromise.resolve())).catch()}}}));
//# sourceMappingURL=participants_filter.min.js.map
File diff suppressed because one or more lines are too long
+10
View File
@@ -0,0 +1,10 @@
define("core_user/private_files",["exports","core_form/dynamicform","core_form/modalform","core/str","core/toast"],(function(_exports,_dynamicform,_modalform,_str,_toast){function _interopRequireDefault(obj){return obj&&obj.__esModule?obj:{default:obj}}
/**
* Module to handle AJAX interactions with user private files
*
* @module core_user/private_files
* @copyright 2020 Marina Glancy
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/Object.defineProperty(_exports,"__esModule",{value:!0}),_exports.initModal=_exports.initDynamicForm=void 0,_dynamicform=_interopRequireDefault(_dynamicform),_modalform=_interopRequireDefault(_modalform);_exports.initDynamicForm=(containerSelector,formClass)=>{const form=new _dynamicform.default(document.querySelector(containerSelector),formClass);form.addEventListener(form.events.FORM_SUBMITTED,(()=>{form.load(),(0,_str.getString)("changessaved").then(_toast.add).catch(null)})),form.addEventListener(form.events.CANCEL_BUTTON_PRESSED,(()=>window.location.reload()))};_exports.initModal=(elementSelector,formClass)=>{document.querySelector(elementSelector).addEventListener("click",(function(e){e.preventDefault();const form=new _modalform.default({formClass:formClass,args:{nosubmit:!0},modalConfig:{title:(0,_str.getString)("privatefilesmanage")},returnFocus:e.target});form.addEventListener(form.events.FORM_SUBMITTED,(()=>window.location.reload())),form.show()}))}}));
//# sourceMappingURL=private_files.min.js.map
+1
View File
@@ -0,0 +1 @@
{"version":3,"file":"private_files.min.js","sources":["../src/private_files.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 <http://www.gnu.org/licenses/>.\n\n/**\n * Module to handle AJAX interactions with user private files\n *\n * @module core_user/private_files\n * @copyright 2020 Marina Glancy\n * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later\n */\nimport DynamicForm from 'core_form/dynamicform';\nimport ModalForm from 'core_form/modalform';\nimport {getString} from 'core/str';\nimport {add as addToast} from 'core/toast';\n\n/**\n * Initialize private files form as AJAX form\n *\n * @param {String} containerSelector\n * @param {String} formClass\n */\nexport const initDynamicForm = (containerSelector, formClass) => {\n const form = new DynamicForm(document.querySelector(containerSelector), formClass);\n\n // When form is saved, refresh it to remove validation errors, if any:\n form.addEventListener(form.events.FORM_SUBMITTED, () => {\n form.load();\n getString('changessaved')\n .then(addToast)\n .catch(null);\n });\n\n // Reload the page on cancel.\n form.addEventListener(form.events.CANCEL_BUTTON_PRESSED, () => window.location.reload());\n};\n\n/**\n * Initialize private files form as Modal form\n *\n * @param {String} elementSelector\n * @param {String} formClass\n */\nexport const initModal = (elementSelector, formClass) => {\n document.querySelector(elementSelector).addEventListener('click', function(e) {\n e.preventDefault();\n const form = new ModalForm({\n formClass,\n args: {nosubmit: true},\n modalConfig: {title: getString('privatefilesmanage')},\n returnFocus: e.target,\n });\n form.addEventListener(form.events.FORM_SUBMITTED, () => window.location.reload());\n form.show();\n });\n};\n"],"names":["containerSelector","formClass","form","DynamicForm","document","querySelector","addEventListener","events","FORM_SUBMITTED","load","then","addToast","catch","CANCEL_BUTTON_PRESSED","window","location","reload","elementSelector","e","preventDefault","ModalForm","args","nosubmit","modalConfig","title","returnFocus","target","show"],"mappings":";;;;;;;yOAiC+B,CAACA,kBAAmBC,mBACzCC,KAAO,IAAIC,qBAAYC,SAASC,cAAcL,mBAAoBC,WAGxEC,KAAKI,iBAAiBJ,KAAKK,OAAOC,gBAAgB,KAC9CN,KAAKO,0BACK,gBACTC,KAAKC,YACLC,MAAM,SAIXV,KAAKI,iBAAiBJ,KAAKK,OAAOM,uBAAuB,IAAMC,OAAOC,SAASC,+BAS1D,CAACC,gBAAiBhB,aACvCG,SAASC,cAAcY,iBAAiBX,iBAAiB,SAAS,SAASY,GACvEA,EAAEC,uBACIjB,KAAO,IAAIkB,mBAAU,CACvBnB,UAAAA,UACAoB,KAAM,CAACC,UAAU,GACjBC,YAAa,CAACC,OAAO,kBAAU,uBAC/BC,YAAaP,EAAEQ,SAEnBxB,KAAKI,iBAAiBJ,KAAKK,OAAOC,gBAAgB,IAAMM,OAAOC,SAASC,WACxEd,KAAKyB"}
+3
View File
@@ -0,0 +1,3 @@
define("core_user/repository",["exports","core/ajax"],(function(_exports,_ajax){Object.defineProperty(_exports,"__esModule",{value:!0}),_exports.unenrolUser=_exports.submitUserEnrolmentForm=_exports.setUserPreferences=_exports.setUserPreference=_exports.sendMessagesToUsers=_exports.getUserPreferences=_exports.getUserPreference=_exports.createNotesForUsers=void 0;_exports.getUserPreference=function(name){let userid=arguments.length>1&&void 0!==arguments[1]?arguments[1]:0;return getUserPreferences(name,userid).then((response=>response.preferences[0].value))};const getUserPreferences=function(){let name=arguments.length>0&&void 0!==arguments[0]?arguments[0]:null,userid=arguments.length>1&&void 0!==arguments[1]?arguments[1]:0;return(0,_ajax.call)([{methodname:"core_user_get_user_preferences",args:{name:name,userid:userid}}])[0]};_exports.getUserPreferences=getUserPreferences;_exports.setUserPreference=function(name){let value=arguments.length>1&&void 0!==arguments[1]?arguments[1]:null,userid=arguments.length>2&&void 0!==arguments[2]?arguments[2]:0;return setUserPreferences([{name:name,value:value,userid:userid}])};const setUserPreferences=preferences=>(0,_ajax.call)([{methodname:"core_user_set_user_preferences",args:{preferences:preferences}}])[0];_exports.setUserPreferences=setUserPreferences;_exports.unenrolUser=userEnrolmentId=>(0,_ajax.call)([{methodname:"core_enrol_unenrol_user_enrolment",args:{ueid:userEnrolmentId}}])[0];_exports.submitUserEnrolmentForm=formdata=>(0,_ajax.call)([{methodname:"core_enrol_submit_user_enrolment_form",args:{formdata:formdata}}])[0];_exports.createNotesForUsers=notes=>(0,_ajax.call)([{methodname:"core_notes_create_notes",args:{notes:notes}}])[0];_exports.sendMessagesToUsers=messages=>(0,_ajax.call)([{methodname:"core_message_send_instant_messages",args:{messages:messages}}])[0]}));
//# sourceMappingURL=repository.min.js.map
+1
View File
@@ -0,0 +1 @@
{"version":3,"file":"repository.min.js","sources":["../src/repository.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 <http://www.gnu.org/licenses/>.\n\n/**\n * Module to handle AJAX interactions.\n *\n * @module core_user/repository\n * @copyright 2020 Andrew Nicols <andrew@nicols.co.uk>\n * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later\n */\n\nimport {call as fetchMany} from 'core/ajax';\n\n/**\n * Get single user preference\n *\n * @param {String} name Name of the preference\n * @param {Number} userid User ID (defaults to current user)\n * @return {Promise}\n */\nexport const getUserPreference = (name, userid = 0) => {\n return getUserPreferences(name, userid)\n .then(response => response.preferences[0].value);\n};\n\n/**\n * Get multiple user preferences\n *\n * @param {String|null} name Name of the preference (omit if you want to retrieve all)\n * @param {Number} userid User ID (defaults to current user)\n * @return {Promise}\n */\nexport const getUserPreferences = (name = null, userid = 0) => {\n return fetchMany([{\n methodname: 'core_user_get_user_preferences',\n args: {name, userid}\n }])[0];\n};\n\n/**\n * Set single user preference\n *\n * @param {String} name Name of the preference\n * @param {String|null} value Value of the preference (omit if you want to remove the current value)\n * @param {Number} userid User ID (defaults to current user)\n * @return {Promise}\n */\nexport const setUserPreference = (name, value = null, userid = 0) => {\n return setUserPreferences([{name, value, userid}]);\n};\n\n/**\n * Set multiple user preferences\n *\n * @param {Object[]} preferences Array of preferences containing name/value/userid attributes\n * @return {Promise}\n */\nexport const setUserPreferences = (preferences) => {\n return fetchMany([{\n methodname: 'core_user_set_user_preferences',\n args: {preferences}\n }])[0];\n};\n\n/**\n * Unenrol the user with the specified user enrolmentid ID.\n *\n * @param {Number} userEnrolmentId\n * @return {Promise}\n */\nexport const unenrolUser = userEnrolmentId => {\n return fetchMany([{\n methodname: 'core_enrol_unenrol_user_enrolment',\n args: {\n ueid: userEnrolmentId,\n },\n }])[0];\n};\n\n/**\n * Submit the user enrolment form with the specified form data.\n *\n * @param {String} formdata\n * @return {Promise}\n */\nexport const submitUserEnrolmentForm = formdata => {\n return fetchMany([{\n methodname: 'core_enrol_submit_user_enrolment_form',\n args: {\n formdata,\n },\n }])[0];\n};\n\nexport const createNotesForUsers = notes => {\n return fetchMany([{\n methodname: 'core_notes_create_notes',\n args: {\n notes\n }\n }])[0];\n};\n\nexport const sendMessagesToUsers = messages => {\n return fetchMany([{\n methodname: 'core_message_send_instant_messages',\n args: {messages}\n }])[0];\n};\n"],"names":["name","userid","getUserPreferences","then","response","preferences","value","methodname","args","setUserPreferences","userEnrolmentId","ueid","formdata","notes","messages"],"mappings":"wYAgCiC,SAACA,UAAMC,8DAAS,SACtCC,mBAAmBF,KAAMC,QAC3BE,MAAKC,UAAYA,SAASC,YAAY,GAAGC,eAUrCJ,mBAAqB,eAACF,4DAAO,KAAMC,8DAAS,SAC9C,cAAU,CAAC,CACdM,WAAY,iCACZC,KAAM,CAACR,KAAAA,KAAMC,OAAAA,WACb,8EAWyB,SAACD,UAAMM,6DAAQ,KAAML,8DAAS,SACpDQ,mBAAmB,CAAC,CAACT,KAAAA,KAAMM,MAAAA,MAAOL,OAAAA,iBAShCQ,mBAAsBJ,cACxB,cAAU,CAAC,CACdE,WAAY,iCACZC,KAAM,CAACH,YAAAA,gBACP,uEASmBK,kBAChB,cAAU,CAAC,CACdH,WAAY,oCACZC,KAAM,CACFG,KAAMD,oBAEV,oCAS+BE,WAC5B,cAAU,CAAC,CACdL,WAAY,wCACZC,KAAM,CACFI,SAAAA,aAEJ,gCAG2BC,QACxB,cAAU,CAAC,CACdN,WAAY,0BACZC,KAAM,CACFK,MAAAA,UAEJ,gCAG2BC,WACxB,cAAU,CAAC,CACdP,WAAY,qCACZC,KAAM,CAACM,SAAAA,aACP"}
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
+306
View File
@@ -0,0 +1,306 @@
// 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/>.
/**
* Allow the user to search for learners.
*
* @module core_user/comboboxsearch/user
* @copyright 2023 Mathew May <mathew.solutions>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
import search_combobox from 'core/comboboxsearch/search_combobox';
import {getStrings} from 'core/str';
import {renderForPromise, replaceNodeContents} from 'core/templates';
import $ from 'jquery';
export default class UserSearch extends search_combobox {
courseID;
groupID;
// A map of user profile field names that is human-readable.
profilestringmap = null;
constructor() {
super();
// Register a couple of events onto the document since we need to check if they are moving off the component.
['click', 'focus'].forEach(eventType => {
// Since we are handling dropdowns manually, ensure we can close it when moving off.
document.addEventListener(eventType, e => {
if (this.searchDropdown.classList.contains('show') && !this.combobox.contains(e.target)) {
this.toggleDropdown();
}
}, true);
});
// Register keyboard events.
this.component.addEventListener('keydown', this.keyHandler.bind(this));
// Define our standard lookups.
this.selectors = {...this.selectors,
courseid: '[data-region="courseid"]',
groupid: '[data-region="groupid"]',
resetPageButton: '[data-action="resetpage"]',
};
this.courseID = this.component.querySelector(this.selectors.courseid).dataset.courseid;
this.groupID = document.querySelector(this.selectors.groupid)?.dataset?.groupid;
this.instance = this.component.querySelector(this.selectors.instance).dataset.instance;
// We need to render some content by default for ARIA purposes.
this.renderDefault();
}
static init() {
return new UserSearch();
}
/**
* The overall div that contains the searching widget.
*
* @returns {string}
*/
componentSelector() {
return '.user-search';
}
/**
* The dropdown div that contains the searching widget result space.
*
* @returns {string}
*/
dropdownSelector() {
return '.usersearchdropdown';
}
/**
* Build the content then replace the node.
*/
async renderDropdown() {
const {html, js} = await renderForPromise('core_user/comboboxsearch/resultset', {
users: this.getMatchedResults().slice(0, 5),
hasresults: this.getMatchedResults().length > 0,
instance: this.instance,
matches: this.getMatchedResults().length,
searchterm: this.getSearchTerm(),
selectall: this.selectAllResultsLink(),
});
replaceNodeContents(this.getHTMLElements().searchDropdown, html, js);
// Remove aria-activedescendant when the available options change.
this.searchInput.removeAttribute('aria-activedescendant');
}
/**
* Build the content then replace the node by default we want our form to exist.
*/
async renderDefault() {
this.setMatchedResults(await this.filterDataset(await this.getDataset()));
this.filterMatchDataset();
await this.renderDropdown();
}
/**
* Get the data we will be searching against in this component.
*
* @returns {Promise<*>}
*/
fetchDataset() {
throw new Error(`fetchDataset() must be implemented in ${this.constructor.name}`);
}
/**
* Dictate to the search component how and what we want to match upon.
*
* @param {Array} filterableData
* @returns {Array} The users that match the given criteria.
*/
async filterDataset(filterableData) {
if (this.getPreppedSearchTerm()) {
const stringMap = await this.getStringMap();
return filterableData.filter((user) => Object.keys(user).some((key) => {
if (user[key] === "" || user[key] === null || !stringMap.get(key)) {
return false;
}
return user[key].toString().toLowerCase().includes(this.getPreppedSearchTerm());
}));
} else {
return [];
}
}
/**
* Given we have a subset of the dataset, set the field that we matched upon to inform the end user.
*
* @returns {Array} The results with the matched fields inserted.
*/
async filterMatchDataset() {
const stringMap = await this.getStringMap();
this.setMatchedResults(
this.getMatchedResults().map((user) => {
for (const [key, value] of Object.entries(user)) {
// Sometimes users have null values in their profile fields.
if (value === null) {
continue;
}
const valueString = value.toString().toLowerCase();
const preppedSearchTerm = this.getPreppedSearchTerm();
const searchTerm = this.getSearchTerm();
// Ensure we match only on expected keys.
const matchingFieldName = stringMap.get(key);
if (matchingFieldName && valueString.includes(preppedSearchTerm)) {
user.matchingFieldName = matchingFieldName;
// Safely prepare our matching results.
const escapedValueString = valueString.replace(/</g, '&lt;');
const escapedMatchingField = escapedValueString.replace(
preppedSearchTerm.replace(/</g, '&lt;'),
`<span class="font-weight-bold">${searchTerm.replace(/</g, '&lt;')}</span>`
);
if (user.email) {
user.matchingField = `${escapedMatchingField} (${user.email})`;
} else {
user.matchingField = escapedMatchingField;
}
break;
}
}
return user;
})
);
}
/**
* The handler for when a user changes the value of the component (selects an option from the dropdown).
*
* @param {Event} e The change event.
*/
changeHandler(e) {
this.toggleDropdown(); // Otherwise the dropdown stays open when user choose an option using keyboard.
if (e.target.value === '0') {
window.location = this.selectAllResultsLink();
} else {
window.location = this.selectOneLink(e.target.value);
}
}
/**
* The handler for when a user presses a key within the component.
*
* @param {KeyboardEvent} e The triggering event that we are working with.
*/
keyHandler(e) {
// Switch the key presses to handle keyboard nav.
switch (e.key) {
case 'ArrowUp':
case 'ArrowDown':
if (
this.getSearchTerm() !== ''
&& !this.searchDropdown.classList.contains('show')
&& e.target.contains(this.combobox)
) {
this.renderAndShow();
}
break;
case 'Enter':
case ' ':
if (e.target.closest(this.selectors.resetPageButton)) {
e.stopPropagation();
window.location = e.target.closest(this.selectors.resetPageButton).href;
break;
}
break;
case 'Escape':
this.toggleDropdown();
this.searchInput.focus({preventScroll: true});
break;
}
}
/**
* When called, hide or show the users dropdown.
*
* @param {Boolean} on Flag to toggle hiding or showing values.
*/
toggleDropdown(on = false) {
if (on) {
this.searchDropdown.classList.add('show');
$(this.searchDropdown).show();
this.getHTMLElements().searchInput.setAttribute('aria-expanded', 'true');
this.searchInput.focus({preventScroll: true});
} else {
this.searchDropdown.classList.remove('show');
$(this.searchDropdown).hide();
// As we are manually handling the dropdown, we need to do some housekeeping manually.
this.getHTMLElements().searchInput.setAttribute('aria-expanded', 'false');
this.searchInput.removeAttribute('aria-activedescendant');
this.searchDropdown.querySelectorAll('.active[role="option"]').forEach(option => {
option.classList.remove('active');
});
}
}
/**
* Build up the view all link.
*/
selectAllResultsLink() {
throw new Error(`selectAllResultsLink() must be implemented in ${this.constructor.name}`);
}
/**
* Build up the view all link that is dedicated to a particular result.
* We will call this function when a user interacts with the combobox to redirect them to show their results in the page.
*
* @param {Number} userID The ID of the user selected.
*/
selectOneLink(userID) {
throw new Error(`selectOneLink(${userID}) must be implemented in ${this.constructor.name}`);
}
/**
* Given the set of profile fields we can possibly search, fetch their strings,
* so we can report to screen readers the field that matched.
*
* @returns {Promise<void>}
*/
getStringMap() {
if (!this.profilestringmap) {
const requiredStrings = [
'username',
'fullname',
'firstname',
'lastname',
'email',
'city',
'country',
'department',
'institution',
'idnumber',
'phone1',
'phone2',
];
this.profilestringmap = getStrings(requiredStrings.map((key) => ({key})))
.then((stringArray) => new Map(
requiredStrings.map((key, index) => ([key, stringArray[index]]))
));
}
return this.profilestringmap;
}
}
+79
View File
@@ -0,0 +1,79 @@
// 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/>.
import ModalForm from 'core_form/modalform';
import {getString} from 'core/str';
/**
* User profile fields editor
*
* @module core_user/edit_profile_fields
* @copyright 2021 Marina Glancy
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
const Selectors = {
actions: {
editCategory: '[data-action="editcategory"]',
editField: '[data-action="editfield"]',
createField: '[data-action="createfield"]',
},
};
export const init = () => {
document.addEventListener('click', function(e) {
let element = e.target.closest(Selectors.actions.editCategory);
if (element) {
e.preventDefault();
const title = element.getAttribute('data-id') ?
getString('profileeditcategory', 'admin', element.getAttribute('data-name')) :
getString('profilecreatenewcategory', 'admin');
const form = new ModalForm({
formClass: 'core_user\\form\\profile_category_form',
args: {id: element.getAttribute('data-id')},
modalConfig: {title},
returnFocus: element,
});
form.addEventListener(form.events.FORM_SUBMITTED, () => window.location.reload());
form.show();
}
element = e.target.closest(Selectors.actions.editField);
if (element) {
e.preventDefault();
const form = new ModalForm({
formClass: 'core_user\\form\\profile_field_form',
args: {id: element.getAttribute('data-id')},
modalConfig: {title: getString('profileeditfield', 'admin', element.getAttribute('data-name'))},
returnFocus: element,
});
form.addEventListener(form.events.FORM_SUBMITTED, () => window.location.reload());
form.show();
}
element = e.target.closest(Selectors.actions.createField);
if (element) {
e.preventDefault();
const form = new ModalForm({
formClass: 'core_user\\form\\profile_field_form',
args: {datatype: element.getAttribute('data-datatype'), categoryid: element.getAttribute('data-categoryid')},
modalConfig: {title: getString('profilecreatenewfield', 'admin', element.getAttribute('data-datatypename'))},
returnFocus: element,
});
form.addEventListener(form.events.FORM_SUBMITTED, () => window.location.reload());
form.show();
}
});
};
+86
View File
@@ -0,0 +1,86 @@
// This file is part of Moodle - https://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/>.
/**
* Provides the required functionality for an autocomplete element to select a user.
*
* @module core_user/form_user_selector
* @copyright 2020 David Mudrák <david@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
import Ajax from 'core/ajax';
import {render as renderTemplate} from 'core/templates';
import {getString} from 'core/str';
/**
* Load the list of users matching the query and render the selector labels for them.
*
* @param {String} selector The selector of the auto complete element.
* @param {String} query The query string.
* @param {Function} callback A callback function receiving an array of results.
* @param {Function} failure A function to call in case of failure, receiving the error message.
*/
export async function transport(selector, query, callback, failure) {
const request = {
methodname: 'core_user_search_identity',
args: {
query: query
}
};
try {
const response = await Ajax.call([request])[0];
if (response.overflow) {
const msg = await getString('toomanyuserstoshow', 'core', '>' + response.maxusersperpage);
callback(msg);
} else {
let labels = [];
response.list.forEach(user => {
labels.push(renderTemplate('core_user/form_user_selector_suggestion', user));
});
labels = await Promise.all(labels);
response.list.forEach((user, index) => {
user.label = labels[index];
});
callback(response.list);
}
} catch (e) {
failure(e);
}
}
/**
* Process the results for auto complete elements.
*
* @param {String} selector The selector of the auto complete element.
* @param {Array} results An array or results returned by {@see transport()}.
* @return {Array} New array of the selector options.
*/
export function processResults(selector, results) {
if (!Array.isArray(results)) {
return results;
} else {
return results.map(result => ({value: result.id, label: result.label}));
}
}
@@ -0,0 +1,192 @@
// 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/>.
/**
* Bulk actions for lists of participants.
*
* @module core_user/local/participants/bulkactions
* @copyright 2020 Andrew Nicols <andrew@nicols.co.uk>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
import * as Repository from 'core_user/repository';
import * as Str from 'core/str';
import ModalEvents from 'core/modal_events';
import SaveCancelModal from 'core/modal_save_cancel';
import Notification from 'core/notification';
import Templates from 'core/templates';
import {add as notifyUser} from 'core/toast';
/**
* Show the add note popup
*
* @param {Number} courseid
* @param {Number[]} users
* @param {String[]} noteStateNames
* @param {HTMLElement} stateHelpIcon
* @return {Promise}
*/
export const showAddNote = (courseid, users, noteStateNames, stateHelpIcon) => {
if (!users.length) {
// No users were selected.
return Promise.resolve();
}
const states = [];
for (let key in noteStateNames) {
switch (key) {
case 'draft':
states.push({value: 'personal', label: noteStateNames[key]});
break;
case 'public':
states.push({value: 'course', label: noteStateNames[key], selected: 1});
break;
case 'site':
states.push({value: key, label: noteStateNames[key]});
break;
}
}
const context = {
stateNames: states,
stateHelpIcon: stateHelpIcon.innerHTML,
};
let titlePromise = null;
if (users.length === 1) {
titlePromise = Str.get_string('addbulknotesingle', 'core_notes');
} else {
titlePromise = Str.get_string('addbulknote', 'core_notes', users.length);
}
return SaveCancelModal.create({
body: Templates.render('core_user/add_bulk_note', context),
title: titlePromise,
buttons: {
save: titlePromise,
},
removeOnClose: true,
show: true,
})
.then(modal => {
modal.getRoot().on(ModalEvents.save, () => submitAddNote(courseid, users, modal));
return modal;
});
};
/**
* Add a note to this list of users.
*
* @param {Number} courseid
* @param {Number[]} users
* @param {Modal} modal
* @return {Promise}
*/
const submitAddNote = (courseid, users, modal) => {
const text = modal.getRoot().find('form textarea').val();
const publishstate = modal.getRoot().find('form select').val();
const notes = users.map(userid => {
return {
userid,
text,
courseid,
publishstate,
};
});
return Repository.createNotesForUsers(notes)
.then(noteIds => {
if (noteIds.length === 1) {
return Str.get_string('addbulknotedonesingle', 'core_notes');
} else {
return Str.get_string('addbulknotedone', 'core_notes', noteIds.length);
}
})
.then(msg => notifyUser(msg))
.catch(Notification.exception);
};
/**
* Show the send message popup.
*
* @param {Number[]} users
* @return {Promise}
*/
export const showSendMessage = users => {
if (!users.length) {
// Nothing to do.
return Promise.resolve();
}
let titlePromise;
if (users.length === 1) {
titlePromise = Str.get_string('sendbulkmessagesingle', 'core_message');
} else {
titlePromise = Str.get_string('sendbulkmessage', 'core_message', users.length);
}
return SaveCancelModal.create({
body: Templates.render('core_user/send_bulk_message', {}),
title: titlePromise,
buttons: {
save: titlePromise,
},
removeOnClose: true,
show: true,
})
.then(modal => {
modal.getRoot().on(ModalEvents.save, (e) => {
const text = modal.getRoot().find('form textarea').val();
if (text.trim() === '') {
modal.getRoot().find('[data-role="messagetextrequired"]').removeAttr('hidden');
e.preventDefault();
return;
}
submitSendMessage(modal, users, text);
});
return modal;
});
};
/**
* Send a message to these users.
*
* @param {Modal} modal
* @param {Number[]} users
* @param {String} text
* @return {Promise}
*/
const submitSendMessage = (modal, users, text) => {
const messages = users.map(touserid => {
return {
touserid,
text,
};
});
return Repository.sendMessagesToUsers(messages)
.then(messageIds => {
if (messageIds.length == 1) {
return Str.get_string('sendbulkmessagesentsingle', 'core_message');
} else {
return Str.get_string('sendbulkmessagesent', 'core_message', messageIds.length);
}
})
.then(msg => notifyUser(msg))
.catch(Notification.exception);
};
+200
View File
@@ -0,0 +1,200 @@
// 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/>.
/**
* Some UI stuff for participants page.
* This is also used by the report/participants/index.php because it has the same functionality.
*
* @module core_user/participants
* @copyright 2017 Damyon Wiese
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
import * as DynamicTable from 'core_table/dynamic';
import * as Str from 'core/str';
import CheckboxToggleAll from 'core/checkbox-toggleall';
import CustomEvents from 'core/custom_interaction_events';
import DynamicTableSelectors from 'core_table/local/dynamic/selectors';
import ModalEvents from 'core/modal_events';
import Notification from 'core/notification';
import Pending from 'core/pending';
import jQuery from 'jquery';
import {showAddNote, showSendMessage} from 'core_user/local/participants/bulkactions';
import 'core/inplace_editable';
const Selectors = {
bulkActionSelect: "#formactionid",
bulkUserSelectedCheckBoxes: "input[data-togglegroup='participants-table'][data-toggle='slave']:checked",
checkCountButton: "#checkall",
showCountText: '[data-region="participant-count"]',
showCountToggle: '[data-action="showcount"]',
stateHelpIcon: '[data-region="state-help-icon"]',
tableForm: uniqueId => `form[data-table-unique-id="${uniqueId}"]`,
};
export const init = ({
uniqueid,
noteStateNames = {},
}) => {
const root = document.querySelector(Selectors.tableForm(uniqueid));
const getTableFromUniqueId = uniqueId => root.querySelector(DynamicTableSelectors.main.fromRegionId(uniqueId));
/**
* Private method.
*
* @method registerEventListeners
* @private
*/
const registerEventListeners = () => {
CustomEvents.define(Selectors.bulkActionSelect, [CustomEvents.events.accessibleChange]);
jQuery(Selectors.bulkActionSelect).on(CustomEvents.events.accessibleChange, e => {
const bulkActionSelect = e.target.closest('select');
const action = bulkActionSelect.value;
const tableRoot = getTableFromUniqueId(uniqueid);
const checkboxes = tableRoot.querySelectorAll(Selectors.bulkUserSelectedCheckBoxes);
const pendingPromise = new Pending('core_user/participants:bulkActionSelect');
if (action.indexOf('#') !== -1) {
e.preventDefault();
const ids = [];
checkboxes.forEach(checkbox => {
ids.push(checkbox.getAttribute('name').replace('user', ''));
});
let bulkAction;
if (action === '#messageselect') {
bulkAction = showSendMessage(ids);
} else if (action === '#addgroupnote') {
bulkAction = showAddNote(
root.dataset.courseId,
ids,
noteStateNames,
root.querySelector(Selectors.stateHelpIcon)
);
}
if (bulkAction) {
const pendingBulkAction = new Pending('core_user/participants:bulkActionSelected');
bulkAction
.then(modal => {
modal.getRoot().on(ModalEvents.hidden, () => {
// Focus on the action select when the dialog is closed.
bulkActionSelect.focus();
});
pendingBulkAction.resolve();
return modal;
})
.catch(Notification.exception);
}
} else if (action !== '' && checkboxes.length) {
bulkActionSelect.form.submit();
}
resetBulkAction(bulkActionSelect);
pendingPromise.resolve();
});
root.addEventListener('click', e => {
// Handle clicking of the "Select all" actions.
const checkCountButton = root.querySelector(Selectors.checkCountButton);
const checkCountButtonClicked = checkCountButton && checkCountButton.contains(e.target);
if (checkCountButtonClicked) {
e.preventDefault();
const tableRoot = getTableFromUniqueId(uniqueid);
DynamicTable.setPageSize(tableRoot, checkCountButton.dataset.targetPageSize)
.then(tableRoot => {
// Update the toggle state.
CheckboxToggleAll.setGroupState(root, 'participants-table', true);
return tableRoot;
})
.catch(Notification.exception);
}
});
// When the content is refreshed, update the row counts in various places.
root.addEventListener(DynamicTable.Events.tableContentRefreshed, e => {
const checkCountButton = root.querySelector(Selectors.checkCountButton);
const tableRoot = e.target;
const defaultPageSize = parseInt(tableRoot.dataset.tableDefaultPerPage, 10);
const currentPageSize = parseInt(tableRoot.dataset.tablePageSize, 10);
const totalRowCount = parseInt(tableRoot.dataset.tableTotalRows, 10);
CheckboxToggleAll.updateSlavesFromMasterState(root, 'participants-table');
const pageCountStrings = [
{
key: 'countparticipantsfound',
component: 'core_user',
param: totalRowCount,
},
];
if (totalRowCount <= defaultPageSize) {
if (checkCountButton) {
checkCountButton.classList.add('hidden');
}
} else if (totalRowCount <= currentPageSize) {
// The are fewer than the current page size.
pageCountStrings.push({
key: 'selectalluserswithcount',
component: 'core',
param: defaultPageSize,
});
if (checkCountButton) {
// The 'Check all [x]' button is only visible when there are values to set.
checkCountButton.classList.add('hidden');
}
} else {
pageCountStrings.push({
key: 'selectalluserswithcount',
component: 'core',
param: totalRowCount,
});
if (checkCountButton) {
checkCountButton.classList.remove('hidden');
}
}
Str.get_strings(pageCountStrings)
.then(([showingParticipantCountString, selectCountString]) => {
const showingParticipantCount = root.querySelector(Selectors.showCountText);
showingParticipantCount.innerHTML = showingParticipantCountString;
if (selectCountString && checkCountButton) {
checkCountButton.value = selectCountString;
}
return;
})
.catch(Notification.exception);
});
};
const resetBulkAction = bulkActionSelect => {
bulkActionSelect.value = '';
};
registerEventListeners();
};
+125
View File
@@ -0,0 +1,125 @@
// 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/>.
/**
* Participants filter management.
*
* @module core_user/participants_filter
* @copyright 2021 Tomo Tsuyuki <tomotsuyuki@catalyst-au.net>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
import CoreFilter from 'core/datafilter';
import * as DynamicTable from 'core_table/dynamic';
import Selectors from 'core/datafilter/selectors';
import Notification from 'core/notification';
import Pending from 'core/pending';
/**
* Initialise the participants filter on the element with the given id.
*
* @param {String} filterRegionId The id for the filter element.
*/
export const init = filterRegionId => {
const filterSet = document.getElementById(filterRegionId);
// Create and initialize filter.
const coreFilter = new CoreFilter(filterSet, function(filters, pendingPromise) {
DynamicTable.setFilters(
DynamicTable.getTableFromId(filterSet.dataset.tableRegion),
{
jointype: parseInt(filterSet.querySelector(Selectors.filterset.fields.join).value, 10),
filters,
}
)
.then(result => {
pendingPromise.resolve();
return result;
})
.catch(Notification.exception);
});
coreFilter.init();
/**
* Set the current filter options based on a provided configuration.
*
* @param {Object} config
* @param {Number} config.jointype
* @param {Object} config.filters
* @returns {Promise}
*/
const setFilterFromConfig = config => {
const filterConfig = Object.entries(config.filters);
if (!filterConfig.length) {
// There are no filters to set from.
return Promise.resolve();
}
// Set the main join type.
filterSet.querySelector(Selectors.filterset.fields.join).value = config.jointype;
const filterPromises = filterConfig.map(([filterType, filterData]) => {
if (filterType === 'courseid') {
// The courseid is a special case.
return false;
}
const filterValues = filterData.values;
if (!filterValues.length) {
// There are no values for this filter.
// Skip it.
return false;
}
return coreFilter.addFilterRow()
.then(([filterRow]) => {
coreFilter.addFilter(filterRow, filterType, filterValues);
return;
});
}).filter(promise => promise);
if (!filterPromises.length) {
return Promise.resolve();
}
return Promise.all(filterPromises)
.then(() => {
return coreFilter.removeEmptyFilters();
})
.then(() => {
coreFilter.updateFiltersOptions();
return;
})
.then(() => {
coreFilter.updateTableFromFilter();
return;
});
};
// Initialize DynamicTable for showing result.
const tableRoot = DynamicTable.getTableFromId(filterSet.dataset.tableRegion);
const initialFilters = DynamicTable.getFilters(tableRoot);
if (initialFilters) {
const initialFilterPromise = new Pending('core/filter:setFilterFromConfig');
// Apply the initial filter configuration.
setFilterFromConfig(initialFilters)
.then(() => initialFilterPromise.resolve())
.catch();
}
};
+67
View File
@@ -0,0 +1,67 @@
// 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/>.
/**
* Module to handle AJAX interactions with user private files
*
* @module core_user/private_files
* @copyright 2020 Marina Glancy
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
import DynamicForm from 'core_form/dynamicform';
import ModalForm from 'core_form/modalform';
import {getString} from 'core/str';
import {add as addToast} from 'core/toast';
/**
* Initialize private files form as AJAX form
*
* @param {String} containerSelector
* @param {String} formClass
*/
export const initDynamicForm = (containerSelector, formClass) => {
const form = new DynamicForm(document.querySelector(containerSelector), formClass);
// When form is saved, refresh it to remove validation errors, if any:
form.addEventListener(form.events.FORM_SUBMITTED, () => {
form.load();
getString('changessaved')
.then(addToast)
.catch(null);
});
// Reload the page on cancel.
form.addEventListener(form.events.CANCEL_BUTTON_PRESSED, () => window.location.reload());
};
/**
* Initialize private files form as Modal form
*
* @param {String} elementSelector
* @param {String} formClass
*/
export const initModal = (elementSelector, formClass) => {
document.querySelector(elementSelector).addEventListener('click', function(e) {
e.preventDefault();
const form = new ModalForm({
formClass,
args: {nosubmit: true},
modalConfig: {title: getString('privatefilesmanage')},
returnFocus: e.target,
});
form.addEventListener(form.events.FORM_SUBMITTED, () => window.location.reload());
form.show();
});
};
+121
View File
@@ -0,0 +1,121 @@
// 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/>.
/**
* Module to handle AJAX interactions.
*
* @module core_user/repository
* @copyright 2020 Andrew Nicols <andrew@nicols.co.uk>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
import {call as fetchMany} from 'core/ajax';
/**
* Get single user preference
*
* @param {String} name Name of the preference
* @param {Number} userid User ID (defaults to current user)
* @return {Promise}
*/
export const getUserPreference = (name, userid = 0) => {
return getUserPreferences(name, userid)
.then(response => response.preferences[0].value);
};
/**
* Get multiple user preferences
*
* @param {String|null} name Name of the preference (omit if you want to retrieve all)
* @param {Number} userid User ID (defaults to current user)
* @return {Promise}
*/
export const getUserPreferences = (name = null, userid = 0) => {
return fetchMany([{
methodname: 'core_user_get_user_preferences',
args: {name, userid}
}])[0];
};
/**
* Set single user preference
*
* @param {String} name Name of the preference
* @param {String|null} value Value of the preference (omit if you want to remove the current value)
* @param {Number} userid User ID (defaults to current user)
* @return {Promise}
*/
export const setUserPreference = (name, value = null, userid = 0) => {
return setUserPreferences([{name, value, userid}]);
};
/**
* Set multiple user preferences
*
* @param {Object[]} preferences Array of preferences containing name/value/userid attributes
* @return {Promise}
*/
export const setUserPreferences = (preferences) => {
return fetchMany([{
methodname: 'core_user_set_user_preferences',
args: {preferences}
}])[0];
};
/**
* Unenrol the user with the specified user enrolmentid ID.
*
* @param {Number} userEnrolmentId
* @return {Promise}
*/
export const unenrolUser = userEnrolmentId => {
return fetchMany([{
methodname: 'core_enrol_unenrol_user_enrolment',
args: {
ueid: userEnrolmentId,
},
}])[0];
};
/**
* Submit the user enrolment form with the specified form data.
*
* @param {String} formdata
* @return {Promise}
*/
export const submitUserEnrolmentForm = formdata => {
return fetchMany([{
methodname: 'core_enrol_submit_user_enrolment_form',
args: {
formdata,
},
}])[0];
};
export const createNotesForUsers = notes => {
return fetchMany([{
methodname: 'core_notes_create_notes',
args: {
notes
}
}])[0];
};
export const sendMessagesToUsers = messages => {
return fetchMany([{
methodname: 'core_message_send_instant_messages',
args: {messages}
}])[0];
};
+362
View File
@@ -0,0 +1,362 @@
// 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/>.
/**
* AMD module for the user enrolment status field in the course participants page.
*
* @module core_user/status_field
* @copyright 2017 Jun Pataleta
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
import * as DynamicTable from 'core_table/dynamic';
import * as Repository from './repository';
import * as Str from 'core/str';
import DynamicTableSelectors from 'core_table/local/dynamic/selectors';
import Fragment from 'core/fragment';
import ModalEvents from 'core/modal_events';
import Notification from 'core/notification';
import Templates from 'core/templates';
import {add as notifyUser} from 'core/toast';
import SaveCancelModal from 'core/modal_save_cancel';
import CancelModal from 'core/modal_cancel';
const Selectors = {
editEnrolment: '[data-action="editenrolment"]',
showDetails: '[data-action="showdetails"]',
unenrol: '[data-action="unenrol"]',
statusElement: '[data-status]',
};
/**
* Get the dynamic table from the specified link.
*
* @param {HTMLElement} link
* @returns {HTMLElement}
*/
const getDynamicTableFromLink = link => link.closest(DynamicTableSelectors.main.region);
/**
* Get the status container from the specified link.
*
* @param {HTMLElement} link
* @returns {HTMLElement}
*/
const getStatusContainer = link => link.closest(Selectors.statusElement);
/**
* Get user enrolment id from the specified link
*
* @param {HTMLElement} link
* @returns {Number}
*/
const getUserEnrolmentIdFromLink = link => link.getAttribute('rel');
/**
* Register all event listeners for the status fields.
*
* @param {Number} contextId
* @param {Number} uniqueId
*/
const registerEventListeners = (contextId, uniqueId) => {
const getBodyFunction = (userEnrolmentId, formData) => getBody(contextId, userEnrolmentId, formData);
document.addEventListener('click', e => {
const tableRoot = e.target.closest(DynamicTableSelectors.main.fromRegionId(uniqueId));
if (!tableRoot) {
return;
}
const editLink = e.target.closest(Selectors.editEnrolment);
if (editLink) {
e.preventDefault();
showEditDialogue(editLink, getBodyFunction);
}
const unenrolLink = e.target.closest(Selectors.unenrol);
if (unenrolLink) {
e.preventDefault();
showUnenrolConfirmation(unenrolLink);
}
const showDetailsLink = e.target.closest(Selectors.showDetails);
if (showDetailsLink) {
e.preventDefault();
showStatusDetails(showDetailsLink);
}
});
};
/**
* Show the edit dialogue.
*
* @param {HTMLElement} link
* @param {Function} getBody Function to get the body for the specified user enrolment
*/
const showEditDialogue = (link, getBody) => {
const container = getStatusContainer(link);
const userEnrolmentId = getUserEnrolmentIdFromLink(link);
SaveCancelModal.create({
large: true,
title: Str.get_string('edituserenrolment', 'enrol', container.dataset.fullname),
body: getBody(userEnrolmentId)
})
.then(modal => {
// Handle save event.
modal.getRoot().on(ModalEvents.save, e => {
// Don't close the modal yet.
e.preventDefault();
// Submit form data.
submitEditFormAjax(link, getBody, modal, userEnrolmentId, container.dataset);
});
// Handle hidden event.
modal.getRoot().on(ModalEvents.hidden, () => {
// Destroy when hidden.
modal.destroy();
});
// Show the modal.
modal.show();
return modal;
})
.catch(Notification.exception);
};
/**
* Show and handle the unenrolment confirmation dialogue.
*
* @param {HTMLElement} link
*/
const showUnenrolConfirmation = link => {
const container = getStatusContainer(link);
const userEnrolmentId = getUserEnrolmentIdFromLink(link);
SaveCancelModal.create()
.then(modal => {
// Handle confirm event.
modal.getRoot().on(ModalEvents.save, e => {
// Don't close the modal yet.
e.preventDefault();
// Submit data.
submitUnenrolFormAjax(
link,
modal,
{
ueid: userEnrolmentId,
},
container.dataset
);
});
// Handle hidden event.
modal.getRoot().on(ModalEvents.hidden, () => {
// Destroy when hidden.
modal.destroy();
});
// Display the delete confirmation modal.
modal.show();
const stringData = [
{
key: 'unenrol',
component: 'enrol',
},
{
key: 'unenrolconfirm',
component: 'enrol',
param: {
user: container.dataset.fullname,
course: container.dataset.coursename,
enrolinstancename: container.dataset.enrolinstancename,
}
}
];
return Promise.all([Str.get_strings(stringData), modal]);
})
.then(([strings, modal]) => {
modal.setTitle(strings[0]);
modal.setSaveButtonText(strings[0]);
modal.setBody(strings[1]);
return modal;
})
.catch(Notification.exception);
};
/**
* Show the user details dialogue.
*
* @param {HTMLElement} link
*/
const showStatusDetails = link => {
const container = getStatusContainer(link);
const context = {
editenrollink: '',
statusclass: container.querySelector('span.badge').getAttribute('class'),
...container.dataset,
};
// Find the edit enrolment link.
const editEnrolLink = container.querySelector(Selectors.editEnrolment);
if (editEnrolLink) {
// If there's an edit enrolment link for this user, clone it into the context for the modal.
context.editenrollink = editEnrolLink.outerHTML;
}
CancelModal.create({
large: true,
title: Str.get_string('enroldetails', 'enrol'),
body: Templates.render('core_user/status_details', context),
})
.then(modal => {
if (editEnrolLink) {
modal.getRoot().on('click', Selectors.editEnrolment, e => {
e.preventDefault();
modal.hide();
// Trigger click event for the edit enrolment link to show the edit enrolment modal.
editEnrolLink.click();
});
}
modal.show();
// Handle hidden event.
modal.getRoot().on(ModalEvents.hidden, () => modal.destroy());
return modal;
})
.catch(Notification.exception);
};
/**
* Submit the edit dialogue.
*
* @param {HTMLElement} clickedLink
* @param {Function} getBody
* @param {Object} modal
* @param {Number} userEnrolmentId
* @param {Object} userData
*/
const submitEditFormAjax = (clickedLink, getBody, modal, userEnrolmentId, userData) => {
const form = modal.getRoot().find('form');
Repository.submitUserEnrolmentForm(form.serialize())
.then(data => {
if (!data.result) {
throw data.result;
}
// Dismiss the modal.
modal.hide();
modal.destroy();
return data;
})
.then(() => {
DynamicTable.refreshTableContent(getDynamicTableFromLink(clickedLink))
.catch(Notification.exception);
return Str.get_string('enrolmentupdatedforuser', 'core_enrol', userData);
})
.then(notificationString => {
notifyUser(notificationString);
return;
})
.catch(() => {
modal.setBody(getBody(userEnrolmentId, JSON.stringify(form.serialize())));
return modal;
});
};
/**
* Submit the unenrolment form.
*
* @param {HTMLElement} clickedLink
* @param {Object} modal
* @param {Object} args
* @param {Object} userData
*/
const submitUnenrolFormAjax = (clickedLink, modal, args, userData) => {
Repository.unenrolUser(args.ueid)
.then(data => {
if (!data.result) {
// Display an alert containing the error message
Notification.alert(data.errors[0].key, data.errors[0].message);
return data;
}
// Dismiss the modal.
modal.hide();
modal.destroy();
return data;
})
.then(() => {
DynamicTable.refreshTableContent(getDynamicTableFromLink(clickedLink))
.catch(Notification.exception);
return Str.get_string('unenrolleduser', 'core_enrol', userData);
})
.then(notificationString => {
notifyUser(notificationString);
return;
})
.catch(Notification.exception);
};
/**
* Get the body fragment.
*
* @param {Number} contextId
* @param {Number} ueid The user enrolment id
* @param {Object} formdata
* @returns {Promise}
*/
const getBody = (contextId, ueid, formdata = null) => Fragment.loadFragment(
'enrol',
'user_enrolment_form',
contextId,
{
ueid,
formdata,
}
);
/**
* Initialise the statu field handler.
*
* @param {object} param
* @param {Number} param.contextid
* @param {Number} param.uniqueid
*/
export const init = ({contextid, uniqueid}) => {
registerEventListeners(contextid, uniqueid);
};