moodle/lib/table/amd/build/dynamic.min.js

3 lines
7.6 KiB
JavaScript

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","core/notification"],function(a,b,c,d,e,f,g){"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=j(b);c=h(c);d=h(d);g=h(g);function h(a){return a&&a.__esModule?a:{default:a}}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 o(a)||n(a)||m(a)||l()}function l(){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 m(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 n(a){if("undefined"!=typeof Symbol&&Symbol.iterator in Object(a))return Array.from(a)}function o(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,k(c.childNodes));return F(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"),x=!1;if(e&&g){x=!0;var y=JSON.parse(a.dataset.tableSortData);y.unshift({sortby:e,sortorder:parseInt(g,10)});a.dataset.tableSortData=JSON.stringify(y)}if(null!==k){if(a.dataset.tableFirstInitial!==k){x=!0}a.dataset.tableFirstInitial=k}if(null!==m){if(a.dataset.tableLastInitial!==m){x=!0}a.dataset.tableLastInitial=m}if(null!==q){if(a.dataset.tablePageSize!=q){x=!0}a.dataset.tablePageSize=q}if(i){var z=JSON.stringify(i);if(a.dataset.tableFilters!==z){x=!0}a.dataset.tableFilters=z}if(x){o=1}if(u){var A=JSON.stringify(u);if(a.dataset.tableHiddenColumns!==A){x=!0}a.dataset.tableHiddenColumns=A}if(null!==o){if(a.dataset.tablePageNumber!=o){x=!0}a.dataset.tablePageNumber=o}if(v&&x){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};var y=function(a,b){var c=2<arguments.length&&arguments[2]!==void 0?arguments[2]:!0;return u(a,{pageSize:b,pageNumber:1},c)};a.setPageSize=y;a.getPageSize=function getPageSize(a){return v(a).tablePageSize};var z=function(a,b){var c=2<arguments.length&&arguments[2]!==void 0?arguments[2]:!0;return u(a,{firstInitial:b},c)};a.setFirstInitial=z;a.getFirstInitial=function getFirstInitial(a){return v(a).tableFirstInitial};var A=function(a,b){var c=2<arguments.length&&arguments[2]!==void 0?arguments[2]:!0;return u(a,{lastInitial:b},c)};a.setLastInitial=A;a.getLastInitial=function getLastInitial(a){return v(a).tableLastInitial};var B=function(a,b){var c=2<arguments.length&&arguments[2]!==void 0?arguments[2]:!0,d=JSON.parse(a.dataset.tableHiddenColumns);d.push(b);return u(a,{hiddenColumns:d},c)};a.hideColumn=B;var C=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});return u(a,{hiddenColumns:d},c)};a.showColumn=C;var D=function(a){return t(a,!0)},E=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).catch(g.default.exception)}var e=a.target.closest(b.initialsBar.links.firstInitial);if(null!==e){a.preventDefault();z(c,e.dataset.initial).catch(g.default.exception)}var f=a.target.closest(b.initialsBar.links.lastInitial);if(null!==f){a.preventDefault();A(c,f.dataset.initial).catch(g.default.exception)}var h=a.target.closest(b.paginationBar.links.pageItem);if(h){a.preventDefault();x(c,h.dataset.pageNumber).catch(g.default.exception)}var i=a.target.closest(b.table.links.hide);if(i){a.preventDefault();B(c,i.dataset.column).catch(g.default.exception)}var j=a.target.closest(b.table.links.show);if(j){a.preventDefault();C(c,j.dataset.column).catch(g.default.exception)}var k=a.target.closest(".resettable a");if(k){a.preventDefault();D(c).catch(g.default.exception)}var l=a.target.closest(b.showCount.links.toggle);if(l){a.preventDefault();y(c,l.dataset.targetPageSize).catch(g.default.exception)}})};a.init=E;var F=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=F});
//# sourceMappingURL=dynamic.min.js.map