Merge branch 'MDL-57680' of https://github.com/timhunt/moodle
[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"],function(a,b,c){"use strict";Object.defineProperty(a,"__esModule",{value:!0});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);function d(a){return g(a)||f(a)||e()}function e(){throw new TypeError("Invalid attempt to spread non-iterable instance")}function f(a){if(Symbol.iterator in Object(a)||"[object Arguments]"===Object.prototype.toString.call(a))return Array.from(a)}function g(a){if(Array.isArray(a)){for(var b=0,c=Array(a.length);b<a.length;b++){c[b]=a[b]}return c}}var h=!1,i=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},j=function(a){return JSON.parse(a.dataset.tableFilters)},k=function(a){var c=j(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,d(c.childNodes));return b})};a.refreshTableContent=k;var l=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,j=b.firstInitial,l=void 0===j?null:j,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;i(a);if(d&&f){a.dataset.tableSortBy=d;a.dataset.tableSortOrder=f}if(null!==l){a.dataset.tableFirstInitial=l}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 k(a)}else{return Promise.resolve()}};a.updateTable=l;a.setFilters=function setFilters(a,b){var c=2<arguments.length&&arguments[2]!==void 0?arguments[2]:!0;return l(a,{filters:b},c)};var m=function(a,b,c){var d=3<arguments.length&&arguments[3]!==void 0?arguments[3]:!0;return l(a,{sortBy:b,sortOrder:c},d)};a.setSortOrder=m;var n=function(a,b){var c=2<arguments.length&&arguments[2]!==void 0?arguments[2]:!0;return l(a,{pageNumber:b},c)};a.setPageNumber=n;a.setPageSize=function setPageSize(a,b){var c=2<arguments.length&&arguments[2]!==void 0?arguments[2]:!0;return l(a,{pageSize:b,pageNumber:0},c)};var o=function(a,b){var c=2<arguments.length&&arguments[2]!==void 0?arguments[2]:!0;return l(a,{firstInitial:b},c)};a.setFirstInitial=o;var p=function(a,b){var c=2<arguments.length&&arguments[2]!==void 0?arguments[2]:!0;return l(a,{lastInitial:b},c)};a.setLastInitial=p;var q=function(a,b){var c=2<arguments.length&&arguments[2]!==void 0?arguments[2]:!0,d=JSON.parse(a.dataset.tableHiddenColumns);d.push(b);l(a,{hiddenColumns:d},c)};a.hideColumn=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=d.filter(function(a){return a!==b});l(a,{hiddenColumns:d},c)};a.showColumn=r;var s=function(){if(h){return}h=!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();m(b,d.dataset.sortby,d.dataset.sortorder)}var e=a.target.closest(c.initialsBar.links.firstInitial);if(null!==e){a.preventDefault();o(b,e.dataset.initial)}var f=a.target.closest(c.initialsBar.links.lastInitial);if(null!==f){a.preventDefault();p(b,f.dataset.initial)}var g=a.target.closest(c.paginationBar.links.pageItem);if(g){a.preventDefault();n(b,g.dataset.pageNumber)}var h=a.target.closest(c.table.links.hide);if(h){a.preventDefault();q(b,h.dataset.column)}var i=a.target.closest(c.table.links.show);if(i){a.preventDefault();r(b,i.dataset.column)}})};a.init=s;var t=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=t});
2 //# sourceMappingURL=dynamic.min.js.map