/pack-rat/003_pack_rat/pack-rat/node_modules/bootstrap-table/docs/dist/extensions/group-by-v2/bootstrap-table-group-by.js |
@@ -0,0 +1,226 @@ |
/** |
* @author: Yura Knoxville |
* @version: v1.0.0 |
*/ |
|
!function ($) { |
|
'use strict'; |
|
var initBodyCaller, |
tableGroups; |
|
// it only does '%s', and return '' when arguments are undefined |
var sprintf = function (str) { |
var args = arguments, |
flag = true, |
i = 1; |
|
str = str.replace(/%s/g, function () { |
var arg = args[i++]; |
|
if (typeof arg === 'undefined') { |
flag = false; |
return ''; |
} |
return arg; |
}); |
return flag ? str : ''; |
}; |
|
var groupBy = function (array , f) { |
var groups = {}; |
array.forEach(function(o) { |
var group = f(o); |
groups[group] = groups[group] || []; |
groups[group].push(o); |
}); |
|
return groups; |
}; |
|
$.extend($.fn.bootstrapTable.defaults, { |
groupBy: false, |
groupByField: '' |
}); |
|
var BootstrapTable = $.fn.bootstrapTable.Constructor, |
_initSort = BootstrapTable.prototype.initSort, |
_initBody = BootstrapTable.prototype.initBody, |
_updateSelected = BootstrapTable.prototype.updateSelected; |
|
BootstrapTable.prototype.initSort = function () { |
_initSort.apply(this, Array.prototype.slice.apply(arguments)); |
|
var that = this; |
tableGroups = []; |
|
if ((this.options.groupBy) && (this.options.groupByField !== '')) { |
|
if ((this.options.sortName != this.options.groupByField)) { |
this.data.sort(function(a, b) { |
return a[that.options.groupByField].localeCompare(b[that.options.groupByField]); |
}); |
} |
|
var that = this; |
var groups = groupBy(that.data, function (item) { |
return [item[that.options.groupByField]]; |
}); |
|
var index = 0; |
$.each(groups, function(key, value) { |
tableGroups.push({ |
id: index, |
name: key |
}); |
|
value.forEach(function(item) { |
if (!item._data) { |
item._data = {}; |
} |
|
item._data['parent-index'] = index; |
}); |
|
index++; |
}); |
} |
} |
|
BootstrapTable.prototype.initBody = function () { |
initBodyCaller = true; |
|
_initBody.apply(this, Array.prototype.slice.apply(arguments)); |
|
if ((this.options.groupBy) && (this.options.groupByField !== '')) { |
var that = this, |
checkBox = false, |
visibleColumns = 0; |
|
this.columns.forEach(function(column) { |
if (column.checkbox) { |
checkBox = true; |
} else { |
if (column.visible) { |
visibleColumns += 1; |
} |
} |
}); |
|
if (this.options.detailView && !this.options.cardView) { |
visibleColumns += 1; |
} |
|
tableGroups.forEach(function(item){ |
var html = []; |
|
html.push(sprintf('<tr class="info groupBy expanded" data-group-index="%s">', item.id)); |
|
if (that.options.detailView && !that.options.cardView) { |
html.push('<td class="detail"></td>'); |
} |
|
if (checkBox) { |
html.push('<td class="bs-checkbox">', |
'<input name="btSelectGroup" type="checkbox" />', |
'</td>' |
); |
} |
|
html.push('<td', |
sprintf(' colspan="%s"', visibleColumns), |
'>', item.name, '</td>' |
); |
|
html.push('</tr>'); |
|
that.$body.find('tr[data-parent-index='+item.id+']:first').before($(html.join(''))); |
}); |
|
this.$selectGroup = []; |
this.$body.find('[name="btSelectGroup"]').each(function() { |
var self = $(this); |
|
that.$selectGroup.push({ |
group: self, |
item: that.$selectItem.filter(function () { |
return ($(this).closest('tr').data('parent-index') === |
self.closest('tr').data('group-index')); |
}) |
}); |
}); |
|
this.$container.off('click', '.groupBy') |
.on('click', '.groupBy', function() { |
$(this).toggleClass('expanded'); |
that.$body.find('tr[data-parent-index='+$(this).closest('tr').data('group-index')+']').toggleClass('hidden'); |
}); |
|
this.$container.off('click', '[name="btSelectGroup"]') |
.on('click', '[name="btSelectGroup"]', function (event) { |
event.stopImmediatePropagation(); |
|
var self = $(this); |
var checked = self.prop('checked'); |
that[checked ? 'checkGroup' : 'uncheckGroup']($(this).closest('tr').data('group-index')); |
}); |
} |
|
initBodyCaller = false; |
this.updateSelected(); |
}; |
|
BootstrapTable.prototype.updateSelected = function () { |
if (!initBodyCaller) { |
_updateSelected.apply(this, Array.prototype.slice.apply(arguments)); |
|
if ((this.options.groupBy) && (this.options.groupByField !== '')) { |
this.$selectGroup.forEach(function (item) { |
var checkGroup = item.item.filter(':enabled').length === |
item.item.filter(':enabled').filter(':checked').length; |
|
item.group.prop('checked', checkGroup); |
}); |
} |
} |
}; |
|
BootstrapTable.prototype.getGroupSelections = function (index) { |
var that = this; |
|
return $.grep(this.data, function (row) { |
return (row[that.header.stateField] && (row._data['parent-index'] === index)); |
}); |
}; |
|
BootstrapTable.prototype.checkGroup = function (index) { |
this.checkGroup_(index, true); |
}; |
|
BootstrapTable.prototype.uncheckGroup = function (index) { |
this.checkGroup_(index, false); |
}; |
|
BootstrapTable.prototype.checkGroup_ = function (index, checked) { |
var rows; |
var filter = function() { |
return ($(this).closest('tr').data('parent-index') === index); |
}; |
|
if (!checked) { |
rows = this.getGroupSelections(index); |
} |
|
this.$selectItem.filter(filter).prop('checked', checked); |
|
|
this.updateRows(); |
this.updateSelected(); |
if (checked) { |
rows = this.getGroupSelections(index); |
} |
this.trigger(checked ? 'check-all' : 'uncheck-all', rows); |
}; |
|
}(jQuery); |
/pack-rat/003_pack_rat/pack-rat/node_modules/bootstrap-table/docs/dist/extensions/group-by-v2/bootstrap-table-group-by.min.js |
@@ -0,0 +1,7 @@ |
/* |
* bootstrap-table - v1.11.1 - 2017-02-22 |
* https://github.com/wenzhixin/bootstrap-table |
* Copyright (c) 2017 zhixin wen |
* Licensed MIT License |
*/ |
!function(a){"use strict";var b,c,d=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:""},e=function(a,b){var c={};return a.forEach(function(a){var d=b(a);c[d]=c[d]||[],c[d].push(a)}),c};a.extend(a.fn.bootstrapTable.defaults,{groupBy:!1,groupByField:""});var f=a.fn.bootstrapTable.Constructor,g=f.prototype.initSort,h=f.prototype.initBody,i=f.prototype.updateSelected;f.prototype.initSort=function(){g.apply(this,Array.prototype.slice.apply(arguments));var b=this;if(c=[],this.options.groupBy&&""!==this.options.groupByField){this.options.sortName!=this.options.groupByField&&this.data.sort(function(a,c){return a[b.options.groupByField].localeCompare(c[b.options.groupByField])});var b=this,d=e(b.data,function(a){return[a[b.options.groupByField]]}),f=0;a.each(d,function(a,b){c.push({id:f,name:a}),b.forEach(function(a){a._data||(a._data={}),a._data["parent-index"]=f}),f++})}},f.prototype.initBody=function(){if(b=!0,h.apply(this,Array.prototype.slice.apply(arguments)),this.options.groupBy&&""!==this.options.groupByField){var e=this,f=!1,g=0;this.columns.forEach(function(a){a.checkbox?f=!0:a.visible&&(g+=1)}),this.options.detailView&&!this.options.cardView&&(g+=1),c.forEach(function(b){var c=[];c.push(d('<tr class="info groupBy expanded" data-group-index="%s">',b.id)),e.options.detailView&&!e.options.cardView&&c.push('<td class="detail"></td>'),f&&c.push('<td class="bs-checkbox">','<input name="btSelectGroup" type="checkbox" />',"</td>"),c.push("<td",d(' colspan="%s"',g),">",b.name,"</td>"),c.push("</tr>"),e.$body.find("tr[data-parent-index="+b.id+"]:first").before(a(c.join("")))}),this.$selectGroup=[],this.$body.find('[name="btSelectGroup"]').each(function(){var b=a(this);e.$selectGroup.push({group:b,item:e.$selectItem.filter(function(){return a(this).closest("tr").data("parent-index")===b.closest("tr").data("group-index")})})}),this.$container.off("click",".groupBy").on("click",".groupBy",function(){a(this).toggleClass("expanded"),e.$body.find("tr[data-parent-index="+a(this).closest("tr").data("group-index")+"]").toggleClass("hidden")}),this.$container.off("click",'[name="btSelectGroup"]').on("click",'[name="btSelectGroup"]',function(b){b.stopImmediatePropagation();var c=a(this),d=c.prop("checked");e[d?"checkGroup":"uncheckGroup"](a(this).closest("tr").data("group-index"))})}b=!1,this.updateSelected()},f.prototype.updateSelected=function(){b||(i.apply(this,Array.prototype.slice.apply(arguments)),this.options.groupBy&&""!==this.options.groupByField&&this.$selectGroup.forEach(function(a){var b=a.item.filter(":enabled").length===a.item.filter(":enabled").filter(":checked").length;a.group.prop("checked",b)}))},f.prototype.getGroupSelections=function(b){var c=this;return a.grep(this.data,function(a){return a[c.header.stateField]&&a._data["parent-index"]===b})},f.prototype.checkGroup=function(a){this.checkGroup_(a,!0)},f.prototype.uncheckGroup=function(a){this.checkGroup_(a,!1)},f.prototype.checkGroup_=function(b,c){var d,e=function(){return a(this).closest("tr").data("parent-index")===b};c||(d=this.getGroupSelections(b)),this.$selectItem.filter(e).prop("checked",c),this.updateRows(),this.updateSelected(),c&&(d=this.getGroupSelections(b)),this.trigger(c?"check-all":"uncheck-all",d)}}(jQuery); |