2022-02-18 09:19:38 +08:00
|
|
|
*/Object.defineProperty(_exports,"__esModule",{value:!0}),_exports.registerEventListeners=void 0,_ajax=_interopRequireDefault(_ajax),_notification=_interopRequireDefault(_notification);const Selectors={regions:{root:'[data-region="core/userfeedback"]'},actions:{}};Selectors.actions.give="".concat(Selectors.regions.root,' [data-action="give"]'),Selectors.actions.remind="".concat(Selectors.regions.root,' [data-action="remind"]');_exports.registerEventListeners=()=>{document.addEventListener("click",(e=>{const giveAction=e.target.closest(Selectors.actions.give);if(giveAction){if(e.preventDefault(),!window.open(giveAction.href))throw new Error("Unable to open popup");Promise.resolve(giveAction).then(hideRoot).then(recordAction).catch(_notification.default.exception)}const remindAction=e.target.closest(Selectors.actions.remind);remindAction&&(e.preventDefault(),Promise.resolve(remindAction).then(hideRoot).then(recordAction).catch(_notification.default.exception))}))};const recordAction=clickedItem=>clickedItem.dataset.record?_ajax.default.call([{methodname:"core_create_userfeedback_action_record",args:{action:clickedItem.dataset.action,contextid:M.cfg.contextid}}])[0]:Promise.resolve(),hideRoot=clickedItem=>(clickedItem.dataset.hide&&clickedItem.closest(Selectors.regions.root).remove(),clickedItem)}));
|