on-demand release 4.0dev+
[moodle.git] / mod / forum / report / summary / amd / build / filters.min.js
CommitLineData
530322e2 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 ("forumreport_summary/filters",["exports","jquery","core/popper","core/custom_interaction_events","forumreport_summary/selectors","core/ajax","core/key_codes","core_form/changechecker"],function(a,b,c,d,e,f,g,h){"use strict";Object.defineProperty(a,"__esModule",{value:!0});a.init=void 0;b=k(b);c=k(c);d=k(d);e=k(e);f=k(f);g=k(g);h=j(h);function i(){if("function"!=typeof WeakMap)return null;var a=new WeakMap;i=function(){return a};return a}function j(a){if(a&&a.__esModule){return a}if(null===a||"object"!==_typeof(a)&&"function"!=typeof a){return{default:a}}var b=i();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 k(a){return a&&a.__esModule?a:{default:a}}var l=function(a){var i=(0,b.default)(a);(0,b.default)(document).ready(function(){(0,b.default)(".loading-icon").hide();(0,b.default)("#summaryreport").removeClass("hidden")});var j=function(a,b){var c=document.forms.filtersform.action,d;if(a){a.preventDefault();var e=c.split("?"),f=e[1],g=b.split("&"),h="",i=[],j=[];f.split("&").forEach(function(a){var b=a.split("=");i.push(b[0]);j.push(b[1])});g.forEach(function(a){var b=a.split("="),c=i.indexOf(b[0]);if(-1<c){j[c]=b[1]}else{i.push(b[0]);j.push(b[1])}});i.forEach(function(a,b){h+="&".concat(a,"=").concat(j[b])});d=e[0]+"?"+h.substr(1)}else{d=c}document.forms.filtersform.action=d;document.forms.filtersform.submit()};(0,b.default)(".resettable").on("click","a",function(a){j(a,a.target.search.substr(1))});(0,b.default)("thead").on("click","a",function(a){j(a,a.target.search.substr(1))});(0,b.default)(".pagination").on("click","a",function(a){j(a,a.target.search.substr(1))});if(document.forms.selectperpage){document.forms.selectperpage.onsubmit=function(a){var b="perpage="+document.forms.selectperpage.elements.perpage.value;j(a,b)}}var k=document.getElementById("summaryreport").querySelector("form.dataformatselector");if(k){k.onsubmit=function(a){var b=k.querySelector("#downloadtype_download").value,c="download=".concat(b),d=document.forms.filtersform.action;j(a,c);document.forms.filtersform.action=d}}var l=function(a){h.unWatchForm(document.forms.filtersform);(0,b.default)(a).addClass("hidden");j(!1)},m=function(a){var b=document.querySelector(a),d=document.querySelector(e.default.filters.date.calendar);d.style.removeProperty("z-index");new c.default(b,d,{placement:"bottom"})},n=function(a,b){b.classList.add("hidden");b.setAttribute("data-openfilter","false");a.classList.add("btn-primary");a.classList.remove("btn-outline-primary");a.setAttribute("aria-expanded",!1)};i.on(d.default.events.activate,e.default.filters.group.selectall,function(){var b=a.querySelectorAll(e.default.filters.group.checkbox+":not(:checked)");b.forEach(function(a){a.checked=!0})});i.on(d.default.events.activate,e.default.filters.group.clear,function(){var b=a.querySelectorAll(e.default.filters.group.checkbox+":checked");b.forEach(function(a){a.checked=!1})});i.on(d.default.events.activate,e.default.filters.group.trigger,function(){var b=a.querySelector(e.default.filters.group.trigger),d=a.querySelector(e.default.filters.group.popover);new c.default(b,d,{placement:"bottom"});d.classList.remove("hidden");d.setAttribute("data-openfilter","true");b.classList.add("btn-outline-primary");b.classList.remove("btn-primary");b.setAttribute("aria-expanded",!0);var f=function(a){if(a.target.id!==b.id&&d!==a.target.closest("[data-openfilter=\"true\"]")&&("undefined"==typeof a.keyCode||a.keyCode===g.default.enter||a.keyCode===g.default.space)){n(b,d);document.removeEventListener("click",f);document.removeEventListener("keyup",f);document.removeEventListener("keyup",h)}};document.addEventListener("click",f);document.addEventListener("keyup",f);var h=function(a){if(a.keyCode===g.default.escape){n(b,d);document.removeEventListener("keyup",h);document.removeEventListener("click",f)}};document.addEventListener("keyup",h)});i.on(d.default.events.activate,e.default.filters.group.save,function(){var b=a.querySelectorAll(e.default.filters.group.checkbox);b.forEach(function(a){var b=document.forms.filtersform,c=a.getAttribute("data-saveid");b.querySelector("#".concat(c)).checked=a.checked});l("#filter-groups-popover")});document.querySelectorAll(e.default.filters.exportlink.link).forEach(function(a){a.addEventListener("click",function(a){document.forms.exportlinkform.action=a.target.dataset.url;document.forms.exportlinkform.submit()})});i.on(d.default.events.activate,e.default.filters.date.trigger,function(){var b=a.querySelector(e.default.filters.date.trigger),d=a.querySelector(e.default.filters.date.popover);new c.default(b,d,{placement:"bottom"});d.classList.remove("hidden");d.setAttribute("data-openfilter","true");d.querySelector("[name=\"filterdatefrompopover[enabled]\"]").focus();b.classList.add("btn-outline-primary");b.classList.remove("btn-primary");b.setAttribute("aria-expanded",!0);var f=function(a){if(a.target.id!==b.id&&d!==a.target.closest("[data-openfilter=\"true\"]")&&("undefined"==typeof a.keyCode||a.keyCode===g.default.enter||a.keyCode===g.default.space)){n(b,d);document.removeEventListener("click",f);document.removeEventListener("keyup",f);document.removeEventListener("keyup",h)}};document.addEventListener("click",f);document.addEventListener("keyup",f);var h=function(a){if(a.keyCode===g.default.escape){n(b,d);document.removeEventListener("keyup",h);document.removeEventListener("click",f)}};document.addEventListener("keyup",h)});i.on(d.default.events.activate,e.default.filters.date.save,function(){var b=document.forms.filtersform,c=a.querySelector(e.default.filters.date.popover),d=c.querySelector("[name=\"filterdatefrompopover[enabled]\"]").checked?1:0,g=c.querySelector("[name=\"filterdatetopopover[enabled]\"]").checked?1:0;if(!d&&!g){b.elements["datefrom[timestamp]"].value=0;b.elements["datefrom[enabled]"].value=d;b.elements["dateto[timestamp]"].value=0;b.elements["dateto[enabled]"].value=g;l("#filter-dates-popover")}else{var h={data:[]};if(d){h.data.push({key:"from",year:c.querySelector("[name=\"filterdatefrompopover[year]\"]").value,month:c.querySelector("[name=\"filterdatefrompopover[month]\"]").value,day:c.querySelector("[name=\"filterdatefrompopover[day]\"]").value,hour:0,minute:0})}if(g){h.data.push({key:"to",year:c.querySelector("[name=\"filterdatetopopover[year]\"]").value,month:c.querySelector("[name=\"filterdatetopopover[month]\"]").value,day:c.querySelector("[name=\"filterdatetopopover[day]\"]").value,hour:23,minute:59})}f.default.call([{methodname:"core_calendar_get_timestamps",args:h}])[0].done(function(a){var c=0,e=0;a.timestamps.forEach(function(a){if("from"===a.key){c=a.timestamp}else if("to"===a.key){e=a.timestamp}});if(0<e&&c>e){var f=document.getElementById("dates-filter-warning");f.classList.remove("hidden");f.classList.add("d-block")}else{b.elements["datefrom[timestamp]"].value=c;b.elements["datefrom[enabled]"].value=d;b.elements["dateto[timestamp]"].value=e;b.elements["dateto[enabled]"].value=g;l("#filter-dates-popover")}})}});i.on(d.default.events.activate,e.default.filters.date.calendariconfrom,function(){m(e.default.filters.date.calendariconfrom)});i.on(d.default.events.activate,e.default.filters.date.calendariconto,function(){m(e.default.filters.date.calendariconto)})};a.init=l});
b29de56d 2//# sourceMappingURL=filters.min.js.map