da081b31a79640a57d905d2dcd707415e379b0bc
[moodle.git] / lib / table / amd / build / dynamic.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_table/dynamic",["exports","core_table/local/dynamic/repository","core_table/local/dynamic/selectors","./local/dynamic/events","core/loadingicon"],function(a,b,c,d,e){"use strict";Object.defineProperty(a,"__esModule",{value:!0});Object.defineProperty(a,"Events",{enumerable:!0,get:function get(){return d.default}});a.getTableFromId=a.init=a.showColumn=a.hideColumn=a.getLastInitial=a.setLastInitial=a.getFirstInitial=a.setFirstInitial=a.getPageSize=a.setPageSize=a.getPageNumber=a.setPageNumber=a.setSortOrder=a.getFilters=a.setFilters=a.updateTable=a.refreshTableContent=void 0;c=g(c);d=function(a){return a&&a.__esModule?a:{default:a}}(d);function f(){if("function"!=typeof WeakMap)return null;var a=new WeakMap;f=function(){return a};return a}function g(a){if(a&&a.__esModule){return a}if(null===a||"object"!==_typeof(a)&&"function"!=typeof a){return{default:a}}var b=f();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 g=d?Object.getOwnPropertyDescriptor(a,e):null;if(g&&(g.get||g.set)){Object.defineProperty(c,e,g)}else{c[e]=a[e]}}}c.default=a;if(b){b.set(a,c)}return c}function h(a){return l(a)||k(a)||j(a)||i()}function i(){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 j(a,b){if(!a)return;if("string"==typeof a)return m(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 m(a,b)}function k(a){if("undefined"!=typeof Symbol&&Symbol.iterator in Object(a))return Array.from(a)}function l(a){if(Array.isArray(a))return m(a)}function m(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}var n=!1,o=function(a){if(!a){throw new Error("The table specified is not a dynamic table and cannot be updated")}if(!a.matches(c.main.region)){throw new Error("The table specified is not a dynamic table and cannot be updated")}return!0},p=function(a){return JSON.parse(a.dataset.tableFilters)},q=function(a){var c=1<arguments.length&&arguments[1]!==void 0?arguments[1]:!1,f=p(a);(0,e.addIconToContainer)(a);return(0,b.fetch)(a.dataset.tableComponent,a.dataset.tableHandler,a.dataset.tableUniqueid,{sortData:JSON.parse(a.dataset.tableSortData),joinType:f.jointype,filters:f.filters,firstinitial:a.dataset.tableFirstInitial,lastinitial:a.dataset.tableLastInitial,pageNumber:a.dataset.tablePageNumber,pageSize:a.dataset.tablePageSize,hiddenColumns:JSON.parse(a.dataset.tableHiddenColumns)},c).then(function(b){var c=document.createElement("div");c.innerHTML=b.html;a.replaceWith.apply(a,h(c.childNodes));return B(a.dataset.tableUniqueid)}).then(function(a){a.dispatchEvent(new CustomEvent(d.default.tableContentRefreshed,{bubbles:!0}));return a})};a.refreshTableContent=q;var r=function(a){var b=1<arguments.length&&arguments[1]!==void 0?arguments[1]:{},c=b.sortBy,d=void 0===c?null:c,e=b.sortOrder,f=void 0===e?null:e,g=b.filters,h=void 0===g?null:g,i=b.firstInitial,j=void 0===i?null:i,k=b.lastInitial,l=void 0===k?null:k,m=b.pageNumber,n=void 0===m?null:m,p=b.pageSize,r=void 0===p?null:p,s=b.hiddenColumns,t=void 0===s?null:s,u=2<arguments.length&&arguments[2]!==void 0?arguments[2]:!0;o(a);if(d&&f){var v=JSON.parse(a.dataset.tableSortData);v.unshift({sortby:d,sortorder:parseInt(f,10)});a.dataset.tableSortData=JSON.stringify(v)}if(null!==j){a.dataset.tableFirstInitial=j}if(null!==l){a.dataset.tableLastInitial=l}if(null!==n){a.dataset.tablePageNumber=n}if(null!==r){a.dataset.tablePageSize=r}if(h){a.dataset.tableFilters=JSON.stringify(h)}if(t){a.dataset.tableHiddenColumns=JSON.stringify(t)}if(u){return q(a)}else{return Promise.resolve(a)}};a.updateTable=r;var s=function(a){o(a);return a.dataset};a.setFilters=function setFilters(a,b){var c=2<arguments.length&&arguments[2]!==void 0?arguments[2]:!0;return r(a,{filters:b},c)};a.getFilters=function getFilters(a){o(a);return p(a)};var t=function(a,b,c){var d=3<arguments.length&&arguments[3]!==void 0?arguments[3]:!0;return r(a,{sortBy:b,sortOrder:c},d)};a.setSortOrder=t;var u=function(a,b){var c=2<arguments.length&&arguments[2]!==void 0?arguments[2]:!0;return r(a,{pageNumber:b},c)};a.setPageNumber=u;a.getPageNumber=function getPageNumber(a){return s(a).tablePageNumber};a.setPageSize=function setPageSize(a,b){var c=2<arguments.length&&arguments[2]!==void 0?arguments[2]:!0;return r(a,{pageSize:b,pageNumber:0},c)};a.getPageSize=function getPageSize(a){return s(a).tablePageSize};var v=function(a,b){var c=2<arguments.length&&arguments[2]!==void 0?arguments[2]:!0;return r(a,{firstInitial:b},c)};a.setFirstInitial=v;a.getFirstInitial=function getFirstInitial(a){return s(a).tableFirstInitial};var w=function(a,b){var c=2<arguments.length&&arguments[2]!==void 0?arguments[2]:!0;return r(a,{lastInitial:b},c)};a.setLastInitial=w;a.getLastInitial=function getLastInitial(a){return s(a).tableLastInitial};var x=function(a,b){var c=2<arguments.length&&arguments[2]!==void 0?arguments[2]:!0,d=JSON.parse(a.dataset.tableHiddenColumns);d.push(b);r(a,{hiddenColumns:d},c)};a.hideColumn=x;var y=function(a,b){var c=2<arguments.length&&arguments[2]!==void 0?arguments[2]:!0,d=JSON.parse(a.dataset.tableHiddenColumns);d=d.filter(function(a){return a!==b});r(a,{hiddenColumns:d},c)};a.showColumn=y;var z=function(a){return q(a,!0)},A=function(){if(n){return}n=!0;document.addEventListener("click",function(a){var b=a.target.closest(c.main.region);if(!b){return}var d=a.target.closest(c.table.links.sortableColumn);if(d){a.preventDefault();t(b,d.dataset.sortby,d.dataset.sortorder)}var e=a.target.closest(c.initialsBar.links.firstInitial);if(null!==e){a.preventDefault();v(b,e.dataset.initial)}var f=a.target.closest(c.initialsBar.links.lastInitial);if(null!==f){a.preventDefault();w(b,f.dataset.initial)}var g=a.target.closest(c.paginationBar.links.pageItem);if(g){a.preventDefault();u(b,g.dataset.pageNumber)}var h=a.target.closest(c.table.links.hide);if(h){a.preventDefault();x(b,h.dataset.column)}var i=a.target.closest(c.table.links.show);if(i){a.preventDefault();y(b,i.dataset.column)}var j=a.target.closest(".resettable a");if(j){a.preventDefault();z(b)}})};a.init=A;var B=function(a){var b=document.querySelector(c.main.fromRegionId(a));if(!b){throw new Error("The table specified is not a dynamic table and cannot be updated")}return b};a.getTableFromId=B});
2 //# sourceMappingURL=dynamic.min.js.map