MDL-68977 enrol_manual: Add pending promises to enrol modal
[moodle.git] / user / amd / build / participantsfilter.min.js
CommitLineData
7b3026fa 1function _typeof(a){"@babel/helpers - typeof";if("function"==typeof Symbol&&"symbol"==typeof Symbol.iterator){_typeof=function(a){return typeof a}}else{_typeof=function(a){return a&&"function"==typeof Symbol&&a.constructor===Symbol&&a!==Symbol.prototype?"symbol":typeof a}}return _typeof(a)}define ("core_user/participantsfilter",["exports","./local/participantsfilter/filtertypes/courseid","core_table/dynamic","./local/participantsfilter/filter","core/str","core/notification","core/pending","./local/participantsfilter/selectors","core/templates"],function(a,b,c,d,e,f,g,h,i){"use strict";Object.defineProperty(a,"__esModule",{value:!0});a.init=void 0;b=l(b);c=k(c);d=l(d);f=l(f);g=l(g);h=l(h);i=l(i);var y="undefined"!=typeof window?window:"undefined"!=typeof self?self:"undefined"!=typeof global?global:{};function j(){if("function"!=typeof WeakMap)return null;var a=new WeakMap;j=function(){return a};return a}function k(a){if(a&&a.__esModule){return a}if(null===a||"object"!==_typeof(a)&&"function"!=typeof a){return{default:a}}var b=j();if(b&&b.has(a)){return b.get(a)}var c={},d=Object.defineProperty&&Object.getOwnPropertyDescriptor;for(var e in a){if(Object.prototype.hasOwnProperty.call(a,e)){var f=d?Object.getOwnPropertyDescriptor(a,e):null;if(f&&(f.get||f.set)){Object.defineProperty(c,e,f)}else{c[e]=a[e]}}}c.default=a;if(b){b.set(a,c)}return c}function l(a){return a&&a.__esModule?a:{default:a}}function m(a){return p(a)||o(a)||s(a)||n()}function n(){throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}function o(a){if("undefined"!=typeof Symbol&&Symbol.iterator in Object(a))return Array.from(a)}function p(a){if(Array.isArray(a))return t(a)}function q(a,b){return v(a)||u(a,b)||s(a,b)||r()}function r(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}function s(a,b){if(!a)return;if("string"==typeof a)return t(a,b);var c=Object.prototype.toString.call(a).slice(8,-1);if("Object"===c&&a.constructor)c=a.constructor.name;if("Map"===c||"Set"===c)return Array.from(c);if("Arguments"===c||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(c))return t(a,b)}function t(a,b){if(null==b||b>a.length)b=a.length;for(var c=0,d=Array(b);c<b;c++){d[c]=a[c]}return d}function u(a,b){if("undefined"==typeof Symbol||!(Symbol.iterator in Object(a)))return;var c=[],d=!0,e=!1,f=void 0;try{for(var g=a[Symbol.iterator](),h;!(d=(h=g.next()).done);d=!0){c.push(h.value);if(b&&c.length===b)break}}catch(a){e=!0;f=a}finally{try{if(!d&&null!=g["return"])g["return"]()}finally{if(e)throw f}}return c}function v(a){if(Array.isArray(a))return a}function w(a,b,c,d,e,f,g){try{var h=a[f](g),i=h.value}catch(a){c(a);return}if(h.done){b(i)}else{Promise.resolve(i).then(d,e)}}function x(a){return function(){var b=this,c=arguments;return new Promise(function(d,e){var h=a.apply(b,c);function f(a){w(h,d,e,f,g,"next",a)}function g(a){w(h,d,e,f,g,"throw",a)}f(void 0)})}}var z=function(a){var j=document.querySelector("#".concat(a)),k={courseid:new b.default("courseid",j)},l=function(){return j.querySelector(h.default.filterset.regions.filterlist)},n=function(){var a=new g.default("core_user/participantsfilter:addFilterRow"),b=1+l().querySelectorAll(h.default.filter.region).length;return i.default.renderForPromise("core_user/local/participantsfilter/filterrow",{rownumber:b}).then(function(a){var b=a.html,c=a.js,d=i.default.appendNodeContents(l(),b,c);return d}).then(function(a){var b=j.querySelector(h.default.data.typeList);a.forEach(function(a){var c=a.querySelector(h.default.filter.fields.type);if(c){c.innerHTML=b.innerHTML}});return a}).then(function(a){A();return a}).then(function(b){a.resolve();return b}).catch(f.default.exception)},o=function(a){var b=j.querySelector(h.default.filterset.regions.datasource);return b.querySelector(h.default.data.fields.byName(a))},p=function(){var a=x(regeneratorRuntime.mark(function a(b,c,e){var f,g,i;return regeneratorRuntime.wrap(function(a){while(1){switch(a.prev=a.next){case 0:b.dataset.filterType=c;f=o(c);g=d.default;if(!f.dataset.filterTypeClass){a.next=7;break}a.next=6;return"function"==typeof y.define&&y.define.amd?new Promise(function(a,b){y.require([f.dataset.filterTypeClass],a,b)}):"undefined"!=typeof module&&module.exports&&"undefined"!=typeof require||"undefined"!=typeof module&&module.component&&y.require&&"component"===y.require.loader?Promise.resolve(require((f.dataset.filterTypeClass))):Promise.resolve(y[f.dataset.filterTypeClass]);case 6:g=a.sent;case 7:k[c]=new g(c,j,e);i=b.querySelector(h.default.filter.fields.type);i.value=c;i.disabled="disabled";A();return a.abrupt("return",k[c]);case 13:case"end":return a.stop();}}},a)}));return function(){return a.apply(this,arguments)}}(),r=function(a){return k[a]},s=function(a,b){var c=l().querySelectorAll(h.default.filter.region).length;if(1===c){u(a,b)}else{t(a,b)}},t=function(){var a=x(regeneratorRuntime.mark(function a(b){var c,d,e,f,g=arguments;return regeneratorRuntime.wrap(function(a){while(1){switch(a.prev=a.next){case 0:c=1<g.length&&g[1]!==void 0?g[1]:!0;d=b.querySelector(h.default.filter.fields.type);e=!!d.value;v(b.dataset.filterType);b.remove();A();if(e&&c){C()}a.next=9;return D();case 9:f=a.sent;l().querySelectorAll(h.default.filter.region).forEach(function(a,b){a.querySelector("legend").innerText=f[b]});case 11:case"end":return a.stop();}}},a)}));return function(){return a.apply(this,arguments)}}(),u=function(a){var b=1<arguments.length&&arguments[1]!==void 0?arguments[1]:!0,c=2<arguments.length&&arguments[2]!==void 0?arguments[2]:1;v(a.dataset.filterType);return i.default.renderForPromise("core_user/local/participantsfilter/filterrow",{rownumber:c}).then(function(b){var c=b.html,d=b.js,e=i.default.replaceNode(a,c,d);return e}).then(function(a){var b=j.querySelector(h.default.data.typeList);a.forEach(function(a){var c=a.querySelector(h.default.filter.fields.type);if(c){c.innerHTML=b.innerHTML}});return a}).then(function(a){A();return a}).then(function(a){if(b){return C()}else{return a}}).catch(f.default.exception)},v=function(a){if(a){var b=r(a);if(b){b.tearDown();delete k[a]}}},w=function(){var a=new g.default("core_user/participantsfilter:setFilterFromConfig"),b=l().querySelectorAll(h.default.filter.region);b.forEach(function(a){return s(a,!1)});return C().then(function(b){a.resolve();return b})},z=function(){var a=l().querySelectorAll(h.default.filter.region);a.forEach(function(a){var b=a.querySelector(h.default.filter.fields.type);if(!b.value){s(a,!1)}})},A=function(){var a=l().querySelectorAll(h.default.filter.region);a.forEach(function(a){var b=a.querySelectorAll(h.default.filter.fields.type+" option");b.forEach(function(b){if(b.value===a.dataset.filterType){b.classList.remove("hidden");b.disabled=!1}else if(k[b.value]){b.classList.add("hidden");b.disabled=!0}else{b.classList.remove("hidden");b.disabled=!1}})});var b=j.querySelector(h.default.filterset.actions.addRow),c=j.querySelectorAll(h.default.data.fields.all);if(c.length<=a.length){b.setAttribute("disabled","disabled")}else{b.removeAttribute("disabled")}if(1===a.length){j.querySelector(h.default.filterset.regions.filtermatch).classList.add("hidden");j.querySelector(h.default.filterset.fields.join).value=1}else{j.querySelector(h.default.filterset.regions.filtermatch).classList.remove("hidden")}},B=function(a){var b=Object.entries(a.filters);if(!b.length){return Promise.resolve()}j.querySelector(h.default.filterset.fields.join).value=a.jointype;var c=b.map(function(a){var b=q(a,2),c=b[0],d=b[1];if("courseid"===c){return!1}var e=d.values;if(!e.length){return!1}return n().then(function(a){var b=q(a,1),d=b[0];return p(d,c,e)})}).filter(function(a){return a});if(!c.length){return Promise.resolve()}return Promise.all(c).then(function(){return z()}).then(A).then(C)},C=function(){var a=new g.default("core_user/participantsfilter:updateTableFromFilter"),b={};Object.values(k).forEach(function(a){b[a.filterValue.name]=a.filterValue});return c.setFilters(c.getTableFromId(j.dataset.tableRegion),{jointype:parseInt(j.querySelector(h.default.filterset.fields.join).value,10),filters:b}).then(function(b){a.resolve();return b}).catch(f.default.exception)},D=function(){var a=x(regeneratorRuntime.mark(function a(){var b,c,d;return regeneratorRuntime.wrap(function(a){while(1){switch(a.prev=a.next){case 0:b=document.querySelector(h.default.data.typeListSelect).length-1;c=[];m(Array(b)).forEach(function(a,b){c.push({key:"filterrowlegend",component:"core_user",param:b+1})});a.next=5;return(0,e.get_strings)(c).then(function(a){return a}).catch(f.default.exception);case 5:d=a.sent;return a.abrupt("return",d);case 7:case"end":return a.stop();}}},a)}));return function(){return a.apply(this,arguments)}}();j.querySelector(h.default.filterset.region).addEventListener("click",function(a){if(a.target.closest(h.default.filterset.actions.addRow)){a.preventDefault();n()}if(a.target.closest(h.default.filterset.actions.applyFilters)){a.preventDefault();C()}if(a.target.closest(h.default.filterset.actions.resetFilters)){a.preventDefault();w()}});j.querySelector(h.default.filterset.regions.filterlist).addEventListener("click",function(a){if(a.target.closest(h.default.filter.actions.remove)){a.preventDefault();s(a.target.closest(h.default.filter.region),!0)}});j.querySelector(h.default.filterset.regions.filterlist).addEventListener("change",function(a){var b=a.target.closest(h.default.filter.fields.type);if(b&&b.value){var c=a.target.closest(h.default.filter.region);p(c,b.value)}});j.querySelector(h.default.filterset.fields.join).addEventListener("change",function(a){j.dataset.filterverb=a.target.value});var E=c.getTableFromId(j.dataset.tableRegion),F=c.getFilters(E);if(F){var G=new g.default("core_user/participantsfilter:setFilterFromConfig");B(F).then(function(){return G.resolve()}).catch()}};a.init=z});
77ba77f1 2//# sourceMappingURL=participantsfilter.min.js.map