corrade-nucleus-nucleons – Blame information for rev 20

Subversion Repositories:
Rev:
Rev Author Line No. Line
20 office 1 /**
2 * @author zhixin wen <wenzhixin2010@gmail.com>
3 * extensions: https://github.com/kayalshri/tableExport.jquery.plugin
4 */
5  
6 (function ($) {
7 'use strict';
8 var sprintf = $.fn.bootstrapTable.utils.sprintf;
9  
10 var TYPE_NAME = {
11 json: 'JSON',
12 xml: 'XML',
13 png: 'PNG',
14 csv: 'CSV',
15 txt: 'TXT',
16 sql: 'SQL',
17 doc: 'MS-Word',
18 excel: 'MS-Excel',
19 xlsx: 'MS-Excel (OpenXML)',
20 powerpoint: 'MS-Powerpoint',
21 pdf: 'PDF'
22 };
23  
24 $.extend($.fn.bootstrapTable.defaults, {
25 showExport: false,
26 exportDataType: 'basic', // basic, all, selected
27 // 'json', 'xml', 'png', 'csv', 'txt', 'sql', 'doc', 'excel', 'powerpoint', 'pdf'
28 exportTypes: ['json', 'xml', 'csv', 'txt', 'sql', 'excel'],
29 exportOptions: {}
30 });
31  
32 $.extend($.fn.bootstrapTable.defaults.icons, {
33 export: 'glyphicon-export icon-share'
34 });
35  
36 $.extend($.fn.bootstrapTable.locales, {
37 formatExport: function () {
38 return 'Export data';
39 }
40 });
41 $.extend($.fn.bootstrapTable.defaults, $.fn.bootstrapTable.locales);
42  
43 var BootstrapTable = $.fn.bootstrapTable.Constructor,
44 _initToolbar = BootstrapTable.prototype.initToolbar;
45  
46 BootstrapTable.prototype.initToolbar = function () {
47 this.showToolbar = this.options.showExport;
48  
49 _initToolbar.apply(this, Array.prototype.slice.apply(arguments));
50  
51 if (this.options.showExport) {
52 var that = this,
53 $btnGroup = this.$toolbar.find('>.btn-group'),
54 $export = $btnGroup.find('div.export');
55  
56 if (!$export.length) {
57 $export = $([
58 '<div class="export btn-group">',
59 '<button class="btn' +
60 sprintf(' btn-%s', this.options.buttonsClass) +
61 sprintf(' btn-%s', this.options.iconSize) +
62 ' dropdown-toggle" aria-label="export type" ' +
63 'title="' + this.options.formatExport() + '" ' +
64 'data-toggle="dropdown" type="button">',
65 sprintf('<i class="%s %s"></i> ', this.options.iconsPrefix, this.options.icons.export),
66 '<span class="caret"></span>',
67 '</button>',
68 '<ul class="dropdown-menu" role="menu">',
69 '</ul>',
70 '</div>'].join('')).appendTo($btnGroup);
71  
72 var $menu = $export.find('.dropdown-menu'),
73 exportTypes = this.options.exportTypes;
74  
75 if (typeof this.options.exportTypes === 'string') {
76 var types = this.options.exportTypes.slice(1, -1).replace(/ /g, '').split(',');
77  
78 exportTypes = [];
79 $.each(types, function (i, value) {
80 exportTypes.push(value.slice(1, -1));
81 });
82 }
83 $.each(exportTypes, function (i, type) {
84 if (TYPE_NAME.hasOwnProperty(type)) {
85 $menu.append(['<li role="menuitem" data-type="' + type + '">',
86 '<a href="javascript:void(0)">',
87 TYPE_NAME[type],
88 '</a>',
89 '</li>'].join(''));
90 }
91 });
92  
93 $menu.find('li').click(function () {
94 var type = $(this).data('type'),
95 doExport = function () {
96 that.$el.tableExport($.extend({}, that.options.exportOptions, {
97 type: type,
98 escape: false
99 }));
100 };
101  
102 if (that.options.exportDataType === 'all' && that.options.pagination) {
103 that.$el.one(that.options.sidePagination === 'server' ? 'post-body.bs.table' : 'page-change.bs.table', function () {
104 doExport();
105 that.togglePagination();
106 });
107 that.togglePagination();
108 } else if (that.options.exportDataType === 'selected') {
109 var data = that.getData(),
110 selectedData = that.getAllSelections();
111  
112 // Quick fix #2220
113 if (that.options.sidePagination === 'server') {
114 data = {total: that.options.totalRows};
115 data[that.options.dataField] = that.getData();
116  
117 selectedData = {total: that.options.totalRows};
118 selectedData[that.options.dataField] = that.getAllSelections();
119 }
120  
121 that.load(selectedData);
122 doExport();
123 that.load(data);
124 } else {
125 doExport();
126 }
127 });
128 }
129 }
130 };
131 })(jQuery);