bootstrap-table-rails 1.10.1 → 1.11.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (26) hide show
  1. checksums.yaml +4 -4
  2. data/lib/bootstrap-table-rails/version.rb +1 -1
  3. data/vendor/assets/javascripts/bootstrap-table-locale-all.js +60 -19
  4. data/vendor/assets/javascripts/bootstrap-table.js +305 -94
  5. data/vendor/assets/javascripts/extensions/bootstrap-table-angular.js +5 -3
  6. data/vendor/assets/javascripts/extensions/bootstrap-table-cookie.js +85 -28
  7. data/vendor/assets/javascripts/extensions/bootstrap-table-copy-rows.js +102 -0
  8. data/vendor/assets/javascripts/extensions/bootstrap-table-editable.js +51 -33
  9. data/vendor/assets/javascripts/extensions/bootstrap-table-export.js +11 -2
  10. data/vendor/assets/javascripts/extensions/bootstrap-table-filter-control.js +216 -71
  11. data/vendor/assets/javascripts/extensions/bootstrap-table-group-by.js +1 -1
  12. data/vendor/assets/javascripts/extensions/bootstrap-table-i18n-enhance.js +34 -0
  13. data/vendor/assets/javascripts/extensions/bootstrap-table-multi-toggle.js +88 -0
  14. data/vendor/assets/javascripts/extensions/bootstrap-table-multiple-search.js +6 -2
  15. data/vendor/assets/javascripts/extensions/bootstrap-table-multiple-sort.js +39 -24
  16. data/vendor/assets/javascripts/extensions/bootstrap-table-natural-sorting.js +12 -2
  17. data/vendor/assets/javascripts/extensions/bootstrap-table-reorder-columns.js +57 -1
  18. data/vendor/assets/javascripts/extensions/bootstrap-table-select2-filter.js +303 -0
  19. data/vendor/assets/javascripts/extensions/bootstrap-table-sticky-header.js +16 -9
  20. data/vendor/assets/javascripts/locale/bootstrap-table-en-US.js +6 -0
  21. data/vendor/assets/javascripts/locale/bootstrap-table-it-IT.js +5 -1
  22. data/vendor/assets/javascripts/locale/bootstrap-table-nl-NL.js +24 -15
  23. data/vendor/assets/javascripts/locale/bootstrap-table-pt-PT.js +18 -3
  24. data/vendor/assets/javascripts/locale/bootstrap-table-zh-CN.js +7 -1
  25. data/vendor/assets/stylesheets/bootstrap-table.css +9 -2
  26. metadata +7 -3
@@ -3,11 +3,13 @@
3
3
  if (typeof angular === 'undefined') {
4
4
  return;
5
5
  }
6
- angular.module('bsTable', []).directive('bsTableControl', function () {
6
+ angular.module('bsTable', [])
7
+ .constant('uiBsTables', {bsTables: {}})
8
+ .directive('bsTableControl', ['uiBsTables', function (uiBsTables) {
7
9
  var CONTAINER_SELECTOR = '.bootstrap-table';
8
10
  var SCROLLABLE_SELECTOR = '.fixed-table-body';
9
11
  var SEARCH_SELECTOR = '.search input';
10
- var bsTables = {};
12
+ var bsTables = uiBsTables.bsTables;
11
13
  function getBsTable (el) {
12
14
  var result;
13
15
  $.each(bsTables, function (id, bsTable) {
@@ -101,5 +103,5 @@
101
103
  });
102
104
  }
103
105
  };
104
- })
106
+ }])
105
107
  })();
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * @author: Dennis Hernández
3
3
  * @webSite: http://djhvscf.github.io/Blog
4
- * @version: v1.2.0
4
+ * @version: v1.2.1
5
5
  *
6
6
  * @update zhixin wen <wenzhixin2010@gmail.com>
7
7
  */
@@ -133,6 +133,38 @@
133
133
  return cookieExpire === undefined ? '' : '; max-age=' + cookieExpire;
134
134
  };
135
135
 
136
+ var initCookieFilters = function (bootstrapTable) {
137
+ setTimeout(function () {
138
+ var parsedCookieFilters = JSON.parse(getCookie(bootstrapTable, bootstrapTable.options.cookieIdTable, cookieIds.filterControl));
139
+
140
+ if (!bootstrapTable.options.filterControlValuesLoaded && parsedCookieFilters) {
141
+ bootstrapTable.options.filterControlValuesLoaded = true;
142
+
143
+ var cachedFilters = {},
144
+ header = getCurrentHeader(bootstrapTable),
145
+ searchControls = getCurrentSearchControls(bootstrapTable),
146
+
147
+ applyCookieFilters = function (element, filteredCookies) {
148
+ $(filteredCookies).each(function (i, cookie) {
149
+ $(element).val(cookie.text);
150
+ cachedFilters[cookie.field] = cookie.text;
151
+ });
152
+ };
153
+
154
+ header.find(searchControls).each(function () {
155
+ var field = $(this).closest('[data-field]').data('field'),
156
+ filteredCookies = $.grep(parsedCookieFilters, function (cookie) {
157
+ return cookie.field === field;
158
+ });
159
+
160
+ applyCookieFilters(this, filteredCookies);
161
+ });
162
+
163
+ bootstrapTable.initColumnSearch(cachedFilters);
164
+ }
165
+ }, 250);
166
+ }
167
+
136
168
  $.extend($.fn.bootstrapTable.defaults, {
137
169
  cookie: false,
138
170
  cookieExpire: '2h',
@@ -151,6 +183,7 @@
151
183
  var BootstrapTable = $.fn.bootstrapTable.Constructor,
152
184
  _init = BootstrapTable.prototype.init,
153
185
  _initTable = BootstrapTable.prototype.initTable,
186
+ _initServer = BootstrapTable.prototype.initServer,
154
187
  _onSort = BootstrapTable.prototype.onSort,
155
188
  _onPageNumber = BootstrapTable.prototype.onPageNumber,
156
189
  _onPageListChange = BootstrapTable.prototype.onPageListChange,
@@ -191,36 +224,50 @@
191
224
  }
192
225
 
193
226
  setCookie(that, cookieIds.filterControl, JSON.stringify(that.options.filterControls));
194
- }).on('post-body.bs.table', function () {
195
- setTimeout(function () {
196
- if (!that.options.filterControlValuesLoaded) {
197
- that.options.filterControlValuesLoaded = true;
198
- var filterControl = JSON.parse(getCookie(that, that.options.cookieIdTable, cookieIds.filterControl));
199
- if (filterControl) {
200
- var field = null,
201
- result = [],
202
- header = getCurrentHeader(that),
203
- searchControls = getCurrentSearchControls(that);
204
-
205
- header.find(searchControls).each(function (index, ele) {
206
- field = $(this).closest('[data-field]').data('field');
207
- result = $.grep(filterControl, function (valueObj) {
208
- return valueObj.field === field;
209
- });
210
-
211
- if (result.length > 0) {
212
- $(this).val(result[0].text);
213
- that.onColumnSearch({currentTarget: $(this)});
214
- }
215
- });
216
- }
217
- }
218
- }, 250);
219
- });
227
+ }).on('post-body.bs.table', initCookieFilters(that));
220
228
  }
221
229
  _init.apply(this, Array.prototype.slice.apply(arguments));
230
+
231
+ $.extend($.fn.bootstrapTable.utils, {
232
+ setCookie: setCookie,
233
+ getCookie: getCookie
234
+ });
222
235
  };
223
236
 
237
+ BootstrapTable.prototype.initServer = function () {
238
+ var bootstrapTable = this,
239
+ selectsWithoutDefaults = [],
240
+
241
+ columnHasSelectControl = function (column) {
242
+ return column.filterControl && column.filterControl === 'select';
243
+ },
244
+
245
+ columnHasDefaultSelectValues = function (column) {
246
+ return column.filterData && column.filterData !== 'column';
247
+ },
248
+
249
+ cookiesPresent = function() {
250
+ return bootstrapTable.options.cookie && bootstrapTable.getCookies(bootstrapTable);
251
+ };
252
+
253
+ selectsWithoutDefaults = $.grep(bootstrapTable.columns, function(column) {
254
+ return columnHasSelectControl(column) && !columnHasDefaultSelectValues(column);
255
+ });
256
+
257
+ // reset variable to original initServer function, so that future calls to initServer
258
+ // use the original function from this point on.
259
+ BootstrapTable.prototype.initServer = _initServer;
260
+
261
+ // early return if we don't need to populate any select values with cookie values
262
+ if (cookiesPresent() && selectsWithoutDefaults.length === 0) {
263
+ return;
264
+ }
265
+
266
+ // call BootstrapTable.prototype.initServer
267
+ _initServer.apply(this, Array.prototype.slice.apply(arguments));
268
+ }
269
+
270
+
224
271
  BootstrapTable.prototype.initTable = function () {
225
272
  _initTable.apply(this, Array.prototype.slice.apply(arguments));
226
273
  this.initCookie();
@@ -310,7 +357,7 @@
310
357
 
311
358
  setCookie(this, cookieIds.columns, JSON.stringify(visibleColumns));
312
359
  };
313
-
360
+
314
361
  BootstrapTable.prototype.selectPage = function (page) {
315
362
  _selectPage.apply(this, Array.prototype.slice.apply(arguments));
316
363
  setCookie(this, cookieIds.pageNumber, page);
@@ -325,6 +372,16 @@
325
372
  }
326
373
  };
327
374
 
375
+ BootstrapTable.prototype.getCookies = function(bootstrapTable) {
376
+ var cookies = [];
377
+ $.each( cookieIds, function( key, value ) {
378
+ var cookie = JSON.parse(getCookie(bootstrapTable, bootstrapTable.options.cookieIdTable, cookieIds.filterControl));
379
+ cookies.concat(cookie);
380
+ });
381
+
382
+ return cookies;
383
+ };
384
+
328
385
  BootstrapTable.prototype.deleteCookie = function (cookieName) {
329
386
  if ((cookieName === '') || (!cookieEnabled())) {
330
387
  return;
@@ -0,0 +1,102 @@
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);
@@ -3,22 +3,22 @@
3
3
  * extensions: https://github.com/vitalets/x-editable
4
4
  */
5
5
 
6
- !function ($) {
6
+ (function($) {
7
7
 
8
8
  'use strict';
9
9
 
10
10
  $.extend($.fn.bootstrapTable.defaults, {
11
11
  editable: true,
12
- onEditableInit: function () {
12
+ onEditableInit: function() {
13
13
  return false;
14
14
  },
15
- onEditableSave: function (field, row, oldValue, $el) {
15
+ onEditableSave: function(field, row, oldValue, $el) {
16
16
  return false;
17
17
  },
18
- onEditableShown: function (field, row, $el, editable) {
18
+ onEditableShown: function(field, row, $el, editable) {
19
19
  return false;
20
20
  },
21
- onEditableHidden: function (field, row, $el, reason) {
21
+ onEditableHidden: function(field, row, $el, reason) {
22
22
  return false;
23
23
  }
24
24
  });
@@ -34,7 +34,7 @@
34
34
  _initTable = BootstrapTable.prototype.initTable,
35
35
  _initBody = BootstrapTable.prototype.initBody;
36
36
 
37
- BootstrapTable.prototype.initTable = function () {
37
+ BootstrapTable.prototype.initTable = function() {
38
38
  var that = this;
39
39
  _initTable.apply(this, Array.prototype.slice.apply(arguments));
40
40
 
@@ -42,46 +42,63 @@
42
42
  return;
43
43
  }
44
44
 
45
- $.each(this.columns, function (i, column) {
45
+ $.each(this.columns, function(i, column) {
46
46
  if (!column.editable) {
47
47
  return;
48
48
  }
49
49
 
50
- var editableOptions = {}, editableDataMarkup = [], editableDataPrefix = 'editable-';
50
+ var editableOptions = {},
51
+ editableDataMarkup = [],
52
+ editableDataPrefix = 'editable-';
51
53
 
52
54
  var processDataOptions = function(key, value) {
53
- // Replace camel case with dashes.
54
- var dashKey = key.replace(/([A-Z])/g, function($1){return "-"+$1.toLowerCase();});
55
- if (dashKey.slice(0, editableDataPrefix.length) == editableDataPrefix) {
56
- var dataKey = dashKey.replace(editableDataPrefix, 'data-');
57
- editableOptions[dataKey] = value;
58
- }
55
+ // Replace camel case with dashes.
56
+ var dashKey = key.replace(/([A-Z])/g, function($1) {
57
+ return "-" + $1.toLowerCase();
58
+ });
59
+ if (dashKey.slice(0, editableDataPrefix.length) == editableDataPrefix) {
60
+ var dataKey = dashKey.replace(editableDataPrefix, 'data-');
61
+ editableOptions[dataKey] = value;
62
+ }
59
63
  };
60
64
 
61
65
  $.each(that.options, processDataOptions);
62
66
 
63
- var _formatter = column.formatter;
64
- column.formatter = function (value, row, index) {
65
- var result = _formatter ? _formatter(value, row, index) : value;
67
+ column.formatter = column.formatter || function(value, row, index) {
68
+ return value;
69
+ };
70
+ column._formatter = column._formatter ? column._formatter : column.formatter;
71
+ column.formatter = function(value, row, index) {
72
+ var result = column._formatter ? column._formatter(value, row, index) : value;
66
73
 
67
74
  $.each(column, processDataOptions);
68
75
 
69
- $.each(editableOptions, function (key, value) {
76
+ $.each(editableOptions, function(key, value) {
70
77
  editableDataMarkup.push(' ' + key + '="' + value + '"');
71
78
  });
72
79
 
73
- return ['<a href="javascript:void(0)"',
74
- ' data-name="' + column.field + '"',
75
- ' data-pk="' + row[that.options.idField] + '"',
76
- ' data-value="' + result + '"',
77
- editableDataMarkup.join(''),
78
- '>' + '</a>'
79
- ].join('');
80
+ var _dont_edit_formatter = false;
81
+ if (column.editable.hasOwnProperty('noeditFormatter')) {
82
+ _dont_edit_formatter = column.editable.noeditFormatter(value, row, index);
83
+ }
84
+
85
+ if (_dont_edit_formatter === false) {
86
+ return ['<a href="javascript:void(0)"',
87
+ ' data-name="' + column.field + '"',
88
+ ' data-pk="' + row[that.options.idField] + '"',
89
+ ' data-value="' + result + '"',
90
+ editableDataMarkup.join(''),
91
+ '>' + '</a>'
92
+ ].join('');
93
+ } else {
94
+ return _dont_edit_formatter;
95
+ }
96
+
80
97
  };
81
98
  });
82
99
  };
83
100
 
84
- BootstrapTable.prototype.initBody = function () {
101
+ BootstrapTable.prototype.initBody = function() {
85
102
  var that = this;
86
103
  _initBody.apply(this, Array.prototype.slice.apply(arguments));
87
104
 
@@ -89,13 +106,13 @@
89
106
  return;
90
107
  }
91
108
 
92
- $.each(this.columns, function (i, column) {
109
+ $.each(this.columns, function(i, column) {
93
110
  if (!column.editable) {
94
111
  return;
95
112
  }
96
113
 
97
114
  that.$body.find('a[data-name="' + column.field + '"]').editable(column.editable)
98
- .off('save').on('save', function (e, params) {
115
+ .off('save').on('save', function(e, params) {
99
116
  var data = that.getData(),
100
117
  index = $(this).parents('tr[data-index]').data('index'),
101
118
  row = data[index],
@@ -104,25 +121,26 @@
104
121
  $(this).data('value', params.submitValue);
105
122
  row[column.field] = params.submitValue;
106
123
  that.trigger('editable-save', column.field, row, oldValue, $(this));
124
+ that.resetFooter();
107
125
  });
108
126
  that.$body.find('a[data-name="' + column.field + '"]').editable(column.editable)
109
- .off('shown').on('shown', function (e, editable) {
127
+ .off('shown').on('shown', function(e, editable) {
110
128
  var data = that.getData(),
111
129
  index = $(this).parents('tr[data-index]').data('index'),
112
130
  row = data[index];
113
-
131
+
114
132
  that.trigger('editable-shown', column.field, row, $(this), editable);
115
133
  });
116
134
  that.$body.find('a[data-name="' + column.field + '"]').editable(column.editable)
117
- .off('hidden').on('hidden', function (e, reason) {
135
+ .off('hidden').on('hidden', function(e, reason) {
118
136
  var data = that.getData(),
119
137
  index = $(this).parents('tr[data-index]').data('index'),
120
138
  row = data[index];
121
-
139
+
122
140
  that.trigger('editable-hidden', column.field, row, $(this), reason);
123
141
  });
124
142
  });
125
143
  this.trigger('editable-init');
126
144
  };
127
145
 
128
- }(jQuery);
146
+ })(jQuery);
@@ -32,6 +32,13 @@
32
32
  export: 'glyphicon-export icon-share'
33
33
  });
34
34
 
35
+ $.extend($.fn.bootstrapTable.locales, {
36
+ formatExport: function () {
37
+ return 'Export data';
38
+ }
39
+ });
40
+ $.extend($.fn.bootstrapTable.defaults, $.fn.bootstrapTable.locales);
41
+
35
42
  var BootstrapTable = $.fn.bootstrapTable.Constructor,
36
43
  _initToolbar = BootstrapTable.prototype.initToolbar;
37
44
 
@@ -48,9 +55,11 @@
48
55
  if (!$export.length) {
49
56
  $export = $([
50
57
  '<div class="export btn-group">',
51
- '<button class="btn btn-default' +
58
+ '<button class="btn' +
59
+ sprintf(' btn-%s', this.options.buttonsClass) +
52
60
  sprintf(' btn-%s', this.options.iconSize) +
53
61
  ' dropdown-toggle" ' +
62
+ 'title="' + this.options.formatExport() + '" ' +
54
63
  'data-toggle="dropdown" type="button">',
55
64
  sprintf('<i class="%s %s"></i> ', this.options.iconsPrefix, this.options.icons.export),
56
65
  '<span class="caret"></span>',
@@ -90,7 +99,7 @@
90
99
  };
91
100
 
92
101
  if (that.options.exportDataType === 'all' && that.options.pagination) {
93
- that.$el.one('load-success.bs.table page-change.bs.table', function () {
102
+ that.$el.one(that.options.sidePagination === 'server' ? 'post-body.bs.table' : 'page-change.bs.table', function () {
94
103
  doExport();
95
104
  that.togglePagination();
96
105
  });