otsdaq_utilities  v2_05_02_indev
download.min.js
1 /* Tabulator v4.5.3 (c) Oliver Folkerd */
2 var _typeof="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(o){return typeof o}:function(o){return o&&"function"==typeof Symbol&&o.constructor===Symbol&&o!==Symbol.prototype?"symbol":typeof o},Download=function(o){this.table=o,this.fields={},this.columnsByIndex=[],this.columnsByField={},this.config={},this.active=!1};Download.prototype.download=function(o,t,n,e,i){function s(n,e){i?!0===i?r.triggerDownload(n,e,o,t,!0):i(n):r.triggerDownload(n,e,o,t)}var r=this,a=!1;this.processConfig(),this.active=e,"function"==typeof o?a=o:r.downloaders[o]?a=r.downloaders[o]:console.warn("Download Error - No such download type found: ",o),this.processColumns(),a&&a.call(this,r.processDefinitions(),r.processData(e||"active"),n||{},s,this.config)},Download.prototype.processConfig=function(){var o={columnGroups:!0,rowGroups:!0,columnCalcs:!0};if(this.table.options.downloadConfig)for(var t in this.table.options.downloadConfig)o[t]=this.table.options.downloadConfig[t];o.rowGroups&&this.table.options.groupBy&&this.table.modExists("groupRows")&&(this.config.rowGroups=!0),o.columnGroups&&this.table.columnManager.columns.length!=this.table.columnManager.columnsByIndex.length&&(this.config.columnGroups=!0),o.columnCalcs&&this.table.modExists("columnCalcs")&&(this.config.columnCalcs=!0)},Download.prototype.processColumns=function(){var o=this;o.columnsByIndex=[],o.columnsByField={},o.table.columnManager.columnsByIndex.forEach(function(t){t.field&&!1!==t.definition.download&&(t.visible||!t.visible&&t.definition.download)&&(o.columnsByIndex.push(t),o.columnsByField[t.field]=t)})},Download.prototype.processDefinitions=function(){var o=this,t=[];return this.config.columnGroups?o.table.columnManager.columns.forEach(function(n){var e=o.processColumnGroup(n);e&&t.push(e)}):o.columnsByIndex.forEach(function(n){!1!==n.download&&t.push(o.processDefinition(n))}),t},Download.prototype.processColumnGroup=function(o){var t=this,n=o.columns,e=0,i=this.processDefinition(o),s={type:"group",title:i.title,depth:1};if(n.length){if(s.subGroups=[],s.width=0,n.forEach(function(o){var n=t.processColumnGroup(o);n.depth>e&&(e=n.depth),n&&(s.width+=n.width,s.subGroups.push(n))}),s.depth+=e,!s.width)return!1}else{if(!o.field||!1===o.definition.download||!(o.visible||!o.visible&&o.definition.download))return!1;s.width=1,s.definition=i}return s},Download.prototype.processDefinition=function(o){var t={};for(var n in o.definition)t[n]=o.definition[n];return void 0!==o.definition.downloadTitle&&(t.title=o.definition.downloadTitle),t},Download.prototype.processData=function(o){var t=this,n=this,e=[],i=[],s=!1,r={};return this.config.rowGroups?("visible"==o?(s=n.table.rowManager.getRows(o),s.forEach(function(o){if("row"==o.type){var t=o.getGroup();-1===i.indexOf(t)&&i.push(t)}})):i=this.table.modules.groupRows.getGroups(),i.forEach(function(o){e.push(t.processGroupData(o,s))})):e=n.table.rowManager.getData(o,"download"),this.config.columnCalcs&&(r=this.table.getCalcResults(),e={calcs:r,data:e}),"function"==typeof n.table.options.downloadDataFormatter&&(e=n.table.options.downloadDataFormatter(e)),e},Download.prototype.processGroupData=function(o,t){var n=this,e=o.getSubGroups(),i={type:"group",key:o.key};return e.length?(i.subGroups=[],e.forEach(function(o){i.subGroups.push(n.processGroupData(o,t))})):t?(i.rows=[],o.rows.forEach(function(o){t.indexOf(o)>-1&&i.rows.push(o.getData("download"))})):i.rows=o.getData(!0,"download"),i},Download.prototype.triggerDownload=function(o,t,n,e,i){var s=document.createElement("a"),r=new Blob([o],{type:t}),e=e||"Tabulator."+("function"==typeof n?"txt":n);(r=this.table.options.downloadReady.call(this.table,o,r))&&(i?window.open(window.URL.createObjectURL(r)):navigator.msSaveOrOpenBlob?navigator.msSaveOrOpenBlob(r,e):(s.setAttribute("href",window.URL.createObjectURL(r)),s.setAttribute("download",e),s.style.display="none",document.body.appendChild(s),s.click(),document.body.removeChild(s)),this.table.options.downloadComplete&&this.table.options.downloadComplete())},Download.prototype.getFieldValue=function(o,t){var n=this.columnsByField[o];return!!n&&n.getFieldValue(t)},Download.prototype.commsReceived=function(o,t,n){switch(t){case"intercept":this.download(n.type,"",n.options,n.active,n.intercept)}},Download.prototype.downloaders={csv:function(o,t,n,e,i){function s(o,t){o.subGroups?o.subGroups.forEach(function(o){s(o,t+1)}):(f.push('"'+String(o.title).split('"').join('""')+'"'),p.push(o.definition.field))}function r(o){o.forEach(function(o){var t=[];p.forEach(function(n){var e=c.getFieldValue(n,o);switch(void 0===e?"undefined":_typeof(e)){case"object":e=JSON.stringify(e);break;case"undefined":case"null":e="";break;default:e=e}t.push('"'+String(e).split('"').join('""')+'"')}),u.push(t.join(d))})}function a(o){o.subGroups?o.subGroups.forEach(function(o){a(o)}):r(o.rows)}var u,l,c=this,f=[],p=[],d=n&&n.delimiter?n.delimiter:",";i.columnGroups?(console.warn("Download Warning - CSV downloader cannot process column groups"),o.forEach(function(o){s(o,0)})):function(){o.forEach(function(o){f.push('"'+String(o.title).split('"').join('""')+'"'),p.push(o.field)})}(),u=[f.join(d)],i.columnCalcs&&(console.warn("Download Warning - CSV downloader cannot process column calculations"),t=t.data),i.rowGroups?(console.warn("Download Warning - CSV downloader cannot process row groups"),t.forEach(function(o){a(o)})):r(t),l=u.join("\n"),n.bom&&(l="\ufeff"+l),e(l,"text/csv")},json:function(o,t,n,e,i){var s;i.columnCalcs&&(console.warn("Download Warning - CSV downloader cannot process column calculations"),t=t.data),s=JSON.stringify(t,null,"\t"),e(s,"application/json")},pdf:function(o,t,n,e,i){function s(o,t){var n=o.width,e=1,i={content:o.title||""};if(o.subGroups?(o.subGroups.forEach(function(o){s(o,t+1)}),e=1):(p.push(o.definition.field),e=m-t),i.rowSpan=e,d[t].push(i),n--,e>1)for(var r=t+1;r<m;r++)d[r].push("");for(var r=0;r<n;r++)d[t].push("")}function r(o){switch(void 0===o?"undefined":_typeof(o)){case"object":o=JSON.stringify(o);break;case"undefined":case"null":o="";break;default:o=o}return o}function a(o){o.forEach(function(o){h.push(u(o))})}function u(o,t){var n=[];return p.forEach(function(e){var i=f.getFieldValue(e,o);i=r(i),t?n.push({content:i,styles:t}):n.push(i)}),n}function l(o,t){var n=[];n.push({content:r(o.key),colSpan:p.length,styles:y}),h.push(n),o.subGroups?o.subGroups.forEach(function(n){l(n,t[o.key]?t[o.key].groups||{}:{})}):(i.columnCalcs&&c(t,o.key,"top"),a(o.rows),i.columnCalcs&&c(t,o.key,"bottom"))}function c(o,t,n){var e=o[t];e&&(n&&(e=e[n]),Object.keys(e).length&&h.push(u(e,b)))}var f=this,p=[],d=[],h=[],w={},m=1,g={},y=n.rowGroupStyles||{fontStyle:"bold",fontSize:12,cellPadding:6,fillColor:220},b=n.rowCalcStyles||{fontStyle:"bold",fontSize:10,cellPadding:4,fillColor:232},v=n.jsPDF||{},E=n&&n.title?n.title:"";if(i.columnCalcs&&(w=t.calcs,t=t.data),v.orientation||(v.orientation=n.orientation||"landscape"),v.unit||(v.unit="pt"),i.columnGroups){o.forEach(function(o){o.depth>m&&(m=o.depth)});for(var S=0;S<m;S++)d.push([]);o.forEach(function(o){s(o,0)})}else!function(){o.forEach(function(o){o.field&&(d.push(o.title||""),p.push(o.field))}),d=[d]}();i.rowGroups?t.forEach(function(o){l(o,w)}):(i.columnCalcs&&c(w,"top"),a(t),i.columnCalcs&&c(w,"bottom"));var C=new jsPDF(v);n&&n.autoTable&&(g="function"==typeof n.autoTable?n.autoTable(C)||{}:n.autoTable),E&&(g.addPageContent=function(o){C.text(E,40,30)}),g.head=d,g.body=h,C.autoTable(g),n&&n.documentProcessing&&n.documentProcessing(C),e(C.output("arraybuffer"),"application/pdf")},xlsx:function(o,t,n,e,i){function s(){function n(o,t){void 0===w[t]&&(w[t]=[]),void 0===p[t]&&(p[t]=[]),o.width>1&&p[t].push({type:"hoz",start:w[t].length,end:w[t].length+o.width-1}),w[t].push(o.title),o.subGroups?o.subGroups.forEach(function(o){n(o,t+1)}):(m.push(o.definition.field),e(m.length),p[t].push({type:"vert",start:m.length-1}))}function e(){var o=0;w.forEach(function(t){var n=t.length;n>o&&(o=n)}),w.forEach(function(t){var n=t.length;if(n<o)for(var e=n;e<o;e++)t.push("")})}function s(){var o=[];return f.forEach(function(t){o.push({s:{r:t,c:0},e:{r:t,c:m.length-1}})}),p.forEach(function(t,n){t.forEach(function(t){"hoz"===t.type?o.push({s:{r:n,c:t.start},e:{r:n,c:t.end}}):n!=w.length-1&&o.push({s:{r:n,c:t.start},e:{r:w.length-1,c:t.start}})})}),o}function r(o){o.forEach(function(o){g.push(u(o))})}function u(o){var t=[];return m.forEach(function(n){var e=a.getFieldValue(n,o);t.push(e instanceof Date||"object"!==(void 0===e?"undefined":_typeof(e))?e:JSON.stringify(e))}),t}function l(o,t,n){var e=o[t];e&&(n&&(e=e[n]),Object.keys(e).length&&(d.push(g.length),g.push(u(e))))}function h(o,t){var n=[];n.push(o.key),f.push(g.length),g.push(n),o.subGroups?o.subGroups.forEach(function(n){h(n,t[o.key]?t[o.key].groups||{}:{})}):(i.columnCalcs&&l(t,o.key,"top"),r(o.rows),i.columnCalcs&&l(t,o.key,"bottom"))}var w=[],m=[],g=[];return i.columnGroups?(o.forEach(function(o){n(o,0)}),w.forEach(function(o){g.push(o)})):function(){o.forEach(function(o){w.push(o.title),m.push(o.field)}),g.push(w)}(),i.rowGroups?t.forEach(function(o){h(o,c)}):(i.columnCalcs&&l(c,"top"),r(t),i.columnCalcs&&l(c,"bottom")),function(){var o={},t={s:{c:0,r:0},e:{c:m.length,r:g.length}};XLSX.utils.sheet_add_aoa(o,g),o["!ref"]=XLSX.utils.encode_range(t);var n=s();return n.length&&(o["!merges"]=n),o}()}var r,a=this,u=n.sheetName||"Sheet1",l=XLSX.utils.book_new(),c={},f=[],p=[],d=[];if(l.SheetNames=[],l.Sheets={},i.columnCalcs&&(c=t.calcs,t=t.data),n.sheetOnly)return void e(s());if(n.sheets)for(var h in n.sheets)!0===n.sheets[h]?(l.SheetNames.push(h),l.Sheets[h]=s()):(l.SheetNames.push(h),this.table.modules.comms.send(n.sheets[h],"download","intercept",{type:"xlsx",options:{sheetOnly:!0},active:a.active,intercept:function(o){l.Sheets[h]=o}}));else l.SheetNames.push(u),l.Sheets[u]=s();n.documentProcessing&&(l=n.documentProcessing(l)),r=XLSX.write(l,{bookType:"xlsx",bookSST:!0,type:"binary"}),e(function(o){for(var t=new ArrayBuffer(o.length),n=new Uint8Array(t),e=0;e!=o.length;++e)n[e]=255&o.charCodeAt(e);return t}(r),"application/octet-stream")},html:function(o,t,n,e,i){this.table.modExists("htmlTableExport",!0)&&e(this.table.modules.htmlTableExport.getHtml(!0,n.style,i),"text/html")}},Tabulator.prototype.registerModule("download",Download);