@cryptotaxi247 / netdata-1 / commits / 65c05242f

a more usable alarms log

Costa Tsaousis (ktsaou) committed Oct 2, 2016 at 03:28 UTC 65c05242f15b57ec922aae2b9d4193beecdd4823
7 files changed +1894 -54
LICENSE.md
+12
@@ -147,3 +147,15 @@ connectivity is not available.
147
148 Copyright 2006, Kirill Simonov
149 [MIT License](http://pyyaml.org)
150 +
151 +- [bootstrap-table](http://bootstrap-table.wenzhixin.net.cn/)
152 +
153 + Copyright (c) 2012-2016 Zhixin Wen <wenzhixin2010@gmail.com>
154 + [MIT License](https://github.com/wenzhixin/bootstrap-table/blob/master/LICENSE)
155 +
156 +- [tableExport.jquery.plugin](https://github.com/hhurz/tableExport.jquery.plugin)
157 +
158 + Copyright (c) 2015,2016 hhurz
159 + [MIT License](http://rawgit.com/hhurz/tableExport.jquery.plugin/master/tableExport.js)
160 +
161 +
web/Makefile.am
+6 -3
@@ -34,16 +34,19 @@ dist_webold_DATA = \
34
35 weblibdir=$(webdir)/lib
36 dist_weblib_DATA = \
37 + lib/bootstrap-3.3.7.min.js \
38 + lib/bootstrap-table.min.js \
39 + lib/bootstrap-table-export.min.js \
40 + lib/tableExport.js \
41 lib/dygraph-combined-f6ec7be.js \
42 lib/dygraph-smooth-plotter.js \
43 lib/jquery-3.1.1.min.js \
44 lib/jquery.peity.min.js \
45 lib/jquery.sparkline.min.js \
42 - lib/morris.min.js \
43 - lib/raphael-min.js \
46 lib/jquery.easypiechart.min.js \
47 lib/jquery.nanoscroller.min.js \
46 - lib/bootstrap-3.3.7.min.js \
48 + lib/morris.min.js \
49 + lib/raphael-min.js \
50 lib/ElementQueries.js \
51 lib/ResizeSensor.js \
52 lib/bootstrap-toggle.min.js \
web/dashboard.js
+15 -9
@@ -5579,6 +5579,7 @@
5579 NETDATA.requiredJs = [
5580 {
5581 url: NETDATA.serverDefault + 'lib/bootstrap-3.3.7.min.js',
5582 + async: false,
5583 isAlreadyLoaded: function() {
5584 // check if bootstrap is loaded
5585 if(typeof $().emulateTransitionEnd == 'function')
@@ -5594,10 +5595,6 @@
5595 {
5596 url: NETDATA.serverDefault + 'lib/jquery.nanoscroller.min.js',
5597 isAlreadyLoaded: function() { return false; }
5597 - },
5598 - {
5599 - url: NETDATA.serverDefault + 'lib/bootstrap-toggle.min.js',
5600 - isAlreadyLoaded: function() { return false; }
5598 }
5599 ];
5600
@@ -5627,7 +5624,11 @@
5624
5625 NETDATA.loadedRequiredJs = 0;
5626 NETDATA.loadRequiredJs = function(index, callback) {
5630 - if(index >= NETDATA.requiredJs.length) return;
5627 + if(index >= NETDATA.requiredJs.length) {
5628 + if(typeof callback === 'function')
5629 + callback();
5630 + return;
5631 + }
5632
5633 if(NETDATA.requiredJs[index].isAlreadyLoaded()) {
5634 NETDATA.loadedRequiredJs++;
@@ -5638,10 +5639,13 @@
5639 if(NETDATA.options.debug.main_loop === true)
5640 console.log('loading ' + NETDATA.requiredJs[index].url);
5641
5642 + var async = true;
5643 + if(typeof NETDATA.requiredJs[index].async !== 'undefined' && NETDATA.requiredJs[index].async === false)
5644 + async = false;
5645 +
5646 $.ajax({
5647 url: NETDATA.requiredJs[index].url,
5648 cache: true,
5644 - async: true,
5649 dataType: "script",
5650 xhrFields: { withCredentials: true } // required for the cookie
5651 })
@@ -5654,11 +5658,13 @@
5658 })
5659 .always(function() {
5660 NETDATA.loadedRequiredJs++;
5657 - if(typeof callback === 'function' && NETDATA.loadedRequiredJs >= NETDATA.requiredJs.length)
5658 - callback();
5661 +
5662 + if(async === false)
5663 + NETDATA.loadRequiredJs(++index, callback);
5664 })
5665
5661 - NETDATA.loadRequiredJs(++index, callback);
5666 + if(async === true)
5667 + NETDATA.loadRequiredJs(++index, callback);
5668 };
5669
5670 NETDATA.loadRequiredCSS = function(index) {
web/index.html
+318 -42
@@ -1369,10 +1369,38 @@
1369
1370 // ----------------------------------------------------------------------------
1371
1372 + function loadJs(url, callback) {
1373 + $.ajax({
1374 + url: url,
1375 + cache: true,
1376 + dataType: "script",
1377 + xhrFields: { withCredentials: true } // required for the cookie
1378 + })
1379 + .fail(function() {
1380 + alert('Cannot load required JS library: ' + url);
1381 + })
1382 + .always(function() {
1383 + if(typeof callback === 'function')
1384 + callback();
1385 + })
1386 + }
1387 +
1388 + var bootstrapTableLoaded = false;
1389 + function loadBootstrapTable(callback) {
1390 + if(bootstrapTableLoaded === false) {
1391 + bootstrapTableLoaded === true;
1392 + loadJs(NETDATA.serverDefault + 'lib/bootstrap-table.min.js?v1.11.0', function() {
1393 + loadJs(NETDATA.serverDefault + 'lib/bootstrap-table-export.min.js?v1.11.0', function() {
1394 + loadJs(NETDATA.serverDefault + 'lib/tableExport.js', callback);
1395 + })
1396 + });
1397 + }
1398 + else callback();
1399 + }
1400 +
1401 function alarmsUpdateModal() {
1402 var active = '<h3>Raised Alarms</h3><table class="table">';
1403 var all = '<h3>All Running Alarms</h3><div class="panel-group" id="alarms_all_accordion" role="tablist" aria-multiselectable="true">';
1375 - var log = '<h3>Alarm Log</h3><table class="table"><tr><th>When</th><th>Chart</th><th>Alarm</th><th>Status</th>';
1404 var footer = '<hr/><a href="https://github.com/firehol/netdata/wiki/Generating-Badges" target="_blank">netdata badges</a> refresh automatically. Their color indicates the state of the alarm: <span style="color: #e05d44"><b>&nbsp;red&nbsp;</b></span> is critical, <span style="color:#fe7d37"><b>&nbsp;orange&nbsp;</b></span> is warning, <span style="color: #4c1"><b>&nbsp;bright green&nbsp;</b></span> is ok, <span style="color: #9f9f9f"><b>&nbsp;light grey&nbsp;</b></span> is undefined (i.e. no data or no status), <span style="color: #000"><b>&nbsp;black&nbsp;</b></span> is not initialized. You can copy and paste their URLs to embed them in any web page.<br/>netdata can send notifications for these alarms. Check <a href="https://github.com/firehol/netdata/blob/master/conf.d/health_alarm_notify.conf">this configuration file</a> for more information.';
1405
1406 NETDATA.alarms.get('all', function(data) {
@@ -1388,14 +1416,30 @@
1416 return;
1417 }
1418
1391 - function frequency_text(seconds, sfx) {
1419 + function timestamp4human(timestamp, space) {
1420 + if(typeof space === 'undefined')
1421 + space = '&nbsp;';
1422 +
1423 + var t = new Date(timestamp * 1000);
1424 + var now = new Date();
1425 +
1426 + if(t.toDateString() == now.toDateString())
1427 + return t.toLocaleTimeString();
1428 +
1429 + return t.toLocaleDateString() + space + t.toLocaleTimeString();
1430 + }
1431 +
1432 + function seconds4human(seconds, sfx, space) {
1433 + if(typeof space === 'undefined')
1434 + space = '&nbsp;';
1435 +
1436 if(seconds === 0)
1437 return 'now';
1438
1439 var suffix = '';
1440 if(seconds < 0) {
1441 seconds = -seconds;
1398 - if(sfx) suffix = '&nbsp;ago';
1442 + if(sfx) suffix = space + 'ago';
1443 }
1444
1445 var hours = Math.floor(seconds / 3600);
@@ -1406,22 +1450,22 @@
1450
1451 var txt = '';
1452
1409 - if(hours > 1) txt += hours.toString() + '&nbsp;hours';
1410 - else if(hours === 1) txt += hours.toString() + '&nbsp;hour';
1453 + if(hours > 1) txt += hours.toString() + space + 'hours';
1454 + else if(hours === 1) txt += hours.toString() + space + 'hour';
1455
1456 if(hours > 0 && minutes > 0 && seconds == 0)
1413 - txt += '&nbsp;and&nbsp;';
1457 + txt += space + 'and' + space;
1458 else if(hours > 0 && minutes > 0 && seconds > 0)
1415 - txt += ',&nbsp;';
1459 + txt += ',' + space;
1460
1417 - if(minutes > 1) txt += minutes.toString() + '&nbsp;minutes';
1418 - else if(minutes === 1) txt += minutes.toString() + '&nbsp;minute';
1461 + if(minutes > 1) txt += minutes.toString() + space + 'minutes';
1462 + else if(minutes === 1) txt += minutes.toString() + space + 'minute';
1463
1464 if((minutes > 0 || minutes > 0) && seconds > 0)
1421 - txt += '&nbsp;and&nbsp;';
1465 + txt += space + 'and' + space;
1466
1423 - if(seconds > 1) txt += seconds.toString() + '&nbsp;seconds';
1424 - else if(seconds === 1) txt += seconds.toString() + '&nbsp;second';
1467 + if(seconds > 1) txt += seconds.toString() + space + 'seconds';
1468 + else if(seconds === 1) txt += seconds.toString() + space + 'second';
1469
1470 return txt + suffix;
1471 }
@@ -1443,7 +1487,7 @@
1487
1488 return '<code>' + alarm.lookup_method + '</code> '
1489 + dimensions + ', of chart <code>' + alarm.chart + '</code>'
1446 - + ', starting <code>' + frequency_text(alarm.lookup_after + alarm.lookup_before, true) + '</code> and up to <code>' + frequency_text(alarm.lookup_before, true) + '</code>'
1490 + + ', starting <code>' + seconds4human(alarm.lookup_after + alarm.lookup_before, true) + '</code> and up to <code>' + seconds4human(alarm.lookup_before, true) + '</code>'
1491 + ((alarm.lookup_options)?(', with options <code>' + alarm.lookup_options.replace(' ', ',&nbsp;') + '</code>'):'')
1492 + '.';
1493 }
@@ -1466,25 +1510,25 @@
1510 var delay = '';
1511 if((alarm.delay_up_duration > 0 || alarm.delay_down_duration > 0) && alarm.delay_multiplier != 0 && alarm.delay_max_duration > 0) {
1512 if(alarm.delay_up_duration == alarm.delay_down_duration) {
1469 - delay += '<small><br/>hysteresis ' + frequency_text(alarm.delay_up_duration);
1513 + delay += '<small><br/>hysteresis ' + seconds4human(alarm.delay_up_duration);
1514 }
1515 else {
1516 delay = '<small><br/>hysteresis ';
1517 if(alarm.delay_up_duration > 0) {
1474 - delay += 'on&nbsp;escalation&nbsp;<code>' + frequency_text(alarm.delay_up_duration) + '</code>, ';
1518 + delay += 'on&nbsp;escalation&nbsp;<code>' + seconds4human(alarm.delay_up_duration) + '</code>, ';
1519 }
1520 if(alarm.delay_down_duration > 0) {
1477 - delay += 'on&nbsp;recovery&nbsp;<code>' + frequency_text(alarm.delay_down_duration) + '</code>, ';
1521 + delay += 'on&nbsp;recovery&nbsp;<code>' + seconds4human(alarm.delay_down_duration) + '</code>, ';
1522 }
1523 }
1524 if(alarm.delay_multiplier != 1.0) {
1525 delay += 'multiplied&nbsp;by&nbsp;<code>' + alarm.delay_multiplier.toString() + '</code>';
1482 - delay += ',&nbsp;up&nbsp;to&nbsp;<code>' + frequency_text(alarm.delay_max_duration) + '</code>';
1526 + delay += ',&nbsp;up&nbsp;to&nbsp;<code>' + seconds4human(alarm.delay_max_duration) + '</code>';
1527 }
1528 delay += '</small>';
1529 }
1530
1487 - html += '<tr><td width="10%" style="text-align:right">check&nbsp;every</td><td>' + frequency_text(alarm.update_every) + '</td></tr>'
1531 + html += '<tr><td width="10%" style="text-align:right">check&nbsp;every</td><td>' + seconds4human(alarm.update_every) + '</td></tr>'
1532 + '<tr><td width="10%" style="text-align:right">execute</td><td><span style="font-family: monospace;">' + alarm.exec + '</span>' + delay + '</td></tr>'
1533 + '<tr><td width="10%" style="text-align:right">source</td><td><span style="font-family: monospace;">' + alarm.source + '</span></td></tr>'
1534 + '</table></td></tr>';
@@ -1622,6 +1666,245 @@
1666 $('#alarm_all_' + id.toString()).html('');
1667 });
1668
1669 + document.getElementById('alarms_log').innerHTML = '<h3>Alarm Log</h3><table id="alarms_log_table"></table>';
1670 +
1671 + loadBootstrapTable(function () {
1672 + $('#alarms_log_table').bootstrapTable({
1673 + url: NETDATA.alarms.server + '/api/v1/alarm_log?all',
1674 + pagination: true,
1675 + pageSize: 10,
1676 + showPaginationSwitch: false,
1677 + search: true,
1678 + searchTimeOut: 300,
1679 + searchAlign: 'left',
1680 + showColumns: true,
1681 + showExport: true,
1682 + exportDataType: 'basic',
1683 + exportOptions: {
1684 + fileName: 'netdata_alarm_log'
1685 + },
1686 + rowStyle: function(row, index) {
1687 + switch(row.status) {
1688 + case 'CRITICAL' : return { classes: 'danger' }; break;
1689 + case 'WARNING' : return { classes: 'warning' }; break;
1690 + case 'UNDEFINED': return { classes: 'info' }; break;
1691 + case 'CLEAR' : return { classes: 'success' }; break;
1692 + }
1693 + return {};
1694 + },
1695 + showFooter: false,
1696 + showHeader: true,
1697 + showRefresh: true,
1698 + showToggle: false,
1699 + sortable: true,
1700 + silentSort: false,
1701 + columns: [
1702 + {
1703 + field: 'when',
1704 + title: 'Event Date',
1705 + valign: 'middle',
1706 + switchable: false,
1707 + sortable: true,
1708 + formatter: function(value, row, index) { return timestamp4human(value, ' '); },
1709 + },
1710 + {
1711 + field: 'hostname',
1712 + title: 'Host',
1713 + valign: 'middle',
1714 + visible: false,
1715 + sortable: true
1716 + },
1717 + {
1718 + field: 'unique_id',
1719 + title: 'Unique ID',
1720 + valign: 'middle',
1721 + visible: false,
1722 + sortable: true
1723 + },
1724 + {
1725 + field: 'alarm_id',
1726 + title: 'Alarm ID',
1727 + valign: 'middle',
1728 + visible: false,
1729 + sortable: true
1730 + },
1731 + {
1732 + field: 'alarm_event_id',
1733 + title: 'Alarm Event ID',
1734 + valign: 'middle',
1735 + visible: false,
1736 + sortable: true
1737 + },
1738 + {
1739 + field: 'chart',
1740 + title: 'Chart',
1741 + valign: 'middle',
1742 + switchable: false,
1743 + sortable: true
1744 + },
1745 + {
1746 + field: 'family',
1747 + title: 'Family',
1748 + valign: 'middle',
1749 + visible: false,
1750 + sortable: true
1751 + },
1752 + {
1753 + field: 'name',
1754 + title: 'Alarm',
1755 + formatter: function(value, row, index) {
1756 + return value.toString().replace(/_/g, ' ');
1757 + },
1758 + valign: 'middle',
1759 + switchable: false,
1760 + sortable: true
1761 + },
1762 + {
1763 + field: 'old_value',
1764 + title: 'Old Value',
1765 + valign: 'middle',
1766 + visible: false,
1767 + sortable: true
1768 + },
1769 + {
1770 + field: 'value',
1771 + title: 'Value',
1772 + formatter: function(value, row, index) {
1773 + return ((value !== null)?Math.floor(value):'NaN').toString();
1774 + },
1775 + align: 'right',
1776 + valign: 'middle',
1777 + sortable: true
1778 + },
1779 + {
1780 + field: 'units',
1781 + title: 'Units',
1782 + valign: 'middle',
1783 + sortable: true
1784 + },
1785 + {
1786 + field: 'old_status',
1787 + title: 'Old Status',
1788 + valign: 'middle',
1789 + visible: false,
1790 + sortable: true
1791 + },
1792 + {
1793 + field: 'status',
1794 + title: 'Status',
1795 + valign: 'middle',
1796 + switchable: false,
1797 + sortable: true
1798 + },
1799 + {
1800 + field: 'duration',
1801 + title: 'Duration',
1802 + formatter: function(value, row, index) { return seconds4human(value, false, ' '); },
1803 + valign: 'middle',
1804 + visible: false,
1805 + sortable: true
1806 + },
1807 + {
1808 + field: 'non_clear_duration',
1809 + title: 'Raised Duration',
1810 + formatter: function(value, row, index) { return seconds4human(value, false, ' '); },
1811 + valign: 'middle',
1812 + visible: false,
1813 + sortable: true
1814 + },
1815 + {
1816 + field: 'recipient',
1817 + title: 'Recipient',
1818 + valign: 'middle',
1819 + visible: false,
1820 + sortable: true
1821 + },
1822 + {
1823 + field: 'processed',
1824 + title: 'Processed Status',
1825 + valign: 'middle',
1826 + visible: false,
1827 + sortable: true
1828 + },
1829 + {
1830 + field: 'updated',
1831 + title: 'Updated Status',
1832 + valign: 'middle',
1833 + visible: false,
1834 + sortable: true
1835 + },
1836 + {
1837 + field: 'updated_by_id',
1838 + title: 'Updated By ID',
1839 + valign: 'middle',
1840 + visible: false,
1841 + sortable: true
1842 + },
1843 + {
1844 + field: 'updates_id',
1845 + title: 'Updates ID',
1846 + valign: 'middle',
1847 + visible: false,
1848 + sortable: true
1849 + },
1850 + {
1851 + field: 'exec',
1852 + title: 'Script',
1853 + valign: 'middle',
1854 + visible: false,
1855 + sortable: true
1856 + },
1857 + {
1858 + field: 'exec_run',
1859 + title: 'Script Run At',
1860 + formatter: function(value, row, index) { return timestamp4human(value, ' '); },
1861 + valign: 'middle',
1862 + visible: false,
1863 + sortable: true
1864 + },
1865 + {
1866 + field: 'exec_code',
1867 + title: 'Script Return Value',
1868 + valign: 'middle',
1869 + visible: false,
1870 + sortable: true
1871 + },
1872 + {
1873 + field: 'delay',
1874 + title: 'Script Delay',
1875 + formatter: function(value, row, index) { return seconds4human(value, false, ' '); },
1876 + valign: 'middle',
1877 + visible: false,
1878 + sortable: true
1879 + },
1880 + {
1881 + field: 'delay_up_to_timestamp',
1882 + title: 'Script Delay Run At',
1883 + formatter: function(value, row, index) { return timestamp4human(value, ' '); },
1884 + valign: 'middle',
1885 + visible: false,
1886 + sortable: true
1887 + },
1888 + {
1889 + field: 'info',
1890 + title: 'Description',
1891 + valign: 'middle',
1892 + visible: false,
1893 + sortable: true
1894 + },
1895 + {
1896 + field: 'source',
1897 + title: 'Alarm Source',
1898 + valign: 'middle',
1899 + visible: false,
1900 + sortable: true
1901 + }
1902 + ]
1903 + });
1904 + console.log($('#alarms_log_table').bootstrapTable('getOptions'));
1905 + });
1906 +
1907 +/*
1908 NETDATA.alarms.get_log(0, function(data) {
1909 if(data === null) {
1910 document.getElementById('alarms_log').innerHTML =
@@ -1642,13 +1925,14 @@
1925 + data[i].status.toString() + '</td></tr>';
1926 i++;
1927 }
1645 - log += "</table>";
1928 + log += "</tbody></table>";
1929
1930 if(i == 0)
1931 log += "<h4>No alarms have been logged in this system.</h4>";
1932
1933 document.getElementById('alarms_log').innerHTML = log;
1934 })
1935 +*/
1936 });
1937 }
1938
@@ -1722,7 +2006,8 @@
2006 $.ajax({
2007 url: 'version.txt',
2008 async: true,
1725 - cache: false
2009 + cache: false,
2010 + xhrFields: { withCredentials: true } // required for the cookie
2011 })
2012 .done(function(data) {
2013 data = data.replace(/(\r\n|\n|\r| |\t)/gm,"");
@@ -2146,11 +2431,17 @@
2431 // callback to add the dashboard info to the
2432 // parallel javascript downloader in netdata
2433 var netdataPrepCallback = function() {
2434 + NETDATA.requiredJs.push({
2435 + url: NETDATA.serverDefault + 'lib/bootstrap-toggle.min.js',
2436 + isAlreadyLoaded: function() { return false; }
2437 + });
2438 +
2439 NETDATA.requiredJs.push({
2440 url: NETDATA.serverDefault + 'dashboard_info.js?v58',
2441 + async: false,
2442 isAlreadyLoaded: function() { return false; }
2443 });
2153 -
2444 +
2445 if(isdemo()) {
2446 document.getElementById('masthead').style.display = 'block';
2447 }
@@ -2284,12 +2575,6 @@
2575 <i class="fa fa-circle"></i> The excellent <a href="http://dygraphs.com/" target="_blank">Dygraphs.com</a> web chart library,
2576 <i class="fa fa-copyright"></i> Copyright 2009, Dan Vanderkam, <a href="http://dygraphs.com/legal.html" target="_blank">MIT License</a>
2577
2287 - <i class="fa fa-circle"></i> <a href="http://omnipotent.net/jquery.sparkline/" target="_blank">jQuery Sparklines</a> web chart library,
2288 - <i class="fa fa-copyright"></i> Copyright 2009-2012, Splunk Inc., <a href="http://opensource.org/licenses/BSD-3-Clause" target="_blank">New BSD License</a>
2289 -
2290 - <i class="fa fa-circle"></i> <a href="http://benpickles.github.io/peity/" target="_blank">Peity</a> web chart library,
2291 - <i class="fa fa-copyright"></i> Copyright 2009-2015, Ben Pickles, <a href="https://github.com/benpickles/peity/blob/master/MIT-LICENCE" target="_blank">MIT License</a>
2292 -
2578 <i class="fa fa-circle"></i> <a href="https://rendro.github.io/easy-pie-chart/" target="_blank">Easy Pie Chart</a> web chart library,
2579 <i class="fa fa-copyright"></i> Copyright 2013, Robert Fleischmann, <a href="https://github.com/rendro/easy-pie-chart/blob/master/LICENSE" target="_blank">MIT License</a>
2580
@@ -2308,25 +2593,16 @@
2593 <i class="fa fa-circle"></i> <a href="https://jamesflorentino.github.io/nanoScrollerJS/" target="_blank">NanoScroller</a>,
2594 <i class="fa fa-copyright"></i> Copyright 2012, James Florentino, <a href="https://github.com/jamesflorentino/nanoScrollerJS/blob/master/LICENSE" target="_blank">MIT License</a>
2595
2311 - <i class="fa fa-circle"></i> <a href="https://github.com/marcj/css-element-queries" target="_blank">CSS Element Queries</a>,
2312 - <i class="fa fa-copyright"></i> Copyright Marc J. Schmidt, <a href="https://github.com/marcj/css-element-queries/blob/master/LICENSE" target="_blank">MIT License</a>
2313 -
2596 <i class="fa fa-circle"></i> <a href="https://fortawesome.github.io/Font-Awesome/" target="_blank">FontAwesome</a>,
2597 <i class="fa fa-copyright"></i> Created by Dave Gandy, Font: <a href="http://scripts.sil.org/OFL" target="_blank">SIL OFL 1.1 License</a>, CSS: <a href="http://opensource.org/licenses/mit-license.html" target="_blank">MIT License</a>
2598
2599 <i class="fa fa-circle"></i> <a href="http://www.iconsdb.com/soylent-red-icons/seo-performance-icon.html" target="_blank">IconsDB.com Icons</a>, Icons provided as CC0 1.0 Universal (CC0 1.0) Public Domain Dedication.
2600
2319 - <i class="fa fa-circle"></i> <a href="http://morrisjs.github.io/morris.js/" target="_blank">morris.js</a>,
2320 - <i class="fa fa-copyright"></i> Copyright 2013, Olly Smith, <a href="http://morrisjs.github.io/morris.js/" target="_blank">Simplified BSD License</a>
2321 -
2322 - <i class="fa fa-circle"></i> <a href="http://raphaeljs.com/" target="_blank">Raphaël</a>,
2323 - <i class="fa fa-copyright"></i> Copyright 2008, Dmitry Baranovskiy, <a href="http://raphaeljs.com/license.html" target="_blank">MIT License</a>
2601 + <i class="fa fa-circle"></i> <a href="http://bootstrap-table.wenzhixin.net.cn/" target="_blank">bootstrap-table</a>,
2602 + <i class="fa fa-copyright"></i> Copyright (c) 2012-2016 Zhixin Wen, <a href="https://github.com/wenzhixin/bootstrap-table/blob/master/LICENSE" target="_blank">MIT License</a>
2603
2325 - <i class="fa fa-circle"></i> <a href="http://C3js.org/" target="_blank">C3</a>,
2326 - <i class="fa fa-copyright"></i> Copyright 2013, Masayuki Tanaka, <a href="https://github.com/masayuki0812/c3/blob/master/LICENSE" target="_blank">MIT License</a>
2327 -
2328 - <i class="fa fa-circle"></i> <a href="http://D3js.org/" target="_blank">D3</a>,
2329 - <i class="fa fa-copyright"></i> Copyright 2015, Mike Bostock, <a href="http://opensource.org/licenses/BSD-3-Clause" target="_blank">BSD License</a>
2604 + <i class="fa fa-circle"></i> <a href="https://github.com/hhurz/tableExport.jquery.plugin" target="_blank">tableExport.jquery.plugin</a>,
2605 + <i class="fa fa-copyright"></i> Copyright (c) 2015,2016 hhurz, <a href="http://rawgit.com/hhurz/tableExport.jquery.plugin/master/tableExport.js" target="_blank">MIT License</a>
2606
2607 </small>
2608 </div>
@@ -2478,7 +2754,7 @@
2754 </div>
2755
2756 <div class="modal fade" id="alarmsModal" tabindex="-1" role="dialog" aria-labelledby="alarmsModalLabel">
2481 - <div class="modal-dialog modal-lg" role="document">
2757 + <div class="modal-dialog modal-lg" role="document" style="display: table;"> <!-- allow the modal to expand horizontally -->
2758 <div class="modal-content">
2759 <div class="modal-header">
2760 <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
@@ -2777,4 +3053,4 @@
3053 </div>
3054 </body>
3055 </html>
2780 -<script async type="text/javascript" src="dashboard.js?v58"></script>
3056 +<script type="text/javascript" src="dashboard.js?v58"></script>
web/lib/bootstrap-table-export.min.js new
+7
@@ -0,0 +1,7 @@
1 +/*
2 +* bootstrap-table - v1.11.0 - 2016-07-02
3 +* https://github.com/wenzhixin/bootstrap-table
4 +* Copyright (c) 2016 zhixin wen
5 +* Licensed MIT License
6 +*/
7 +!function(a){"use strict";var b=a.fn.bootstrapTable.utils.sprintf,c={json:"JSON",xml:"XML",png:"PNG",csv:"CSV",txt:"TXT",sql:"SQL",doc:"MS-Word",excel:"MS-Excel",powerpoint:"MS-Powerpoint",pdf:"PDF"};a.extend(a.fn.bootstrapTable.defaults,{showExport:!1,exportDataType:"basic",exportTypes:["json","xml","csv","txt","sql","excel"],exportOptions:{}}),a.extend(a.fn.bootstrapTable.defaults.icons,{"export":"glyphicon-export icon-share"}),a.extend(a.fn.bootstrapTable.locales,{formatExport:function(){return"Export data"}}),a.extend(a.fn.bootstrapTable.defaults,a.fn.bootstrapTable.locales);var d=a.fn.bootstrapTable.Constructor,e=d.prototype.initToolbar;d.prototype.initToolbar=function(){if(this.showToolbar=this.options.showExport,e.apply(this,Array.prototype.slice.apply(arguments)),this.options.showExport){var d=this,f=this.$toolbar.find(">.btn-group"),g=f.find("div.export");if(!g.length){g=a(['<div class="export btn-group">','<button class="btn'+b(" btn-%s",this.options.buttonsClass)+b(" btn-%s",this.options.iconSize)+' dropdown-toggle" title="'+this.options.formatExport()+'" data-toggle="dropdown" type="button">',b('<i class="%s %s"></i> ',this.options.iconsPrefix,this.options.icons["export"]),'<span class="caret"></span>',"</button>",'<ul class="dropdown-menu" role="menu">',"</ul>","</div>"].join("")).appendTo(f);var h=g.find(".dropdown-menu"),i=this.options.exportTypes;if("string"==typeof this.options.exportTypes){var j=this.options.exportTypes.slice(1,-1).replace(/ /g,"").split(",");i=[],a.each(j,function(a,b){i.push(b.slice(1,-1))})}a.each(i,function(a,b){c.hasOwnProperty(b)&&h.append(['<li data-type="'+b+'">','<a href="javascript:void(0)">',c[b],"</a>","</li>"].join(""))}),h.find("li").click(function(){var b=a(this).data("type"),c=function(){d.$el.tableExport(a.extend({},d.options.exportOptions,{type:b,escape:!1}))};if("all"===d.options.exportDataType&&d.options.pagination)d.$el.one("server"===d.options.sidePagination?"post-body.bs.table":"page-change.bs.table",function(){c(),d.togglePagination()}),d.togglePagination();else if("selected"===d.options.exportDataType){var e=d.getData(),f=d.getAllSelections();d.load(f),c(),d.load(e)}else c()})}}}}(jQuery);
\ No newline at end of file
web/lib/bootstrap-table.min.js new
+8
@@ -0,0 +1,8 @@
1 +/*
2 +* bootstrap-table - v1.11.0 - 2016-07-02
3 +* https://github.com/wenzhixin/bootstrap-table
4 +* Copyright (c) 2016 zhixin wen
5 +* Licensed MIT License
6 +*/
7 +!function(a){"use strict";var b=null,c=function(a){var b=arguments,c=!0,d=1;return a=a.replace(/%s/g,function(){var a=b[d++];return"undefined"==typeof a?(c=!1,""):a}),c?a:""},d=function(b,c,d,e){var f="";return a.each(b,function(a,b){return b[c]===e?(f=b[d],!1):!0}),f},e=function(b,c){var d=-1;return a.each(b,function(a,b){return b.field===c?(d=a,!1):!0}),d},f=function(b){var c,d,e,f=0,g=[];for(c=0;c<b[0].length;c++)f+=b[0][c].colspan||1;for(c=0;c<b.length;c++)for(g[c]=[],d=0;f>d;d++)g[c][d]=!1;for(c=0;c<b.length;c++)for(d=0;d<b[c].length;d++){var h=b[c][d],i=h.rowspan||1,j=h.colspan||1,k=a.inArray(!1,g[c]);for(1===j&&(h.fieldIndex=k,"undefined"==typeof h.field&&(h.field=k)),e=0;i>e;e++)g[c+e][k]=!0;for(e=0;j>e;e++)g[c][k+e]=!0}},g=function(){if(null===b){var c,d,e=a("<p/>").addClass("fixed-table-scroll-inner"),f=a("<div/>").addClass("fixed-table-scroll-outer");f.append(e),a("body").append(f),c=e[0].offsetWidth,f.css("overflow","scroll"),d=e[0].offsetWidth,c===d&&(d=f[0].clientWidth),f.remove(),b=c-d}return b},h=function(b,d,e,f){var g=d;if("string"==typeof d){var h=d.split(".");h.length>1?(g=window,a.each(h,function(a,b){g=g[b]})):g=window[d]}return"object"==typeof g?g:"function"==typeof g?g.apply(b,e):!g&&"string"==typeof d&&c.apply(this,[d].concat(e))?c.apply(this,[d].concat(e)):f},i=function(b,c,d){var e=Object.getOwnPropertyNames(b),f=Object.getOwnPropertyNames(c),g="";if(d&&e.length!==f.length)return!1;for(var h=0;h<e.length;h++)if(g=e[h],a.inArray(g,f)>-1&&b[g]!==c[g])return!1;return!0},j=function(a){return"string"==typeof a?a.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/"/g,"&quot;").replace(/'/g,"&#039;").replace(/`/g,"&#x60;"):a},k=function(b){var c=0;return b.children().each(function(){c<a(this).outerHeight(!0)&&(c=a(this).outerHeight(!0))}),c},l=function(a){for(var b in a){var c=b.split(/(?=[A-Z])/).join("-").toLowerCase();c!==b&&(a[c]=a[b],delete a[b])}return a},m=function(a,b,c){var d=a;if("string"!=typeof b||a.hasOwnProperty(b))return c?j(a[b]):a[b];var e=b.split(".");for(var f in e)d=d&&d[e[f]];return c?j(d):d},n=function(){return!!(navigator.userAgent.indexOf("MSIE ")>0||navigator.userAgent.match(/Trident.*rv\:11\./))},o=function(){Object.keys||(Object.keys=function(){var a=Object.prototype.hasOwnProperty,b=!{toString:null}.propertyIsEnumerable("toString"),c=["toString","toLocaleString","valueOf","hasOwnProperty","isPrototypeOf","propertyIsEnumerable","constructor"],d=c.length;return function(e){if("object"!=typeof e&&("function"!=typeof e||null===e))throw new TypeError("Object.keys called on non-object");var f,g,h=[];for(f in e)a.call(e,f)&&h.push(f);if(b)for(g=0;d>g;g++)a.call(e,c[g])&&h.push(c[g]);return h}}())},p=function(b,c){this.options=c,this.$el=a(b),this.$el_=this.$el.clone(),this.timeoutId_=0,this.timeoutFooter_=0,this.init()};p.DEFAULTS={classes:"table table-hover",locale:void 0,height:void 0,undefinedText:"-",sortName:void 0,sortOrder:"asc",sortStable:!1,striped:!1,columns:[[]],data:[],dataField:"rows",method:"get",url:void 0,ajax:void 0,cache:!0,contentType:"application/json",dataType:"json",ajaxOptions:{},queryParams:function(a){return a},queryParamsType:"limit",responseHandler:function(a){return a},pagination:!1,onlyInfoPagination:!1,sidePagination:"client",totalRows:0,pageNumber:1,pageSize:10,pageList:[10,25,50,100],paginationHAlign:"right",paginationVAlign:"bottom",paginationDetailHAlign:"left",paginationPreText:"&lsaquo;",paginationNextText:"&rsaquo;",search:!1,searchOnEnterKey:!1,strictSearch:!1,searchAlign:"right",selectItemName:"btSelectItem",showHeader:!0,showFooter:!1,showColumns:!1,showPaginationSwitch:!1,showRefresh:!1,showToggle:!1,buttonsAlign:"right",smartDisplay:!0,escape:!1,minimumCountColumns:1,idField:void 0,uniqueId:void 0,cardView:!1,detailView:!1,detailFormatter:function(){return""},trimOnSearch:!0,clickToSelect:!1,singleSelect:!1,toolbar:void 0,toolbarAlign:"left",checkboxHeader:!0,sortable:!0,silentSort:!0,maintainSelected:!1,searchTimeOut:500,searchText:"",iconSize:void 0,buttonsClass:"default",iconsPrefix:"glyphicon",icons:{paginationSwitchDown:"glyphicon-collapse-down icon-chevron-down",paginationSwitchUp:"glyphicon-collapse-up icon-chevron-up",refresh:"glyphicon-refresh icon-refresh",toggle:"glyphicon-list-alt icon-list-alt",columns:"glyphicon-th icon-th",detailOpen:"glyphicon-plus icon-plus",detailClose:"glyphicon-minus icon-minus"},customSearch:a.noop,customSort:a.noop,rowStyle:function(){return{}},rowAttributes:function(){return{}},footerStyle:function(){return{}},onAll:function(){return!1},onClickCell:function(){return!1},onDblClickCell:function(){return!1},onClickRow:function(){return!1},onDblClickRow:function(){return!1},onSort:function(){return!1},onCheck:function(){return!1},onUncheck:function(){return!1},onCheckAll:function(){return!1},onUncheckAll:function(){return!1},onCheckSome:function(){return!1},onUncheckSome:function(){return!1},onLoadSuccess:function(){return!1},onLoadError:function(){return!1},onColumnSwitch:function(){return!1},onPageChange:function(){return!1},onSearch:function(){return!1},onToggle:function(){return!1},onPreBody:function(){return!1},onPostBody:function(){return!1},onPostHeader:function(){return!1},onExpandRow:function(){return!1},onCollapseRow:function(){return!1},onRefreshOptions:function(){return!1},onRefresh:function(){return!1},onResetView:function(){return!1}},p.LOCALES={},p.LOCALES["en-US"]=p.LOCALES.en={formatLoadingMessage:function(){return"Loading, please wait..."},formatRecordsPerPage:function(a){return c("%s rows per page",a)},formatShowingRows:function(a,b,d){return c("Showing %s to %s of %s rows",a,b,d)},formatDetailPagination:function(a){return c("Showing %s rows",a)},formatSearch:function(){return"Search"},formatNoMatches:function(){return"No matching records found"},formatPaginationSwitch:function(){return"Hide/Show pagination"},formatRefresh:function(){return"Refresh"},formatToggle:function(){return"Toggle"},formatColumns:function(){return"Columns"},formatAllRows:function(){return"All"}},a.extend(p.DEFAULTS,p.LOCALES["en-US"]),p.COLUMN_DEFAULTS={radio:!1,checkbox:!1,checkboxEnabled:!0,field:void 0,title:void 0,titleTooltip:void 0,"class":void 0,align:void 0,halign:void 0,falign:void 0,valign:void 0,width:void 0,sortable:!1,order:"asc",visible:!0,switchable:!0,clickToSelect:!0,formatter:void 0,footerFormatter:void 0,events:void 0,sorter:void 0,sortName:void 0,cellStyle:void 0,searchable:!0,searchFormatter:!0,cardVisible:!0},p.EVENTS={"all.bs.table":"onAll","click-cell.bs.table":"onClickCell","dbl-click-cell.bs.table":"onDblClickCell","click-row.bs.table":"onClickRow","dbl-click-row.bs.table":"onDblClickRow","sort.bs.table":"onSort","check.bs.table":"onCheck","uncheck.bs.table":"onUncheck","check-all.bs.table":"onCheckAll","uncheck-all.bs.table":"onUncheckAll","check-some.bs.table":"onCheckSome","uncheck-some.bs.table":"onUncheckSome","load-success.bs.table":"onLoadSuccess","load-error.bs.table":"onLoadError","column-switch.bs.table":"onColumnSwitch","page-change.bs.table":"onPageChange","search.bs.table":"onSearch","toggle.bs.table":"onToggle","pre-body.bs.table":"onPreBody","post-body.bs.table":"onPostBody","post-header.bs.table":"onPostHeader","expand-row.bs.table":"onExpandRow","collapse-row.bs.table":"onCollapseRow","refresh-options.bs.table":"onRefreshOptions","reset-view.bs.table":"onResetView","refresh.bs.table":"onRefresh"},p.prototype.init=function(){this.initLocale(),this.initContainer(),this.initTable(),this.initHeader(),this.initData(),this.initFooter(),this.initToolbar(),this.initPagination(),this.initBody(),this.initSearchText(),this.initServer()},p.prototype.initLocale=function(){if(this.options.locale){var b=this.options.locale.split(/-|_/);b[0].toLowerCase(),b[1]&&b[1].toUpperCase(),a.fn.bootstrapTable.locales[this.options.locale]?a.extend(this.options,a.fn.bootstrapTable.locales[this.options.locale]):a.fn.bootstrapTable.locales[b.join("-")]?a.extend(this.options,a.fn.bootstrapTable.locales[b.join("-")]):a.fn.bootstrapTable.locales[b[0]]&&a.extend(this.options,a.fn.bootstrapTable.locales[b[0]])}},p.prototype.initContainer=function(){this.$container=a(['<div class="bootstrap-table">','<div class="fixed-table-toolbar"></div>',"top"===this.options.paginationVAlign||"both"===this.options.paginationVAlign?'<div class="fixed-table-pagination" style="clear: both;"></div>':"",'<div class="fixed-table-container">','<div class="fixed-table-header"><table></table></div>','<div class="fixed-table-body">','<div class="fixed-table-loading">',this.options.formatLoadingMessage(),"</div>","</div>",'<div class="fixed-table-footer"><table><tr></tr></table></div>',"bottom"===this.options.paginationVAlign||"both"===this.options.paginationVAlign?'<div class="fixed-table-pagination"></div>':"","</div>","</div>"].join("")),this.$container.insertAfter(this.$el),this.$tableContainer=this.$container.find(".fixed-table-container"),this.$tableHeader=this.$container.find(".fixed-table-header"),this.$tableBody=this.$container.find(".fixed-table-body"),this.$tableLoading=this.$container.find(".fixed-table-loading"),this.$tableFooter=this.$container.find(".fixed-table-footer"),this.$toolbar=this.$container.find(".fixed-table-toolbar"),this.$pagination=this.$container.find(".fixed-table-pagination"),this.$tableBody.append(this.$el),this.$container.after('<div class="clearfix"></div>'),this.$el.addClass(this.options.classes),this.options.striped&&this.$el.addClass("table-striped"),-1!==a.inArray("table-no-bordered",this.options.classes.split(" "))&&this.$tableContainer.addClass("table-no-bordered")},p.prototype.initTable=function(){var b=this,c=[],d=[];if(this.$header=this.$el.find(">thead"),this.$header.length||(this.$header=a("<thead></thead>").appendTo(this.$el)),this.$header.find("tr").each(function(){var b=[];a(this).find("th").each(function(){"undefined"!=typeof a(this).data("field")&&a(this).data("field",a(this).data("field")+""),b.push(a.extend({},{title:a(this).html(),"class":a(this).attr("class"),titleTooltip:a(this).attr("title"),rowspan:a(this).attr("rowspan")?+a(this).attr("rowspan"):void 0,colspan:a(this).attr("colspan")?+a(this).attr("colspan"):void 0},a(this).data()))}),c.push(b)}),a.isArray(this.options.columns[0])||(this.options.columns=[this.options.columns]),this.options.columns=a.extend(!0,[],c,this.options.columns),this.columns=[],f(this.options.columns),a.each(this.options.columns,function(c,d){a.each(d,function(d,e){e=a.extend({},p.COLUMN_DEFAULTS,e),"undefined"!=typeof e.fieldIndex&&(b.columns[e.fieldIndex]=e),b.options.columns[c][d]=e})}),!this.options.data.length){var e=[];this.$el.find(">tbody>tr").each(function(c){var f={};f._id=a(this).attr("id"),f._class=a(this).attr("class"),f._data=l(a(this).data()),a(this).find(">td").each(function(d){for(var g,h,i=a(this),j=+i.attr("colspan")||1,k=+i.attr("rowspan")||1;e[c]&&e[c][d];d++);for(g=d;d+j>g;g++)for(h=c;c+k>h;h++)e[h]||(e[h]=[]),e[h][g]=!0;var m=b.columns[d].field;f[m]=a(this).html(),f["_"+m+"_id"]=a(this).attr("id"),f["_"+m+"_class"]=a(this).attr("class"),f["_"+m+"_rowspan"]=a(this).attr("rowspan"),f["_"+m+"_colspan"]=a(this).attr("colspan"),f["_"+m+"_title"]=a(this).attr("title"),f["_"+m+"_data"]=l(a(this).data())}),d.push(f)}),this.options.data=d,d.length&&(this.fromHtml=!0)}},p.prototype.initHeader=function(){var b=this,d={},e=[];this.header={fields:[],styles:[],classes:[],formatters:[],events:[],sorters:[],sortNames:[],cellStyles:[],searchables:[]},a.each(this.options.columns,function(f,g){e.push("<tr>"),0===f&&!b.options.cardView&&b.options.detailView&&e.push(c('<th class="detail" rowspan="%s"><div class="fht-cell"></div></th>',b.options.columns.length)),a.each(g,function(a,f){var g="",h="",i="",j="",k=c(' class="%s"',f["class"]),l=(b.options.sortOrder||f.order,"px"),m=f.width;if(void 0===f.width||b.options.cardView||"string"==typeof f.width&&-1!==f.width.indexOf("%")&&(l="%"),f.width&&"string"==typeof f.width&&(m=f.width.replace("%","").replace("px","")),h=c("text-align: %s; ",f.halign?f.halign:f.align),i=c("text-align: %s; ",f.align),j=c("vertical-align: %s; ",f.valign),j+=c("width: %s; ",!f.checkbox&&!f.radio||m?m?m+l:void 0:"36px"),"undefined"!=typeof f.fieldIndex){if(b.header.fields[f.fieldIndex]=f.field,b.header.styles[f.fieldIndex]=i+j,b.header.classes[f.fieldIndex]=k,b.header.formatters[f.fieldIndex]=f.formatter,b.header.events[f.fieldIndex]=f.events,b.header.sorters[f.fieldIndex]=f.sorter,b.header.sortNames[f.fieldIndex]=f.sortName,b.header.cellStyles[f.fieldIndex]=f.cellStyle,b.header.searchables[f.fieldIndex]=f.searchable,!f.visible)return;if(b.options.cardView&&!f.cardVisible)return;d[f.field]=f}e.push("<th"+c(' title="%s"',f.titleTooltip),f.checkbox||f.radio?c(' class="bs-checkbox %s"',f["class"]||""):k,c(' style="%s"',h+j),c(' rowspan="%s"',f.rowspan),c(' colspan="%s"',f.colspan),c(' data-field="%s"',f.field),"tabindex='0'",">"),e.push(c('<div class="th-inner %s">',b.options.sortable&&f.sortable?"sortable both":"")),g=f.title,f.checkbox&&(!b.options.singleSelect&&b.options.checkboxHeader&&(g='<input name="btSelectAll" type="checkbox" />'),b.header.stateField=f.field),f.radio&&(g="",b.header.stateField=f.field,b.options.singleSelect=!0),e.push(g),e.push("</div>"),e.push('<div class="fht-cell"></div>'),e.push("</div>"),e.push("</th>")}),e.push("</tr>")}),this.$header.html(e.join("")),this.$header.find("th[data-field]").each(function(){a(this).data(d[a(this).data("field")])}),this.$container.off("click",".th-inner").on("click",".th-inner",function(c){var d=a(this);return b.options.detailView&&d.closest(".bootstrap-table")[0]!==b.$container[0]?!1:void(b.options.sortable&&d.parent().data().sortable&&b.onSort(c))}),this.$header.children().children().off("keypress").on("keypress",function(c){if(b.options.sortable&&a(this).data().sortable){var d=c.keyCode||c.which;13==d&&b.onSort(c)}}),a(window).off("resize.bootstrap-table"),!this.options.showHeader||this.options.cardView?(this.$header.hide(),this.$tableHeader.hide(),this.$tableLoading.css("top",0)):(this.$header.show(),this.$tableHeader.show(),this.$tableLoading.css("top",this.$header.outerHeight()+1),this.getCaret(),a(window).on("resize.bootstrap-table",a.proxy(this.resetWidth,this))),this.$selectAll=this.$header.find('[name="btSelectAll"]'),this.$selectAll.off("click").on("click",function(){var c=a(this).prop("checked");b[c?"checkAll":"uncheckAll"](),b.updateSelected()})},p.prototype.initFooter=function(){!this.options.showFooter||this.options.cardView?this.$tableFooter.hide():this.$tableFooter.show()},p.prototype.initData=function(a,b){this.data="append"===b?this.data.concat(a):"prepend"===b?[].concat(a).concat(this.data):a||this.options.data,this.options.data="append"===b?this.options.data.concat(a):"prepend"===b?[].concat(a).concat(this.options.data):this.data,"server"!==this.options.sidePagination&&this.initSort()},p.prototype.initSort=function(){var b=this,c=this.options.sortName,d="desc"===this.options.sortOrder?-1:1,e=a.inArray(this.options.sortName,this.header.fields);return this.options.customSort!==a.noop?void this.options.customSort.apply(this,[this.options.sortName,this.options.sortOrder]):void(-1!==e&&(this.options.sortStable&&a.each(this.data,function(a,b){b.hasOwnProperty("_position")||(b._position=a)}),this.data.sort(function(f,g){b.header.sortNames[e]&&(c=b.header.sortNames[e]);var i=m(f,c,b.options.escape),j=m(g,c,b.options.escape),k=h(b.header,b.header.sorters[e],[i,j]);return void 0!==k?d*k:((void 0===i||null===i)&&(i=""),(void 0===j||null===j)&&(j=""),b.options.sortStable&&i===j&&(i=f._position,j=g._position),a.isNumeric(i)&&a.isNumeric(j)?(i=parseFloat(i),j=parseFloat(j),j>i?-1*d:d):i===j?0:("string"!=typeof i&&(i=i.toString()),-1===i.localeCompare(j)?-1*d:d))})))},p.prototype.onSort=function(b){var c="keypress"===b.type?a(b.currentTarget):a(b.currentTarget).parent(),d=this.$header.find("th").eq(c.index());return this.$header.add(this.$header_).find("span.order").remove(),this.options.sortName===c.data("field")?this.options.sortOrder="asc"===this.options.sortOrder?"desc":"asc":(this.options.sortName=c.data("field"),this.options.sortOrder="asc"===c.data("order")?"desc":"asc"),this.trigger("sort",this.options.sortName,this.options.sortOrder),c.add(d).data("order",this.options.sortOrder),this.getCaret(),"server"===this.options.sidePagination?void this.initServer(this.options.silentSort):(this.initSort(),void this.initBody())},p.prototype.initToolbar=function(){var b,d,e=this,f=[],g=0,i=0;this.$toolbar.find(".bs-bars").children().length&&a("body").append(a(this.options.toolbar)),this.$toolbar.html(""),("string"==typeof this.options.toolbar||"object"==typeof this.options.toolbar)&&a(c('<div class="bs-bars pull-%s"></div>',this.options.toolbarAlign)).appendTo(this.$toolbar).append(a(this.options.toolbar)),f=[c('<div class="columns columns-%s btn-group pull-%s">',this.options.buttonsAlign,this.options.buttonsAlign)],"string"==typeof this.options.icons&&(this.options.icons=h(null,this.options.icons)),this.options.showPaginationSwitch&&f.push(c('<button class="btn'+c(" btn-%s",this.options.buttonsClass)+c(" btn-%s",this.options.iconSize)+'" type="button" name="paginationSwitch" title="%s">',this.options.formatPaginationSwitch()),c('<i class="%s %s"></i>',this.options.iconsPrefix,this.options.icons.paginationSwitchDown),"</button>"),this.options.showRefresh&&f.push(c('<button class="btn'+c(" btn-%s",this.options.buttonsClass)+c(" btn-%s",this.options.iconSize)+'" type="button" name="refresh" title="%s">',this.options.formatRefresh()),c('<i class="%s %s"></i>',this.options.iconsPrefix,this.options.icons.refresh),"</button>"),this.options.showToggle&&f.push(c('<button class="btn'+c(" btn-%s",this.options.buttonsClass)+c(" btn-%s",this.options.iconSize)+'" type="button" name="toggle" title="%s">',this.options.formatToggle()),c('<i class="%s %s"></i>',this.options.iconsPrefix,this.options.icons.toggle),"</button>"),this.options.showColumns&&(f.push(c('<div class="keep-open btn-group" title="%s">',this.options.formatColumns()),'<button type="button" class="btn'+c(" btn-%s",this.options.buttonsClass)+c(" btn-%s",this.options.iconSize)+' dropdown-toggle" data-toggle="dropdown">',c('<i class="%s %s"></i>',this.options.iconsPrefix,this.options.icons.columns),' <span class="caret"></span>',"</button>",'<ul class="dropdown-menu" role="menu">'),a.each(this.columns,function(a,b){if(!(b.radio||b.checkbox||e.options.cardView&&!b.cardVisible)){var d=b.visible?' checked="checked"':"";b.switchable&&(f.push(c('<li><label><input type="checkbox" data-field="%s" value="%s"%s> %s</label></li>',b.field,a,d,b.title)),i++)}}),f.push("</ul>","</div>")),f.push("</div>"),(this.showToolbar||f.length>2)&&this.$toolbar.append(f.join("")),this.options.showPaginationSwitch&&this.$toolbar.find('button[name="paginationSwitch"]').off("click").on("click",a.proxy(this.togglePagination,this)),this.options.showRefresh&&this.$toolbar.find('button[name="refresh"]').off("click").on("click",a.proxy(this.refresh,this)),this.options.showToggle&&this.$toolbar.find('button[name="toggle"]').off("click").on("click",function(){e.toggleView()}),this.options.showColumns&&(b=this.$toolbar.find(".keep-open"),i<=this.options.minimumCountColumns&&b.find("input").prop("disabled",!0),b.find("li").off("click").on("click",function(a){a.stopImmediatePropagation()}),b.find("input").off("click").on("click",function(){var b=a(this);e.toggleColumn(a(this).val(),b.prop("checked"),!1),e.trigger("column-switch",a(this).data("field"),b.prop("checked"))})),this.options.search&&(f=[],f.push('<div class="pull-'+this.options.searchAlign+' search">',c('<input class="form-control'+c(" input-%s",this.options.iconSize)+'" type="text" placeholder="%s">',this.options.formatSearch()),"</div>"),this.$toolbar.append(f.join("")),d=this.$toolbar.find(".search input"),d.off("keyup drop").on("keyup drop",function(b){e.options.searchOnEnterKey&&13!==b.keyCode||a.inArray(b.keyCode,[37,38,39,40])>-1||(clearTimeout(g),g=setTimeout(function(){e.onSearch(b)},e.options.searchTimeOut))}),n()&&d.off("mouseup").on("mouseup",function(a){clearTimeout(g),g=setTimeout(function(){e.onSearch(a)},e.options.searchTimeOut)}))},p.prototype.onSearch=function(b){var c=a.trim(a(b.currentTarget).val());this.options.trimOnSearch&&a(b.currentTarget).val()!==c&&a(b.currentTarget).val(c),c!==this.searchText&&(this.searchText=c,this.options.searchText=c,this.options.pageNumber=1,this.initSearch(),this.updatePagination(),this.trigger("search",c))},p.prototype.initSearch=function(){var b=this;if("server"!==this.options.sidePagination){if(this.options.customSearch!==a.noop)return void this.options.customSearch.apply(this,[this.searchText]);var c=this.searchText&&(this.options.escape?j(this.searchText):this.searchText).toLowerCase(),d=a.isEmptyObject(this.filterColumns)?null:this.filterColumns;this.data=d?a.grep(this.options.data,function(b){for(var c in d)if(a.isArray(d[c])&&-1===a.inArray(b[c],d[c])||b[c]!==d[c])return!1;return!0}):this.options.data,this.data=c?a.grep(this.data,function(d,f){for(var g=0;g<b.header.fields.length;g++)if(b.header.searchables[g]){var i,j=a.isNumeric(b.header.fields[g])?parseInt(b.header.fields[g],10):b.header.fields[g],k=b.columns[e(b.columns,j)];if("string"==typeof j){i=d;for(var l=j.split("."),m=0;m<l.length;m++)i=i[l[m]];k&&k.searchFormatter&&(i=h(k,b.header.formatters[g],[i,d,f],i))}else i=d[j];if("string"==typeof i||"number"==typeof i)if(b.options.strictSearch){if((i+"").toLowerCase()===c)return!0}else if(-1!==(i+"").toLowerCase().indexOf(c))return!0}return!1}):this.data}},p.prototype.initPagination=function(){if(!this.options.pagination)return void this.$pagination.hide();this.$pagination.show();var b,d,e,f,g,h,i,j,k,l=this,m=[],n=!1,o=this.getData(),p=this.options.pageList;if("server"!==this.options.sidePagination&&(this.options.totalRows=o.length),this.totalPages=0,this.options.totalRows){if(this.options.pageSize===this.options.formatAllRows())this.options.pageSize=this.options.totalRows,n=!0;else if(this.options.pageSize===this.options.totalRows){var q="string"==typeof this.options.pageList?this.options.pageList.replace("[","").replace("]","").replace(/ /g,"").toLowerCase().split(","):this.options.pageList;a.inArray(this.options.formatAllRows().toLowerCase(),q)>-1&&(n=!0)}this.totalPages=~~((this.options.totalRows-1)/this.options.pageSize)+1,this.options.totalPages=this.totalPages}if(this.totalPages>0&&this.options.pageNumber>this.totalPages&&(this.options.pageNumber=this.totalPages),this.pageFrom=(this.options.pageNumber-1)*this.options.pageSize+1,this.pageTo=this.options.pageNumber*this.options.pageSize,this.pageTo>this.options.totalRows&&(this.pageTo=this.options.totalRows),m.push('<div class="pull-'+this.options.paginationDetailHAlign+' pagination-detail">','<span class="pagination-info">',this.options.onlyInfoPagination?this.options.formatDetailPagination(this.options.totalRows):this.options.formatShowingRows(this.pageFrom,this.pageTo,this.options.totalRows),"</span>"),!this.options.onlyInfoPagination){m.push('<span class="page-list">');var r=[c('<span class="btn-group %s">',"top"===this.options.paginationVAlign||"both"===this.options.paginationVAlign?"dropdown":"dropup"),'<button type="button" class="btn'+c(" btn-%s",this.options.buttonsClass)+c(" btn-%s",this.options.iconSize)+' dropdown-toggle" data-toggle="dropdown">','<span class="page-size">',n?this.options.formatAllRows():this.options.pageSize,"</span>",' <span class="caret"></span>',"</button>",'<ul class="dropdown-menu" role="menu">'];if("string"==typeof this.options.pageList){var s=this.options.pageList.replace("[","").replace("]","").replace(/ /g,"").split(",");p=[],a.each(s,function(a,b){p.push(b.toUpperCase()===l.options.formatAllRows().toUpperCase()?l.options.formatAllRows():+b)})}for(a.each(p,function(a,b){if(!l.options.smartDisplay||0===a||p[a-1]<=l.options.totalRows){var d;d=n?b===l.options.formatAllRows()?' class="active"':"":b===l.options.pageSize?' class="active"':"",r.push(c('<li%s><a href="javascript:void(0)">%s</a></li>',d,b))}}),r.push("</ul></span>"),m.push(this.options.formatRecordsPerPage(r.join(""))),m.push("</span>"),m.push("</div>",'<div class="pull-'+this.options.paginationHAlign+' pagination">','<ul class="pagination'+c(" pagination-%s",this.options.iconSize)+'">','<li class="page-pre"><a href="javascript:void(0)">'+this.options.paginationPreText+"</a></li>"),this.totalPages<5?(d=1,e=this.totalPages):(d=this.options.pageNumber-2,e=d+4,1>d&&(d=1,e=5),e>this.totalPages&&(e=this.totalPages,d=e-4)),this.totalPages>=6&&(this.options.pageNumber>=3&&(m.push('<li class="page-first'+(1===this.options.pageNumber?" active":"")+'">','<a href="javascript:void(0)">',1,"</a>","</li>"),d++),this.options.pageNumber>=4&&(4==this.options.pageNumber||6==this.totalPages||7==this.totalPages?d--:m.push('<li class="page-first-separator disabled">','<a href="javascript:void(0)">...</a>',"</li>"),e--)),this.totalPages>=7&&this.options.pageNumber>=this.totalPages-2&&d--,6==this.totalPages?this.options.pageNumber>=this.totalPages-2&&e++:this.totalPages>=7&&(7==this.totalPages||this.options.pageNumber>=this.totalPages-3)&&e++,b=d;e>=b;b++)m.push('<li class="page-number'+(b===this.options.pageNumber?" active":"")+'">','<a href="javascript:void(0)">',b,"</a>","</li>");this.totalPages>=8&&this.options.pageNumber<=this.totalPages-4&&m.push('<li class="page-last-separator disabled">','<a href="javascript:void(0)">...</a>',"</li>"),this.totalPages>=6&&this.options.pageNumber<=this.totalPages-3&&m.push('<li class="page-last'+(this.totalPages===this.options.pageNumber?" active":"")+'">','<a href="javascript:void(0)">',this.totalPages,"</a>","</li>"),m.push('<li class="page-next"><a href="javascript:void(0)">'+this.options.paginationNextText+"</a></li>","</ul>","</div>")}this.$pagination.html(m.join("")),this.options.onlyInfoPagination||(f=this.$pagination.find(".page-list a"),g=this.$pagination.find(".page-first"),h=this.$pagination.find(".page-pre"),i=this.$pagination.find(".page-next"),j=this.$pagination.find(".page-last"),k=this.$pagination.find(".page-number"),this.options.smartDisplay&&(this.totalPages<=1&&this.$pagination.find("div.pagination").hide(),(p.length<2||this.options.totalRows<=p[0])&&this.$pagination.find("span.page-list").hide(),this.$pagination[this.getData().length?"show":"hide"]()),n&&(this.options.pageSize=this.options.formatAllRows()),f.off("click").on("click",a.proxy(this.onPageListChange,this)),g.off("click").on("click",a.proxy(this.onPageFirst,this)),h.off("click").on("click",a.proxy(this.onPagePre,this)),i.off("click").on("click",a.proxy(this.onPageNext,this)),j.off("click").on("click",a.proxy(this.onPageLast,this)),k.off("click").on("click",a.proxy(this.onPageNumber,this)))},p.prototype.updatePagination=function(b){b&&a(b.currentTarget).hasClass("disabled")||(this.options.maintainSelected||this.resetRows(),this.initPagination(),"server"===this.options.sidePagination?this.initServer():this.initBody(),this.trigger("page-change",this.options.pageNumber,this.options.pageSize))},p.prototype.onPageListChange=function(b){var c=a(b.currentTarget);c.parent().addClass("active").siblings().removeClass("active"),this.options.pageSize=c.text().toUpperCase()===this.options.formatAllRows().toUpperCase()?this.options.formatAllRows():+c.text(),this.$toolbar.find(".page-size").text(this.options.pageSize),this.updatePagination(b)},p.prototype.onPageFirst=function(a){this.options.pageNumber=1,this.updatePagination(a)},p.prototype.onPagePre=function(a){this.options.pageNumber-1===0?this.options.pageNumber=this.options.totalPages:this.options.pageNumber--,this.updatePagination(a)},p.prototype.onPageNext=function(a){this.options.pageNumber+1>this.options.totalPages?this.options.pageNumber=1:this.options.pageNumber++,this.updatePagination(a)},p.prototype.onPageLast=function(a){this.options.pageNumber=this.totalPages,this.updatePagination(a)},p.prototype.onPageNumber=function(b){this.options.pageNumber!==+a(b.currentTarget).text()&&(this.options.pageNumber=+a(b.currentTarget).text(),this.updatePagination(b))},p.prototype.initBody=function(b){var f=this,g=[],i=this.getData();this.trigger("pre-body",i),this.$body=this.$el.find(">tbody"),this.$body.length||(this.$body=a("<tbody></tbody>").appendTo(this.$el)),this.options.pagination&&"server"!==this.options.sidePagination||(this.pageFrom=1,this.pageTo=i.length);for(var k=this.pageFrom-1;k<this.pageTo;k++){var l,n=i[k],o={},p=[],q="",r={},s=[];if(o=h(this.options,this.options.rowStyle,[n,k],o),o&&o.css)for(l in o.css)p.push(l+": "+o.css[l]);if(r=h(this.options,this.options.rowAttributes,[n,k],r))for(l in r)s.push(c('%s="%s"',l,j(r[l])));n._data&&!a.isEmptyObject(n._data)&&a.each(n._data,function(a,b){"index"!==a&&(q+=c(' data-%s="%s"',a,b))}),g.push("<tr",c(" %s",s.join(" ")),c(' id="%s"',a.isArray(n)?void 0:n._id),c(' class="%s"',o.classes||(a.isArray(n)?void 0:n._class)),c(' data-index="%s"',k),c(' data-uniqueid="%s"',n[this.options.uniqueId]),c("%s",q),">"),this.options.cardView&&g.push(c('<td colspan="%s"><div class="card-views">',this.header.fields.length)),!this.options.cardView&&this.options.detailView&&g.push("<td>",'<a class="detail-icon" href="javascript:">',c('<i class="%s %s"></i>',this.options.iconsPrefix,this.options.icons.detailOpen),"</a>","</td>"),a.each(this.header.fields,function(b,e){var i="",j=m(n,e,f.options.escape),l="",q={},r="",s=f.header.classes[b],t="",u="",v="",w="",x=f.columns[b];if(!(f.fromHtml&&"undefined"==typeof j||!x.visible||f.options.cardView&&!x.cardVisible)){if(o=c('style="%s"',p.concat(f.header.styles[b]).join("; ")),n["_"+e+"_id"]&&(r=c(' id="%s"',n["_"+e+"_id"])),n["_"+e+"_class"]&&(s=c(' class="%s"',n["_"+e+"_class"])),n["_"+e+"_rowspan"]&&(u=c(' rowspan="%s"',n["_"+e+"_rowspan"])),n["_"+e+"_colspan"]&&(v=c(' colspan="%s"',n["_"+e+"_colspan"])),n["_"+e+"_title"]&&(w=c(' title="%s"',n["_"+e+"_title"])),q=h(f.header,f.header.cellStyles[b],[j,n,k,e],q),q.classes&&(s=c(' class="%s"',q.classes)),q.css){var y=[];for(var z in q.css)y.push(z+": "+q.css[z]);o=c('style="%s"',y.concat(f.header.styles[b]).join("; "))}j=h(x,f.header.formatters[b],[j,n,k],j),n["_"+e+"_data"]&&!a.isEmptyObject(n["_"+e+"_data"])&&a.each(n["_"+e+"_data"],function(a,b){"index"!==a&&(t+=c(' data-%s="%s"',a,b))}),x.checkbox||x.radio?(l=x.checkbox?"checkbox":l,l=x.radio?"radio":l,i=[c(f.options.cardView?'<div class="card-view %s">':'<td class="bs-checkbox %s">',x["class"]||""),"<input"+c(' data-index="%s"',k)+c(' name="%s"',f.options.selectItemName)+c(' type="%s"',l)+c(' value="%s"',n[f.options.idField])+c(' checked="%s"',j===!0||j&&j.checked?"checked":void 0)+c(' disabled="%s"',!x.checkboxEnabled||j&&j.disabled?"disabled":void 0)+" />",f.header.formatters[b]&&"string"==typeof j?j:"",f.options.cardView?"</div>":"</td>"].join(""),n[f.header.stateField]=j===!0||j&&j.checked):(j="undefined"==typeof j||null===j?f.options.undefinedText:j,i=f.options.cardView?['<div class="card-view">',f.options.showHeader?c('<span class="title" %s>%s</span>',o,d(f.columns,"field","title",e)):"",c('<span class="value">%s</span>',j),"</div>"].join(""):[c("<td%s %s %s %s %s %s %s>",r,s,o,t,u,v,w),j,"</td>"].join(""),f.options.cardView&&f.options.smartDisplay&&""===j&&(i='<div class="card-view"></div>')),g.push(i)}}),this.options.cardView&&g.push("</div></td>"),g.push("</tr>")}g.length||g.push('<tr class="no-records-found">',c('<td colspan="%s">%s</td>',this.$header.find("th").length,this.options.formatNoMatches()),"</tr>"),this.$body.html(g.join("")),b||this.scrollTo(0),this.$body.find("> tr[data-index] > td").off("click dblclick").on("click dblclick",function(b){var d=a(this),g=d.parent(),h=f.data[g.data("index")],i=d[0].cellIndex,j=f.getVisibleFields(),k=j[f.options.detailView&&!f.options.cardView?i-1:i],l=f.columns[e(f.columns,k)],n=m(h,k,f.options.escape);if(!d.find(".detail-icon").length&&(f.trigger("click"===b.type?"click-cell":"dbl-click-cell",k,n,h,d),f.trigger("click"===b.type?"click-row":"dbl-click-row",h,g,k),
8 +"click"===b.type&&f.options.clickToSelect&&l.clickToSelect)){var o=g.find(c('[name="%s"]',f.options.selectItemName));o.length&&o[0].click()}}),this.$body.find("> tr[data-index] > td > .detail-icon").off("click").on("click",function(){var b=a(this),d=b.parent().parent(),e=d.data("index"),g=i[e];if(d.next().is("tr.detail-view"))b.find("i").attr("class",c("%s %s",f.options.iconsPrefix,f.options.icons.detailOpen)),d.next().remove(),f.trigger("collapse-row",e,g);else{b.find("i").attr("class",c("%s %s",f.options.iconsPrefix,f.options.icons.detailClose)),d.after(c('<tr class="detail-view"><td colspan="%s"></td></tr>',d.find("td").length));var j=d.next().find("td"),k=h(f.options,f.options.detailFormatter,[e,g,j],"");1===j.length&&j.append(k),f.trigger("expand-row",e,g,j)}f.resetView()}),this.$selectItem=this.$body.find(c('[name="%s"]',this.options.selectItemName)),this.$selectItem.off("click").on("click",function(b){b.stopImmediatePropagation();var c=a(this),d=c.prop("checked"),e=f.data[c.data("index")];f.options.maintainSelected&&a(this).is(":radio")&&a.each(f.options.data,function(a,b){b[f.header.stateField]=!1}),e[f.header.stateField]=d,f.options.singleSelect&&(f.$selectItem.not(this).each(function(){f.data[a(this).data("index")][f.header.stateField]=!1}),f.$selectItem.filter(":checked").not(this).prop("checked",!1)),f.updateSelected(),f.trigger(d?"check":"uncheck",e,c)}),a.each(this.header.events,function(b,c){if(c){"string"==typeof c&&(c=h(null,c));var d=f.header.fields[b],e=a.inArray(d,f.getVisibleFields());f.options.detailView&&!f.options.cardView&&(e+=1);for(var g in c)f.$body.find(">tr:not(.no-records-found)").each(function(){var b=a(this),h=b.find(f.options.cardView?".card-view":"td").eq(e),i=g.indexOf(" "),j=g.substring(0,i),k=g.substring(i+1),l=c[g];h.find(k).off(j).on(j,function(a){var c=b.data("index"),e=f.data[c],g=e[d];l.apply(this,[a,g,e,c])})})}}),this.updateSelected(),this.resetView(),this.trigger("post-body",i)},p.prototype.initServer=function(b,c,d){var e,f=this,g={},i={searchText:this.searchText,sortName:this.options.sortName,sortOrder:this.options.sortOrder};this.options.pagination&&(i.pageSize=this.options.pageSize===this.options.formatAllRows()?this.options.totalRows:this.options.pageSize,i.pageNumber=this.options.pageNumber),(d||this.options.url||this.options.ajax)&&("limit"===this.options.queryParamsType&&(i={search:i.searchText,sort:i.sortName,order:i.sortOrder},this.options.pagination&&(i.offset=this.options.pageSize===this.options.formatAllRows()?0:this.options.pageSize*(this.options.pageNumber-1),i.limit=this.options.pageSize===this.options.formatAllRows()?this.options.totalRows:this.options.pageSize)),a.isEmptyObject(this.filterColumnsPartial)||(i.filter=JSON.stringify(this.filterColumnsPartial,null)),g=h(this.options,this.options.queryParams,[i],g),a.extend(g,c||{}),g!==!1&&(b||this.$tableLoading.show(),e=a.extend({},h(null,this.options.ajaxOptions),{type:this.options.method,url:d||this.options.url,data:"application/json"===this.options.contentType&&"post"===this.options.method?JSON.stringify(g):g,cache:this.options.cache,contentType:this.options.contentType,dataType:this.options.dataType,success:function(a){a=h(f.options,f.options.responseHandler,[a],a),f.load(a),f.trigger("load-success",a),b||f.$tableLoading.hide()},error:function(a){f.trigger("load-error",a.status,a),b||f.$tableLoading.hide()}}),this.options.ajax?h(this,this.options.ajax,[e],null):(this._xhr&&4!==this._xhr.readyState&&this._xhr.abort(),this._xhr=a.ajax(e))))},p.prototype.initSearchText=function(){if(this.options.search&&""!==this.options.searchText){var a=this.$toolbar.find(".search input");a.val(this.options.searchText),this.onSearch({currentTarget:a})}},p.prototype.getCaret=function(){var b=this;a.each(this.$header.find("th"),function(c,d){a(d).find(".sortable").removeClass("desc asc").addClass(a(d).data("field")===b.options.sortName?b.options.sortOrder:"both")})},p.prototype.updateSelected=function(){var b=this.$selectItem.filter(":enabled").length&&this.$selectItem.filter(":enabled").length===this.$selectItem.filter(":enabled").filter(":checked").length;this.$selectAll.add(this.$selectAll_).prop("checked",b),this.$selectItem.each(function(){a(this).closest("tr")[a(this).prop("checked")?"addClass":"removeClass"]("selected")})},p.prototype.updateRows=function(){var b=this;this.$selectItem.each(function(){b.data[a(this).data("index")][b.header.stateField]=a(this).prop("checked")})},p.prototype.resetRows=function(){var b=this;a.each(this.data,function(a,c){b.$selectAll.prop("checked",!1),b.$selectItem.prop("checked",!1),b.header.stateField&&(c[b.header.stateField]=!1)})},p.prototype.trigger=function(b){var c=Array.prototype.slice.call(arguments,1);b+=".bs.table",this.options[p.EVENTS[b]].apply(this.options,c),this.$el.trigger(a.Event(b),c),this.options.onAll(b,c),this.$el.trigger(a.Event("all.bs.table"),[b,c])},p.prototype.resetHeader=function(){clearTimeout(this.timeoutId_),this.timeoutId_=setTimeout(a.proxy(this.fitHeader,this),this.$el.is(":hidden")?100:0)},p.prototype.fitHeader=function(){var b,d,e,f,h=this;if(h.$el.is(":hidden"))return void(h.timeoutId_=setTimeout(a.proxy(h.fitHeader,h),100));if(b=this.$tableBody.get(0),d=b.scrollWidth>b.clientWidth&&b.scrollHeight>b.clientHeight+this.$header.outerHeight()?g():0,this.$el.css("margin-top",-this.$header.outerHeight()),e=a(":focus"),e.length>0){var i=e.parents("th");if(i.length>0){var j=i.attr("data-field");if(void 0!==j){var k=this.$header.find("[data-field='"+j+"']");k.length>0&&k.find(":input").addClass("focus-temp")}}}this.$header_=this.$header.clone(!0,!0),this.$selectAll_=this.$header_.find('[name="btSelectAll"]'),this.$tableHeader.css({"margin-right":d}).find("table").css("width",this.$el.outerWidth()).html("").attr("class",this.$el.attr("class")).append(this.$header_),f=a(".focus-temp:visible:eq(0)"),f.length>0&&(f.focus(),this.$header.find(".focus-temp").removeClass("focus-temp")),this.$header.find("th[data-field]").each(function(){h.$header_.find(c('th[data-field="%s"]',a(this).data("field"))).data(a(this).data())});var l=this.getVisibleFields(),m=this.$header_.find("th");this.$body.find(">tr:first-child:not(.no-records-found) > *").each(function(b){var d=a(this),e=b;h.options.detailView&&!h.options.cardView&&(0===b&&h.$header_.find("th.detail").find(".fht-cell").width(d.innerWidth()),e=b-1);var f=h.$header_.find(c('th[data-field="%s"]',l[e]));f.length>1&&(f=a(m[d[0].cellIndex])),f.find(".fht-cell").width(d.innerWidth())}),this.$tableBody.off("scroll").on("scroll",function(){h.$tableHeader.scrollLeft(a(this).scrollLeft()),h.options.showFooter&&!h.options.cardView&&h.$tableFooter.scrollLeft(a(this).scrollLeft())}),h.trigger("post-header")},p.prototype.resetFooter=function(){var b=this,d=b.getData(),e=[];this.options.showFooter&&!this.options.cardView&&(!this.options.cardView&&this.options.detailView&&e.push('<td><div class="th-inner">&nbsp;</div><div class="fht-cell"></div></td>'),a.each(this.columns,function(a,f){var g,i="",j="",k=[],l={},m=c(' class="%s"',f["class"]);if(f.visible&&(!b.options.cardView||f.cardVisible)){if(i=c("text-align: %s; ",f.falign?f.falign:f.align),j=c("vertical-align: %s; ",f.valign),l=h(null,b.options.footerStyle),l&&l.css)for(g in l.css)k.push(g+": "+l.css[g]);e.push("<td",m,c(' style="%s"',i+j+k.concat().join("; ")),">"),e.push('<div class="th-inner">'),e.push(h(f,f.footerFormatter,[d],"&nbsp;")||"&nbsp;"),e.push("</div>"),e.push('<div class="fht-cell"></div>'),e.push("</div>"),e.push("</td>")}}),this.$tableFooter.find("tr").html(e.join("")),this.$tableFooter.show(),clearTimeout(this.timeoutFooter_),this.timeoutFooter_=setTimeout(a.proxy(this.fitFooter,this),this.$el.is(":hidden")?100:0))},p.prototype.fitFooter=function(){var b,c,d;return clearTimeout(this.timeoutFooter_),this.$el.is(":hidden")?void(this.timeoutFooter_=setTimeout(a.proxy(this.fitFooter,this),100)):(c=this.$el.css("width"),d=c>this.$tableBody.width()?g():0,this.$tableFooter.css({"margin-right":d}).find("table").css("width",c).attr("class",this.$el.attr("class")),b=this.$tableFooter.find("td"),void this.$body.find(">tr:first-child:not(.no-records-found) > *").each(function(c){var d=a(this);b.eq(c).find(".fht-cell").width(d.innerWidth())}))},p.prototype.toggleColumn=function(a,b,d){if(-1!==a&&(this.columns[a].visible=b,this.initHeader(),this.initSearch(),this.initPagination(),this.initBody(),this.options.showColumns)){var e=this.$toolbar.find(".keep-open input").prop("disabled",!1);d&&e.filter(c('[value="%s"]',a)).prop("checked",b),e.filter(":checked").length<=this.options.minimumCountColumns&&e.filter(":checked").prop("disabled",!0)}},p.prototype.toggleRow=function(a,b,d){-1!==a&&this.$body.find("undefined"!=typeof a?c('tr[data-index="%s"]',a):c('tr[data-uniqueid="%s"]',b))[d?"show":"hide"]()},p.prototype.getVisibleFields=function(){var b=this,c=[];return a.each(this.header.fields,function(a,d){var f=b.columns[e(b.columns,d)];f.visible&&c.push(d)}),c},p.prototype.resetView=function(a){var b=0;if(a&&a.height&&(this.options.height=a.height),this.$selectAll.prop("checked",this.$selectItem.length>0&&this.$selectItem.length===this.$selectItem.filter(":checked").length),this.options.height){var c=k(this.$toolbar),d=k(this.$pagination),e=this.options.height-c-d;this.$tableContainer.css("height",e+"px")}return this.options.cardView?(this.$el.css("margin-top","0"),this.$tableContainer.css("padding-bottom","0"),void this.$tableFooter.hide()):(this.options.showHeader&&this.options.height?(this.$tableHeader.show(),this.resetHeader(),b+=this.$header.outerHeight()):(this.$tableHeader.hide(),this.trigger("post-header")),this.options.showFooter&&(this.resetFooter(),this.options.height&&(b+=this.$tableFooter.outerHeight()+1)),this.getCaret(),this.$tableContainer.css("padding-bottom",b+"px"),void this.trigger("reset-view"))},p.prototype.getData=function(b){return!this.searchText&&a.isEmptyObject(this.filterColumns)&&a.isEmptyObject(this.filterColumnsPartial)?b?this.options.data.slice(this.pageFrom-1,this.pageTo):this.options.data:b?this.data.slice(this.pageFrom-1,this.pageTo):this.data},p.prototype.load=function(b){var c=!1;"server"===this.options.sidePagination?(this.options.totalRows=b.total,c=b.fixedScroll,b=b[this.options.dataField]):a.isArray(b)||(c=b.fixedScroll,b=b.data),this.initData(b),this.initSearch(),this.initPagination(),this.initBody(c)},p.prototype.append=function(a){this.initData(a,"append"),this.initSearch(),this.initPagination(),this.initSort(),this.initBody(!0)},p.prototype.prepend=function(a){this.initData(a,"prepend"),this.initSearch(),this.initPagination(),this.initSort(),this.initBody(!0)},p.prototype.remove=function(b){var c,d,e=this.options.data.length;if(b.hasOwnProperty("field")&&b.hasOwnProperty("values")){for(c=e-1;c>=0;c--)d=this.options.data[c],d.hasOwnProperty(b.field)&&-1!==a.inArray(d[b.field],b.values)&&this.options.data.splice(c,1);e!==this.options.data.length&&(this.initSearch(),this.initPagination(),this.initSort(),this.initBody(!0))}},p.prototype.removeAll=function(){this.options.data.length>0&&(this.options.data.splice(0,this.options.data.length),this.initSearch(),this.initPagination(),this.initBody(!0))},p.prototype.getRowByUniqueId=function(a){var b,c,d,e=this.options.uniqueId,f=this.options.data.length,g=null;for(b=f-1;b>=0;b--){if(c=this.options.data[b],c.hasOwnProperty(e))d=c[e];else{if(!c._data.hasOwnProperty(e))continue;d=c._data[e]}if("string"==typeof d?a=a.toString():"number"==typeof d&&(Number(d)===d&&d%1===0?a=parseInt(a):d===Number(d)&&0!==d&&(a=parseFloat(a))),d===a){g=c;break}}return g},p.prototype.removeByUniqueId=function(a){var b=this.options.data.length,c=this.getRowByUniqueId(a);c&&this.options.data.splice(this.options.data.indexOf(c),1),b!==this.options.data.length&&(this.initSearch(),this.initPagination(),this.initBody(!0))},p.prototype.updateByUniqueId=function(b){var c=this,d=a.isArray(b)?b:[b];a.each(d,function(b,d){var e;d.hasOwnProperty("id")&&d.hasOwnProperty("row")&&(e=a.inArray(c.getRowByUniqueId(d.id),c.options.data),-1!==e&&a.extend(c.options.data[e],d.row))}),this.initSearch(),this.initSort(),this.initBody(!0)},p.prototype.insertRow=function(a){a.hasOwnProperty("index")&&a.hasOwnProperty("row")&&(this.data.splice(a.index,0,a.row),this.initSearch(),this.initPagination(),this.initSort(),this.initBody(!0))},p.prototype.updateRow=function(b){var c=this,d=a.isArray(b)?b:[b];a.each(d,function(b,d){d.hasOwnProperty("index")&&d.hasOwnProperty("row")&&a.extend(c.options.data[d.index],d.row)}),this.initSearch(),this.initSort(),this.initBody(!0)},p.prototype.showRow=function(a){(a.hasOwnProperty("index")||a.hasOwnProperty("uniqueId"))&&this.toggleRow(a.index,a.uniqueId,!0)},p.prototype.hideRow=function(a){(a.hasOwnProperty("index")||a.hasOwnProperty("uniqueId"))&&this.toggleRow(a.index,a.uniqueId,!1)},p.prototype.getRowsHidden=function(b){var c=a(this.$body[0]).children().filter(":hidden"),d=0;if(b)for(;d<c.length;d++)a(c[d]).show();return c},p.prototype.mergeCells=function(b){var c,d,e,f=b.index,g=a.inArray(b.field,this.getVisibleFields()),h=b.rowspan||1,i=b.colspan||1,j=this.$body.find(">tr");if(this.options.detailView&&!this.options.cardView&&(g+=1),e=j.eq(f).find(">td").eq(g),!(0>f||0>g||f>=this.data.length)){for(c=f;f+h>c;c++)for(d=g;g+i>d;d++)j.eq(c).find(">td").eq(d).hide();e.attr("rowspan",h).attr("colspan",i).show()}},p.prototype.updateCell=function(a){a.hasOwnProperty("index")&&a.hasOwnProperty("field")&&a.hasOwnProperty("value")&&(this.data[a.index][a.field]=a.value,a.reinit!==!1&&(this.initSort(),this.initBody(!0)))},p.prototype.getOptions=function(){return this.options},p.prototype.getSelections=function(){var b=this;return a.grep(this.options.data,function(a){return a[b.header.stateField]})},p.prototype.getAllSelections=function(){var b=this;return a.grep(this.options.data,function(a){return a[b.header.stateField]})},p.prototype.checkAll=function(){this.checkAll_(!0)},p.prototype.uncheckAll=function(){this.checkAll_(!1)},p.prototype.checkInvert=function(){var b=this,c=b.$selectItem.filter(":enabled"),d=c.filter(":checked");c.each(function(){a(this).prop("checked",!a(this).prop("checked"))}),b.updateRows(),b.updateSelected(),b.trigger("uncheck-some",d),d=b.getSelections(),b.trigger("check-some",d)},p.prototype.checkAll_=function(a){var b;a||(b=this.getSelections()),this.$selectAll.add(this.$selectAll_).prop("checked",a),this.$selectItem.filter(":enabled").prop("checked",a),this.updateRows(),a&&(b=this.getSelections()),this.trigger(a?"check-all":"uncheck-all",b)},p.prototype.check=function(a){this.check_(!0,a)},p.prototype.uncheck=function(a){this.check_(!1,a)},p.prototype.check_=function(a,b){var d=this.$selectItem.filter(c('[data-index="%s"]',b)).prop("checked",a);this.data[b][this.header.stateField]=a,this.updateSelected(),this.trigger(a?"check":"uncheck",this.data[b],d)},p.prototype.checkBy=function(a){this.checkBy_(!0,a)},p.prototype.uncheckBy=function(a){this.checkBy_(!1,a)},p.prototype.checkBy_=function(b,d){if(d.hasOwnProperty("field")&&d.hasOwnProperty("values")){var e=this,f=[];a.each(this.options.data,function(g,h){if(!h.hasOwnProperty(d.field))return!1;if(-1!==a.inArray(h[d.field],d.values)){var i=e.$selectItem.filter(":enabled").filter(c('[data-index="%s"]',g)).prop("checked",b);h[e.header.stateField]=b,f.push(h),e.trigger(b?"check":"uncheck",h,i)}}),this.updateSelected(),this.trigger(b?"check-some":"uncheck-some",f)}},p.prototype.destroy=function(){this.$el.insertBefore(this.$container),a(this.options.toolbar).insertBefore(this.$el),this.$container.next().remove(),this.$container.remove(),this.$el.html(this.$el_.html()).css("margin-top","0").attr("class",this.$el_.attr("class")||"")},p.prototype.showLoading=function(){this.$tableLoading.show()},p.prototype.hideLoading=function(){this.$tableLoading.hide()},p.prototype.togglePagination=function(){this.options.pagination=!this.options.pagination;var a=this.$toolbar.find('button[name="paginationSwitch"] i');this.options.pagination?a.attr("class",this.options.iconsPrefix+" "+this.options.icons.paginationSwitchDown):a.attr("class",this.options.iconsPrefix+" "+this.options.icons.paginationSwitchUp),this.updatePagination()},p.prototype.refresh=function(a){a&&a.url&&(this.options.pageNumber=1),this.initServer(a&&a.silent,a&&a.query,a&&a.url),this.trigger("refresh",a)},p.prototype.resetWidth=function(){this.options.showHeader&&this.options.height&&this.fitHeader(),this.options.showFooter&&this.fitFooter()},p.prototype.showColumn=function(a){this.toggleColumn(e(this.columns,a),!0,!0)},p.prototype.hideColumn=function(a){this.toggleColumn(e(this.columns,a),!1,!0)},p.prototype.getHiddenColumns=function(){return a.grep(this.columns,function(a){return!a.visible})},p.prototype.getVisibleColumns=function(){return a.grep(this.columns,function(a){return a.visible})},p.prototype.toggleAllColumns=function(b){if(a.each(this.columns,function(a){this.columns[a].visible=b}),this.initHeader(),this.initSearch(),this.initPagination(),this.initBody(),this.options.showColumns){var c=this.$toolbar.find(".keep-open input").prop("disabled",!1);c.filter(":checked").length<=this.options.minimumCountColumns&&c.filter(":checked").prop("disabled",!0)}},p.prototype.showAllColumns=function(){this.toggleAllColumns(!0)},p.prototype.hideAllColumns=function(){this.toggleAllColumns(!1)},p.prototype.filterBy=function(b){this.filterColumns=a.isEmptyObject(b)?{}:b,this.options.pageNumber=1,this.initSearch(),this.updatePagination()},p.prototype.scrollTo=function(a){return"string"==typeof a&&(a="bottom"===a?this.$tableBody[0].scrollHeight:0),"number"==typeof a&&this.$tableBody.scrollTop(a),"undefined"==typeof a?this.$tableBody.scrollTop():void 0},p.prototype.getScrollPosition=function(){return this.scrollTo()},p.prototype.selectPage=function(a){a>0&&a<=this.options.totalPages&&(this.options.pageNumber=a,this.updatePagination())},p.prototype.prevPage=function(){this.options.pageNumber>1&&(this.options.pageNumber--,this.updatePagination())},p.prototype.nextPage=function(){this.options.pageNumber<this.options.totalPages&&(this.options.pageNumber++,this.updatePagination())},p.prototype.toggleView=function(){this.options.cardView=!this.options.cardView,this.initHeader(),this.initBody(),this.trigger("toggle",this.options.cardView)},p.prototype.refreshOptions=function(b){i(this.options,b,!0)||(this.options=a.extend(this.options,b),this.trigger("refresh-options",this.options),this.destroy(),this.init())},p.prototype.resetSearch=function(a){var b=this.$toolbar.find(".search input");b.val(a||""),this.onSearch({currentTarget:b})},p.prototype.expandRow_=function(a,b){var d=this.$body.find(c('> tr[data-index="%s"]',b));d.next().is("tr.detail-view")===(a?!1:!0)&&d.find("> td > .detail-icon").click()},p.prototype.expandRow=function(a){this.expandRow_(!0,a)},p.prototype.collapseRow=function(a){this.expandRow_(!1,a)},p.prototype.expandAllRows=function(b){if(b){var d=this.$body.find(c('> tr[data-index="%s"]',0)),e=this,f=null,g=!1,h=-1;if(d.next().is("tr.detail-view")?d.next().next().is("tr.detail-view")||(d.next().find(".detail-icon").click(),g=!0):(d.find("> td > .detail-icon").click(),g=!0),g)try{h=setInterval(function(){f=e.$body.find("tr.detail-view").last().find(".detail-icon"),f.length>0?f.click():clearInterval(h)},1)}catch(i){clearInterval(h)}}else for(var j=this.$body.children(),k=0;k<j.length;k++)this.expandRow_(!0,a(j[k]).data("index"))},p.prototype.collapseAllRows=function(b){if(b)this.expandRow_(!1,0);else for(var c=this.$body.children(),d=0;d<c.length;d++)this.expandRow_(!1,a(c[d]).data("index"))},p.prototype.updateFormatText=function(a,b){this.options[c("format%s",a)]&&("string"==typeof b?this.options[c("format%s",a)]=function(){return b}:"function"==typeof b&&(this.options[c("format%s",a)]=b)),this.initToolbar(),this.initPagination(),this.initBody()};var q=["getOptions","getSelections","getAllSelections","getData","load","append","prepend","remove","removeAll","insertRow","updateRow","updateCell","updateByUniqueId","removeByUniqueId","getRowByUniqueId","showRow","hideRow","getRowsHidden","mergeCells","checkAll","uncheckAll","checkInvert","check","uncheck","checkBy","uncheckBy","refresh","resetView","resetWidth","destroy","showLoading","hideLoading","showColumn","hideColumn","getHiddenColumns","getVisibleColumns","showAllColumns","hideAllColumns","filterBy","scrollTo","getScrollPosition","selectPage","prevPage","nextPage","togglePagination","toggleView","refreshOptions","resetSearch","expandRow","collapseRow","expandAllRows","collapseAllRows","updateFormatText"];a.fn.bootstrapTable=function(b){var c,d=Array.prototype.slice.call(arguments,1);return this.each(function(){var e=a(this),f=e.data("bootstrap.table"),g=a.extend({},p.DEFAULTS,e.data(),"object"==typeof b&&b);if("string"==typeof b){if(a.inArray(b,q)<0)throw new Error("Unknown method: "+b);if(!f)return;c=f[b].apply(f,d),"destroy"===b&&e.removeData("bootstrap.table")}f||e.data("bootstrap.table",f=new p(this,g))}),"undefined"==typeof c?this:c},a.fn.bootstrapTable.Constructor=p,a.fn.bootstrapTable.defaults=p.DEFAULTS,a.fn.bootstrapTable.columnDefaults=p.COLUMN_DEFAULTS,a.fn.bootstrapTable.locales=p.LOCALES,a.fn.bootstrapTable.methods=q,a.fn.bootstrapTable.utils={sprintf:c,getFieldIndex:e,compareObjects:i,calculateObjectValue:h,getItemField:m,objectKeys:o,isIEBrowser:n},a(function(){a('[data-toggle="table"]').bootstrapTable()})}(jQuery);
\ No newline at end of file
web/lib/tableExport.js new
+1528
@@ -0,0 +1,1528 @@
1 +/**
2 + * @preserve tableExport.jquery.plugin
3 + *
4 + * Copyright (c) 2015,2016 hhurz, https://github.com/hhurz/tableExport.jquery.plugin
5 + * Original work Copyright (c) 2014 Giri Raj, https://github.com/kayalshri/
6 + *
7 + * Licensed under the MIT License, http://opensource.org/licenses/mit-license
8 + */
9 +
10 +(function ($) {
11 + $.fn.extend({
12 + tableExport: function (options) {
13 + var defaults = {
14 + consoleLog: false,
15 + csvEnclosure: '"',
16 + csvSeparator: ',',
17 + csvUseBOM: true,
18 + displayTableName: false,
19 + escape: false,
20 + excelstyles: [], // e.g. ['border-bottom', 'border-top', 'border-left', 'border-right']
21 + fileName: 'tableExport',
22 + htmlContent: false,
23 + ignoreColumn: [],
24 + ignoreRow:[],
25 + jsonScope: 'all', // head, data, all
26 + jspdf: {orientation: 'p',
27 + unit: 'pt',
28 + format: 'a4', // jspdf page format or 'bestfit' for autmatic paper format selection
29 + margins: {left: 20, right: 10, top: 10, bottom: 10},
30 + autotable: {styles: {cellPadding: 2,
31 + rowHeight: 12,
32 + fontSize: 8,
33 + fillColor: 255, // color value or 'inherit' to use css background-color from html table
34 + textColor: 50, // color value or 'inherit' to use css color from html table
35 + fontStyle: 'normal', // normal, bold, italic, bolditalic or 'inherit' to use css font-weight and fonst-style from html table
36 + overflow: 'ellipsize', // visible, hidden, ellipsize or linebreak
37 + halign: 'left', // left, center, right
38 + valign: 'middle' // top, middle, bottom
39 + },
40 + headerStyles: {fillColor: [52, 73, 94],
41 + textColor: 255,
42 + fontStyle: 'bold',
43 + halign: 'center'
44 + },
45 + alternateRowStyles: {fillColor: 245
46 + },
47 + tableExport: {onAfterAutotable: null,
48 + onBeforeAutotable: null,
49 + onTable: null
50 + }
51 + }
52 + },
53 + numbers: {html: {decimalMark: '.',
54 + thousandsSeparator: ','
55 + },
56 + output: {decimalMark: '.',
57 + thousandsSeparator: ','
58 + }
59 + },
60 + onCellData: null,
61 + onCellHtmlData: null,
62 + outputMode: 'file', // 'file', 'string' or 'base64'
63 + pdfmake: {enabled: false}, // true: use pdfmake instead of jspdf(-autotable)
64 + tbodySelector: 'tr',
65 + tfootSelector: 'tr', // set empty ('') to prevent export of tfoot rows
66 + theadSelector: 'tr',
67 + tableName: 'myTableName',
68 + type: 'csv', // 'csv', 'txt', 'sql', 'json', 'xml', 'excel', 'doc', 'png' or 'pdf'
69 + worksheetName: 'xlsWorksheetName'
70 + };
71 +
72 + var FONT_ROW_RATIO = 1.15;
73 + var el = this;
74 + var DownloadEvt = null;
75 + var $hrows = [];
76 + var $rows = [];
77 + var rowIndex = 0;
78 + var rowspans = [];
79 + var trData = '';
80 + var colNames = [];
81 +
82 + $.extend(true, defaults, options);
83 +
84 + colNames = GetColumnNames (el);
85 +
86 + if (defaults.type == 'csv' || defaults.type == 'txt') {
87 +
88 + var csvData = "";
89 + var rowlength = 0;
90 + rowIndex = 0;
91 +
92 + function CollectCsvData (tgroup, tselector, rowselector, length) {
93 +
94 + $rows = $(el).find(tgroup).first().find(tselector);
95 + $rows.each(function () {
96 + trData = "";
97 + ForEachVisibleCell(this, rowselector, rowIndex, length + $rows.length,
98 + function (cell, row, col) {
99 + trData += csvString(cell, row, col) + defaults.csvSeparator;
100 + });
101 + trData = $.trim(trData).substring(0, trData.length - 1);
102 + if (trData.length > 0) {
103 +
104 + if (csvData.length > 0)
105 + csvData += "\n";
106 +
107 + csvData += trData;
108 + }
109 + rowIndex++;
110 + });
111 +
112 + return $rows.length;
113 + }
114 +
115 + rowlength += CollectCsvData ('thead', defaults.theadSelector, 'th,td', rowlength);
116 + rowlength += CollectCsvData ('tbody', defaults.tbodySelector, 'td', rowlength);
117 + if (defaults.tfootSelector.length)
118 + CollectCsvData ('tfoot', defaults.tfootSelector, 'td', rowlength);
119 +
120 + csvData += "\n";
121 +
122 + //output
123 + if (defaults.consoleLog === true)
124 + console.log(csvData);
125 +
126 + if (defaults.outputMode === 'string')
127 + return csvData;
128 +
129 + if (defaults.outputMode === 'base64')
130 + return base64encode(csvData);
131 +
132 + try {
133 + var blob = new Blob([csvData], {type: "text/" + (defaults.type == 'csv' ? 'csv' : 'plain') + ";charset=utf-8"});
134 + saveAs(blob, defaults.fileName + '.' + defaults.type, (defaults.type != 'csv' || defaults.csvUseBOM === false));
135 + }
136 + catch (e) {
137 + downloadFile(defaults.fileName + '.' + defaults.type,
138 + 'data:text/' + (defaults.type == 'csv' ? 'csv' : 'plain') + ';charset=utf-8,' + ((defaults.type == 'csv' && defaults.csvUseBOM)? '\ufeff' : ''),
139 + csvData);
140 + }
141 +
142 + } else if (defaults.type == 'sql') {
143 +
144 + // Header
145 + rowIndex = 0;
146 + var tdData = "INSERT INTO `" + defaults.tableName + "` (";
147 + $hrows = $(el).find('thead').first().find(defaults.theadSelector);
148 + $hrows.each(function () {
149 + ForEachVisibleCell(this, 'th,td', rowIndex, $hrows.length,
150 + function (cell, row, col) {
151 + tdData += "'" + parseString(cell, row, col) + "',";
152 + });
153 + rowIndex++;
154 + tdData = $.trim(tdData);
155 + tdData = $.trim(tdData).substring(0, tdData.length - 1);
156 + });
157 + tdData += ") VALUES ";
158 + // Row vs Column
159 + $rows = $(el).find('tbody').first().find(defaults.tbodySelector);
160 + if (defaults.tfootSelector.length)
161 + $rows.push.apply ($rows, $(el).find('tfoot').find(defaults.tfootSelector));
162 + $rows.each(function () {
163 + trData = "";
164 + ForEachVisibleCell(this, 'td', rowIndex, $hrows.length + $rows.length,
165 + function (cell, row, col) {
166 + trData += "'" + parseString(cell, row, col) + "',";
167 + });
168 + if (trData.length > 3) {
169 + tdData += "(" + trData;
170 + tdData = $.trim(tdData).substring(0, tdData.length - 1);
171 + tdData += "),";
172 + }
173 + rowIndex++;
174 + });
175 +
176 + tdData = $.trim(tdData).substring(0, tdData.length - 1);
177 + tdData += ";";
178 +
179 + //output
180 + if (defaults.consoleLog === true)
181 + console.log(tdData);
182 +
183 + if (defaults.outputMode === 'string')
184 + return tdData;
185 +
186 + if (defaults.outputMode === 'base64')
187 + return base64encode(tdData);
188 +
189 + try {
190 + var blob = new Blob([tdData], {type: "text/plain;charset=utf-8"});
191 + saveAs(blob, defaults.fileName + '.sql');
192 + }
193 + catch (e) {
194 + downloadFile(defaults.fileName + '.sql',
195 + 'data:application/sql;charset=utf-8,',
196 + tdData);
197 + }
198 +
199 + } else if (defaults.type == 'json') {
200 +
201 + var jsonHeaderArray = [];
202 + $hrows = $(el).find('thead').first().find(defaults.theadSelector);
203 + $hrows.each(function () {
204 + var jsonArrayTd = [];
205 +
206 + ForEachVisibleCell(this, 'th,td', rowIndex, $hrows.length,
207 + function (cell, row, col) {
208 + jsonArrayTd.push(parseString(cell, row, col));
209 + });
210 + jsonHeaderArray.push(jsonArrayTd);
211 + });
212 +
213 + var jsonArray = [];
214 + $rows = $(el).find('tbody').first().find(defaults.tbodySelector);
215 + if (defaults.tfootSelector.length)
216 + $rows.push.apply ($rows, $(el).find('tfoot').find(defaults.tfootSelector));
217 + $rows.each(function () {
218 + var jsonObjectTd = {};
219 +
220 + var colIndex = 0;
221 + ForEachVisibleCell(this, 'td', rowIndex, $hrows.length + $rows.length,
222 + function (cell, row, col) {
223 + if (jsonHeaderArray.length) {
224 + jsonObjectTd[jsonHeaderArray[jsonHeaderArray.length-1][colIndex]] = parseString(cell, row, col);
225 + } else {
226 + jsonObjectTd[colIndex] = parseString(cell, row, col);
227 + }
228 + colIndex++;
229 + });
230 + if ($.isEmptyObject(jsonObjectTd) == false)
231 + jsonArray.push(jsonObjectTd);
232 +
233 + rowIndex++;
234 + });
235 +
236 + var sdata = "";
237 +
238 + if (defaults.jsonScope == 'head')
239 + sdata = JSON.stringify(jsonHeaderArray);
240 + else if (defaults.jsonScope == 'data')
241 + sdata = JSON.stringify(jsonArray);
242 + else // all
243 + sdata = JSON.stringify({header: jsonHeaderArray, data: jsonArray});
244 +
245 + if (defaults.consoleLog === true)
246 + console.log(sdata);
247 +
248 + if (defaults.outputMode === 'string')
249 + return sdata;
250 +
251 + if (defaults.outputMode === 'base64')
252 + return base64encode(sdata);
253 +
254 + try {
255 + var blob = new Blob([sdata], {type: "application/json;charset=utf-8"});
256 + saveAs(blob, defaults.fileName + '.json');
257 + }
258 + catch (e) {
259 + downloadFile(defaults.fileName + '.json',
260 + 'data:application/json;charset=utf-8;base64,',
261 + sdata);
262 + }
263 +
264 + } else if (defaults.type === 'xml') {
265 +
266 + rowIndex = 0;
267 + var xml = '<?xml version="1.0" encoding="utf-8"?>';
268 + xml += '<tabledata><fields>';
269 +
270 + // Header
271 + $hrows = $(el).find('thead').first().find(defaults.theadSelector);
272 + $hrows.each(function () {
273 +
274 + ForEachVisibleCell(this, 'th,td', rowIndex, $rows.length,
275 + function (cell, row, col) {
276 + xml += "<field>" + parseString(cell, row, col) + "</field>";
277 + });
278 + rowIndex++;
279 + });
280 + xml += '</fields><data>';
281 +
282 + // Row Vs Column
283 + var rowCount = 1;
284 + $rows = $(el).find('tbody').first().find(defaults.tbodySelector);
285 + if (defaults.tfootSelector.length)
286 + $rows.push.apply ($rows, $(el).find('tfoot').find(defaults.tfootSelector));
287 + $rows.each(function () {
288 + var colCount = 1;
289 + trData = "";
290 + ForEachVisibleCell(this, 'td', rowIndex, $hrows.length + $rows.length,
291 + function (cell, row, col) {
292 + trData += "<column-" + colCount + ">" + parseString(cell, row, col) + "</column-" + colCount + ">";
293 + colCount++;
294 + });
295 + if (trData.length > 0 && trData != "<column-1></column-1>") {
296 + xml += '<row id="' + rowCount + '">' + trData + '</row>';
297 + rowCount++;
298 + }
299 +
300 + rowIndex++;
301 + });
302 + xml += '</data></tabledata>';
303 +
304 + //output
305 + if (defaults.consoleLog === true)
306 + console.log(xml);
307 +
308 + if (defaults.outputMode === 'string')
309 + return xml;
310 +
311 + if (defaults.outputMode === 'base64')
312 + return base64encode(xml);
313 +
314 + try {
315 + var blob = new Blob([xml], {type: "application/xml;charset=utf-8"});
316 + saveAs(blob, defaults.fileName + '.xml');
317 + }
318 + catch (e) {
319 + downloadFile(defaults.fileName + '.xml',
320 + 'data:application/xml;charset=utf-8;base64,',
321 + xml);
322 + }
323 +
324 + } else if (defaults.type == 'excel' || defaults.type == 'xls' || defaults.type == 'word' || defaults.type == 'doc') {
325 +
326 + var MSDocType = (defaults.type == 'excel' || defaults.type == 'xls') ? 'excel' : 'word';
327 + var MSDocExt = (MSDocType == 'excel') ? 'xls' : 'doc';
328 + var MSDocSchema = 'xmlns:x="urn:schemas-microsoft-com:office:' + MSDocType + '"';
329 + var $tables = $(el).filter(function() {
330 + return $(this).data("tableexport-display") != 'none' &&
331 + ($(this).is(':visible') ||
332 + $(this).data("tableexport-display") == 'always');
333 + });
334 + var docData = '';
335 +
336 + $tables.each(function(){
337 + rowIndex = 0;
338 +
339 + colNames = GetColumnNames (this);
340 +
341 + docData += '<table><thead>';
342 + // Header
343 + $hrows = $(this).find('thead').first().find(defaults.theadSelector);
344 + $hrows.each(function() {
345 + trData = "";
346 + ForEachVisibleCell(this, 'th,td', rowIndex, $hrows.length,
347 + function(cell, row, col) {
348 + if (cell != null) {
349 + var thstyle = '';
350 + trData += '<th';
351 + for (var styles in defaults.excelstyles) {
352 + if (defaults.excelstyles.hasOwnProperty(styles)) {
353 + var thcss = $(cell).css(defaults.excelstyles[styles]);
354 + if (thcss != '' && thcss !='0px none rgb(0, 0, 0)') {
355 + if (thstyle == '')
356 + thstyle = 'style="';
357 + thstyle += defaults.excelstyles[styles] + ':' + thcss + ';';
358 + }
359 + }
360 + }
361 + if (thstyle != '' )
362 + trData += ' ' + thstyle + '"';
363 + if ($(cell).is("[colspan]"))
364 + trData += ' colspan="' + $(cell).attr('colspan') + '"';
365 + if ($(cell).is("[rowspan]"))
366 + trData += ' rowspan="' + $(cell).attr('rowspan') + '"';
367 + trData += '>' + parseString(cell, row, col) + '</th>';
368 + }
369 + });
370 + if (trData.length > 0)
371 + docData += '<tr>' + trData + '</tr>';
372 + rowIndex++;
373 + });
374 +
375 + docData += '</thead><tbody>';
376 + // Row Vs Column
377 + $rows = $(this).find('tbody').first().find(defaults.tbodySelector);
378 + if (defaults.tfootSelector.length)
379 + $rows.push.apply ($rows, $(el).find('tfoot').find(defaults.tfootSelector));
380 + $rows.each(function() {
381 + trData = "";
382 + ForEachVisibleCell(this, 'td', rowIndex, $hrows.length + $rows.length,
383 + function(cell, row, col) {
384 + if (cell != null) {
385 + var tdstyle = '';
386 + var tdcss = $(cell).data("tableexport-msonumberformat");
387 +
388 + if (typeof tdcss == 'undefined' && typeof defaults.onMsoNumberFormat === 'function')
389 + tdcss = defaults.onMsoNumberFormat(cell, row, col);
390 +
391 + if (typeof tdcss != 'undefined' && tdcss != '') {
392 + if (tdstyle == '')
393 + tdstyle = 'style="';
394 + tdstyle = 'style="mso-number-format:\'' + tdcss + '\'';
395 + }
396 +
397 + trData += '<td';
398 + for (var styles in defaults.excelstyles) {
399 + if (defaults.excelstyles.hasOwnProperty(styles)) {
400 + tdcss = $(cell).css(defaults.excelstyles[styles]);
401 + if (tdcss != '' && tdcss !='0px none rgb(0, 0, 0)') {
402 + if (tdstyle == '')
403 + tdstyle = 'style="';
404 + tdstyle += defaults.excelstyles[styles] + ':' + tdcss + ';';
405 + }
406 + }
407 + }
408 + if (tdstyle != '' )
409 + trData += ' ' + tdstyle + '"';
410 + if ($(cell).is("[colspan]"))
411 + trData += ' colspan="' + $(cell).attr('colspan') + '"';
412 + if ($(cell).is("[rowspan]"))
413 + trData += ' rowspan="' + $(cell).attr('rowspan') + '"';
414 + trData += '>' + parseString(cell, row, col) + '</td>';
415 + }
416 + });
417 + if (trData.length > 0)
418 + docData += '<tr>' + trData + '</tr>';
419 + rowIndex++;
420 + });
421 +
422 + if (defaults.displayTableName)
423 + docData += '<tr><td></td></tr><tr><td></td></tr><tr><td>' + parseString($('<p>' + defaults.tableName + '</p>')) + '</td></tr>';
424 +
425 + docData += '</tbody></table>';
426 +
427 + if (defaults.consoleLog === true)
428 + console.log(docData);
429 + });
430 +
431 + var docFile = '<html xmlns:o="urn:schemas-microsoft-com:office:office" ' + MSDocSchema + ' xmlns="http://www.w3.org/TR/REC-html40">';
432 + docFile += '<meta http-equiv="content-type" content="application/vnd.ms-' + MSDocType + '; charset=UTF-8">';
433 + docFile += "<head>";
434 + if (MSDocType === 'excel') {
435 + docFile += "<!--[if gte mso 9]>";
436 + docFile += "<xml>";
437 + docFile += "<x:ExcelWorkbook>";
438 + docFile += "<x:ExcelWorksheets>";
439 + docFile += "<x:ExcelWorksheet>";
440 + docFile += "<x:Name>";
441 + docFile += defaults.worksheetName;
442 + docFile += "</x:Name>";
443 + docFile += "<x:WorksheetOptions>";
444 + docFile += "<x:DisplayGridlines/>";
445 + docFile += "</x:WorksheetOptions>";
446 + docFile += "</x:ExcelWorksheet>";
447 + docFile += "</x:ExcelWorksheets>";
448 + docFile += "</x:ExcelWorkbook>";
449 + docFile += "</xml>";
450 + docFile += "<![endif]-->";
451 + }
452 + docFile += "</head>";
453 + docFile += "<body>";
454 + docFile += docData;
455 + docFile += "</body>";
456 + docFile += "</html>";
457 +
458 + if (defaults.consoleLog === true)
459 + console.log(docFile);
460 +
461 + if (defaults.outputMode === 'string')
462 + return docFile;
463 +
464 + if (defaults.outputMode === 'base64')
465 + return base64encode(docFile);
466 +
467 + try {
468 + var blob = new Blob([docFile], {type: 'application/vnd.ms-' + defaults.type});
469 + saveAs(blob, defaults.fileName + '.' + MSDocExt);
470 + }
471 + catch (e) {
472 + downloadFile(defaults.fileName + '.' + MSDocExt,
473 + 'data:application/vnd.ms-' + MSDocType + ';base64,',
474 + docFile);
475 + }
476 +
477 + } else if (defaults.type == 'xlsx') {
478 +
479 + var data = [];
480 + var ranges = [];
481 + rowIndex = 0;
482 +
483 + $rows = $(el).find('thead').first().find(defaults.theadSelector);
484 + $rows.push.apply ($rows, $(el).find('tbody').first().find(defaults.tbodySelector));
485 + if (defaults.tfootSelector.length)
486 + $rows.push.apply ($rows, $(el).find('tfoot').find(defaults.tfootSelector));
487 +
488 + $rows.each(function () {
489 + var cols = [];
490 + ForEachVisibleCell(this, 'th,td', rowIndex, $rows.length,
491 + function (cell, row, col) {
492 + if (typeof cell !== 'undefined' && cell != null) {
493 +
494 + var colspan = cell.getAttribute('colspan');
495 + var rowspan = cell.getAttribute('rowspan');
496 +
497 + var cellValue = parseString(cell, row, col);
498 +
499 + if(cellValue !== "" && cellValue == +cellValue) cellValue = +cellValue;
500 +
501 + //Skip ranges
502 + ranges.forEach(function(range) {
503 + if(rowIndex >= range.s.r && rowIndex <= range.e.r && cols.length >= range.s.c && cols.length <= range.e.c) {
504 + for(var i = 0; i <= range.e.c - range.s.c; ++i) cols.push(null);
505 + }
506 + });
507 +
508 + //Handle Row Span
509 + if (rowspan || colspan) {
510 + rowspan = rowspan || 1;
511 + colspan = colspan || 1;
512 + ranges.push({s:{r:rowIndex, c:cols.length},e:{r:rowIndex+rowspan-1, c:cols.length+colspan-1}});
513 + };
514 +
515 + //Handle Value
516 + cols.push(cellValue !== "" ? cellValue : null);
517 +
518 + //Handle Colspan
519 + if (colspan) for (var k = 0; k < colspan - 1; ++k) cols.push(null);
520 + }
521 + });
522 + data.push(cols);
523 + rowIndex++;
524 + });
525 + console.log(data);
526 +
527 + var wb = new jx_Workbook(),
528 + ws = jx_createSheet(data);
529 +
530 + // add ranges to worksheet
531 + ws['!merges'] = ranges;
532 +
533 + // add worksheet to workbook
534 + wb.SheetNames.push(defaults.worksheetName);
535 + wb.Sheets[defaults.worksheetName] = ws;
536 +
537 + var wbout = XLSX.write(wb, {bookType: defaults.type, bookSST: false, type: 'binary'});
538 +
539 + try {
540 + var blob = new Blob([jx_s2ab(wbout)], {type: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet; charset=UTF-8'});
541 + saveAs(blob, defaults.fileName + '.' + defaults.type);
542 + }
543 + catch (e) {
544 + downloadFile(defaults.fileName + '.' + defaults.type,
545 + 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet; charset=UTF-8',
546 + data);
547 + }
548 +
549 + } else if (defaults.type == 'png') {
550 + //html2canvas($(el)[0], {
551 + // onrendered: function (canvas) {
552 + html2canvas($(el)[0]).then(
553 + function (canvas) {
554 +
555 + var image = canvas.toDataURL();
556 + image = image.substring(22); // remove data stuff
557 +
558 + var byteString = atob(image);
559 + var buffer = new ArrayBuffer(byteString.length);
560 + var intArray = new Uint8Array(buffer);
561 +
562 + for (var i = 0; i < byteString.length; i++)
563 + intArray[i] = byteString.charCodeAt(i);
564 +
565 + if (defaults.consoleLog === true)
566 + console.log(byteString);
567 +
568 + if (defaults.outputMode === 'string')
569 + return byteString;
570 +
571 + if (defaults.outputMode === 'base64')
572 + return base64encode(image);
573 +
574 + try {
575 + var blob = new Blob([buffer], {type: "image/png"});
576 + saveAs(blob, defaults.fileName + '.png');
577 + }
578 + catch (e) {
579 + downloadFile(defaults.fileName + '.png',
580 + 'data:image/png,',
581 + image);
582 + }
583 + //}
584 + });
585 +
586 + } else if (defaults.type == 'pdf') {
587 +
588 + if (defaults.pdfmake.enabled === true) {
589 + // pdf output using pdfmake
590 + // https://github.com/bpampuch/pdfmake
591 +
592 + var widths = [];
593 + var body = [];
594 + rowIndex = 0;
595 +
596 + $hrows = $(this).find('thead').find(defaults.theadSelector);
597 + $hrows.each(function () {
598 + var h = [];
599 +
600 + ForEachVisibleCell(this, 'th,td', rowIndex, $hrows.length,
601 + function (cell, row, col) {
602 + h.push(parseString(cell, row, col));
603 + });
604 +
605 + if (h.length)
606 + body.push(h);
607 +
608 + for(var i = widths.length; i < h.length;i++)
609 + widths.push("*");
610 +
611 + rowIndex++;
612 + });
613 +
614 + $rows = $(this).find('tbody').find(defaults.tbodySelector);
615 + if (defaults.tfootSelector.length)
616 + $rows.push.apply ($rows, $(el).find('tfoot').find(defaults.tfootSelector));
617 +
618 + $rows.each(function () {
619 + var r = [];
620 +
621 + ForEachVisibleCell(this, 'td', rowIndex, $hrows.length + $rows.length,
622 + function (cell, row, col) {
623 + r.push(parseString(cell, row, col));
624 + });
625 +
626 + if (r.length)
627 + body.push(r);
628 + rowIndex++;
629 + });
630 +
631 + var docDefinition = {
632 + pageOrientation: 'landscape',
633 + content: [
634 + {
635 + table: {
636 + headerRows: $hrows.length,
637 + widths: widths,
638 + body: body
639 + }
640 + }
641 + ]
642 + };
643 + pdfMake.createPdf(docDefinition).getBuffer(function (buffer) {
644 +
645 + try {
646 + var blob = new Blob([buffer], {type: "application/pdf"});
647 + saveAs(blob, defaults.fileName + '.pdf');
648 + }
649 + catch (e) {
650 + downloadFile(defaults.fileName + '.pdf',
651 + 'data:application/pdf;base64,',
652 + buffer);
653 + }
654 + });
655 +
656 + }
657 + else if (defaults.jspdf.autotable === false) {
658 + // pdf output using jsPDF's core html support
659 +
660 + var addHtmlOptions = {
661 + dim: {
662 + w: getPropertyUnitValue($(el).first().get(0), 'width', 'mm'),
663 + h: getPropertyUnitValue($(el).first().get(0), 'height', 'mm')
664 + },
665 + pagesplit: false
666 + };
667 +
668 + var doc = new jsPDF(defaults.jspdf.orientation, defaults.jspdf.unit, defaults.jspdf.format);
669 + doc.addHTML($(el).first(),
670 + defaults.jspdf.margins.left,
671 + defaults.jspdf.margins.top,
672 + addHtmlOptions,
673 + function () {
674 + jsPdfOutput(doc);
675 + });
676 + //delete doc;
677 + }
678 + else {
679 + // pdf output using jsPDF AutoTable plugin
680 + // https://github.com/simonbengtsson/jsPDF-AutoTable
681 +
682 + var teOptions = defaults.jspdf.autotable.tableExport;
683 +
684 + // When setting jspdf.format to 'bestfit' tableExport tries to choose
685 + // the minimum required paper format and orientation in which the table
686 + // (or tables in multitable mode) completely fits without column adjustment
687 + if (typeof defaults.jspdf.format === 'string' && defaults.jspdf.format.toLowerCase() === 'bestfit') {
688 + var pageFormats = {
689 + 'a0': [2383.94, 3370.39], 'a1': [1683.78, 2383.94],
690 + 'a2': [1190.55, 1683.78], 'a3': [841.89, 1190.55],
691 + 'a4': [595.28, 841.89]
692 + };
693 + var rk = '', ro = '';
694 + var mw = 0;
695 +
696 + $(el).filter(':visible').each(function () {
697 + if ($(this).css('display') != 'none') {
698 + var w = getPropertyUnitValue($(this).get(0), 'width', 'pt');
699 +
700 + if (w > mw) {
701 + if (w > pageFormats['a0'][0]) {
702 + rk = 'a0';
703 + ro = 'l';
704 + }
705 + for (var key in pageFormats) {
706 + if (pageFormats.hasOwnProperty(key)) {
707 + if (pageFormats[key][1] > w) {
708 + rk = key;
709 + ro = 'l';
710 + if (pageFormats[key][0] > w)
711 + ro = 'p';
712 + }
713 + }
714 + }
715 + mw = w;
716 + }
717 + }
718 + });
719 + defaults.jspdf.format = (rk == '' ? 'a4' : rk);
720 + defaults.jspdf.orientation = (ro == '' ? 'w' : ro);
721 + }
722 +
723 + // The jsPDF doc object is stored in defaults.jspdf.autotable.tableExport,
724 + // thus it can be accessed from any callback function
725 + teOptions.doc = new jsPDF(defaults.jspdf.orientation,
726 + defaults.jspdf.unit,
727 + defaults.jspdf.format);
728 +
729 + $(el).filter(function() {
730 + return $(this).data("tableexport-display") != 'none' &&
731 + ($(this).is(':visible') ||
732 + $(this).data("tableexport-display") == 'always');
733 + }).each(function () {
734 + var colKey;
735 + var rowIndex = 0;
736 +
737 + colNames = GetColumnNames (this);
738 +
739 + teOptions.columns = [];
740 + teOptions.rows = [];
741 + teOptions.rowoptions = {};
742 +
743 + // onTable: optional callback function for every matching table that can be used
744 + // to modify the tableExport options or to skip the output of a particular table
745 + // if the table selector targets multiple tables
746 + if (typeof teOptions.onTable === 'function')
747 + if (teOptions.onTable($(this), defaults) === false)
748 + return true; // continue to next iteration step (table)
749 +
750 + // each table works with an own copy of AutoTable options
751 + defaults.jspdf.autotable.tableExport = null; // avoid deep recursion error
752 + var atOptions = $.extend(true, {}, defaults.jspdf.autotable);
753 + defaults.jspdf.autotable.tableExport = teOptions;
754 +
755 + atOptions.margin = {};
756 + $.extend(true, atOptions.margin, defaults.jspdf.margins);
757 + atOptions.tableExport = teOptions;
758 +
759 + // Fix jsPDF Autotable's row height calculation
760 + if (typeof atOptions.beforePageContent !== 'function') {
761 + atOptions.beforePageContent = function (data) {
762 + if (data.pageCount == 1) {
763 + var all = data.table.rows.concat(data.table.headerRow);
764 + all.forEach(function (row) {
765 + if ( row.height > 0 ) {
766 + row.height += (2 - FONT_ROW_RATIO) / 2 * row.styles.fontSize;
767 + data.table.height += (2 - FONT_ROW_RATIO) / 2 * row.styles.fontSize;
768 + }
769 + });
770 + }
771 + }
772 + }
773 +
774 + if (typeof atOptions.createdHeaderCell !== 'function') {
775 + // apply some original css styles to pdf header cells
776 + atOptions.createdHeaderCell = function (cell, data) {
777 +
778 + // jsPDF AutoTable plugin v2.0.14 fix: each cell needs its own styles object
779 + cell.styles = $.extend({}, data.row.styles);
780 +
781 + if (typeof teOptions.columns [data.column.dataKey] != 'undefined') {
782 + var col = teOptions.columns [data.column.dataKey];
783 +
784 + if (typeof col.rect != 'undefined') {
785 + var rh;
786 +
787 + cell.contentWidth = col.rect.width;
788 +
789 + if (typeof teOptions.heightRatio == 'undefined' || teOptions.heightRatio == 0) {
790 + if (data.row.raw [data.column.dataKey].rowspan)
791 + rh = data.row.raw [data.column.dataKey].rect.height / data.row.raw [data.column.dataKey].rowspan;
792 + else
793 + rh = data.row.raw [data.column.dataKey].rect.height;
794 +
795 + teOptions.heightRatio = cell.styles.rowHeight / rh;
796 + }
797 +
798 + rh = data.row.raw [data.column.dataKey].rect.height * teOptions.heightRatio;
799 + if (rh > cell.styles.rowHeight)
800 + cell.styles.rowHeight = rh;
801 + }
802 +
803 + if (typeof col.style != 'undefined' && col.style.hidden !== true) {
804 + cell.styles.halign = col.style.align;
805 + if (atOptions.styles.fillColor === 'inherit')
806 + cell.styles.fillColor = col.style.bcolor;
807 + if (atOptions.styles.textColor === 'inherit')
808 + cell.styles.textColor = col.style.color;
809 + if (atOptions.styles.fontStyle === 'inherit')
810 + cell.styles.fontStyle = col.style.fstyle;
811 + }
812 + }
813 + }
814 + }
815 +
816 + if (typeof atOptions.createdCell !== 'function') {
817 + // apply some original css styles to pdf table cells
818 + atOptions.createdCell = function (cell, data) {
819 + var rowopt = teOptions.rowoptions [data.row.index + ":" + data.column.dataKey];
820 +
821 + if (typeof rowopt != 'undefined' &&
822 + typeof rowopt.style != 'undefined' &&
823 + rowopt.style.hidden !== true) {
824 + cell.styles.halign = rowopt.style.align;
825 + if (atOptions.styles.fillColor === 'inherit')
826 + cell.styles.fillColor = rowopt.style.bcolor;
827 + if (atOptions.styles.textColor === 'inherit')
828 + cell.styles.textColor = rowopt.style.color;
829 + if (atOptions.styles.fontStyle === 'inherit')
830 + cell.styles.fontStyle = rowopt.style.fstyle;
831 + }
832 + }
833 + }
834 +
835 + if (typeof atOptions.drawHeaderCell !== 'function') {
836 + atOptions.drawHeaderCell = function (cell, data) {
837 + var colopt = teOptions.columns [data.column.dataKey];
838 +
839 + if ((colopt.style.hasOwnProperty("hidden") != true || colopt.style.hidden !== true) &&
840 + colopt.rowIndex >= 0 )
841 + return prepareAutoTableText (cell, data, colopt);
842 + else
843 + return false; // cell is hidden
844 + }
845 + }
846 +
847 + if (typeof atOptions.drawCell !== 'function') {
848 + atOptions.drawCell = function (cell, data) {
849 + var rowopt = teOptions.rowoptions [data.row.index + ":" + data.column.dataKey];
850 + if ( prepareAutoTableText (cell, data, rowopt) ) {
851 +
852 + teOptions.doc.rect(cell.x, cell.y, cell.width, cell.height, cell.styles.fillStyle);
853 +
854 + if (typeof rowopt != 'undefined' && typeof rowopt.kids != 'undefined' && rowopt.kids.length > 0) {
855 +
856 + var dh = cell.height / rowopt.rect.height;
857 + if ( dh > teOptions.dh || typeof teOptions.dh == 'undefined' )
858 + teOptions.dh = dh;
859 + teOptions.dw = cell.width / rowopt.rect.width;
860 +
861 + drawCellElements (cell, rowopt.kids, teOptions);
862 + }
863 + teOptions.doc.autoTableText(cell.text, cell.textPos.x, cell.textPos.y, {
864 + halign: cell.styles.halign,
865 + valign: cell.styles.valign
866 + });
867 + }
868 + return false;
869 + }
870 + }
871 +
872 + // collect header and data rows
873 + teOptions.headerrows = [];
874 + $hrows = $(this).find('thead').find(defaults.theadSelector);
875 + $hrows.each(function () {
876 + colKey = 0;
877 +
878 + teOptions.headerrows[rowIndex] = [];
879 +
880 + ForEachVisibleCell(this, 'th,td', rowIndex, $hrows.length,
881 + function (cell, row, col) {
882 + var obj = getCellStyles (cell);
883 + obj.title = parseString(cell, row, col);
884 + obj.key = colKey++;
885 + obj.rowIndex = rowIndex;
886 + teOptions.headerrows[rowIndex].push(obj);
887 + });
888 + rowIndex++;
889 + });
890 +
891 + if (rowIndex > 0) {
892 + // iterate through last row
893 + $.each(teOptions.headerrows[rowIndex-1], function () {
894 + if (rowIndex > 1 && this.rect == null)
895 + obj = teOptions.headerrows[rowIndex-2][this.key];
896 + else
897 + obj = this;
898 +
899 + if (obj != null)
900 + teOptions.columns.push(obj);
901 + });
902 + }
903 +
904 + var rowCount = 0;
905 + $rows = $(this).find('tbody').find(defaults.tbodySelector);
906 + if (defaults.tfootSelector.length)
907 + $rows.push.apply ($rows, $(el).find('tfoot').find(defaults.tfootSelector));
908 + $rows.each(function () {
909 + var rowData = [];
910 + colKey = 0;
911 +
912 + ForEachVisibleCell(this, 'td', rowIndex, $hrows.length + $rows.length,
913 + function (cell, row, col) {
914 + if (typeof teOptions.columns[colKey] === 'undefined') {
915 + // jsPDF-Autotable needs columns. Thus define hidden ones for tables without thead
916 + var obj = {
917 + title: '',
918 + key: colKey,
919 + style: {
920 + hidden: true
921 + }
922 + };
923 + teOptions.columns.push(obj);
924 + }
925 + if (typeof cell !== 'undefined' && cell != null) {
926 + var obj = getCellStyles (cell);
927 + obj.kids = $(cell).children();
928 + teOptions.rowoptions [rowCount + ":" + colKey++] = obj;
929 + }
930 + else {
931 + var obj = $.extend(true, {}, teOptions.rowoptions [rowCount + ":" + (colKey-1)]);
932 + obj.colspan = -1;
933 + teOptions.rowoptions [rowCount + ":" + colKey++] = obj;
934 + }
935 +
936 + rowData.push(parseString(cell, row, col));
937 + });
938 + if (rowData.length) {
939 + teOptions.rows.push(rowData);
940 + rowCount++
941 + }
942 + rowIndex++;
943 + });
944 +
945 + // onBeforeAutotable: optional callback function before calling
946 + // jsPDF AutoTable that can be used to modify the AutoTable options
947 + if (typeof teOptions.onBeforeAutotable === 'function')
948 + teOptions.onBeforeAutotable($(this), teOptions.columns, teOptions.rows, atOptions);
949 +
950 + teOptions.doc.autoTable(teOptions.columns, teOptions.rows, atOptions);
951 +
952 + // onAfterAutotable: optional callback function after returning
953 + // from jsPDF AutoTable that can be used to modify the AutoTable options
954 + if (typeof teOptions.onAfterAutotable === 'function')
955 + teOptions.onAfterAutotable($(this), atOptions);
956 +
957 + // set the start position for the next table (in case there is one)
958 + defaults.jspdf.autotable.startY = teOptions.doc.autoTableEndPosY() + atOptions.margin.top;
959 + });
960 +
961 + jsPdfOutput(teOptions.doc);
962 +
963 + if (typeof teOptions.headerrows != 'undefined')
964 + teOptions.headerrows.length = 0;
965 + if (typeof teOptions.columns != 'undefined')
966 + teOptions.columns.length = 0;
967 + if (typeof teOptions.rows != 'undefined')
968 + teOptions.rows.length = 0;
969 + delete teOptions.doc;
970 + teOptions.doc = null;
971 + }
972 + }
973 +
974 + function FindColObject (objects, colIndex, rowIndex) {
975 + var result = null;
976 + $.each(objects, function () {
977 + if (this.rowIndex == rowIndex && this.key == colIndex) {
978 + result = this;
979 + return false;
980 + }
981 + });
982 + return result;
983 + }
984 +
985 + function GetColumnNames (table) {
986 + var result = [];
987 + $(table).find('thead').first().find('th').each(function(index, el) {
988 + if ($(el).attr("data-field") !== undefined)
989 + result[index] = $(el).attr("data-field");
990 + else
991 + result[index] = index.toString();
992 + });
993 + return result;
994 + }
995 +
996 + function isColumnIgnored($row, colIndex) {
997 + var result = false;
998 + if (defaults.ignoreColumn.length > 0) {
999 + if (typeof defaults.ignoreColumn[0] == 'string') {
1000 + if (colNames.length > colIndex && typeof colNames[colIndex] != 'undefined')
1001 + if ($.inArray(colNames[colIndex], defaults.ignoreColumn) != -1)
1002 + result = true;
1003 + }
1004 + else if (typeof defaults.ignoreColumn[0] == 'number') {
1005 + if ($.inArray(colIndex, defaults.ignoreColumn) != -1 ||
1006 + $.inArray(colIndex-$row.length, defaults.ignoreColumn) != -1)
1007 + result = true;
1008 + }
1009 + }
1010 + return result;
1011 + }
1012 +
1013 + function ForEachVisibleCell(tableRow, selector, rowIndex, rowCount, cellcallback) {
1014 + if ($.inArray(rowIndex, defaults.ignoreRow) == -1 &&
1015 + $.inArray(rowIndex-rowCount, defaults.ignoreRow) == -1) {
1016 +
1017 + var $row = $(tableRow).filter(function() {
1018 + return $(this).data("tableexport-display") != 'none' &&
1019 + ($(this).is(':visible') ||
1020 + $(this).data("tableexport-display") == 'always' ||
1021 + $(this).closest('table').data("tableexport-display") == 'always');
1022 + }).find(selector);
1023 +
1024 + var rowColspan = 0;
1025 + var rowColIndex = 0;
1026 +
1027 + $row.each(function (colIndex) {
1028 + if ($(this).data("tableexport-display") == 'always' ||
1029 + ($(this).css('display') != 'none' &&
1030 + $(this).css('visibility') != 'hidden' &&
1031 + $(this).data("tableexport-display") != 'none')) {
1032 + if (isColumnIgnored($row, colIndex) == false) {
1033 + if (typeof (cellcallback) === "function") {
1034 + var c, Colspan = 0;
1035 + var r, Rowspan = 0;
1036 +
1037 + // handle rowspans from previous rows
1038 + if (typeof rowspans[rowIndex] != 'undefined' && rowspans[rowIndex].length > 0) {
1039 + for (c = 0; c <= colIndex; c++) {
1040 + if (typeof rowspans[rowIndex][c] != 'undefined') {
1041 + cellcallback(null, rowIndex, c);
1042 + delete rowspans[rowIndex][c];
1043 + colIndex++;
1044 + }
1045 + }
1046 + }
1047 + rowColIndex = colIndex;
1048 +
1049 + if ($(this).is("[colspan]")) {
1050 + Colspan = parseInt($(this).attr('colspan'));
1051 + rowColspan += Colspan > 0 ? Colspan - 1 : 0;
1052 + }
1053 +
1054 + if ($(this).is("[rowspan]"))
1055 + Rowspan = parseInt($(this).attr('rowspan'));
1056 +
1057 + // output content of current cell
1058 + cellcallback(this, rowIndex, colIndex);
1059 +
1060 + // handle colspan of current cell
1061 + for (c = 0; c < Colspan - 1; c++)
1062 + cellcallback(null, rowIndex, colIndex + c);
1063 +
1064 + // store rowspan for following rows
1065 + if (Rowspan) {
1066 + for (r = 1; r < Rowspan; r++) {
1067 + if (typeof rowspans[rowIndex + r] == 'undefined')
1068 + rowspans[rowIndex + r] = [];
1069 +
1070 + rowspans[rowIndex + r][colIndex + rowColspan] = "";
1071 +
1072 + for (c = 1; c < Colspan; c++)
1073 + rowspans[rowIndex + r][colIndex + rowColspan - c] = "";
1074 + }
1075 + }
1076 + }
1077 + }
1078 + }
1079 + });
1080 + // handle rowspans from previous rows
1081 + if (typeof rowspans[rowIndex] != 'undefined' && rowspans[rowIndex].length > 0) {
1082 + for (c = 0; c <= rowspans[rowIndex].length; c++) {
1083 + if (typeof rowspans[rowIndex][c] != 'undefined') {
1084 + cellcallback(null, rowIndex, c);
1085 + delete rowspans[rowIndex][c];
1086 + }
1087 + }
1088 + }
1089 + }
1090 + }
1091 +
1092 + function jsPdfOutput(doc) {
1093 + if (defaults.consoleLog === true)
1094 + console.log(doc.output());
1095 +
1096 + if (defaults.outputMode === 'string')
1097 + return doc.output();
1098 +
1099 + if (defaults.outputMode === 'base64')
1100 + return base64encode(doc.output());
1101 +
1102 + try {
1103 + var blob = doc.output('blob');
1104 + saveAs(blob, defaults.fileName + '.pdf');
1105 + }
1106 + catch (e) {
1107 + downloadFile(defaults.fileName + '.pdf',
1108 + 'data:application/pdf;base64,',
1109 + doc.output());
1110 + }
1111 + }
1112 +
1113 + function prepareAutoTableText (cell, data, cellopt) {
1114 + var cs = 0;
1115 + if ( typeof cellopt != 'undefined' )
1116 + cs = cellopt.colspan;
1117 +
1118 + if ( cs >= 0 ) {
1119 + // colspan handling
1120 + var cellWidth = cell.width;
1121 + var textPosX = cell.textPos.x;
1122 + var i = data.table.columns.indexOf(data.column);
1123 +
1124 + for (var c = 1; c < cs; c++) {
1125 + var column = data.table.columns[i+c];
1126 + cellWidth += column.width;
1127 + }
1128 +
1129 + if ( cs > 1 ) {
1130 + if ( cell.styles.halign === 'right' )
1131 + textPosX = cell.textPos.x + cellWidth - cell.width;
1132 + else if ( cell.styles.halign === 'center' )
1133 + textPosX = cell.textPos.x + (cellWidth - cell.width) / 2;
1134 + }
1135 +
1136 + cell.width = cellWidth;
1137 + cell.textPos.x = textPosX;
1138 +
1139 + if ( typeof cellopt != 'undefined' && cellopt.rowspan > 1 )
1140 + cell.height = cell.height * cellopt.rowspan;
1141 +
1142 + // fix jsPDF's calculation of text position
1143 + if ( cell.styles.valign === 'middle' || cell.styles.valign === 'bottom' ) {
1144 + var splittedText = typeof cell.text === 'string' ? cell.text.split(/\r\n|\r|\n/g) : cell.text;
1145 + var lineCount = splittedText.length || 1;
1146 + if (lineCount > 2)
1147 + cell.textPos.y -= ((2 - FONT_ROW_RATIO) / 2 * data.row.styles.fontSize) * (lineCount-2) / 3 ;
1148 + }
1149 + return true;
1150 + }
1151 + else
1152 + return false; // cell is hidden (colspan = -1), don't draw it
1153 + }
1154 +
1155 + function drawCellElements (cell, elements, teOptions) {
1156 + elements.each(function () {
1157 + var kids = $(this).children();
1158 +
1159 + if ( $(this).is("div") ) {
1160 + var bcolor = rgb2array(getStyle(this, 'background-color'), [255, 255, 255]);
1161 + var lcolor = rgb2array(getStyle(this, 'border-top-color'), [0, 0, 0]);
1162 + var lwidth = getPropertyUnitValue(this, 'border-top-width', defaults.jspdf.unit);
1163 +
1164 + var r = this.getBoundingClientRect();
1165 + var ux = this.offsetLeft * teOptions.dw;
1166 + var uy = this.offsetTop * teOptions.dh;
1167 + var uw = r.width * teOptions.dw;
1168 + var uh = r.height * teOptions.dh;
1169 +
1170 + teOptions.doc.setDrawColor.apply (undefined, lcolor);
1171 + teOptions.doc.setFillColor.apply (undefined, bcolor);
1172 + teOptions.doc.setLineWidth (lwidth);
1173 + teOptions.doc.rect(cell.x + ux, cell.y + uy, uw, uh, lwidth ? "FD" : "F");
1174 + }
1175 +
1176 + if (typeof kids != 'undefined' && kids.length > 0)
1177 + drawCellElements (cell, kids, teOptions);
1178 + });
1179 + }
1180 +
1181 + function escapeRegExp(string) {
1182 + return string.replace(/([.*+?^=!:${}()|\[\]\/\\])/g, "\\$1");
1183 + }
1184 +
1185 + function replaceAll(string, find, replace) {
1186 + return string.replace(new RegExp(escapeRegExp(find), 'g'), replace);
1187 + }
1188 +
1189 + // Takes a string and encapsulates it (by default in double-quotes) if it
1190 + // contains the csv field separator, spaces, or linebreaks.
1191 + function csvString(cell, rowIndex, colIndex) {
1192 + var result = '';
1193 +
1194 + if (cell != null) {
1195 + var dataString = parseString(cell, rowIndex, colIndex);
1196 +
1197 + var csvValue = (dataString === null || dataString == '') ? '' : dataString.toString();
1198 +
1199 + if (dataString instanceof Date)
1200 + result = defaults.csvEnclosure + dataString.toLocaleString() + defaults.csvEnclosure;
1201 + else {
1202 + result = replaceAll(csvValue, defaults.csvEnclosure, defaults.csvEnclosure + defaults.csvEnclosure);
1203 +
1204 + if (result.indexOf(defaults.csvSeparator) >= 0 || /[\r\n ]/g.test(result))
1205 + result = defaults.csvEnclosure + result + defaults.csvEnclosure;
1206 + }
1207 + }
1208 +
1209 + return result;
1210 + }
1211 +
1212 + function parseNumber(value) {
1213 + value = value || "0";
1214 + value = replaceAll(value, defaults.numbers.html.decimalMark, '.');
1215 + value = replaceAll(value, defaults.numbers.html.thousandsSeparator, '');
1216 +
1217 + return typeof value === "number" || jQuery.isNumeric(value) !== false ? value : false;
1218 + }
1219 +
1220 +
1221 + function parseString(cell, rowIndex, colIndex) {
1222 + var result = '';
1223 +
1224 + if (cell != null) {
1225 + var $cell = $(cell);
1226 + var htmlData;
1227 +
1228 + if ($cell[0].hasAttribute("data-tableexport-value"))
1229 + htmlData = $cell.data("tableexport-value");
1230 + else
1231 + htmlData = $cell.html();
1232 +
1233 + if (typeof defaults.onCellHtmlData === 'function')
1234 + htmlData = defaults.onCellHtmlData($cell, rowIndex, colIndex, htmlData);
1235 +
1236 + if (defaults.htmlContent === true) {
1237 + result = $.trim(htmlData);
1238 + }
1239 + else {
1240 + var text = htmlData.replace(/\n/g,'\u2028').replace(/<br\s*[\/]?>/gi, '\u2060');
1241 + var obj = $('<div/>').html(text).contents();
1242 + text = '';
1243 + $.each(obj.text().split("\u2028"), function(i, v) {
1244 + if (i > 0)
1245 + text += " ";
1246 + text += $.trim(v);
1247 + });
1248 +
1249 + $.each(text.split("\u2060"), function(i, v) {
1250 + if (i > 0)
1251 + result += "\n";
1252 + result += $.trim(v).replace(/\u00AD/g, ""); // remove soft hyphens
1253 + });
1254 +
1255 + if (defaults.numbers.html.decimalMark != defaults.numbers.output.decimalMark ||
1256 + defaults.numbers.html.thousandsSeparator != defaults.numbers.output.thousandsSeparator) {
1257 + var number = parseNumber (result);
1258 +
1259 + if ( number !== false ) {
1260 + var frac = ("" + number).split('.');
1261 + if ( frac.length == 1 )
1262 + frac[1] = "";
1263 + var mod = frac[0].length > 3 ? frac[0].length % 3 : 0;
1264 +
1265 + result = (number < 0 ? "-" : "") +
1266 + (defaults.numbers.output.thousandsSeparator ? ((mod ? frac[0].substr(0, mod) + defaults.numbers.output.thousandsSeparator : "") + frac[0].substr(mod).replace(/(\d{3})(?=\d)/g, "$1" + defaults.numbers.output.thousandsSeparator)) : frac[0]) +
1267 + (frac[1].length ? defaults.numbers.output.decimalMark + frac[1] : "");
1268 + }
1269 + }
1270 + }
1271 +
1272 + if (defaults.escape === true) {
1273 + result = escape(result);
1274 + }
1275 +
1276 + if (typeof defaults.onCellData === 'function') {
1277 + result = defaults.onCellData($cell, rowIndex, colIndex, result);
1278 + }
1279 + }
1280 +
1281 + return result;
1282 + }
1283 +
1284 + function hyphenate(a, b, c) {
1285 + return b + "-" + c.toLowerCase();
1286 + }
1287 +
1288 + function rgb2array(rgb_string, default_result) {
1289 + var re = /^rgb\((\d{1,3}),\s*(\d{1,3}),\s*(\d{1,3})\)$/;
1290 + var bits = re.exec(rgb_string);
1291 + var result = default_result;
1292 + if (bits)
1293 + result = [ parseInt(bits[1]), parseInt(bits[2]), parseInt(bits[3]) ];
1294 + return result;
1295 + }
1296 +
1297 + function getCellStyles (cell) {
1298 + var a = getStyle(cell, 'text-align');
1299 + var fw = getStyle(cell, 'font-weight');
1300 + var fs = getStyle(cell, 'font-style');
1301 + var f = '';
1302 + if (a == 'start')
1303 + a = getStyle(cell, 'direction') == 'rtl' ? 'right' : 'left';
1304 + if (fw >= 700)
1305 + f = 'bold';
1306 + if (fs == 'italic')
1307 + f += fs;
1308 + if (f == '')
1309 + f = 'normal';
1310 +
1311 + var result = {
1312 + style: {
1313 + align: a,
1314 + bcolor: rgb2array(getStyle(cell, 'background-color'), [255, 255, 255]),
1315 + color: rgb2array(getStyle(cell, 'color'), [0, 0, 0]),
1316 + fstyle: f
1317 + },
1318 + colspan: (parseInt($(cell).attr('colspan')) || 0),
1319 + rowspan: (parseInt($(cell).attr('rowspan')) || 0)
1320 + };
1321 +
1322 + if (cell !== null) {
1323 + var r = cell.getBoundingClientRect();
1324 + result.rect = {
1325 + width: r.width,
1326 + height: r.height
1327 + };
1328 + }
1329 +
1330 + return result;
1331 + }
1332 +
1333 + // get computed style property
1334 + function getStyle(target, prop) {
1335 + try {
1336 + if (window.getComputedStyle) { // gecko and webkit
1337 + prop = prop.replace(/([a-z])([A-Z])/, hyphenate); // requires hyphenated, not camel
1338 + return window.getComputedStyle(target, null).getPropertyValue(prop);
1339 + }
1340 + if (target.currentStyle) { // ie
1341 + return target.currentStyle[prop];
1342 + }
1343 + return target.style[prop];
1344 + }
1345 + catch (e) {
1346 + }
1347 + return "";
1348 + }
1349 +
1350 + function getUnitValue(parent, value, unit) {
1351 + var baseline = 100; // any number serves
1352 +
1353 + var temp = document.createElement("div"); // create temporary element
1354 + temp.style.overflow = "hidden"; // in case baseline is set too low
1355 + temp.style.visibility = "hidden"; // no need to show it
1356 +
1357 + parent.appendChild(temp); // insert it into the parent for em, ex and %
1358 +
1359 + temp.style.width = baseline + unit;
1360 + var factor = baseline / temp.offsetWidth;
1361 +
1362 + parent.removeChild(temp); // clean up
1363 +
1364 + return (value * factor);
1365 + }
1366 +
1367 + function getPropertyUnitValue(target, prop, unit) {
1368 + var value = getStyle(target, prop); // get the computed style value
1369 +
1370 + var numeric = value.match(/\d+/); // get the numeric component
1371 + if (numeric !== null) {
1372 + numeric = numeric[0]; // get the string
1373 +
1374 + return getUnitValue (target.parentElement, numeric, unit);
1375 + }
1376 + return 0;
1377 + }
1378 +
1379 + function jx_Workbook() {
1380 + if(!(this instanceof jx_Workbook)) return new jx_Workbook();
1381 + this.SheetNames = [];
1382 + this.Sheets = {};
1383 + }
1384 +
1385 + function jx_s2ab(s) {
1386 + var buf = new ArrayBuffer(s.length);
1387 + var view = new Uint8Array(buf);
1388 + for (var i=0; i!=s.length; ++i) view[i] = s.charCodeAt(i) & 0xFF;
1389 + return buf;
1390 + }
1391 +
1392 + function jx_datenum(v, date1904) {
1393 + if(date1904) v+=1462;
1394 + var epoch = Date.parse(v);
1395 + return (epoch - new Date(Date.UTC(1899, 11, 30))) / (24 * 60 * 60 * 1000);
1396 + }
1397 +
1398 + function jx_createSheet(data) {
1399 + var ws = {};
1400 + var range = {s: {c:10000000, r:10000000}, e: {c:0, r:0 }};
1401 + for(var R = 0; R != data.length; ++R) {
1402 + for(var C = 0; C != data[R].length; ++C) {
1403 + if(range.s.r > R) range.s.r = R;
1404 + if(range.s.c > C) range.s.c = C;
1405 + if(range.e.r < R) range.e.r = R;
1406 + if(range.e.c < C) range.e.c = C;
1407 + var cell = {v: data[R][C] };
1408 + if(cell.v == null) continue;
1409 + var cell_ref = XLSX.utils.encode_cell({c:C,r:R});
1410 +
1411 + if(typeof cell.v === 'number') cell.t = 'n';
1412 + else if(typeof cell.v === 'boolean') cell.t = 'b';
1413 + else if(cell.v instanceof Date) {
1414 + cell.t = 'n'; cell.z = XLSX.SSF._table[14];
1415 + cell.v = datenum(cell.v);
1416 + }
1417 + else cell.t = 's';
1418 + ws[cell_ref] = cell;
1419 + }
1420 + }
1421 +
1422 + if(range.s.c < 10000000) ws['!ref'] = XLSX.utils.encode_range(range);
1423 + return ws;
1424 + }
1425 +
1426 + function downloadFile(filename, header, data) {
1427 +
1428 + var ua = window.navigator.userAgent;
1429 + if (ua.indexOf("MSIE ") > 0 || !!ua.match(/Trident.*rv\:11\./)) {
1430 + // Internet Explorer (<= 9) workaround by Darryl (https://github.com/dawiong/tableExport.jquery.plugin)
1431 + // based on sampopes answer on http://stackoverflow.com/questions/22317951
1432 + // ! Not working for json and pdf format !
1433 + var frame = document.createElement("iframe");
1434 +
1435 + if (frame) {
1436 + document.body.appendChild(frame);
1437 + frame.setAttribute("style", "display:none");
1438 + frame.contentDocument.open("txt/html", "replace");
1439 + frame.contentDocument.write(data);
1440 + frame.contentDocument.close();
1441 + frame.focus();
1442 +
1443 + frame.contentDocument.execCommand("SaveAs", true, filename);
1444 + document.body.removeChild(frame);
1445 + }
1446 + }
1447 + else {
1448 + var DownloadLink = document.createElement('a');
1449 +
1450 + if (DownloadLink) {
1451 + DownloadLink.style.display = 'none';
1452 + DownloadLink.download = filename;
1453 +
1454 + if (header.toLowerCase().indexOf("base64,") >= 0)
1455 + DownloadLink.href = header + base64encode(data);
1456 + else
1457 + DownloadLink.href = header + encodeURIComponent(data);
1458 +
1459 + document.body.appendChild(DownloadLink);
1460 +
1461 + if (document.createEvent) {
1462 + if (DownloadEvt == null)
1463 + DownloadEvt = document.createEvent('MouseEvents');
1464 +
1465 + DownloadEvt.initEvent('click', true, false);
1466 + DownloadLink.dispatchEvent(DownloadEvt);
1467 + }
1468 + else if (document.createEventObject)
1469 + DownloadLink.fireEvent('onclick');
1470 + else if (typeof DownloadLink.onclick == 'function')
1471 + DownloadLink.onclick();
1472 +
1473 + document.body.removeChild(DownloadLink);
1474 + }
1475 + }
1476 + }
1477 +
1478 + function utf8Encode(string) {
1479 + string = string.replace(/\x0d\x0a/g, "\x0a");
1480 + var utftext = "";
1481 + for (var n = 0; n < string.length; n++) {
1482 + var c = string.charCodeAt(n);
1483 + if (c < 128) {
1484 + utftext += String.fromCharCode(c);
1485 + }
1486 + else if ((c > 127) && (c < 2048)) {
1487 + utftext += String.fromCharCode((c >> 6) | 192);
1488 + utftext += String.fromCharCode((c & 63) | 128);
1489 + }
1490 + else {
1491 + utftext += String.fromCharCode((c >> 12) | 224);
1492 + utftext += String.fromCharCode(((c >> 6) & 63) | 128);
1493 + utftext += String.fromCharCode((c & 63) | 128);
1494 + }
1495 + }
1496 + return utftext;
1497 + }
1498 +
1499 + function base64encode(input) {
1500 + var keyStr = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";
1501 + var output = "";
1502 + var chr1, chr2, chr3, enc1, enc2, enc3, enc4;
1503 + var i = 0;
1504 + input = utf8Encode(input);
1505 + while (i < input.length) {
1506 + chr1 = input.charCodeAt(i++);
1507 + chr2 = input.charCodeAt(i++);
1508 + chr3 = input.charCodeAt(i++);
1509 + enc1 = chr1 >> 2;
1510 + enc2 = ((chr1 & 3) << 4) | (chr2 >> 4);
1511 + enc3 = ((chr2 & 15) << 2) | (chr3 >> 6);
1512 + enc4 = chr3 & 63;
1513 + if (isNaN(chr2)) {
1514 + enc3 = enc4 = 64;
1515 + } else if (isNaN(chr3)) {
1516 + enc4 = 64;
1517 + }
1518 + output = output +
1519 + keyStr.charAt(enc1) + keyStr.charAt(enc2) +
1520 + keyStr.charAt(enc3) + keyStr.charAt(enc4);
1521 + }
1522 + return output;
1523 + }
1524 +
1525 + return this;
1526 + }
1527 + });
1528 +})(jQuery);