weekly release 4.0dev
[moodle.git] / user / amd / build / participantsfilter.min.js
1 function _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","core/custom_interaction_events","jquery"],function(a,b,c,d,e,f,g,h,i,j,k){"use strict";Object.defineProperty(a,"__esModule",{value:!0});a.init=void 0;b=n(b);c=m(c);d=n(d);f=n(f);g=n(g);h=n(h);i=n(i);j=n(j);k=n(k);var A="undefined"!=typeof window?window:"undefined"!=typeof self?self:"undefined"!=typeof global?global:{};function l(){if("function"!=typeof WeakMap)return null;var a=new WeakMap;l=function(){return a};return a}function m(a){if(a&&a.__esModule){return a}if(null===a||"object"!==_typeof(a)&&"function"!=typeof a){return{default:a}}var b=l();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 n(a){return a&&a.__esModule?a:{default:a}}function o(a){return r(a)||q(a)||u(a)||p()}function p(){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 q(a){if("undefined"!=typeof Symbol&&Symbol.iterator in Object(a))return Array.from(a)}function r(a){if(Array.isArray(a))return v(a)}function s(a,b){return x(a)||w(a,b)||u(a,b)||t()}function t(){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 u(a,b){if(!a)return;if("string"==typeof a)return v(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 v(a,b)}function v(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 w(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 x(a){if(Array.isArray(a))return a}function y(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 z(a){return function(){var b=this,c=arguments;return new Promise(function(d,e){var h=a.apply(b,c);function f(a){y(h,d,e,f,g,"next",a)}function g(a){y(h,d,e,f,g,"throw",a)}f(void 0)})}}var B=function(a){var l=document.querySelector("#".concat(a)),m={courseid:new b.default("courseid",l)},n=function(){return l.querySelector(h.default.filterset.regions.filterlist)},p=function(){var a=new g.default("core_user/participantsfilter:addFilterRow"),b=1+n().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(n(),b,c);return d}).then(function(a){var b=l.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){C();return a}).then(function(b){a.resolve();return b}).catch(f.default.exception)},q=function(a){var b=l.querySelector(h.default.filterset.regions.datasource);return b.querySelector(h.default.data.fields.byName(a))},r=function(){var a=z(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=q(c);g=d.default;if(!f.dataset.filterTypeClass){a.next=7;break}a.next=6;return"function"==typeof A.define&&A.define.amd?new Promise(function(a,b){A.require([f.dataset.filterTypeClass],a,b)}):"undefined"!=typeof module&&module.exports&&"undefined"!=typeof require||"undefined"!=typeof module&&module.component&&A.require&&"component"===A.require.loader?Promise.resolve(require((f.dataset.filterTypeClass))):Promise.resolve(A[f.dataset.filterTypeClass]);case 6:g=a.sent;case 7:m[c]=new g(c,l,e);i=b.querySelector(h.default.filter.fields.type);i.value=c;i.disabled="disabled";C();return a.abrupt("return",m[c]);case 13:case"end":return a.stop();}}},a)}));return function(){return a.apply(this,arguments)}}(),t=function(a){return m[a]},u=function(a,b){var c=n().querySelectorAll(h.default.filter.region).length;if(1===c){w(a,b)}else{v(a,b)}},v=function(){var a=z(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;x(b.dataset.filterType);b.remove();C();if(e&&c){E()}a.next=9;return F();case 9:f=a.sent;n().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)}}(),w=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;x(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=l.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){C();return a}).then(function(a){if(b){return E()}else{return a}}).catch(f.default.exception)},x=function(a){if(a){var b=t(a);if(b){b.tearDown();delete m[a]}}},y=function(){var a=new g.default("core_user/participantsfilter:setFilterFromConfig"),b=n().querySelectorAll(h.default.filter.region);b.forEach(function(a){return u(a,!1)});return E().then(function(b){a.resolve();return b})},B=function(){var a=n().querySelectorAll(h.default.filter.region);a.forEach(function(a){var b=a.querySelector(h.default.filter.fields.type);if(!b.value){u(a,!1)}})},C=function(){var a=n().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(m[b.value]){b.classList.add("hidden");b.disabled=!0}else{b.classList.remove("hidden");b.disabled=!1}})});var b=l.querySelector(h.default.filterset.actions.addRow),c=l.querySelectorAll(h.default.data.fields.all);if(c.length<=a.length){b.setAttribute("disabled","disabled")}else{b.removeAttribute("disabled")}if(1===a.length){l.querySelector(h.default.filterset.regions.filtermatch).classList.add("hidden");l.querySelector(h.default.filterset.fields.join).value=2;l.dataset.filterverb=2}else{l.querySelector(h.default.filterset.regions.filtermatch).classList.remove("hidden")}},D=function(a){var b=Object.entries(a.filters);if(!b.length){return Promise.resolve()}l.querySelector(h.default.filterset.fields.join).value=a.jointype;var c=b.map(function(a){var b=s(a,2),c=b[0],d=b[1];if("courseid"===c){return!1}var e=d.values;if(!e.length){return!1}return p().then(function(a){var b=s(a,1),d=b[0];return r(d,c,e)})}).filter(function(a){return a});if(!c.length){return Promise.resolve()}return Promise.all(c).then(function(){return B()}).then(C).then(E)},E=function(){var a=new g.default("core_user/participantsfilter:updateTableFromFilter"),b={};Object.values(m).forEach(function(a){b[a.filterValue.name]=a.filterValue});return c.setFilters(c.getTableFromId(l.dataset.tableRegion),{jointype:parseInt(l.querySelector(h.default.filterset.fields.join).value,10),filters:b}).then(function(b){a.resolve();return b}).catch(f.default.exception)},F=function(){var a=z(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=[];o(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)}}();l.querySelector(h.default.filterset.region).addEventListener("click",function(a){if(a.target.closest(h.default.filterset.actions.addRow)){a.preventDefault();p()}if(a.target.closest(h.default.filterset.actions.applyFilters)){a.preventDefault();E()}if(a.target.closest(h.default.filterset.actions.resetFilters)){a.preventDefault();y()}});l.querySelector(h.default.filterset.regions.filterlist).addEventListener("click",function(a){if(a.target.closest(h.default.filter.actions.remove)){a.preventDefault();u(a.target.closest(h.default.filter.region),!0)}});var G=(0,k.default)(n());j.default.define(G,[j.default.events.accessibleChange]);G.on(j.default.events.accessibleChange,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);r(c,b.value)}});l.querySelector(h.default.filterset.fields.join).addEventListener("change",function(a){l.dataset.filterverb=a.target.value});var H=c.getTableFromId(l.dataset.tableRegion),I=c.getFilters(H);if(I){var J=new g.default("core_user/participantsfilter:setFilterFromConfig");D(I).then(function(){return J.resolve()}).catch()}};a.init=B});
2 //# sourceMappingURL=participantsfilter.min.js.map