69210d83352233a4c9b5ef99527657a8e1b793e9
[moodle.git] / lib / table / amd / build / dynamic.min.js
1 define ("core_table/dynamic",["exports","core_table/local/dynamic/repository","core_table/local/dynamic/selectors","./local/dynamic/events"],function(a,b,c,d){"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.setLastInitial=a.setFirstInitial=a.setPageSize=a.setPageNumber=a.setSortOrder=a.setFilters=a.updateTable=a.refreshTableContent=void 0;c=function(a){if(a&&a.__esModule){return a}else{var b={};if(null!=a){for(var c in a){if(Object.prototype.hasOwnProperty.call(a,c)){var d=Object.defineProperty&&Object.getOwnPropertyDescriptor?Object.getOwnPropertyDescriptor(a,c):{};if(d.get||d.set){Object.defineProperty(b,c,d)}else{b[c]=a[c]}}}}b.default=a;return b}}(c);d=function(a){return a&&a.__esModule?a:{default:a}}(d);function e(a){return h(a)||g(a)||f()}function f(){throw new TypeError("Invalid attempt to spread non-iterable instance")}function g(a){if(Symbol.iterator in Object(a)||"[object Arguments]"===Object.prototype.toString.call(a))return Array.from(a)}function h(a){if(Array.isArray(a)){for(var b=0,c=Array(a.length);b<a.length;b++){c[b]=a[b]}return c}}var i=!1,j=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},k=function(a){return JSON.parse(a.dataset.tableFilters)},l=function(a){var c=k(a);return(0,b.fetch)(a.dataset.tableComponent,a.dataset.tableHandler,a.dataset.tableUniqueid,{sortBy:a.dataset.tableSortBy,sortOrder:a.dataset.tableSortOrder,joinType:c.jointype,filters:c.filters,firstinitial:a.dataset.tableFirstInitial,lastinitial:a.dataset.tableLastInitial,pageNumber:a.dataset.tablePageNumber,pageSize:a.dataset.tablePageSize,hiddenColumns:JSON.parse(a.dataset.tableHiddenColumns)}).then(function(b){var c=document.createElement("div");c.innerHTML=b.html;a.replaceWith.apply(a,e(c.childNodes));return u(a.dataset.tableUniqueid)}).then(function(a){a.dispatchEvent(new CustomEvent(d.default.tableContentRefreshed,{bubbles:!0}));return a})};a.refreshTableContent=l;var m=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,k=void 0===i?null:i,m=b.lastInitial,n=void 0===m?null:m,o=b.pageNumber,p=void 0===o?null:o,q=b.pageSize,r=void 0===q?null:q,s=b.hiddenColumns,t=void 0===s?null:s,u=2<arguments.length&&arguments[2]!==void 0?arguments[2]:!0;j(a);if(d&&f){a.dataset.tableSortBy=d;a.dataset.tableSortOrder=f}if(null!==k){a.dataset.tableFirstInitial=k}if(null!==n){a.dataset.tableLastInitial=n}if(null!==p){a.dataset.tablePageNumber=p}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 l(a)}else{return Promise.resolve(a)}};a.updateTable=m;a.setFilters=function setFilters(a,b){var c=2<arguments.length&&arguments[2]!==void 0?arguments[2]:!0;return m(a,{filters:b},c)};var n=function(a,b,c){var d=3<arguments.length&&arguments[3]!==void 0?arguments[3]:!0;return m(a,{sortBy:b,sortOrder:c},d)};a.setSortOrder=n;var o=function(a,b){var c=2<arguments.length&&arguments[2]!==void 0?arguments[2]:!0;return m(a,{pageNumber:b},c)};a.setPageNumber=o;a.setPageSize=function setPageSize(a,b){var c=2<arguments.length&&arguments[2]!==void 0?arguments[2]:!0;return m(a,{pageSize:b,pageNumber:0},c)};var p=function(a,b){var c=2<arguments.length&&arguments[2]!==void 0?arguments[2]:!0;return m(a,{firstInitial:b},c)};a.setFirstInitial=p;var q=function(a,b){var c=2<arguments.length&&arguments[2]!==void 0?arguments[2]:!0;return m(a,{lastInitial:b},c)};a.setLastInitial=q;var r=function(a,b){var c=2<arguments.length&&arguments[2]!==void 0?arguments[2]:!0,d=JSON.parse(a.dataset.tableHiddenColumns);d.push(b);m(a,{hiddenColumns:d},c)};a.hideColumn=r;var s=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});m(a,{hiddenColumns:d},c)};a.showColumn=s;var t=function(){if(i){return}i=!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();n(b,d.dataset.sortby,d.dataset.sortorder)}var e=a.target.closest(c.initialsBar.links.firstInitial);if(null!==e){a.preventDefault();p(b,e.dataset.initial)}var f=a.target.closest(c.initialsBar.links.lastInitial);if(null!==f){a.preventDefault();q(b,f.dataset.initial)}var g=a.target.closest(c.paginationBar.links.pageItem);if(g){a.preventDefault();o(b,g.dataset.pageNumber)}var h=a.target.closest(c.table.links.hide);if(h){a.preventDefault();r(b,h.dataset.column)}var i=a.target.closest(c.table.links.show);if(i){a.preventDefault();s(b,i.dataset.column)}})};a.init=t;var u=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=u});
2 //# sourceMappingURL=dynamic.min.js.map