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