corrade-nucleus-nucleons – Blame information for rev 20

Subversion Repositories:
Rev:
Rev Author Line No. Line
20 office 1 /**
2 * @author Homer Glascock <HopGlascock@gmail.com>
3 * @version: v1.0.0
4 */
5  
6 !function ($) {
7 "use strict";
8  
9 var calculateObjectValue = $.fn.bootstrapTable.utils.calculateObjectValue,
10 sprintf = $.fn.bootstrapTable.utils.sprintf;
11  
12 var copytext = function (text) {
13 var textField = document.createElement('textarea');
14 $(textField).html(text);
15 document.body.appendChild(textField);
16 textField.select();
17  
18 try {
19 document.execCommand('copy');
20 }
21 catch (e) {
22 console.log("Oops, unable to copy");
23 }
24 $(textField).remove();
25 };
26  
27 $.extend($.fn.bootstrapTable.defaults, {
28 copyBtn: false,
29 copyWHiddenBtn: false,
30 copyDelemeter: ", "
31 });
32  
33 $.fn.bootstrapTable.methods.push('copyColumnsToClipboard', 'copyColumnsToClipboardWithHidden');
34  
35 var BootstrapTable = $.fn.bootstrapTable.Constructor,
36 _initToolbar = BootstrapTable.prototype.initToolbar;
37  
38 BootstrapTable.prototype.initToolbar = function () {
39  
40 _initToolbar.apply(this, Array.prototype.slice.apply(arguments));
41  
42 var that = this,
43 $btnGroup = this.$toolbar.find('>.btn-group');
44  
45 if (this.options.clickToSelect || this.options.singleSelect) {
46  
47 if (this.options.copyBtn) {
48 var copybtn = "<button class='btn btn-default' id='copyBtn'><span class='glyphicon glyphicon-copy icon-pencil'></span></button>";
49 $btnGroup.append(copybtn);
50 $btnGroup.find('#copyBtn').click(function () { that.copyColumnsToClipboard(); });
51 }
52  
53 if (this.options.copyWHiddenBtn) {
54 var copyhiddenbtn = "<button class='btn btn-default' id='copyWHiddenBtn'><span class='badge'><span class='glyphicon glyphicon-copy icon-pencil'></span></span></button>";
55 $btnGroup.append(copyhiddenbtn);
56 $btnGroup.find('#copyWHiddenBtn').click(function () { that.copyColumnsToClipboardWithHidden(); });
57 }
58 }
59 };
60  
61 BootstrapTable.prototype.copyColumnsToClipboard = function () {
62 var that = this,
63 ret = "",
64 delimet = this.options.copyDelemeter;
65  
66 $.each(that.getSelections(), function (index, row) {
67 $.each(that.options.columns[0], function (indy, column) {
68 if (column.field !== "state" && column.field !== "RowNumber" && column.visible) {
69 if (row[column.field] !== null) {
70 ret += calculateObjectValue(column, that.header.formatters[indy], [row[column.field], row, index], row[column.field]);
71 }
72 ret += delimet;
73 }
74 });
75  
76 ret += "\r\n";
77 });
78  
79 copytext(ret);
80 };
81  
82 BootstrapTable.prototype.copyColumnsToClipboardWithHidden = function () {
83 var that = this,
84 ret = "",
85 delimet = this.options.copyDelemeter;
86  
87 $.each(that.getSelections(), function (index, row) {
88 $.each(that.options.columns[0], function (indy, column) {
89 if (column.field != "state" && column.field !== "RowNumber") {
90 if (row[column.field] !== null) {
91 ret += calculateObjectValue(column, that.header.formatters[indy], [row[column.field], row, index], row[column.field]);
92 }
93 ret += delimet;
94 }
95 });
96  
97 ret += "\r\n";
98 });
99  
100 copytext(ret);
101 };
102 }(jQuery);