mirror of
https://github.com/snipe/snipe-it.git
synced 2024-12-29 07:29:44 -08:00
7e41c74cc3
Signed-off-by: snipe <[email protected]>
107 lines
3.9 KiB
JavaScript
Executable file
107 lines
3.9 KiB
JavaScript
Executable file
/**
|
|
* @author zhixin wen <[email protected]>
|
|
* extensions: https://github.com/kayalshri/tableExport.jquery.plugin
|
|
*/
|
|
|
|
(function ($) {
|
|
'use strict';
|
|
|
|
var TYPE_NAME = {
|
|
json: 'JSON',
|
|
xml: 'XML',
|
|
png: 'PNG',
|
|
csv: 'CSV',
|
|
txt: 'TXT',
|
|
sql: 'SQL',
|
|
doc: 'MS-Word',
|
|
excel: 'MS-Excel',
|
|
powerpoint: 'MS-Powerpoint',
|
|
pdf: 'PDF'
|
|
};
|
|
|
|
$.extend($.fn.bootstrapTable.defaults, {
|
|
showExport: false,
|
|
exportDataType: 'basic', // basic, all, selected
|
|
// 'json', 'xml', 'png', 'csv', 'txt', 'sql', 'doc', 'excel', 'powerpoint', 'pdf'
|
|
exportTypes: ['json', 'xml', 'csv', 'txt', 'sql', 'excel'],
|
|
exportOptions: {}
|
|
});
|
|
|
|
var BootstrapTable = $.fn.bootstrapTable.Constructor,
|
|
_initToolbar = BootstrapTable.prototype.initToolbar;
|
|
|
|
BootstrapTable.prototype.initToolbar = function () {
|
|
this.showToolbar = this.options.showExport;
|
|
|
|
_initToolbar.apply(this, Array.prototype.slice.apply(arguments));
|
|
|
|
if (this.options.showExport) {
|
|
var that = this,
|
|
$btnGroup = this.$toolbar.find('>.btn-group'),
|
|
$export = $btnGroup.find('div.export');
|
|
|
|
if (!$export.length) {
|
|
$export = $([
|
|
'<div class="export btn-group">',
|
|
'<button class="btn btn-default dropdown-toggle" ' +
|
|
'data-toggle="dropdown" type="button">',
|
|
'<i class="fas fa-download" aria-hidden="true"></i> ',
|
|
'<span class="sr-only">Export</span>',
|
|
'<span class="caret"></span>',
|
|
'</button>',
|
|
'<ul class="dropdown-menu" role="menu">',
|
|
'</ul>',
|
|
'</div>'].join('')).appendTo($btnGroup);
|
|
|
|
var $menu = $export.find('.dropdown-menu'),
|
|
exportTypes = this.options.exportTypes;
|
|
|
|
if (typeof this.options.exportTypes === 'string') {
|
|
var types = this.options.exportTypes.slice(1, -1).replace(/ /g, '').split(',');
|
|
|
|
exportTypes = [];
|
|
$.each(types, function (i, value) {
|
|
exportTypes.push(value.slice(1, -1));
|
|
});
|
|
}
|
|
$.each(exportTypes, function (i, type) {
|
|
if (TYPE_NAME.hasOwnProperty(type)) {
|
|
$menu.append(['<li role="menuitem" data-type="' + type + '">',
|
|
'<a href="javascript:void(0)">',
|
|
TYPE_NAME[type],
|
|
'</a>',
|
|
'</li>'].join(''));
|
|
}
|
|
});
|
|
|
|
$menu.find('li').click(function () {
|
|
var type = $(this).data('type'),
|
|
doExport = function () {
|
|
that.$el.tableExport($.extend({}, that.options.exportOptions, {
|
|
type: type,
|
|
escape: false
|
|
}));
|
|
};
|
|
|
|
if (that.options.exportDataType === 'all' && that.options.pagination) {
|
|
that.$el.one('load-success.bs.table page-change.bs.table', function () {
|
|
doExport();
|
|
that.togglePagination();
|
|
});
|
|
that.togglePagination();
|
|
} else if (that.options.exportDataType === 'selected') {
|
|
var data = that.getData(),
|
|
selectedData = that.getAllSelections();
|
|
|
|
that.load(selectedData);
|
|
doExport();
|
|
that.load(data);
|
|
} else {
|
|
doExport();
|
|
}
|
|
});
|
|
}
|
|
}
|
|
};
|
|
})(jQuery);
|