Add bootstrap extensions and export libs

This commit is contained in:
madd15
2015-07-28 13:59:34 +09:30
parent 5eedd7810f
commit b85e9bb97f
37 changed files with 2733 additions and 0 deletions
@@ -0,0 +1,234 @@
/**
* @author: Dennis Hernández
* @webSite: http://djhvscf.github.io/Blog
* @version: v1.1.0
*
* @update zhixin wen <wenzhixin2010@gmail.com>
*/
(function ($) {
'use strict';
var idsStateSaveList = {
sortOrder: 'bs.table.sortOrder',
sortName: 'bs.table.sortName',
pageNumber: 'bs.table.pageNumber',
pageList: 'bs.table.pageList',
columns: 'bs.table.columns',
searchText: 'bs.table.searchText'
};
var cookieEnabled = function () {
return (navigator.cookieEnabled) ? true : false;
};
var setCookie = function (that, cookieName, sValue, sPath, sDomain, bSecure) {
if ((!that.options.stateSave) || (!cookieEnabled()) || (that.options.stateSaveIdTable === '')) {
return;
}
var tableName = that.options.stateSaveIdTable,
vEnd = that.options.stateSaveExpire;
cookieName = tableName + '.' + cookieName;
if (!cookieName || /^(?:expires|max\-age|path|domain|secure)$/i.test(cookieName)) {
return false;
}
document.cookie = encodeURIComponent(cookieName) + '=' + encodeURIComponent(sValue) + calculateExpiration(vEnd) + (sDomain ? '; domain=' + sDomain : '') + (sPath ? '; path=' + sPath : '') + (bSecure ? '; secure' : '');
return true;
};
var getCookie = function (tableName, cookieName) {
cookieName = tableName + '.' + cookieName;
if (!cookieName) {
return null;
}
return decodeURIComponent(document.cookie.replace(new RegExp('(?:(?:^|.*;)\\s*' + encodeURIComponent(cookieName).replace(/[\-\.\+\*]/g, '\\$&') + '\\s*\\=\\s*([^;]*).*$)|^.*$'), '$1')) || null;
};
var hasCookie = function (cookieName) {
if (!cookieName) {
return false;
}
return (new RegExp('(?:^|;\\s*)' + encodeURIComponent(cookieName).replace(/[\-\.\+\*]/g, '\\$&') + '\\s*\\=')).test(document.cookie);
};
var deleteCookie = function (tableName, cookieName, sPath, sDomain) {
cookieName = tableName + '.' + cookieName;
if (!hasCookie(cookieName)) {
return false;
}
document.cookie = encodeURIComponent(cookieName) + '=; expires=Thu, 01 Jan 1970 00:00:00 GMT' + (sDomain ? '; domain=' + sDomain : '') + (sPath ? '; path=' + sPath : '');
return true;
};
var calculateExpiration = function(vEnd) {
var time = vEnd.replace(/[0-9]/, ''); //s,mi,h,d,m,y
vEnd = vEnd.replace(/[A-Za-z]/, ''); //number
switch (time.toLowerCase()) {
case 's':
vEnd = +vEnd;
break;
case 'mi':
vEnd = vEnd * 60;
break;
case 'h':
vEnd = vEnd * 60 * 60;
break;
case 'd':
vEnd = vEnd * 24 * 60 * 60;
break;
case 'm':
vEnd = vEnd * 30 * 24 * 60 * 60;
break;
case 'y':
vEnd = vEnd * 365 * 30 * 24 * 60 * 60;
break;
default:
vEnd = undefined;
break;
}
return vEnd === undefined ? '' : '; max-age=' + vEnd;
}
$.extend($.fn.bootstrapTable.defaults, {
stateSave: false,
stateSaveExpire: '2h',
stateSaveIdTable: ''
});
$.fn.bootstrapTable.methods.push('deleteCookie');
var BootstrapTable = $.fn.bootstrapTable.Constructor,
_initTable = BootstrapTable.prototype.initTable,
_onSort = BootstrapTable.prototype.onSort,
_onPageNumber = BootstrapTable.prototype.onPageNumber,
_onPageListChange = BootstrapTable.prototype.onPageListChange,
_onPageFirst = BootstrapTable.prototype.onPageFirst,
_onPagePre = BootstrapTable.prototype.onPagePre,
_onPageNext = BootstrapTable.prototype.onPageNext,
_onPageLast = BootstrapTable.prototype.onPageLast,
_toggleColumn = BootstrapTable.prototype.toggleColumn,
_onSearch = BootstrapTable.prototype.onSearch;
// init save data after initTable function
BootstrapTable.prototype.initTable = function () {
_initTable.apply(this, Array.prototype.slice.apply(arguments));
this.initStateSave();
};
BootstrapTable.prototype.initStateSave = function () {
if (!this.options.stateSave) {
return;
}
if (!cookieEnabled()) {
return;
}
if (this.options.stateSaveIdTable === '') {
return;
}
var sortOrderStateSave = getCookie(this.options.stateSaveIdTable, idsStateSaveList.sortOrder),
sortOrderStateName = getCookie(this.options.stateSaveIdTable, idsStateSaveList.sortName),
pageNumberStateSave = getCookie(this.options.stateSaveIdTable, idsStateSaveList.pageNumber),
pageListStateSave = getCookie(this.options.stateSaveIdTable, idsStateSaveList.pageList),
columnsStateSave = JSON.parse(getCookie(this.options.stateSaveIdTable, idsStateSaveList.columns)),
searchStateSave = getCookie(this.options.stateSaveIdTable, idsStateSaveList.searchText);
if (sortOrderStateSave) {
this.options.sortOrder = sortOrderStateSave;
this.options.sortName = sortOrderStateName;
}
if (pageNumberStateSave) {
this.options.pageNumber = +pageNumberStateSave;
}
if (pageListStateSave) {
this.options.pageSize = pageListStateSave ===
this.options.formatAllRows() ? pageListStateSave : +pageListStateSave;
}
if (columnsStateSave) {
$.each(this.options.columns, function (i, column) {
column.visible = columnsStateSave.indexOf(i) !== -1;
});
}
if (searchStateSave) {
this.options.searchText = searchStateSave;
}
};
BootstrapTable.prototype.onSort = function () {
_onSort.apply(this, Array.prototype.slice.apply(arguments));
setCookie(this, idsStateSaveList.sortOrder, this.options.sortOrder);
setCookie(this, idsStateSaveList.sortName, this.options.sortName);
};
BootstrapTable.prototype.onPageNumber = function () {
_onPageNumber.apply(this, Array.prototype.slice.apply(arguments));
setCookie(this, idsStateSaveList.pageNumber, this.options.pageNumber);
};
BootstrapTable.prototype.onPageListChange = function () {
_onPageListChange.apply(this, Array.prototype.slice.apply(arguments));
setCookie(this, idsStateSaveList.pageList, this.options.pageSize);
};
BootstrapTable.prototype.onPageFirst = function () {
_onPageFirst.apply(this, Array.prototype.slice.apply(arguments));
setCookie(this, idsStateSaveList.pageNumber, this.options.pageNumber);
};
BootstrapTable.prototype.onPagePre = function () {
_onPagePre.apply(this, Array.prototype.slice.apply(arguments));
setCookie(this, idsStateSaveList.pageNumber, this.options.pageNumber);
};
BootstrapTable.prototype.onPageNext = function () {
_onPageNext.apply(this, Array.prototype.slice.apply(arguments));
setCookie(this, idsStateSaveList.pageNumber, this.options.pageNumber);
};
BootstrapTable.prototype.onPageLast = function () {
_onPageLast.apply(this, Array.prototype.slice.apply(arguments));
setCookie(this, idsStateSaveList.pageNumber, this.options.pageNumber);
};
BootstrapTable.prototype.toggleColumn = function () {
_toggleColumn.apply(this, Array.prototype.slice.apply(arguments));
var visibleColumns = [];
$.each(this.options.columns, function (i) {
if (this.visible) {
visibleColumns.push(i);
}
});
setCookie(this, idsStateSaveList.columns, JSON.stringify(visibleColumns));
};
BootstrapTable.prototype.onSearch = function () {
_onSearch.apply(this, Array.prototype.slice.apply(arguments));
setCookie(this, idsStateSaveList.searchText, this.searchText);
};
BootstrapTable.prototype.deleteCookie = function (cookieName) {
if ((cookieName === '') || (!cookieEnabled())) {
return;
}
deleteCookie(idsStateSaveList[cookieName]);
};
})(jQuery);
@@ -0,0 +1,7 @@
/*
* bootstrap-table - v1.8.1 - 2015-05-29
* https://github.com/wenzhixin/bootstrap-table
* Copyright (c) 2015 zhixin wen
* Licensed MIT License
*/
!function(a){"use strict";var b={sortOrder:"bs.table.sortOrder",sortName:"bs.table.sortName",pageNumber:"bs.table.pageNumber",pageList:"bs.table.pageList",columns:"bs.table.columns",searchText:"bs.table.searchText"},c=function(){return navigator.cookieEnabled?!0:!1},d=function(a,b,d,e,f,g){if(a.options.stateSave&&c()&&""!==a.options.stateSaveIdTable){var i=a.options.stateSaveIdTable,j=a.options.stateSaveExpire;return b=i+"."+b,!b||/^(?:expires|max\-age|path|domain|secure)$/i.test(b)?!1:(document.cookie=encodeURIComponent(b)+"="+encodeURIComponent(d)+h(j)+(f?"; domain="+f:"")+(e?"; path="+e:"")+(g?"; secure":""),!0)}},e=function(a,b){return b=a+"."+b,b?decodeURIComponent(document.cookie.replace(new RegExp("(?:(?:^|.*;)\\s*"+encodeURIComponent(b).replace(/[\-\.\+\*]/g,"\\$&")+"\\s*\\=\\s*([^;]*).*$)|^.*$"),"$1"))||null:null},f=function(a){return a?new RegExp("(?:^|;\\s*)"+encodeURIComponent(a).replace(/[\-\.\+\*]/g,"\\$&")+"\\s*\\=").test(document.cookie):!1},g=function(a,b,c,d){return b=a+"."+b,f(b)?(document.cookie=encodeURIComponent(b)+"=; expires=Thu, 01 Jan 1970 00:00:00 GMT"+(d?"; domain="+d:"")+(c?"; path="+c:""),!0):!1},h=function(a){var b=a.replace(/[0-9]/,"");switch(a=a.replace(/[A-Za-z]/,""),b.toLowerCase()){case"s":a=+a;break;case"mi":a=60*a;break;case"h":a=60*a*60;break;case"d":a=24*a*60*60;break;case"m":a=30*a*24*60*60;break;case"y":a=365*a*30*24*60*60;break;default:a=void 0}return void 0===a?"":"; max-age="+a};a.extend(a.fn.bootstrapTable.defaults,{stateSave:!1,stateSaveExpire:"2h",stateSaveIdTable:""}),a.fn.bootstrapTable.methods.push("deleteCookie");var i=a.fn.bootstrapTable.Constructor,j=i.prototype.initTable,k=i.prototype.onSort,l=i.prototype.onPageNumber,m=i.prototype.onPageListChange,n=i.prototype.onPageFirst,o=i.prototype.onPagePre,p=i.prototype.onPageNext,q=i.prototype.onPageLast,r=i.prototype.toggleColumn,s=i.prototype.onSearch;i.prototype.initTable=function(){j.apply(this,Array.prototype.slice.apply(arguments)),this.initStateSave()},i.prototype.initStateSave=function(){if(this.options.stateSave&&c()&&""!==this.options.stateSaveIdTable){var d=e(this.options.stateSaveIdTable,b.sortOrder),f=e(this.options.stateSaveIdTable,b.sortName),g=e(this.options.stateSaveIdTable,b.pageNumber),h=e(this.options.stateSaveIdTable,b.pageList),i=JSON.parse(e(this.options.stateSaveIdTable,b.columns)),j=e(this.options.stateSaveIdTable,b.searchText);d&&(this.options.sortOrder=d,this.options.sortName=f),g&&(this.options.pageNumber=+g),h&&(this.options.pageSize=h===this.options.formatAllRows()?h:+h),i&&a.each(this.options.columns,function(a,b){b.visible=-1!==i.indexOf(a)}),j&&(this.options.searchText=j)}},i.prototype.onSort=function(){k.apply(this,Array.prototype.slice.apply(arguments)),d(this,b.sortOrder,this.options.sortOrder),d(this,b.sortName,this.options.sortName)},i.prototype.onPageNumber=function(){l.apply(this,Array.prototype.slice.apply(arguments)),d(this,b.pageNumber,this.options.pageNumber)},i.prototype.onPageListChange=function(){m.apply(this,Array.prototype.slice.apply(arguments)),d(this,b.pageList,this.options.pageSize)},i.prototype.onPageFirst=function(){n.apply(this,Array.prototype.slice.apply(arguments)),d(this,b.pageNumber,this.options.pageNumber)},i.prototype.onPagePre=function(){o.apply(this,Array.prototype.slice.apply(arguments)),d(this,b.pageNumber,this.options.pageNumber)},i.prototype.onPageNext=function(){p.apply(this,Array.prototype.slice.apply(arguments)),d(this,b.pageNumber,this.options.pageNumber)},i.prototype.onPageLast=function(){q.apply(this,Array.prototype.slice.apply(arguments)),d(this,b.pageNumber,this.options.pageNumber)},i.prototype.toggleColumn=function(){r.apply(this,Array.prototype.slice.apply(arguments));var c=[];a.each(this.options.columns,function(a){this.visible&&c.push(a)}),d(this,b.columns,JSON.stringify(c))},i.prototype.onSearch=function(){s.apply(this,Array.prototype.slice.apply(arguments)),d(this,b.searchText,this.searchText)},i.prototype.deleteCookie=function(a){""!==a&&c()&&g(b[a])}}(jQuery);
@@ -0,0 +1,83 @@
/**
* @author zhixin wen <wenzhixin2010@gmail.com>
* extensions: https://github.com/vitalets/x-editable
*/
!function ($) {
'use strict';
$.extend($.fn.bootstrapTable.defaults, {
editable: true,
onEditableInit: function () {
return false;
},
onEditableSave: function (field, row, oldValue, $el) {
return false;
}
});
$.extend($.fn.bootstrapTable.Constructor.EVENTS, {
'editable-init.bs.table': 'onEditableInit',
'editable-save.bs.table': 'onEditableSave'
});
var BootstrapTable = $.fn.bootstrapTable.Constructor,
_initTable = BootstrapTable.prototype.initTable,
_initBody = BootstrapTable.prototype.initBody;
BootstrapTable.prototype.initTable = function () {
var that = this;
_initTable.apply(this, Array.prototype.slice.apply(arguments));
if (!this.options.editable) {
return;
}
$.each(this.options.columns, function (i, column) {
if (!column.editable) {
return;
}
var _formatter = column.formatter;
column.formatter = function (value, row, index) {
var result = _formatter ? _formatter(value, row, index) : value;
return ['<a href="javascript:void(0)"',
' data-name="' + column.field + '"',
' data-pk="' + row[that.options.idField] + '"',
' data-value="' + result + '"',
'>' + '</a>'
].join('');
};
});
};
BootstrapTable.prototype.initBody = function () {
var that = this;
_initBody.apply(this, Array.prototype.slice.apply(arguments));
if (!this.options.editable) {
return;
}
$.each(this.options.columns, function (i, column) {
if (!column.editable) {
return;
}
that.$body.find('a[data-name="' + column.field + '"]').editable(column.editable)
.off('save').on('save', function (e, params) {
var data = that.getData(),
index = $(this).parents('tr[data-index]').data('index'),
row = data[index],
oldValue = row[column.field];
row[column.field] = params.submitValue;
that.trigger('editable-save', column.field, row, oldValue, $(this));
});
});
this.trigger('editable-init');
};
}(jQuery);
@@ -0,0 +1,7 @@
/*
* bootstrap-table - v1.8.1 - 2015-05-29
* https://github.com/wenzhixin/bootstrap-table
* Copyright (c) 2015 zhixin wen
* Licensed MIT License
*/
!function(a){"use strict";a.extend(a.fn.bootstrapTable.defaults,{editable:!0,onEditableInit:function(){return!1},onEditableSave:function(){return!1}}),a.extend(a.fn.bootstrapTable.Constructor.EVENTS,{"editable-init.bs.table":"onEditableInit","editable-save.bs.table":"onEditableSave"});var b=a.fn.bootstrapTable.Constructor,c=b.prototype.initTable,d=b.prototype.initBody;b.prototype.initTable=function(){var b=this;c.apply(this,Array.prototype.slice.apply(arguments)),this.options.editable&&a.each(this.options.columns,function(a,c){if(c.editable){var d=c.formatter;c.formatter=function(a,e,f){var g=d?d(a,e,f):a;return['<a href="javascript:void(0)"',' data-name="'+c.field+'"',' data-pk="'+e[b.options.idField]+'"',' data-value="'+g+'"',"></a>"].join("")}}})},b.prototype.initBody=function(){var b=this;d.apply(this,Array.prototype.slice.apply(arguments)),this.options.editable&&(a.each(this.options.columns,function(c,d){d.editable&&b.$body.find('a[data-name="'+d.field+'"]').editable(d.editable).off("save").on("save",function(c,e){var f=b.getData(),g=a(this).parents("tr[data-index]").data("index"),h=f[g],i=h[d.field];h[d.field]=e.submitValue,b.trigger("editable-save",d.field,h,i,a(this))})}),this.trigger("editable-init"))}}(jQuery);
@@ -0,0 +1,84 @@
/**
* @author zhixin wen <wenzhixin2010@gmail.com>
* 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,
// '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="glyphicon glyphicon-export icon-share"></i> ',
'<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 data-type="' + type + '">',
'<a href="javascript:void(0)">',
TYPE_NAME[type],
'</a>',
'</li>'].join(''));
}
});
$menu.find('li').click(function () {
that.$el.tableExport($.extend({}, that.options.exportOptions, {
type: $(this).data('type'),
escape: false
}));
});
}
}
};
})(jQuery);
@@ -0,0 +1,7 @@
/*
* bootstrap-table - v1.8.1 - 2015-05-29
* https://github.com/wenzhixin/bootstrap-table
* Copyright (c) 2015 zhixin wen
* Licensed MIT License
*/
!function(a){"use strict";var b={json:"JSON",xml:"XML",png:"PNG",csv:"CSV",txt:"TXT",sql:"SQL",doc:"MS-Word",excel:"Ms-Excel",powerpoint:"Ms-Powerpoint",pdf:"PDF"};a.extend(a.fn.bootstrapTable.defaults,{showExport:!1,exportTypes:["json","xml","csv","txt","sql","excel"],exportOptions:{}});var c=a.fn.bootstrapTable.Constructor,d=c.prototype.initToolbar;c.prototype.initToolbar=function(){if(this.showToolbar=this.options.showExport,d.apply(this,Array.prototype.slice.apply(arguments)),this.options.showExport){var c=this,e=this.$toolbar.find(">.btn-group"),f=e.find("div.export");if(!f.length){f=a(['<div class="export btn-group">','<button class="btn btn-default dropdown-toggle" data-toggle="dropdown" type="button">','<i class="glyphicon glyphicon-export icon-share"></i> ','<span class="caret"></span>',"</button>",'<ul class="dropdown-menu" role="menu">',"</ul>","</div>"].join("")).appendTo(e);var g=f.find(".dropdown-menu"),h=this.options.exportTypes;if("string"==typeof this.options.exportTypes){var i=this.options.exportTypes.slice(1,-1).replace(/ /g,"").split(",");h=[],a.each(i,function(a,b){h.push(b.slice(1,-1))})}a.each(h,function(a,c){b.hasOwnProperty(c)&&g.append(['<li data-type="'+c+'">','<a href="javascript:void(0)">',b[c],"</a>","</li>"].join(""))}),g.find("li").click(function(){c.$el.tableExport(a.extend({},c.options.exportOptions,{type:a(this).data("type"),escape:!1}))})}}}}(jQuery);
@@ -0,0 +1,283 @@
/**
* @author: Dennis Hernández
* @webSite: http://djhvscf.github.io/Blog
* @version: v1.0.0
*/
!function ($) {
'use strict';
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 getFieldIndex = function (columns, field) {
var index = -1;
$.each(columns, function (i, column) {
if (column.field === field) {
index = i;
return false;
}
return true;
});
return index;
};
var calculateObjectValue = function (self, name, args, defaultValue) {
if (typeof name === 'string') {
// support obj.func1.func2
var names = name.split('.');
if (names.length > 1) {
name = window;
$.each(names, function (i, f) {
name = name[f];
});
} else {
name = window[name];
}
}
if (typeof name === 'object') {
return name;
}
if (typeof name === 'function') {
return name.apply(self, args);
}
return defaultValue;
};
$.extend($.fn.bootstrapTable.defaults, {
filterControl: false,
onColumnSearch: function (field, text) {
return false;
}
});
$.extend($.fn.bootstrapTable.COLUMN_DEFAULTS, {
filterControl: undefined,
filterData: undefined
});
$.extend($.fn.bootstrapTable.Constructor.EVENTS, {
'column-search.bs.table': 'onColumnSearch'
});
var BootstrapTable = $.fn.bootstrapTable.Constructor,
_initHeader = BootstrapTable.prototype.initHeader,
_initBody = BootstrapTable.prototype.initBody,
_initSearch = BootstrapTable.prototype.initSearch;
BootstrapTable.prototype.initHeader = function () {
_initHeader.apply(this, Array.prototype.slice.apply(arguments));
if (!this.options.filterControl) {
return;
}
var addedFilterControl = false,
that = this,
isVisible,
html,
timeoutId = 0;
$.each(this.options.columns, function (i, column) {
isVisible = 'hidden';
html = [];
if (!column.visible) {
return;
}
if (!column.filterControl) {
html.push('<div style="height: 34px;"></div>');
} else {
html.push('<div style="margin: 0px 2px 2px 2px;" class="filterControl">');
if (column.filterControl && column.searchable) {
addedFilterControl = true;
isVisible = 'visible'
}
switch (column.filterControl.toLowerCase()) {
case 'input' :
html.push(sprintf('<input type="text" class="form-control" style="width: 100%; visibility: %s">', isVisible));
break;
case 'select':
html.push(sprintf('<select class="%s form-control" style="width: 100%; visibility: %s"></select>',
column.field, isVisible))
break;
}
}
that.$header.find(sprintf('.th-inner:eq("%s")', i)).next().append(html.join(''));
if (column.filterData !== undefined && column.filterData.toLowerCase() !== 'column') {
var filterDataType = column.filterData.substring(0, 3);
var filterDataSource = column.filterData.substring(4, column.filterData.length);
var selectControl = $('.' + column.field);
selectControl.append($("<option></option>")
.attr("value", '')
.text(''));
switch (filterDataType) {
case 'url':
$.ajax({
url: filterDataSource,
dataType: 'json',
success: function (data) {
$.each(data, function (key, value) {
selectControl.append($("<option></option>")
.attr("value", key)
.text(value));
});
}
});
break;
case 'var':
var variableValues = window[filterDataSource];
for (var key in variableValues) {
selectControl.append($("<option></option>")
.attr("value", key)
.text(variableValues[key]));
};
break;
}
}
});
if (addedFilterControl) {
this.$header.off('keyup', 'input').on('keyup', 'input', function (event) {
clearTimeout(timeoutId);
timeoutId = setTimeout(function () {
that.onColumnSearch(event);
}, that.options.searchTimeOut);
});
this.$header.off('change', 'select').on('change', 'select', function (event) {
clearTimeout(timeoutId);
timeoutId = setTimeout(function () {
that.onColumnSearch(event);
}, that.options.searchTimeOut);
});
} else {
this.$header.find('.filterControl').hide();
}
};
BootstrapTable.prototype.initBody = function () {
_initBody.apply(this, Array.prototype.slice.apply(arguments));
var that = this,
data = this.getData();
for (var i = this.pageFrom - 1; i < this.pageTo; i++) {
var key,
item = data[i];
$.each(this.header.fields, function (j, field) {
var value = item[field],
column = that.options.columns[getFieldIndex(that.options.columns, field)];
value = calculateObjectValue(that.header,
that.header.formatters[j], [value, item, i], value);
if ((!column.checkbox) || (!column.radio)) {
if (column.filterControl !== undefined && column.filterControl.toLowerCase() === 'select'
&& column.searchable) {
if (column.filterData === undefined || column.filterData.toLowerCase() === 'column') {
var selectControl = $('.' + column.field),
iOpt = 0,
exitsOpt = false,
options;
if (selectControl !== undefined) {
options = selectControl.get(0).options;
if (options.length === 0) {
//Added the default option
selectControl.append($("<option></option>")
.attr("value", '')
.text(''));
selectControl.append($("<option></option>")
.attr("value", value)
.text(value));
} else {
for (; iOpt < options.length; iOpt++) {
if (options[iOpt].value === value) {
exitsOpt = true;
break;
}
}
if (!exitsOpt) {
selectControl.append($("<option></option>")
.attr("value", value)
.text(value));
}
}
}
}
}
}
});
}
};
BootstrapTable.prototype.initSearch = function () {
_initSearch.apply(this, Array.prototype.slice.apply(arguments));
var that = this;
var fp = $.isEmptyObject(this.filterColumnsPartial) ? null : this.filterColumnsPartial;
//Check partial column filter
this.data = fp ? $.grep(this.data, function (item, i) {
for (var key in fp) {
var fval = fp[key].toLowerCase();
var value = item[key];
value = calculateObjectValue(that.header,
that.header.formatters[$.inArray(key, that.header.fields)],
[value, item, i], value);
if (!($.inArray(key, that.header.fields) !== -1 &&
(typeof value === 'string' || typeof value === 'number') &&
(value + '').toLowerCase().indexOf(fval) !== -1)) {
return false;
}
}
return true;
}) : this.data;
};
BootstrapTable.prototype.onColumnSearch = function (event) {
var text = $.trim($(event.currentTarget).val());
var $field = $(event.currentTarget).parent().parent().parent().data('field')
if ($.isEmptyObject(this.filterColumnsPartial)) {
this.filterColumnsPartial = {};
}
if (text) {
this.filterColumnsPartial[$field] = text;
} else {
delete this.filterColumnsPartial[$field];
}
this.options.pageNumber = 1;
this.onSearch(event);
this.updatePagination();
this.trigger('column-search', $field, text);
};
}(jQuery);
@@ -0,0 +1,7 @@
/*
* bootstrap-table - v1.8.1 - 2015-05-29
* https://github.com/wenzhixin/bootstrap-table
* Copyright (c) 2015 zhixin wen
* Licensed MIT License
*/
!function(a){"use strict";var b=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:""},c=function(b,c){var d=-1;return a.each(b,function(a,b){return b.field===c?(d=a,!1):!0}),d},d=function(b,c,d,e){if("string"==typeof c){var f=c.split(".");f.length>1?(c=window,a.each(f,function(a,b){c=c[b]})):c=window[c]}return"object"==typeof c?c:"function"==typeof c?c.apply(b,d):e};a.extend(a.fn.bootstrapTable.defaults,{filterControl:!1,onColumnSearch:function(){return!1}}),a.extend(a.fn.bootstrapTable.COLUMN_DEFAULTS,{filterControl:void 0,filterData:void 0}),a.extend(a.fn.bootstrapTable.Constructor.EVENTS,{"column-search.bs.table":"onColumnSearch"});var e=a.fn.bootstrapTable.Constructor,f=e.prototype.initHeader,g=e.prototype.initBody,h=e.prototype.initSearch;e.prototype.initHeader=function(){if(f.apply(this,Array.prototype.slice.apply(arguments)),this.options.filterControl){var c,d,e=!1,g=this,h=0;a.each(this.options.columns,function(f,h){if(c="hidden",d=[],h.visible){if(h.filterControl)switch(d.push('<div style="margin: 0px 2px 2px 2px;" class="filterControl">'),h.filterControl&&h.searchable&&(e=!0,c="visible"),h.filterControl.toLowerCase()){case"input":d.push(b('<input type="text" class="form-control" style="width: 100%; visibility: %s">',c));break;case"select":d.push(b('<select class="%s form-control" style="width: 100%; visibility: %s"></select>',h.field,c))}else d.push('<div style="height: 34px;"></div>');if(g.$header.find(b('.th-inner:eq("%s")',f)).next().append(d.join("")),void 0!==h.filterData&&"column"!==h.filterData.toLowerCase()){var i=h.filterData.substring(0,3),j=h.filterData.substring(4,h.filterData.length),k=a("."+h.field);switch(k.append(a("<option></option>").attr("value","").text("")),i){case"url":a.ajax({url:j,dataType:"json",success:function(b){a.each(b,function(b,c){k.append(a("<option></option>").attr("value",b).text(c))})}});break;case"var":var l=window[j];for(var m in l)k.append(a("<option></option>").attr("value",m).text(l[m]))}}}}),e?(this.$header.off("keyup","input").on("keyup","input",function(a){clearTimeout(h),h=setTimeout(function(){g.onColumnSearch(a)},g.options.searchTimeOut)}),this.$header.off("change","select").on("change","select",function(a){clearTimeout(h),h=setTimeout(function(){g.onColumnSearch(a)},g.options.searchTimeOut)})):this.$header.find(".filterControl").hide()}},e.prototype.initBody=function(){g.apply(this,Array.prototype.slice.apply(arguments));for(var b=this,e=this.getData(),f=this.pageFrom-1;f<this.pageTo;f++){var h=e[f];a.each(this.header.fields,function(e,g){var i=h[g],j=b.options.columns[c(b.options.columns,g)];if(i=d(b.header,b.header.formatters[e],[i,h,f],i),!(j.checkbox&&j.radio||void 0===j.filterControl||"select"!==j.filterControl.toLowerCase()||!j.searchable||void 0!==j.filterData&&"column"!==j.filterData.toLowerCase())){var k,l=a("."+j.field),m=0,n=!1;if(void 0!==l)if(k=l.get(0).options,0===k.length)l.append(a("<option></option>").attr("value","").text("")),l.append(a("<option></option>").attr("value",i).text(i));else{for(;m<k.length;m++)if(k[m].value===i){n=!0;break}n||l.append(a("<option></option>").attr("value",i).text(i))}}})}},e.prototype.initSearch=function(){h.apply(this,Array.prototype.slice.apply(arguments));var b=this,c=a.isEmptyObject(this.filterColumnsPartial)?null:this.filterColumnsPartial;this.data=c?a.grep(this.data,function(e,f){for(var g in c){var h=c[g].toLowerCase(),i=e[g];if(i=d(b.header,b.header.formatters[a.inArray(g,b.header.fields)],[i,e,f],i),-1===a.inArray(g,b.header.fields)||"string"!=typeof i&&"number"!=typeof i||-1===(i+"").toLowerCase().indexOf(h))return!1}return!0}):this.data},e.prototype.onColumnSearch=function(b){var c=a.trim(a(b.currentTarget).val()),d=a(b.currentTarget).parent().parent().parent().data("field");a.isEmptyObject(this.filterColumnsPartial)&&(this.filterColumnsPartial={}),c?this.filterColumnsPartial[d]=c:delete this.filterColumnsPartial[d],this.options.pageNumber=1,this.onSearch(b),this.updatePagination(),this.trigger("column-search",d,c)}}(jQuery);
@@ -0,0 +1,67 @@
/**
* @author zhixin wen <wenzhixin2010@gmail.com>
* extensions: https://github.com/lukaskral/bootstrap-table-filter
*/
!function($) {
'use strict';
$.extend($.fn.bootstrapTable.defaults, {
showFilter: false
});
var BootstrapTable = $.fn.bootstrapTable.Constructor,
_init = BootstrapTable.prototype.init,
_initSearch = BootstrapTable.prototype.initSearch;
BootstrapTable.prototype.init = function () {
_init.apply(this, Array.prototype.slice.apply(arguments));
var that = this;
this.$el.on('load-success.bs.table', function () {
if (that.options.showFilter) {
$(that.options.toolbar).bootstrapTableFilter({
connectTo: that.$el
});
}
});
};
BootstrapTable.prototype.initSearch = function () {
_initSearch.apply(this, Array.prototype.slice.apply(arguments));
if (this.options.sidePagination !== 'server') {
if (typeof this.searchCallback === 'function') {
this.data = $.grep(this.options.data, this.searchCallback);
}
}
};
BootstrapTable.prototype.getData = function () {
return (this.searchText || this.searchCallback) ? this.data : this.options.data;
};
BootstrapTable.prototype.getColumns = function () {
return this.options.columns;
};
BootstrapTable.prototype.registerSearchCallback = function (callback) {
this.searchCallback = callback;
};
BootstrapTable.prototype.updateSearch = function () {
this.options.pageNumber = 1;
this.initSearch();
this.updatePagination();
};
BootstrapTable.prototype.getServerUrl = function () {
return (this.options.sidePagination === 'server') ? this.options.url : false;
};
$.fn.bootstrapTable.methods.push('getColumns',
'registerSearchCallback', 'updateSearch',
'getServerUrl');
}(jQuery);
@@ -0,0 +1,7 @@
/*
* bootstrap-table - v1.8.1 - 2015-05-29
* https://github.com/wenzhixin/bootstrap-table
* Copyright (c) 2015 zhixin wen
* Licensed MIT License
*/
!function(a){"use strict";a.extend(a.fn.bootstrapTable.defaults,{showFilter:!1});var b=a.fn.bootstrapTable.Constructor,c=b.prototype.init,d=b.prototype.initSearch;b.prototype.init=function(){c.apply(this,Array.prototype.slice.apply(arguments));var b=this;this.$el.on("load-success.bs.table",function(){b.options.showFilter&&a(b.options.toolbar).bootstrapTableFilter({connectTo:b.$el})})},b.prototype.initSearch=function(){d.apply(this,Array.prototype.slice.apply(arguments)),"server"!==this.options.sidePagination&&"function"==typeof this.searchCallback&&(this.data=a.grep(this.options.data,this.searchCallback))},b.prototype.getData=function(){return this.searchText||this.searchCallback?this.data:this.options.data},b.prototype.getColumns=function(){return this.options.columns},b.prototype.registerSearchCallback=function(a){this.searchCallback=a},b.prototype.updateSearch=function(){this.options.pageNumber=1,this.initSearch(),this.updatePagination()},b.prototype.getServerUrl=function(){return"server"===this.options.sidePagination?this.options.url:!1},a.fn.bootstrapTable.methods.push("getColumns","registerSearchCallback","updateSearch","getServerUrl")}(jQuery);
@@ -0,0 +1,70 @@
/**
* @author: Dennis Hernández
* @webSite: http://djhvscf.github.io/Blog
* @version: v1.2.0
*/
(function ($) {
'use strict';
$.extend($.fn.bootstrapTable.defaults, {
flat: false
});
var BootstrapTable = $.fn.bootstrapTable.Constructor,
_initData = BootstrapTable.prototype.initData;
BootstrapTable.prototype.initData = function (data, type) {
if( this.options.flat ){
data = data === undefined ? this.options.data : data;
data = sd.flatHelper(data);
}
_initData.apply(this, [data, type]);
};
//Main functions
var sd = {
flat: function (element) {
var result = {};
function recurse(cur, prop) {
if (Object(cur) !== cur) {
result[prop] = cur;
} else if ($.isArray(cur)) {
for (var i = 0, l = cur.length; i < l; i++) {
recurse(cur[i], prop ? prop + "." + i : "" + i);
if (l == 0) {
result[prop] = [];
}
}
} else {
var isEmpty = true;
for (var p in cur) {
isEmpty = false;
recurse(cur[p], prop ? prop + "." + p : p);
}
if (isEmpty) {
result[prop] = {};
}
}
}
recurse(element, "");
return result;
},
flatHelper: function (data) {
var flatArray = [],
arrayHelper = [];
if (!$.isArray(data)) {
arrayHelper.push(data);
data = arrayHelper;
}
$.each(data, function (i, element) {
flatArray.push(sd.flat(element));
});
return flatArray;
}
};
})(jQuery);
@@ -0,0 +1,7 @@
/*
* bootstrap-table - v1.8.1 - 2015-05-29
* https://github.com/wenzhixin/bootstrap-table
* Copyright (c) 2015 zhixin wen
* Licensed MIT License
*/
!function(a){"use strict";a.extend(a.fn.bootstrapTable.defaults,{flat:!1});var b=a.fn.bootstrapTable.Constructor,c=b.prototype.initData;b.prototype.initData=function(a,b){this.options.flat&&(a=void 0===a?this.options.data:a,a=d.flatHelper(a)),c.apply(this,[a,b])};var d={flat:function(b){function c(b,e){if(Object(b)!==b)d[e]=b;else if(a.isArray(b))for(var f=0,g=b.length;g>f;f++)c(b[f],e?e+"."+f:""+f),0==g&&(d[e]=[]);else{var h=!0;for(var i in b)h=!1,c(b[i],e?e+"."+i:i);h&&(d[e]={})}}var d={};return c(b,""),d},flatHelper:function(b){var c=[],e=[];return a.isArray(b)||(e.push(b),b=e),a.each(b,function(a,b){c.push(d.flat(b))}),c}}}(jQuery);
@@ -0,0 +1,81 @@
/**
* @author: Dennis Hernández
* @webSite: http://djhvscf.github.io/Blog
* @version: v1.0.0
*
* @update zhixin wen <wenzhixin2010@gmail.com>
*/
!function ($) {
'use strict';
$.extend($.fn.bootstrapTable.defaults, {
keyEvents: false
});
var BootstrapTable = $.fn.bootstrapTable.Constructor,
_init = BootstrapTable.prototype.init;
BootstrapTable.prototype.init = function () {
_init.apply(this, Array.prototype.slice.apply(arguments));
this.initKeyEvents();
};
BootstrapTable.prototype.initKeyEvents = function () {
if (this.options.keyEvents) {
var that = this;
$(document).off('keydown').on('keydown', function (e) {
var $search = that.$toolbar.find('.search input'),
$refresh = that.$toolbar.find('button[name="refresh"]'),
$toggle = that.$toolbar.find('button[name="toggle"]'),
$paginationSwitch = that.$toolbar.find('button[name="paginationSwitch"]');
if (document.activeElement === $search.get(0)) {
return true;
}
switch (e.keyCode) {
case 83: //s
if (!that.options.search) {
return;
}
$search.focus();
return false;
case 82: //r
if (!that.options.showRefresh) {
return;
}
$refresh.click();
return false;
case 84: //t
if (!that.options.showToggle) {
return;
}
$toggle.click();
return false;
case 80: //p
if (!that.options.showPaginationSwitch) {
return;
}
$paginationSwitch.click();
return false;
case 37: // left
if (!that.options.pagination) {
return;
}
that.prevPage();
return false;
case 39: // right
if (!that.options.pagination) {
return;
}
that.nextPage();
return;
}
});
}
};
}(jQuery);
@@ -0,0 +1,7 @@
/*
* bootstrap-table - v1.8.1 - 2015-05-29
* https://github.com/wenzhixin/bootstrap-table
* Copyright (c) 2015 zhixin wen
* Licensed MIT License
*/
!function(a){"use strict";a.extend(a.fn.bootstrapTable.defaults,{keyEvents:!1});var b=a.fn.bootstrapTable.Constructor,c=b.prototype.init;b.prototype.init=function(){c.apply(this,Array.prototype.slice.apply(arguments)),this.initKeyEvents()},b.prototype.initKeyEvents=function(){if(this.options.keyEvents){var b=this;a(document).off("keydown").on("keydown",function(a){var c=b.$toolbar.find(".search input"),d=b.$toolbar.find('button[name="refresh"]'),e=b.$toolbar.find('button[name="toggle"]'),f=b.$toolbar.find('button[name="paginationSwitch"]');if(document.activeElement===c.get(0))return!0;switch(a.keyCode){case 83:if(!b.options.search)return;return c.focus(),!1;case 82:if(!b.options.showRefresh)return;return d.click(),!1;case 84:if(!b.options.showToggle)return;return e.click(),!1;case 80:if(!b.options.showPaginationSwitch)return;return f.click(),!1;case 37:if(!b.options.pagination)return;return b.prevPage(),!1;case 39:if(!b.options.pagination)return;return void b.nextPage()}})}}}(jQuery);
@@ -0,0 +1,87 @@
/**
* @author: Dennis Hernández
* @webSite: http://djhvscf.github.io/Blog
* @version: v1.1.0
*/
!function ($) {
'use strict';
var resetView = function (that) {
if (that.options.height || that.options.showFooter) {
setTimeout(that.resetView(), 1);
}
};
var changeView = function (that, width, height) {
if (that.options.minHeight) {
if (checkValuesLessEqual(width, that.options.minWidth) && checkValuesLessEqual(height, that.options.minHeight)) {
conditionCardView(that);
} else if (checkValuesGreater(width, that.options.minWidth) && checkValuesGreater(height, that.options.minHeight)) {
conditionFullView(that);
}
} else {
if (checkValuesLessEqual(width, that.options.minWidth)) {
conditionCardView(that);
} else if (checkValuesGreater(width, that.options.minWidth)) {
conditionFullView(that);
}
}
resetView(that);
};
var checkValuesLessEqual = function (currentValue, targetValue) {
return currentValue <= targetValue;
};
var checkValuesGreater = function (currentValue, targetValue) {
return currentValue > targetValue;
};
var conditionCardView = function (that) {
changeTableView(that, false);
};
var conditionFullView = function (that) {
changeTableView(that, true);
};
var changeTableView = function (that, cardViewState) {
that.options.cardView = cardViewState;
that.toggleView();
};
$.extend($.fn.bootstrapTable.defaults, {
mobileResponsive: false,
minWidth: 562,
minHeight: undefined,
checkOnInit: true,
toggled: false
});
var BootstrapTable = $.fn.bootstrapTable.Constructor,
_init = BootstrapTable.prototype.init;
BootstrapTable.prototype.init = function () {
_init.apply(this, Array.prototype.slice.apply(arguments));
if (!this.options.mobileResponsive) {
return;
}
if (!this.options.minWidth) {
return;
}
var that = this;
$(window).resize(function () {
changeView(that, $(this).width(), $(this).height())
});
if (this.options.checkOnInit) {
changeView(this, $(window).width(), $(window).height());
}
};
}(jQuery);
@@ -0,0 +1,7 @@
/*
* bootstrap-table - v1.8.1 - 2015-05-29
* https://github.com/wenzhixin/bootstrap-table
* Copyright (c) 2015 zhixin wen
* Licensed MIT License
*/
!function(a){"use strict";var b=function(a){(a.options.height||a.options.showFooter)&&setTimeout(a.resetView(),1)},c=function(a,c,h){a.options.minHeight?d(c,a.options.minWidth)&&d(h,a.options.minHeight)?f(a):e(c,a.options.minWidth)&&e(h,a.options.minHeight)&&g(a):d(c,a.options.minWidth)?f(a):e(c,a.options.minWidth)&&g(a),b(a)},d=function(a,b){return b>=a},e=function(a,b){return a>b},f=function(a){h(a,!1)},g=function(a){h(a,!0)},h=function(a,b){a.options.cardView=b,a.toggleView()};a.extend(a.fn.bootstrapTable.defaults,{mobileResponsive:!1,minWidth:562,minHeight:void 0,checkOnInit:!0,toggled:!1});var i=a.fn.bootstrapTable.Constructor,j=i.prototype.init;i.prototype.init=function(){if(j.apply(this,Array.prototype.slice.apply(arguments)),this.options.mobileResponsive&&this.options.minWidth){var b=this;a(window).resize(function(){c(b,a(this).width(),a(this).height())}),this.options.checkOnInit&&c(this,a(window).width(),a(window).height())}}}(jQuery);
@@ -0,0 +1,370 @@
/**
* @author Nadim Basalamah <dimbslmh@gmail.com>
* @version: v1.0.0
* https://github.com/dimbslmh/bootstrap-table/tree/master/src/extensions/multiple-sort/bootstrap-table-multiple-sort.js
*/
(function($) {
'use strict';
var isSingleSort = false;
var sort_order = {
asc: 'Ascending',
desc: 'Descending'
},
arrowAsc = 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABMAAAATCAYAAAByUDbMAAAAZ' +
'0lEQVQ4y2NgGLKgquEuFxBPAGI2ahhWCsS/gDibUoO0gPgxEP8H4ttArEyuQYxAPBd' +
'qEAxPBImTY5gjEL9DM+wTENuQahAvEO9DMwiGdwAxOymGJQLxTyD+jgWDxCMZRsEoGAVo' +
'AADeemwtPcZI2wAAAABJRU5ErkJggg==',
arrowDesc = 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABMAAAATCAYAAAByUDbMAAAAZUlEQVQ4y2NgGAWj' +
'YBSggaqGu5FA/BOIv2PBIPFEUgxjB+IdQPwfC94HxLykus4GiD+hGfQOiB3J8SojEE9EM2wuSJ' +
'zcsFMG4ttQgx4DsRalkZENxL+AuJQaMcsGxBOAmGvopk8AVz1sLZgg0bsAAAAASUVORK5CYII= ';
var showSortModal = function(that) {
if (!$("#sortModal").hasClass("modal")) {
var sModal = ' <div class="modal fade" id="sortModal" tabindex="-1" role="dialog" aria-labelledby="sortModalLabel" aria-hidden="true">';
sModal += ' <div class="modal-dialog">';
sModal += ' <div class="modal-content">';
sModal += ' <div class="modal-header">';
sModal += ' <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>';
sModal += ' <h4 class="modal-title" id="sortModalLabel">' + that.options.formatMultipleSort() + '</h4>';
sModal += ' </div>';
sModal += ' <div class="modal-body">';
sModal += ' <div class="bootstrap-table">';
sModal += ' <div class="fixed-table-toolbar">';
sModal += ' <div class="bars">';
sModal += ' <div id="toolbar">';
sModal += ' <button id="add" type="button" class="btn btn-default"><i class="' + that.options.iconsPrefix + ' ' + that.options.icons.plus + '"></i> ' + that.options.formatAddLevel() + '</button>';
sModal += ' <button id="delete" type="button" class="btn btn-default" disabled><i class="' + that.options.iconsPrefix + ' ' + that.options.icons.minus + '"></i> ' + that.options.formatDeleteLevel() + '</button>';
sModal += ' </div>';
sModal += ' </div>';
sModal += ' </div>';
sModal += ' <div class="fixed-table-container">';
sModal += ' <table id="multi-sort" class="table">';
sModal += ' <thead>';
sModal += ' <tr>';
sModal += ' <th></th>';
sModal += ' <th><div class="th-inner">' + that.options.formatColumn() + '</div></th>';
sModal += ' <th><div class="th-inner">' + that.options.formatOrder() + '</div></th>';
sModal += ' </tr>';
sModal += ' </thead>';
sModal += ' <tbody></tbody>';
sModal += ' </table>';
sModal += ' </div>';
sModal += ' </div>';
sModal += ' </div>';
sModal += ' <div class="modal-footer">';
sModal += ' <button type="button" class="btn btn-default" data-dismiss="modal">' + that.options.formatCancel() + '</button>';
sModal += ' <button type="button" class="btn btn-primary">' + that.options.formatSort() + '</button>';
sModal += ' </div>';
sModal += ' </div>';
sModal += ' </div>';
sModal += ' </div>';
$("body").append($(sModal));
var $sortModal = $('#sortModal'),
$rows = $sortModal.find("tbody > tr");
$sortModal.off('click', '#add').on('click', '#add', function() {
var total = $sortModal.find('.multi-sort-name:first option').length,
current = $sortModal.find('tbody tr').length;
if (current < total) {
current++;
that.addLevel();
that.setButtonStates();
}
});
$sortModal.off('click', '#delete').on('click', '#delete', function() {
var total = $sortModal.find('.multi-sort-name:first option').length,
current = $sortModal.find('tbody tr').length;
if (current > 1 && current <= total) {
current--;
$sortModal.find('tbody tr:last').remove();
that.setButtonStates();
}
});
$sortModal.off('click', '.btn-primary').on('click', '.btn-primary', function() {
var $rows = $sortModal.find("tbody > tr"),
$alert = $sortModal.find('div.alert'),
fields = [],
results = [];
that.options.sortPriority = $.map($rows, function(row) {
var $row = $(row),
name = $row.find('.multi-sort-name').val(),
order = $row.find('.multi-sort-order').val();
fields.push(name);
return {
sortName: name,
sortOrder: order
};
});
var sorted_fields = fields.sort();
for (var i = 0; i < fields.length - 1; i++) {
if (sorted_fields[i + 1] == sorted_fields[i]) {
results.push(sorted_fields[i]);
}
}
if (results.length > 0) {
if ($alert.length === 0) {
$alert = '<div class="alert alert-danger" role="alert"><strong>' + that.options.formatDuplicateAlertTitle() + '</strong> ' + that.options.formatDuplicateAlertDescription() + '</div>';
$($alert).insertBefore($sortModal.find('.bars'));
}
} else {
if ($alert.length === 1) {
$($alert).remove();
}
that.options.sortName = "";
that.onMultipleSort();
$sortModal.modal('hide');
}
});
if (that.options.sortPriority === null) {
if (that.options.sortName) {
that.options.sortPriority = [{
sortName: that.options.sortName,
sortOrder: that.options.sortOrder
}];
}
}
if (that.options.sortPriority !== null) {
if ($rows.length < that.options.sortPriority.length && typeof that.options.sortPriority === 'object') {
for (var i = 0; i < that.options.sortPriority.length; i++) {
that.addLevel(i, that.options.sortPriority[i]);
}
}
} else {
that.addLevel(0);
}
that.setButtonStates();
}
};
$.extend($.fn.bootstrapTable.defaults, {
showMultiSort: false,
sortPriority: null,
onMultipleSort: function() {
return false;
}
});
$.extend($.fn.bootstrapTable.defaults.icons, {
sort: 'glyphicon-sort',
plus: 'glyphicon-plus',
minus: 'glyphicon-minus'
});
$.extend($.fn.bootstrapTable.Constructor.EVENTS, {
'multiple-sort.bs.table': 'onMultipleSort'
});
$.extend($.fn.bootstrapTable.locales, {
formatMultipleSort: function() {
return 'Multiple Sort';
},
formatAddLevel: function() {
return "Add Level";
},
formatDeleteLevel: function() {
return "Delete Level";
},
formatColumn: function() {
return "Column";
},
formatOrder: function() {
return "Order";
},
formatSortBy: function() {
return "Sort by";
},
formatThenBy: function() {
return "Then by";
},
formatSort: function() {
return "Sort";
},
formatCancel: function() {
return "Cancel";
},
formatDuplicateAlertTitle: function() {
return "Duplicate(s) detected!";
},
formatDuplicateAlertDescription: function() {
return "Please remove or change any duplicate column.";
}
});
$.extend($.fn.bootstrapTable.defaults, $.fn.bootstrapTable.locales);
var BootstrapTable = $.fn.bootstrapTable.Constructor,
_initToolbar = BootstrapTable.prototype.initToolbar;
BootstrapTable.prototype.initToolbar = function() {
this.showToolbar = true;
var that = this;
_initToolbar.apply(this, Array.prototype.slice.apply(arguments));
if (this.options.showMultiSort) {
var $btnGroup = this.$toolbar.find('>.btn-group'),
$multiSortBtn = $btnGroup.find('div.multi-sort');
if (!$multiSortBtn.length) {
$multiSortBtn = ' <button class="multi-sort btn btn-default' + (this.options.iconSize === undefined ? '' : ' btn-' + this.options.iconSize) + '" type="button" data-toggle="modal" data-target="#sortModal" title="' + this.options.formatMultipleSort() + '">';
$multiSortBtn += ' <i class="' + this.options.iconsPrefix + ' ' + this.options.icons.sort + '"></i>';
$multiSortBtn += '</button>';
$btnGroup.append($multiSortBtn);
showSortModal(that);
}
this.$el.one('sort.bs.table', function() {
isSingleSort = true;
});
this.$el.on('multiple-sort.bs.table', function() {
isSingleSort = false;
});
this.$el.on('load-success.bs.table', function() {
if (!isSingleSort && that.options.sortPriority !== null && typeof that.options.sortPriority === 'object') {
that.onMultipleSort();
}
});
this.$el.on('column-switch.bs.table', function() {
that.options.sortPriority = null;
$('#sortModal').remove();
showSortModal(that);
});
}
};
BootstrapTable.prototype.onMultipleSort = function() {
var that = this;
var cmp = function(x, y) {
return x > y ? 1 : x < y ? -1 : 0;
};
var arrayCmp = function(a, b) {
var arr1 = [],
arr2 = [];
for (var i = 0; i < that.options.sortPriority.length; i++) {
var order = that.options.sortPriority[i].sortOrder === 'desc' ? -1 : 1,
aa = a[that.options.sortPriority[i].sortName],
bb = b[that.options.sortPriority[i].sortName];
if (aa === undefined || aa === null) {
aa = '';
}
if (bb === undefined || bb === null) {
bb = '';
}
if ($.isNumeric(aa) && $.isNumeric(bb)) {
aa = parseFloat(aa);
bb = parseFloat(bb);
}
if (typeof aa !== 'string') {
aa = aa.toString();
}
arr1.push(
order * cmp(aa, bb));
arr2.push(
order * cmp(bb, aa));
}
return cmp(arr1, arr2);
};
this.data.sort(function(a, b) {
return arrayCmp(a, b);
});
this.initBody();
this.assignSortableArrows();
this.trigger('multiple-sort');
};
BootstrapTable.prototype.addLevel = function(index, sortPriority) {
var $sortModal = $("#sortModal"),
text = index === 0 ? this.options.formatSortBy() : this.options.formatThenBy();
$sortModal.find('tbody')
.append($('<tr>')
.append($('<td>').text(text))
.append($('<td>').append($('<select class="form-control multi-sort-name">')))
.append($('<td>').append($('<select class="form-control multi-sort-order">')))
);
var $multiSortName = $sortModal.find('.multi-sort-name').last(),
$multiSortOrder = $sortModal.find('.multi-sort-order').last();
this.options.columns.forEach(function(column) {
if (column.sortable === false || column.visible === false) {
return true;
}
$multiSortName.append('<option value="' + column.field + '">' + column.title + '</option>');
});
$.each(sort_order, function(value, order) {
$multiSortOrder.append('<option value="' + value + '">' + order + '</option>');
});
if (sortPriority !== undefined) {
$multiSortName.find('option[value="' + sortPriority.sortName + '"]').attr("selected", true);
$multiSortOrder.find('option[value="' + sortPriority.sortOrder + '"]').attr("selected", true);
}
};
BootstrapTable.prototype.assignSortableArrows = function() {
var that = this,
headers = that.$header.find('th');
for (var i = 0; i < headers.length; i++) {
for (var c = 0; c < that.options.sortPriority.length; c++) {
if ($(headers[i]).data('field') === that.options.sortPriority[c].sortName) {
$(headers[i]).find('.sortable').css('background-image', 'url(' + (that.options.sortPriority[c].sortOrder === 'desc' ? arrowDesc : arrowAsc) + ')');
}
}
}
};
BootstrapTable.prototype.setButtonStates = function() {
var $sortModal = $('#sortModal'),
total = $sortModal.find('.multi-sort-name:first option').length,
current = $sortModal.find('tbody tr').length;
if (current == total) {
$sortModal.find('#add').attr('disabled', 'disabled');
}
if (current > 1) {
$sortModal.find('#delete').removeAttr('disabled');
}
if (current < total) {
$sortModal.find('#add').removeAttr('disabled');
}
if (current == 1) {
$sortModal.find('#delete').attr('disabled', 'disabled');
}
};
})(jQuery);
File diff suppressed because one or more lines are too long
@@ -0,0 +1,47 @@
/**
* @author: Brian Huisman
* @webSite: http://www.greywyvern.com
* @version: v1.0.0
* JS function to allow natural sorting on bootstrap-table columns
* just add data-sorter="alphanum" to any th
*
* @update Dennis Hernández <http://djhvscf.github.io/Blog>
*/
function alphanum(a, b) {
function chunkify(t) {
var tz = [],
x = 0,
y = -1,
n = 0,
i,
j;
while (i = (j = t.charAt(x++)).charCodeAt(0)) {
var m = (i === 46 || (i >= 48 && i <= 57));
if (m !== n) {
tz[++y] = "";
n = m;
}
tz[y] += j;
}
return tz;
}
var aa = chunkify(a);
var bb = chunkify(b);
for (x = 0; aa[x] && bb[x]; x++) {
if (aa[x] !== bb[x]) {
var c = Number(aa[x]),
d = Number(bb[x]);
if (c == aa[x] && d == bb[x]) {
return c - d;
} else {
return (aa[x] > bb[x]) ? 1 : -1;
}
}
}
return aa.length - bb.length;
}
@@ -0,0 +1,7 @@
/*
* bootstrap-table - v1.8.1 - 2015-05-29
* https://github.com/wenzhixin/bootstrap-table
* Copyright (c) 2015 zhixin wen
* Licensed MIT License
*/
function alphanum(a,b){function c(a){for(var b,c,d=[],e=0,f=-1,g=0;b=(c=a.charAt(e++)).charCodeAt(0);){var h=46===b||b>=48&&57>=b;h!==g&&(d[++f]="",g=h),d[f]+=c}return d}var d=c(a),e=c(b);for(x=0;d[x]&&e[x];x++)if(d[x]!==e[x]){var f=Number(d[x]),g=Number(e[x]);return f==d[x]&&g==e[x]?f-g:d[x]>e[x]?1:-1}return d.length-e.length}
@@ -0,0 +1,118 @@
/**
* @author: Dennis Hernández
* @webSite: http://djhvscf.github.io/Blog
* @version: v1.1.0
*/
!function ($) {
'use strict';
var getFieldIndex = function (columns, field) {
var index = -1;
$.each(columns, function (i, column) {
if (column.field === field) {
index = i;
return false;
}
return true;
});
return index;
};
$.extend($.fn.bootstrapTable.defaults, {
reorderableColumns: false,
maxMovingRows: 10,
onReorderColumn: function (headerFields) {
return false;
}
});
$.extend($.fn.bootstrapTable.Constructor.EVENTS, {
'reorder-column.bs.table': 'onReorderColumn'
});
var BootstrapTable = $.fn.bootstrapTable.Constructor,
_initHeader = BootstrapTable.prototype.initHeader,
_toggleColumn = BootstrapTable.prototype.toggleColumn,
_toggleView = BootstrapTable.prototype.toggleView,
_resetView = BootstrapTable.prototype.resetView;
BootstrapTable.prototype.initHeader = function () {
_initHeader.apply(this, Array.prototype.slice.apply(arguments));
if (!this.options.reorderableColumns) {
return;
}
this.makeRowsReorderable();
};
BootstrapTable.prototype.toggleColumn = function () {
_toggleColumn.apply(this, Array.prototype.slice.apply(arguments));
if (!this.options.reorderableColumns) {
return;
}
this.makeRowsReorderable();
};
BootstrapTable.prototype.toggleView = function () {
_toggleView.apply(this, Array.prototype.slice.apply(arguments));
if (!this.options.reorderableColumns) {
return;
}
if (this.options.cardView) {
return;
}
this.makeRowsReorderable();
};
BootstrapTable.prototype.resetView = function () {
_resetView.apply(this, Array.prototype.slice.apply(arguments));
if (!this.options.reorderableColumns) {
return;
}
this.makeRowsReorderable();
};
BootstrapTable.prototype.makeRowsReorderable = function () {
var that = this;
try {
$(this.$el).dragtable('destroy');
} catch (e) {}
$(this.$el).dragtable({
maxMovingRows: that.options.maxMovingRows,
clickDelay:200,
beforeStop: function() {
var ths = [],
columns = [],
columnIndex = -1;
that.$header.find('th').each(function (i) {
ths.push($(this).data('field'));
});
for (var i = 0; i < ths.length; i++ ) {
columnIndex = getFieldIndex(that.options.columns, ths[i]);
if (columnIndex !== -1) {
columns.push(that.options.columns[columnIndex]);
that.options.columns.splice(columnIndex, 1);
}
}
that.options.columns = that.options.columns.concat(columns);
that.header.fields = ths;
that.resetView();
that.trigger('reorder-column', ths);
}
});
};
}(jQuery);
@@ -0,0 +1,7 @@
/*
* bootstrap-table - v1.8.1 - 2015-05-29
* https://github.com/wenzhixin/bootstrap-table
* Copyright (c) 2015 zhixin wen
* Licensed MIT License
*/
!function(a){"use strict";var b=function(b,c){var d=-1;return a.each(b,function(a,b){return b.field===c?(d=a,!1):!0}),d};a.extend(a.fn.bootstrapTable.defaults,{reorderableColumns:!1,maxMovingRows:10,onReorderColumn:function(){return!1}}),a.extend(a.fn.bootstrapTable.Constructor.EVENTS,{"reorder-column.bs.table":"onReorderColumn"});var c=a.fn.bootstrapTable.Constructor,d=c.prototype.initHeader,e=c.prototype.toggleColumn,f=c.prototype.toggleView,g=c.prototype.resetView;c.prototype.initHeader=function(){d.apply(this,Array.prototype.slice.apply(arguments)),this.options.reorderableColumns&&this.makeRowsReorderable()},c.prototype.toggleColumn=function(){e.apply(this,Array.prototype.slice.apply(arguments)),this.options.reorderableColumns&&this.makeRowsReorderable()},c.prototype.toggleView=function(){f.apply(this,Array.prototype.slice.apply(arguments)),this.options.reorderableColumns&&(this.options.cardView||this.makeRowsReorderable())},c.prototype.resetView=function(){g.apply(this,Array.prototype.slice.apply(arguments)),this.options.reorderableColumns&&this.makeRowsReorderable()},c.prototype.makeRowsReorderable=function(){var c=this;try{a(this.$el).dragtable("destroy")}catch(d){}a(this.$el).dragtable({maxMovingRows:c.options.maxMovingRows,clickDelay:200,beforeStop:function(){var d=[],e=[],f=-1;c.$header.find("th").each(function(){d.push(a(this).data("field"))});for(var g=0;g<d.length;g++)f=b(c.options.columns,d[g]),-1!==f&&(e.push(c.options.columns[f]),c.options.columns.splice(f,1));c.options.columns=c.options.columns.concat(e),c.header.fields=d,c.resetView(),c.trigger("reorder-column",d)}})}}(jQuery);
@@ -0,0 +1,14 @@
.reorder_rows_onDragClass td {
background-color: #eee;
-webkit-box-shadow: 11px 5px 12px 2px #333, 0 1px 0 #ccc inset, 0 -1px 0 #ccc inset;
-webkit-box-shadow: 6px 3px 5px #555, 0 1px 0 #ccc inset, 0 -1px 0 #ccc inset;
-moz-box-shadow: 6px 4px 5px 1px #555, 0 1px 0 #ccc inset, 0 -1px 0 #ccc inset;
-box-shadow: 6px 4px 5px 1px #555, 0 1px 0 #ccc inset, 0 -1px 0 #ccc inset;
}
.reorder_rows_onDragClass td:last-child {
-webkit-box-shadow: 8px 7px 12px 0 #333, 0 1px 0 #ccc inset, 0 -1px 0 #ccc inset;
-webkit-box-shadow: 1px 8px 6px -4px #555, 0 1px 0 #ccc inset, 0 -1px 0 #ccc inset;
-moz-box-shadow: 0 9px 4px -4px #555, 0 1px 0 #ccc inset, 0 -1px 0 #ccc inset, -1px 0 0 #ccc inset;
-box-shadow: 0 9px 4px -4px #555, 0 1px 0 #ccc inset, 0 -1px 0 #ccc inset, -1px 0 0 #ccc inset;
}
@@ -0,0 +1,115 @@
/**
* @author: Dennis Hernández
* @webSite: http://djhvscf.github.io/Blog
* @version: v1.0.0
*/
!function ($) {
'use strict';
var isSearch = false;
var rowAttr = function (row, index) {
return {
id: 'customId_' + index
};
};
$.extend($.fn.bootstrapTable.defaults, {
reorderableRows: false,
onDragStyle: null,
onDropStyle: null,
onDragClass: "reorder_rows_onDragClass",
dragHandle: null,
useRowAttrFunc: false,
onReorderRowsDrag: function (table, row) {
return false;
},
onReorderRowsDrop: function (table, row) {
return false;
},
onReorderRow: function (newData) {
return false;
}
});
$.extend($.fn.bootstrapTable.Constructor.EVENTS, {
'reorder-row.bs.table': 'onReorderRow'
});
var BootstrapTable = $.fn.bootstrapTable.Constructor,
_init = BootstrapTable.prototype.init,
_initSearch = BootstrapTable.prototype.initSearch;
BootstrapTable.prototype.init = function () {
_init.apply(this, Array.prototype.slice.apply(arguments));
if (!this.options.reorderableRows) {
return;
}
var that = this;
if (this.options.useRowAttrFunc) {
this.options.rowAttributes = rowAttr;
}
var onPostBody = this.options.onPostBody;
this.options.onPostBody = function () {
setTimeout(function () {
that.makeRowsReorderable();
onPostBody.apply();
}, 1);
};
};
BootstrapTable.prototype.initSearch = function () {
_initSearch.apply(this, Array.prototype.slice.apply(arguments));
if (!this.options.reorderableRows) {
return;
}
//Known issue after search if you reorder the rows the data is not display properly
//isSearch = true;
};
BootstrapTable.prototype.makeRowsReorderable = function () {
if (this.options.cardView) {
return;
}
var that = this;
this.$el.tableDnD({
onDragStyle: that.options.onDragStyle,
onDropStyle: that.options.onDropStyle,
onDragClass: that.options.onDragClass,
onDrop: that.onDrop,
onDragStart: that.options.onReorderRowsDrag,
dragHandle: that.options.dragHandle
});
};
BootstrapTable.prototype.onDrop = function (table, row) {
var tableBs = $(table),
tableBsData = tableBs.data('bootstrap.table'),
tableBsOptions = tableBs.data('bootstrap.table').options,
row = null,
newData = [];
for (var i = 0; i < table.tBodies[0].rows.length; i++) {
row = $(table.tBodies[0].rows[i]);
newData.push(tableBsOptions.data[row.data('index')]);
row.data('index', i).attr('data-index', i);
}
tableBsOptions.data = newData;
//Call the user defined function
tableBsOptions.onReorderRowsDrop.apply(table, row);
//Call the event reorder-row
tableBsData.trigger('reorder-row', newData);
};
}(jQuery);
@@ -0,0 +1,7 @@
/*
* bootstrap-table - v1.8.1 - 2015-05-29
* https://github.com/wenzhixin/bootstrap-table
* Copyright (c) 2015 zhixin wen
* Licensed MIT License
*/
!function(a){"use strict";var b=function(a,b){return{id:"customId_"+b}};a.extend(a.fn.bootstrapTable.defaults,{reorderableRows:!1,onDragStyle:null,onDropStyle:null,onDragClass:"reorder_rows_onDragClass",dragHandle:null,useRowAttrFunc:!1,onReorderRowsDrag:function(){return!1},onReorderRowsDrop:function(){return!1},onReorderRow:function(){return!1}}),a.extend(a.fn.bootstrapTable.Constructor.EVENTS,{"reorder-row.bs.table":"onReorderRow"});var c=a.fn.bootstrapTable.Constructor,d=c.prototype.init,e=c.prototype.initSearch;c.prototype.init=function(){if(d.apply(this,Array.prototype.slice.apply(arguments)),this.options.reorderableRows){var a=this;this.options.useRowAttrFunc&&(this.options.rowAttributes=b);var c=this.options.onPostBody;this.options.onPostBody=function(){setTimeout(function(){a.makeRowsReorderable(),c.apply()},1)}}},c.prototype.initSearch=function(){e.apply(this,Array.prototype.slice.apply(arguments)),!this.options.reorderableRows},c.prototype.makeRowsReorderable=function(){if(!this.options.cardView){var a=this;this.$el.tableDnD({onDragStyle:a.options.onDragStyle,onDropStyle:a.options.onDropStyle,onDragClass:a.options.onDragClass,onDrop:a.onDrop,onDragStart:a.options.onReorderRowsDrag,dragHandle:a.options.dragHandle})}},c.prototype.onDrop=function(b,c){for(var d=a(b),e=d.data("bootstrap.table"),f=d.data("bootstrap.table").options,c=null,g=[],h=0;h<b.tBodies[0].rows.length;h++)c=a(b.tBodies[0].rows[h]),g.push(f.data[c.data("index")]),c.data("index",h).attr("data-index",h);f.data=g,f.onReorderRowsDrop.apply(b,c),e.trigger("reorder-row",g)}}(jQuery);
@@ -0,0 +1,74 @@
/**
* @author: Dennis Hernández
* @webSite: http://djhvscf.github.io/Blog
* @version: v1.0.0
*/
(function ($) {
'use strict';
var initResizable = function (that) {
//Deletes the plugin to re-create it
that.$el.colResizable({disable: true});
//Creates the plugin
that.$el.colResizable({
liveDrag: that.options.liveDrag,
fixed: that.options.fixed,
headerOnly: that.options.headerOnly,
minWidth: that.options.minWidth,
hoverCursor: that.options.hoverCursor,
dragCursor: that.options.dragCursor,
onResize: that.onResize,
onDrag: that.options.onResizableDrag
});
};
$.extend($.fn.bootstrapTable.defaults, {
resizable: false,
liveDrag: false,
fixed: true,
headerOnly: false,
minWidth: 15,
hoverCursor: 'e-resize',
dragCursor: 'e-resize',
onResizableResize: function (e) {
return false;
},
onResizableDrag: function (e) {
return false;
}
});
var BootstrapTable = $.fn.bootstrapTable.Constructor,
_toggleView = BootstrapTable.prototype.toggleView,
_resetView = BootstrapTable.prototype.resetView;
BootstrapTable.prototype.toggleView = function () {
_toggleView.apply(this, Array.prototype.slice.apply(arguments));
if (this.options.resizable && this.options.cardView) {
//Deletes the plugin
$(this.$el).colResizable({disable: true});
}
};
BootstrapTable.prototype.resetView = function () {
var that = this;
_resetView.apply(this, Array.prototype.slice.apply(arguments));
if (this.options.resizable) {
// because in fitHeader function, we use setTimeout(func, 100);
setTimeout(function () {
initResizable(that);
}, 100);
}
};
BootstrapTable.prototype.onResize = function (e) {
var that = $(e.currentTarget);
that.bootstrapTable('resetView');
that.data('bootstrap.table').options.onResizableResize.apply(e);
}
})(jQuery);
@@ -0,0 +1,7 @@
/*
* bootstrap-table - v1.8.1 - 2015-05-29
* https://github.com/wenzhixin/bootstrap-table
* Copyright (c) 2015 zhixin wen
* Licensed MIT License
*/
!function(a){"use strict";var b=function(a){a.$el.colResizable({disable:!0}),a.$el.colResizable({liveDrag:a.options.liveDrag,fixed:a.options.fixed,headerOnly:a.options.headerOnly,minWidth:a.options.minWidth,hoverCursor:a.options.hoverCursor,dragCursor:a.options.dragCursor,onResize:a.onResize,onDrag:a.options.onResizableDrag})};a.extend(a.fn.bootstrapTable.defaults,{resizable:!1,liveDrag:!1,fixed:!0,headerOnly:!1,minWidth:15,hoverCursor:"e-resize",dragCursor:"e-resize",onResizableResize:function(){return!1},onResizableDrag:function(){return!1}});var c=a.fn.bootstrapTable.Constructor,d=c.prototype.toggleView,e=c.prototype.resetView;c.prototype.toggleView=function(){d.apply(this,Array.prototype.slice.apply(arguments)),this.options.resizable&&this.options.cardView&&a(this.$el).colResizable({disable:!0})},c.prototype.resetView=function(){var a=this;e.apply(this,Array.prototype.slice.apply(arguments)),this.options.resizable&&setTimeout(function(){b(a)},100)},c.prototype.onResize=function(b){var c=a(b.currentTarget);c.bootstrapTable("resetView"),c.data("bootstrap.table").options.onResizableResize.apply(b)}}(jQuery);
@@ -0,0 +1,237 @@
/**
* @author: aperez <aperez@datadec.es>
* @version: v2.0.0
*
* @update Dennis Hernández <http://djhvscf.github.io/Blog>
*/
!function($) {
'use strict';
var firstLoad = false;
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 calculateObjectValue = function (self, name, args, defaultValue) {
if (typeof name === 'string') {
// support obj.func1.func2
var names = name.split('.');
if (names.length > 1) {
name = window;
$.each(names, function (i, f) {
name = name[f];
});
} else {
name = window[name];
}
}
if (typeof name === 'object') {
return name;
}
if (typeof name === 'function') {
return name.apply(self, args);
}
return defaultValue;
};
var showAvdSearch = function(pColumns, searchTitle, searchText, that) {
if (!$("#avdSearchModal").hasClass("modal")) {
var vModal = "<div id=\"avdSearchModal\" class=\"modal fade\" tabindex=\"-1\" role=\"dialog\" aria-labelledby=\"mySmallModalLabel\" aria-hidden=\"true\">";
vModal += "<div class=\"modal-dialog modal-xs\">";
vModal += " <div class=\"modal-content\">";
vModal += " <div class=\"modal-header\">";
vModal += " <button type=\"button\" class=\"close\" data-dismiss=\"modal\" aria-hidden=\"true\" >&times;</button>";
vModal += sprintf(" <h4 class=\"modal-title\">%s</h4>", searchTitle);
vModal += " </div>";
vModal += " <div class=\"modal-body modal-body-custom\">";
vModal += " <div class=\"container-fluid\" id=\"avdSearchModalContent\" style=\"padding-right: 0px;padding-left: 0px;\" >";
vModal += " </div>";
vModal += " </div>";
vModal += " </div>";
vModal += " </div>";
vModal += "</div>";
$("body").append($(vModal));
var vFormAvd = createFormAvd(pColumns, searchText, that),
timeoutId = 0;;
$('#avdSearchModalContent').append(vFormAvd.join(''));
$('#' + that.options.idForm).off('keyup blur', 'input').on('keyup blur', 'input', function (event) {
clearTimeout(timeoutId);
timeoutId = setTimeout(function () {
that.onColumnAdvancedSearch(event);
}, that.options.searchTimeOut);
});
$("#btnCloseAvd").click(function() {
$("#avdSearchModal").modal('hide');
});
$("#avdSearchModal").modal();
} else {
$("#avdSearchModal").modal();
}
};
var createFormAvd = function(pColumns, searchText, that) {
var htmlForm = [];
htmlForm.push(sprintf('<form class="form-horizontal" id="%s" action="%s" >', that.options.idForm, that.options.actionForm));
for (var i in pColumns) {
var vObjCol = pColumns[i];
if (!vObjCol.checkbox && vObjCol.visible && vObjCol.searchable) {
htmlForm.push('<div class="form-group">');
htmlForm.push(sprintf('<label class="col-sm-4 control-label">%s</label>', vObjCol.title));
htmlForm.push('<div class="col-sm-6">');
htmlForm.push(sprintf('<input type="text" class="form-control input-md" name="%s" placeholder="%s" id="%s">', vObjCol.field, vObjCol.title, vObjCol.field));
htmlForm.push('</div>');
htmlForm.push('</div>');
}
}
htmlForm.push('<div class="form-group">');
htmlForm.push('<div class="col-sm-offset-9 col-sm-3">');
htmlForm.push(sprintf('<button type="button" id="btnCloseAvd" class="btn btn-default" >%s</button>', searchText));
htmlForm.push('</div>');
htmlForm.push('</div>');
htmlForm.push('</form>');
return htmlForm;
};
$.extend($.fn.bootstrapTable.defaults, {
advancedSearch: false,
idForm: 'advancedSearch',
actionForm: '',
idTable: undefined,
onColumnAdvancedSearch: function (field, text) {
return false;
}
});
$.extend($.fn.bootstrapTable.defaults.icons, {
advancedSearchIcon: 'glyphicon-chevron-down'
});
$.extend($.fn.bootstrapTable.Constructor.EVENTS, {
'column-advanced-search.bs.table': 'onColumnAdvancedSearch'
});
$.extend($.fn.bootstrapTable.locales, {
formatAdvancedSearch: function() {
return 'Advanced search';
},
formatAdvancedCloseButton: function() {
return "Close";
}
});
$.extend($.fn.bootstrapTable.defaults, $.fn.bootstrapTable.locales);
var BootstrapTable = $.fn.bootstrapTable.Constructor,
_initToolbar = BootstrapTable.prototype.initToolbar,
_load = BootstrapTable.prototype.load,
_initSearch = BootstrapTable.prototype.initSearch;
BootstrapTable.prototype.initToolbar = function() {
_initToolbar.apply(this, Array.prototype.slice.apply(arguments));
if (!this.options.search) {
return;
}
if (!this.options.advancedSearch) {
return;
}
var that = this,
html = [];
html.push(sprintf('<div class="columns columns-%s btn-group pull-%s" role="group">', this.options.buttonsAlign, this.options.buttonsAlign));
html.push(sprintf('<button class="btn btn-default%s' + '" type="button" name="advancedSearch" title="%s">', that.options.iconSize === undefined ? '' : ' btn-' + that.options.iconSize, that.options.formatAdvancedSearch()));
html.push(sprintf('<i class="%s %s"></i>', that.options.iconsPrefix, that.options.icons.advancedSearchIcon))
html.push('</button></div>');
that.$toolbar.prepend(html.join(''));
that.$toolbar.find('button[name="advancedSearch"]')
.off('click').on('click', function() {
showAvdSearch(that.options.columns, that.options.formatAdvancedSearch(), that.options.formatAdvancedCloseButton(), that);
});
};
BootstrapTable.prototype.load = function(data) {
_load.apply(this, Array.prototype.slice.apply(arguments));
if (typeof this.options.idTable === 'undefined') {
return;
} else {
if (!firstLoad) {
var height = parseInt($(".bootstrap-table").height());
height += 10;
$("#" + this.options.idTable).bootstrapTable("resetView", {height: height});
firstLoad = true;
}
}
};
BootstrapTable.prototype.initSearch = function () {
_initSearch.apply(this, Array.prototype.slice.apply(arguments));
var that = this;
var fp = $.isEmptyObject(this.filterColumnsPartial) ? null : this.filterColumnsPartial;
this.data = fp ? $.grep(this.data, function (item, i) {
for (var key in fp) {
var fval = fp[key].toLowerCase();
var value = item[key];
value = calculateObjectValue(that.header,
that.header.formatters[$.inArray(key, that.header.fields)],
[value, item, i], value);
if (!($.inArray(key, that.header.fields) !== -1 &&
(typeof value === 'string' || typeof value === 'number') &&
(value + '').toLowerCase().indexOf(fval) !== -1)) {
return false;
}
}
return true;
}) : this.data;
};
BootstrapTable.prototype.onColumnAdvancedSearch = function (event) {
var text = $.trim($(event.currentTarget).val());
var $field = $(event.currentTarget)[0].id;
if ($.isEmptyObject(this.filterColumnsPartial)) {
this.filterColumnsPartial = {};
}
if (text) {
this.filterColumnsPartial[$field] = text;
} else {
delete this.filterColumnsPartial[$field];
}
this.options.pageNumber = 1;
this.onSearch(event);
this.updatePagination();
this.trigger('column-advanced-search', $field, text);
};
}(jQuery);
@@ -0,0 +1,7 @@
/*
* bootstrap-table - v1.8.1 - 2015-05-29
* https://github.com/wenzhixin/bootstrap-table
* Copyright (c) 2015 zhixin wen
* Licensed MIT License
*/
!function(a){"use strict";var b=!1,c=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:""},d=function(b,c,d,e){if("string"==typeof c){var f=c.split(".");f.length>1?(c=window,a.each(f,function(a,b){c=c[b]})):c=window[c]}return"object"==typeof c?c:"function"==typeof c?c.apply(b,d):e},e=function(b,d,e,g){if(a("#avdSearchModal").hasClass("modal"))a("#avdSearchModal").modal();else{var h='<div id="avdSearchModal" class="modal fade" tabindex="-1" role="dialog" aria-labelledby="mySmallModalLabel" aria-hidden="true">';h+='<div class="modal-dialog modal-xs">',h+=' <div class="modal-content">',h+=' <div class="modal-header">',h+=' <button type="button" class="close" data-dismiss="modal" aria-hidden="true" >&times;</button>',h+=c(' <h4 class="modal-title">%s</h4>',d),h+=" </div>",h+=' <div class="modal-body modal-body-custom">',h+=' <div class="container-fluid" id="avdSearchModalContent" style="padding-right: 0px;padding-left: 0px;" >',h+=" </div>",h+=" </div>",h+=" </div>",h+=" </div>",h+="</div>",a("body").append(a(h));var i=f(b,e,g),j=0;a("#avdSearchModalContent").append(i.join("")),a("#"+g.options.idForm).off("keyup blur","input").on("keyup blur","input",function(a){clearTimeout(j),j=setTimeout(function(){g.onColumnAdvancedSearch(a)},g.options.searchTimeOut)}),a("#btnCloseAvd").click(function(){a("#avdSearchModal").modal("hide")}),a("#avdSearchModal").modal()}},f=function(a,b,d){var e=[];e.push(c('<form class="form-horizontal" id="%s" action="%s" >',d.options.idForm,d.options.actionForm));for(var f in a){var g=a[f];!g.checkbox&&g.visible&&g.searchable&&(e.push('<div class="form-group">'),e.push(c('<label class="col-sm-4 control-label">%s</label>',g.title)),e.push('<div class="col-sm-6">'),e.push(c('<input type="text" class="form-control input-md" name="%s" placeholder="%s" id="%s">',g.field,g.title,g.field)),e.push("</div>"),e.push("</div>"))}return e.push('<div class="form-group">'),e.push('<div class="col-sm-offset-9 col-sm-3">'),e.push(c('<button type="button" id="btnCloseAvd" class="btn btn-default" >%s</button>',b)),e.push("</div>"),e.push("</div>"),e.push("</form>"),e};a.extend(a.fn.bootstrapTable.defaults,{advancedSearch:!1,idForm:"advancedSearch",actionForm:"",idTable:void 0,onColumnAdvancedSearch:function(){return!1}}),a.extend(a.fn.bootstrapTable.defaults.icons,{advancedSearchIcon:"glyphicon-chevron-down"}),a.extend(a.fn.bootstrapTable.Constructor.EVENTS,{"column-advanced-search.bs.table":"onColumnAdvancedSearch"}),a.extend(a.fn.bootstrapTable.locales,{formatAdvancedSearch:function(){return"Advanced search"},formatAdvancedCloseButton:function(){return"Close"}}),a.extend(a.fn.bootstrapTable.defaults,a.fn.bootstrapTable.locales);var g=a.fn.bootstrapTable.Constructor,h=g.prototype.initToolbar,i=g.prototype.load,j=g.prototype.initSearch;g.prototype.initToolbar=function(){if(h.apply(this,Array.prototype.slice.apply(arguments)),this.options.search&&this.options.advancedSearch){var a=this,b=[];b.push(c('<div class="columns columns-%s btn-group pull-%s" role="group">',this.options.buttonsAlign,this.options.buttonsAlign)),b.push(c('<button class="btn btn-default%s" type="button" name="advancedSearch" title="%s">',void 0===a.options.iconSize?"":" btn-"+a.options.iconSize,a.options.formatAdvancedSearch())),b.push(c('<i class="%s %s"></i>',a.options.iconsPrefix,a.options.icons.advancedSearchIcon)),b.push("</button></div>"),a.$toolbar.prepend(b.join("")),a.$toolbar.find('button[name="advancedSearch"]').off("click").on("click",function(){e(a.options.columns,a.options.formatAdvancedSearch(),a.options.formatAdvancedCloseButton(),a)})}},g.prototype.load=function(){if(i.apply(this,Array.prototype.slice.apply(arguments)),"undefined"!=typeof this.options.idTable&&!b){var c=parseInt(a(".bootstrap-table").height());c+=10,a("#"+this.options.idTable).bootstrapTable("resetView",{height:c}),b=!0}},g.prototype.initSearch=function(){j.apply(this,Array.prototype.slice.apply(arguments));var b=this,c=a.isEmptyObject(this.filterColumnsPartial)?null:this.filterColumnsPartial;this.data=c?a.grep(this.data,function(e,f){for(var g in c){var h=c[g].toLowerCase(),i=e[g];if(i=d(b.header,b.header.formatters[a.inArray(g,b.header.fields)],[i,e,f],i),-1===a.inArray(g,b.header.fields)||"string"!=typeof i&&"number"!=typeof i||-1===(i+"").toLowerCase().indexOf(h))return!1}return!0}):this.data},g.prototype.onColumnAdvancedSearch=function(b){var c=a.trim(a(b.currentTarget).val()),d=a(b.currentTarget)[0].id;a.isEmptyObject(this.filterColumnsPartial)&&(this.filterColumnsPartial={}),c?this.filterColumnsPartial[d]=c:delete this.filterColumnsPartial[d],this.options.pageNumber=1,this.onSearch(b),this.updatePagination(),this.trigger("column-advanced-search",d,c)}}(jQuery);
+2
View File
@@ -0,0 +1,2 @@
/*! @source http://purl.eligrey.com/github/FileSaver.js/blob/master/FileSaver.js */
var saveAs=saveAs||function(e){"use strict";if("undefined"==typeof navigator||!/MSIE [1-9]\./.test(navigator.userAgent)){var t=e.document,n=function(){return e.URL||e.webkitURL||e},o=t.createElementNS("http://www.w3.org/1999/xhtml","a"),r="download"in o,i=function(n){var o=t.createEvent("MouseEvents");o.initMouseEvent("click",!0,!1,e,0,0,0,0,0,!1,!1,!1,!1,0,null),n.dispatchEvent(o)},a=e.webkitRequestFileSystem,c=e.requestFileSystem||a||e.mozRequestFileSystem,u=function(t){(e.setImmediate||e.setTimeout)(function(){throw t},0)},f="application/octet-stream",s=0,d=500,l=function(t){var o=function(){"string"==typeof t?n().revokeObjectURL(t):t.remove()};e.chrome?o():setTimeout(o,d)},v=function(e,t,n){t=[].concat(t);for(var o=t.length;o--;){var r=e["on"+t[o]];if("function"==typeof r)try{r.call(e,n||e)}catch(i){u(i)}}},p=function(e){return/^\s*(?:text\/\S*|application\/xml|\S*\/\S*\+xml)\s*;.*charset\s*=\s*utf-8/i.test(e.type)?new Blob(["\ufeff",e],{type:e.type}):e},w=function(t,u){t=p(t);var d,w,y,m=this,S=t.type,h=!1,O=function(){v(m,"writestart progress write writeend".split(" "))},E=function(){if((h||!d)&&(d=n().createObjectURL(t)),w)w.location.href=d;else{var o=e.open(d,"_blank");void 0==o&&"undefined"!=typeof safari&&(e.location.href=d)}m.readyState=m.DONE,O(),l(d)},R=function(e){return function(){return m.readyState!==m.DONE?e.apply(this,arguments):void 0}},b={create:!0,exclusive:!1};return m.readyState=m.INIT,u||(u="download"),r?(d=n().createObjectURL(t),o.href=d,o.download=u,i(o),m.readyState=m.DONE,O(),void l(d)):(e.chrome&&S&&S!==f&&(y=t.slice||t.webkitSlice,t=y.call(t,0,t.size,f),h=!0),a&&"download"!==u&&(u+=".download"),(S===f||a)&&(w=e),c?(s+=t.size,void c(e.TEMPORARY,s,R(function(e){e.root.getDirectory("saved",b,R(function(e){var n=function(){e.getFile(u,b,R(function(e){e.createWriter(R(function(n){n.onwriteend=function(t){w.location.href=e.toURL(),m.readyState=m.DONE,v(m,"writeend",t),l(e)},n.onerror=function(){var e=n.error;e.code!==e.ABORT_ERR&&E()},"writestart progress write abort".split(" ").forEach(function(e){n["on"+e]=m["on"+e]}),n.write(t),m.abort=function(){n.abort(),m.readyState=m.DONE},m.readyState=m.WRITING}),E)}),E)};e.getFile(u,{create:!1},R(function(e){e.remove(),n()}),R(function(e){e.code===e.NOT_FOUND_ERR?n():E()}))}),E)}),E)):void E())},y=w.prototype,m=function(e,t){return new w(e,t)};return"undefined"!=typeof navigator&&navigator.msSaveOrOpenBlob?function(e,t){return navigator.msSaveOrOpenBlob(p(e),t)}:(y.abort=function(){var e=this;e.readyState=e.DONE,v(e,"abort")},y.readyState=y.INIT=0,y.WRITING=1,y.DONE=2,y.error=y.onwritestart=y.onprogress=y.onwrite=y.onabort=y.onerror=y.onwriteend=null,m)}}("undefined"!=typeof self&&self||"undefined"!=typeof window&&window||this.content);"undefined"!=typeof module&&module.exports?module.exports.saveAs=saveAs:"undefined"!=typeof define&&null!==define&&null!=define.amd&&define([],function(){return saveAs});
@@ -0,0 +1,9 @@
Copyright © 2015 [Eli Grey][1].
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
[1]: http://eligrey.com
+22
View File
@@ -0,0 +1,22 @@
Copyright (c) 2012 Niklas von Hertzen
Permission is hereby granted, free of charge, to any person
obtaining a copy of this software and associated documentation
files (the "Software"), to deal in the Software without
restriction, including without limitation the rights to use,
copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the
Software is furnished to do so, subject to the following
conditions:
The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
OTHER DEALINGS IN THE SOFTWARE.
File diff suppressed because one or more lines are too long
@@ -0,0 +1,20 @@
Copyright (c) 2014 Simon Bengtsson, https://github.com/someatoms/jspdf-autotable
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:
The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,418 @@
/**
* jsPDF AutoTable plugin
* Copyright (c) 2014 Simon Bengtsson, https://github.com/someatoms/jsPDF-AutoTable
*
* Licensed under the MIT License.
* http://opensource.org/licenses/mit-license
*/
(function (API) {
'use strict';
// On every new jsPDF object, clear variables
API.events.push(['initialized', function () {
doc = undefined;
cellPos = undefined;
pageCount = 1;
settings = undefined;
}], false);
var MIN_COLUMN_WIDTH = 25;
var doc, cellPos, pageCount = 1, settings;
// See README.md or examples for documentation of the options
// return a new instance every time to avoid references issues
var defaultOptions = function () {
return {
padding: 5,
fontSize: 10,
lineHeight: 20,
renderHeader: function (doc, pageNumber, settings) {
},
renderFooter: function (doc, lastCellPos, pageNumber, settings) {
},
renderHeaderCell: function (x, y, width, height, key, value, settings) {
doc.setFillColor(52, 73, 94); // Asphalt
doc.setTextColor(255, 255, 255);
doc.setFontStyle('bold');
doc.rect(x, y, width, height, 'F');
y += settings.lineHeight / 2 + API.autoTableTextHeight() / 2;
doc.text(value, x + settings.padding, y);
},
renderCell: function (x, y, width, height, key, value, row, settings) {
doc.setFillColor(row % 2 === 0 ? 245 : 255);
doc.setTextColor(50);
doc.rect(x, y, width, height, 'F');
y += settings.lineHeight / 2 + API.autoTableTextHeight() / 2 - 2.5;
doc.text(value, x + settings.padding, y);
},
margins: {right: 40, left: 40, top: 50, bottom: 40},
startY: false,
overflow: 'ellipsize', // false, ellipsize or linebreak (false passes the raw text to renderCell)
overflowColumns: false, // Specify which colums that gets subjected to the overflow method chosen. false indicates all
avoidPageSplit: false,
extendWidth: true
}
};
/**
* Create a table from a set of rows and columns.
*
* @param {Object[]|String[]} columns Either as an array of objects or array of strings
* @param {Object[][]|String[][]} data Either as an array of objects or array of strings
* @param {Object} [options={}] Options that will override the default ones (above)
*/
API.autoTable = function (columns, data, options) {
options = options || {};
columns = columns || [];
doc = this;
var userFontSize = doc.internal.getFontSize();
initData({columns: columns, data: data});
initOptions(options);
cellPos = {
x: settings.margins.left,
y: settings.startY === false ? settings.margins.top : settings.startY
};
var tableHeight = settings.margins.bottom + settings.margins.top + settings.lineHeight * (data.length + 1) + 5 + settings.startY;
if (settings.startY !== false && settings.avoidPageSplit && tableHeight > doc.internal.pageSize.height) {
pageCount++;
doc.addPage();
cellPos.y = settings.margins.top;
}
settings.renderHeader(doc, pageCount, settings);
var columnWidths = calculateColumnWidths(data, columns);
printHeader(columns, columnWidths);
printRows(columns, data, columnWidths);
settings.renderFooter(doc, cellPos, pageCount, settings);
doc.setFontSize(userFontSize);
return this;
};
/**
* Returns the Y position of the last drawn cell
* @returns int
*/
API.autoTableEndPosY = function () {
// If cellPos is not set, autoTable() has probably not been called
return cellPos ? cellPos.y : false;
};
/**
* @deprecated Use autoTableEndPosY()
*/
API.autoTableEndPos = function () {
return cellPos;
};
/**
* Parses an html table. To draw a table, use it like this:
* `doc.autoTable(false, doc.autoTableHtmlToJson(tableDomElem))`
*
* @param table Html table element
* @param indexBased Boolean flag if result should be returned as seperate cols and data
* @returns []|{} Array of objects with object keys as headers or based on indexes if indexBased is set to true
*/
API.autoTableHtmlToJson = function (table, indexBased) {
var data = [], headers = {}, header = table.rows[0], i, tableRow, rowData, j;
if (indexBased) {
headers = [];
for (i = 0; i < header.cells.length; i++) {
headers.push(header.cells[i] ? header.cells[i].textContent : '');
}
for (i = 1; i < table.rows.length; i++) {
tableRow = table.rows[i];
rowData = [];
for (j = 0; j < header.cells.length; j++) {
rowData.push(tableRow.cells[j] ? tableRow.cells[j].textContent : '');
}
data.push(rowData);
}
return {columns: headers, data: data};
} else {
for (i = 0; i < header.cells.length; i++) {
headers[i] = header.cells[i] ? header.cells[i].textContent : '';
}
for (i = 1; i < table.rows.length; i++) {
tableRow = table.rows[i];
rowData = {};
for (j = 0; j < header.cells.length; j++) {
rowData[headers[j]] = tableRow.cells[j] ? tableRow.cells[j].textContent : '';
}
data.push(rowData);
}
return data;
}
};
/**
* Basically the same as getLineHeight() in 1.0+ versions of jsPDF, however
* added here for backwards compatibility with version 0.9
*
* Export it to make it available in drawCell and drawHeaderCell
*/
API.autoTableTextHeight = function() {
// The value 1.15 comes from from the jsPDF source code and looks about right
return doc.internal.getFontSize() * 1.15;
};
/**
* Transform all to the object initialization form
* @param params
*/
function initData(params) {
// Object only initial
if (!params.columns || params.columns.length === 0) {
var keys = Object.keys(params.data[0]);
Array.prototype.push.apply(params.columns, keys);
params.columns.forEach(function (title, i) {
params.columns[i] = {title: title, key: keys[i]};
});
}
// Array initialization form
else if (typeof params.columns[0] === 'string') {
params.data.forEach(function (row, i) {
var obj = {};
for (var j = 0; j < row.length; j++) {
obj[j] = params.data[i][j];
}
params.data[i] = obj;
});
params.columns.forEach(function (title, i) {
params.columns[i] = {title: title, key: i};
});
} else {
// Use options as is
}
}
function initOptions(raw) {
settings = defaultOptions();
Object.keys(raw).forEach(function (key) {
settings[key] = raw[key];
});
doc.setFontSize(settings.fontSize);
// Backwards compatibility
if(settings.margins.horizontal !== undefined) {
settings.margins.left = settings.margins.horizontal;
settings.margins.right = settings.margins.horizontal;
} else {
settings.margins.horizontal = settings.margins.left;
}
}
function calculateColumnWidths(rows, columns) {
var widths = {};
// Optimal widths
var optimalTableWidth = 0;
columns.forEach(function (header) {
var widest = getStringWidth(header.title || '', true);
if(typeof header.width == "number") {
widest = header.width;
} else {
rows.forEach(function (row) {
if (!header.hasOwnProperty('key'))
throw new Error("The key attribute is required in every header");
var w = getStringWidth(stringify(row, header.key));
if (w > widest) {
widest = w;
}
});
}
widths[header.key] = widest;
optimalTableWidth += widest;
});
var paddingAndMargin = settings.padding * 2 * columns.length + settings.margins.left + settings.margins.right;
var spaceDiff = doc.internal.pageSize.width - optimalTableWidth - paddingAndMargin;
var keys = Object.keys(widths);
if (spaceDiff < 0) {
// Shrink columns
var shrinkableColumns = [];
var shrinkableColumnWidths = 0;
if (settings.overflowColumns === false) {
keys.forEach(function (key) {
if (widths[key] > MIN_COLUMN_WIDTH) {
shrinkableColumns.push(key);
shrinkableColumnWidths += widths[key];
}
});
} else {
shrinkableColumns = settings.overflowColumns;
shrinkableColumns.forEach(function (col) {
shrinkableColumnWidths += widths[col];
});
}
shrinkableColumns.forEach(function (key) {
widths[key] += spaceDiff * (widths[key] / shrinkableColumnWidths);
});
} else if (spaceDiff > 0 && settings.extendWidth) {
// Fill page horizontally
keys.forEach(function (key) {
widths[key] += spaceDiff / keys.length;
});
}
return widths;
}
function printHeader(headers, columnWidths) {
if (!headers) return;
// First calculate the height of the row
// (to do that the maxium amount of rows first need to be found)
var maxRows = 1;
if (settings.overflow === 'linebreak') {
// Font style must be the same as in function renderHeaderCell()
doc.setFontStyle('bold');
headers.forEach(function (header) {
if (isOverflowColumn(header)) {
var value = header.title || '';
var arr = doc.splitTextToSize(value, columnWidths[header.key]);
if (arr.length > maxRows) {
maxRows = arr.length;
}
}
});
}
var rowHeight = settings.lineHeight + (maxRows - 1) * API.autoTableTextHeight() + 5;
// Avoid isolated table headers when drawing multiple tables. Add a new page
// if cellpos would be at the end of page after drawing the header row
var newPage = (cellPos.y + settings.margins.bottom + rowHeight * 2) >= doc.internal.pageSize.height;
if (newPage) {
settings.renderFooter(doc, cellPos, pageCount, settings);
doc.addPage();
cellPos = {x: settings.margins.left, y: settings.margins.top};
pageCount++;
settings.renderHeader(doc, pageCount, settings);
}
headers.forEach(function (header) {
var width = columnWidths[header.key] + settings.padding * 2;
var value = header.title || '';
if (settings.overflow === 'linebreak') {
if (isOverflowColumn(header)) {
value = doc.splitTextToSize(value, columnWidths[header.key]);
}
} else if (settings.overflow === 'ellipsize') {
value = ellipsize(columnWidths[header.key], value);
}
settings.renderHeaderCell(cellPos.x, cellPos.y, width, rowHeight, header.key, value, settings);
cellPos.x += width;
});
doc.setTextColor(70, 70, 70);
doc.setFontStyle('normal');
cellPos.y += rowHeight;
cellPos.x = settings.margins.left;
}
function printRows(headers, rows, columnWidths) {
for (var i = 0; i < rows.length; i++) {
var row = rows[i];
// First calculate the height of the row
// (to do that the maxium amount of rows first need to be found)
var maxRows = 1;
if (settings.overflow === 'linebreak') {
headers.forEach(function (header) {
if (isOverflowColumn(header)) {
var value = stringify(row, header.key);
var arr = doc.splitTextToSize(value, columnWidths[header.key]);
if (arr.length > maxRows) {
maxRows = arr.length;
}
}
});
}
var rowHeight = settings.lineHeight + (maxRows - 1) * API.autoTableTextHeight();
// Render the cell
headers.forEach(function (header) {
var value = stringify(row, header.key);
if (settings.overflow === 'linebreak') {
if (isOverflowColumn(header)) {
value = doc.splitTextToSize(value, columnWidths[header.key]);
}
} else if (settings.overflow === 'ellipsize') {
value = ellipsize(columnWidths[header.key], value);
}
var width = columnWidths[header.key] + settings.padding * 2;
settings.renderCell(cellPos.x, cellPos.y, width, rowHeight, header.key, value, i, settings);
cellPos.x = cellPos.x + columnWidths[header.key] + settings.padding * 2;
});
// Add a new page if cellpos is at the end of page
var newPage = (cellPos.y + settings.margins.bottom + rowHeight * 2) >= doc.internal.pageSize.height;
if (newPage) {
if (i+1 < rows.length) {
settings.renderFooter(doc, cellPos, pageCount, settings);
doc.addPage();
cellPos = {x: settings.margins.left, y: settings.margins.top};
pageCount++;
settings.renderHeader(doc, pageCount, settings);
printHeader(headers, columnWidths);
}
} else {
cellPos.y += rowHeight;
cellPos.x = settings.margins.left;
}
}
}
function isOverflowColumn(header) {
return settings.overflowColumns === false || settings.overflowColumns.indexOf(header.key) !== -1;
}
/**
* Ellipsize the text to fit in the width
* @param width
* @param text
*/
function ellipsize(width, text) {
if (width >= getStringWidth(text)) {
return text;
}
while (width < getStringWidth(text + "...")) {
if (text.length < 2) {
break;
}
text = text.substring(0, text.length - 1);
}
text += "...";
return text;
}
function stringify(row, key) {
return row.hasOwnProperty(key) ? '' + row[key] : '';
}
function getStringWidth(txt, isBold) {
if(isBold) {
doc.setFontStyle('bold');
}
var strWidth = doc.getStringUnitWidth(txt) * doc.internal.getFontSize();
if(isBold) {
doc.setFontStyle('normal');
}
return strWidth;
}
})(jsPDF.API);
@@ -0,0 +1,20 @@
Copyright (c) 2010-2014 James Hall, https://github.com/MrRio/jsPDF
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:
The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
File diff suppressed because one or more lines are too long