diff --git a/dist/jquery.bootgrid.js b/dist/jquery.bootgrid.js index 4f27d44..fa7e367 100644 --- a/dist/jquery.bootgrid.js +++ b/dist/jquery.bootgrid.js @@ -3,8 +3,7 @@ * Copyright (c) 2014-2015 Rafael Staib (http://www.jquery-bootgrid.com) * Licensed under MIT http://www.opensource.org/licenses/MIT */ -;(function ($, window, undefined) -{ +;(function ($, window, undefined) { /*jshint validthis: true */ "use strict"; @@ -16,17 +15,14 @@ // GRID INTERNAL FUNCTIONS // ===================== - function appendRow(row) - { + function appendRow(row) { var that = this; - function exists(item) - { + function exists(item) { return that.identifier && item[that.identifier] === row[that.identifier]; } - if (!this.rows.contains(exists)) - { + if (!this.rows.contains(exists)) { this.rows.push(row); return true; } @@ -34,21 +30,18 @@ return false; } - function findFooterAndHeaderItems(selector) - { + function findFooterAndHeaderItems(selector) { var footer = (this.footer) ? this.footer.find(selector) : $(), header = (this.header) ? this.header.find(selector) : $(); return $.merge(footer, header); } - function getParams(context) - { - return (context) ? $.extend({}, this.cachedParams, { ctx: context }) : + function getParams(context) { + return (context) ? $.extend({}, this.cachedParams, {ctx: context}) : this.cachedParams; } - function getRequest() - { + function getRequest() { var request = { current: this.current, rowCount: this.rowCount, @@ -61,19 +54,16 @@ return this.options.requestHandler($.extend(true, request, post)); } - function getCssSelector(css) - { + function getCssSelector(css) { return "." + $.trim(css).replace(/\s+/gm, "."); } - function getUrl() - { + function getUrl() { var url = this.options.url; return ($.isFunction(url)) ? url() : url; } - function init() - { + function init() { this.element.trigger("initialize" + namespace); loadColumns.call(this); // Loads columns from HTML thead tag @@ -88,28 +78,23 @@ this.element.trigger("initialized" + namespace); } - function highlightAppendedRows(rows) - { - if (this.options.highlightRows) - { + function highlightAppendedRows(rows) { + if (this.options.highlightRows) { // todo: implement } } - function isVisible(column) - { + function isVisible(column) { return column.visible; } - function loadColumns() - { + function loadColumns() { var that = this, firstHeadRow = this.element.find("thead > tr").first(), sorted = false; /*jshint -W018*/ - firstHeadRow.children().each(function () - { + firstHeadRow.children().each(function () { var $this = $(this), data = $this.data(), column = { @@ -127,25 +112,22 @@ sortable: !(data.sortable === false), // default: true visible: !(data.visible === false), // default: true visibleInSelection: !(data.visibleInSelection === false), // default: true - width: ($.isNumeric(data.width)) ? data.width + "px" : + width: ($.isNumeric(data.width)) ? data.width + "px" : (typeof(data.width) === "string") ? data.width : null }; that.columns.push(column); - if (column.order != null) - { + if (column.order != null) { that.sortDictionary[column.id] = column.order; } // Prevents multiple identifiers - if (column.identifier) - { + if (column.identifier) { that.identifier = column.id; that.converter = column.converter; } // ensures that only the first order will be applied in case of multi sorting is disabled - if (!that.options.multiSort && column.order !== null) - { + if (!that.options.multiSort && column.order !== null) { sorted = true; } }); @@ -153,47 +135,103 @@ } /* - response = { - current: 1, - rowCount: 10, - rows: [{}, {}], - sort: [{ "columnId": "asc" }], - total: 101 - } - */ - - function loadData() - { + response = { + current: 1, + rowCount: 10, + rows: [{}, {}], + sort: [{ "columnId": "asc" }], + total: 101 + } + */ + + function loadData() { var that = this; this.element._bgBusyAria(true).trigger("load" + namespace); showLoading.call(this); - function containsPhrase(row) - { + function containsPhrase(row) { + var innerMatch = false; + var outerMatch = true; + var searchMatch = false; + var constraintsMatch = false; + if (Object.keys(that.searchParams).length > 0) { //if there are search parameters + for (var index = 0; index < that.columns.length; index++) { //check each column + innerMatch = false; + column = that.columns[index]; + if (column.searchable) { //only if the column is searchable + if (that.searchParams[index.toString()] != null) { //if there is a search parameter on this column + var phraseNum; + if (that.constraints[index.toString()] != null){ //if there is a constraint on that column + innerMatch = true; + for (phraseNum = that.searchParams[index.toString()].length - 1; phraseNum >= 0; phraseNum--) { + constraintsMatch = false; + if (that.constraints[index.toString()][phraseNum] == "greater") { //if the constraint it "greater" + //if the things to be equated are numbers, they are cast to numbers before being checked + if (!isNaN(Number(row[column.id])) && !isNaN(Number(that.searchParams[index.toString()][phraseNum]))) { + if (Number(row[column.id]) >= Number(that.searchParams[index.toString()][phraseNum])) { + constraintsMatch = true; + } + } + else { + if (row[column.id] >= that.searchParams[index.toString()][phraseNum]) { + constraintsMatch = true; + } + } + } + else { + if (!isNaN(Number(row[column.id])) && !isNaN(Number(that.searchParams[index.toString()][phraseNum]))) { + if (Number(row[column.id]) <= Number(that.searchParams[index.toString()][phraseNum])) { + constraintsMatch = true; + } + } + else { + if (row[column.id] <= that.searchParams[index.toString()][phraseNum]) { + constraintsMatch = true; + } + } + } //Check that all the search parameters for the column are true + innerMatch = innerMatch && constraintsMatch; + } + + } + //if there are no contraints on that column + else { + for (phraseNum = that.searchParams[index.toString()].length - 1; phraseNum >= 0; phraseNum--) { + searchPattern = new RegExp(that.searchParams[index.toString()][phraseNum], (that.options.caseSensitive) ? "g" : "gi"); + if (column.converter.to(row[column.id]).search(searchPattern) > -1) { + innerMatch = true; + break; + } + } + } + //Make sure all the searchParams are true + outerMatch = outerMatch && innerMatch; + } + } + + } + } var column, searchPattern = new RegExp(that.searchPhrase, (that.options.caseSensitive) ? "g" : "gi"); - for (var i = 0; i < that.columns.length; i++) - { + for (var i = 0; i < that.columns.length; i++) { column = that.columns[i]; if (column.searchable && column.visible && - column.converter.to(row[column.id]).search(searchPattern) > -1) - { - return true; + column.converter.to(row[column.id]).search(searchPattern) > -1) { + searchMatch = true; } } - return false; + //Return whether the column searchParams matched and the search bar itself match + return (outerMatch && searchMatch); } - function update(rows, total) - { + function update(rows, total) { that.currentRows = rows; setTotals.call(that, total); - if (!that.options.keepSelection) - { + if (!that.options.keepSelection) { that.selectedRows = []; } @@ -204,31 +242,26 @@ that.element._bgBusyAria(false).trigger("loaded" + namespace); } - if (this.options.ajax) - { + if (this.options.ajax) { var request = getRequest.call(this), url = getUrl.call(this); - if (url == null || typeof url !== "string" || url.length === 0) - { + if (url == null || typeof url !== "string" || url.length === 0) { throw new Error("Url setting must be a none empty string or a function that returns one."); } // aborts the previous ajax request if not already finished or failed - if (this.xqr) - { + if (this.xqr) { this.xqr.abort(); } var settings = { url: url, data: request, - success: function(response) - { + success: function (response) { that.xqr = null; - if (typeof (response) === "string") - { + if (typeof (response) === "string") { response = $.parseJSON(response); } @@ -237,12 +270,10 @@ that.current = response.current; update(response.rows, response.total); }, - error: function (jqXHR, textStatus, errorThrown) - { + error: function (jqXHR, textStatus, errorThrown) { that.xqr = null; - if (textStatus !== "abort") - { + if (textStatus !== "abort") { renderNoResultsRow.call(that); // overrides loading mask that.element._bgBusyAria(false).trigger("loaded" + namespace); } @@ -252,36 +283,51 @@ this.xqr = $.ajax(settings); } - else - { - var rows = (this.searchPhrase.length > 0) ? this.rows.where(containsPhrase) : this.rows, - total = rows.length; - if (this.rowCount !== -1) - { + else { + var rows = (this.searchPhrase.length > 0 || Object.keys(that.searchParams).length > 0) ? this.rows.where(containsPhrase) : this.rows; + if (this.subtree) { + rows.forEach(function (currentValue, index, array) { + var checkRow = currentValue; + var re = new RegExp("^" + checkRow[this.identifier] + ".*"); + this.rows.forEach(function (currentValue, index, array) { + if (re.test(currentValue[this.identifier]) && rows.indexOf(currentValue) < 0) { + rows.push(currentValue); + } + }, this); + }, this); + var empty = true; + for (var field in this.sortDictionary){ + empty = false; + break; + } + if (empty){ + rows.sort(this.defaultSort); + } + } + var total = rows.length; + if (this.rowCount !== -1) { rows = rows.page(this.current, this.rowCount); } // todo: improve the following comment // setTimeout decouples the initialization so that adding event handlers happens before - window.setTimeout(function () { update(rows, total); }, 10); + window.setTimeout(function () { + update(rows, total); + }, 10); } } - function loadRows() - { - if (!this.options.ajax) - { + function loadRows() { + if (!this.options.ajax) { var that = this, rows = this.element.find("tbody > tr"); - rows.each(function () - { + rows.each(function () { var $this = $(this), cells = $this.children("td"), row = {}; - $.each(that.columns, function (i, column) - { + $.each(that.columns, function (i, column) { row[column.id] = column.converter.from(cells.eq(i).text()); }); @@ -293,15 +339,13 @@ } } - function setTotals(total) - { + function setTotals(total) { this.total = total; this.totalPages = (this.rowCount === -1) ? 1 : Math.ceil(this.total / this.rowCount); } - function prepareTable() - { + function prepareTable() { var tpl = this.options.templates, wrapper = (this.element.parent().hasClass(this.options.css.responsiveTable)) ? this.element.parent() : this.element; @@ -309,46 +353,38 @@ this.element.addClass(this.options.css.table); // checks whether there is an tbody element; otherwise creates one - if (this.element.children("tbody").length === 0) - { + if (this.element.children("tbody").length === 0) { this.element.append(tpl.body); } - if (this.options.navigation & 1) - { - this.header = $(tpl.header.resolve(getParams.call(this, { id: this.element._bgId() + "-header" }))); + if (this.options.navigation & 1) { + this.header = $(tpl.header.resolve(getParams.call(this, {id: this.element._bgId() + "-header"}))); wrapper.before(this.header); } - if (this.options.navigation & 2) - { - this.footer = $(tpl.footer.resolve(getParams.call(this, { id: this.element._bgId() + "-footer" }))); + if (this.options.navigation & 2) { + this.footer = $(tpl.footer.resolve(getParams.call(this, {id: this.element._bgId() + "-footer"}))); wrapper.after(this.footer); } } - function renderActions() - { - if (this.options.navigation !== 0) - { + function renderActions() { + if (this.options.navigation !== 0) { var css = this.options.css, selector = getCssSelector(css.actions), actionItems = findFooterAndHeaderItems.call(this, selector); - if (actionItems.length > 0) - { + if (actionItems.length > 0) { var that = this, tpl = this.options.templates, actions = $(tpl.actions.resolve(getParams.call(this))); // Refresh Button - if (this.options.ajax) - { - var refreshIcon = tpl.icon.resolve(getParams.call(this, { iconCss: css.iconRefresh })), + if (this.options.ajax) { + var refreshIcon = tpl.icon.resolve(getParams.call(this, {iconCss: css.iconRefresh})), refresh = $(tpl.actionButton.resolve(getParams.call(this, - { content: refreshIcon, text: this.options.labels.refresh }))) - .on("click" + namespace, function (e) - { + {content: refreshIcon, text: this.options.labels.refresh}))) + .on("click" + namespace, function (e) { // todo: prevent multiple fast clicks (fast click detection) e.stopPropagation(); that.current = 1; @@ -368,43 +404,37 @@ } } - function renderColumnSelection(actions) - { - if (this.options.columnSelection && this.columns.length > 1) - { + function renderColumnSelection(actions) { + if (this.options.columnSelection && this.columns.length > 1) { var that = this, css = this.options.css, tpl = this.options.templates, - icon = tpl.icon.resolve(getParams.call(this, { iconCss: css.iconColumns })), - dropDown = $(tpl.actionDropDown.resolve(getParams.call(this, { content: icon }))), + icon = tpl.icon.resolve(getParams.call(this, {iconCss: css.iconColumns})), + dropDown = $(tpl.actionDropDown.resolve(getParams.call(this, {content: icon}))), selector = getCssSelector(css.dropDownItem), checkboxSelector = getCssSelector(css.dropDownItemCheckbox), itemsSelector = getCssSelector(css.dropDownMenuItems); - $.each(this.columns, function (i, column) - { - if (column.visibleInSelection) - { + $.each(this.columns, function (i, column) { + if (column.visibleInSelection) { var item = $(tpl.actionDropDownCheckboxItem.resolve(getParams.call(that, - { name: column.id, label: column.text, checked: column.visible }))) - .on("click" + namespace, selector, function (e) - { - e.stopPropagation(); - - var $this = $(this), - checkbox = $this.find(checkboxSelector); - if (!checkbox.prop("disabled")) - { - column.visible = checkbox.prop("checked"); - var enable = that.columns.where(isVisible).length > 1; - $this.parents(itemsSelector).find(selector + ":has(" + checkboxSelector + ":checked)") - ._bgEnableAria(enable).find(checkboxSelector)._bgEnableField(enable); - - that.element.find("tbody").empty(); // Fixes an column visualization bug - renderTableHeader.call(that); - loadData.call(that); - } - }); + {name: column.id, label: column.text, checked: column.visible}))) + .on("click" + namespace, selector, function (e) { + e.stopPropagation(); + + var $this = $(this), + checkbox = $this.find(checkboxSelector); + if (!checkbox.prop("disabled")) { + column.visible = checkbox.prop("checked"); + var enable = that.columns.where(isVisible).length > 1; + $this.parents(itemsSelector).find(selector + ":has(" + checkboxSelector + ":checked)") + ._bgEnableAria(enable).find(checkboxSelector)._bgEnableField(enable); + + that.element.find("tbody").empty(); // Fixes an column visualization bug + renderTableHeader.call(that); + loadData.call(that); + } + }); dropDown.find(getCssSelector(css.dropDownMenuItems)).append(item); } }); @@ -412,15 +442,12 @@ } } - function renderInfos() - { - if (this.options.navigation !== 0) - { + function renderInfos() { + if (this.options.navigation !== 0) { var selector = getCssSelector(this.options.css.infos), infoItems = findFooterAndHeaderItems.call(this, selector); - if (infoItems.length > 0) - { + if (infoItems.length > 0) { var end = (this.current * this.rowCount), infos = $(this.options.templates.infos.resolve(getParams.call(this, { end: (this.total === 0 || end === -1 || end > this.total) ? this.total : end, @@ -433,28 +460,23 @@ } } - function renderNoResultsRow() - { + function renderNoResultsRow() { var tbody = this.element.children("tbody").first(), tpl = this.options.templates, count = this.columns.where(isVisible).length; - if (this.selection) - { + if (this.selection) { count = count + 1; } - tbody.html(tpl.noResults.resolve(getParams.call(this, { columns: count }))); + tbody.html(tpl.noResults.resolve(getParams.call(this, {columns: count}))); } - function renderPagination() - { - if (this.options.navigation !== 0) - { + function renderPagination() { + if (this.options.navigation !== 0) { var selector = getCssSelector(this.options.css.pagination), paginationItems = findFooterAndHeaderItems.call(this, selector)._bgShowAria(this.rowCount !== -1); - if (this.rowCount !== -1 && paginationItems.length > 0) - { + if (this.rowCount !== -1 && paginationItems.length > 0) { var tpl = this.options.templates, current = this.current, totalPages = this.totalPages, @@ -472,15 +494,13 @@ renderPaginationItem.call(this, pagination, "prev", "<", "prev") ._bgEnableAria(current > 1); - for (var i = 0; i < count; i++) - { + for (var i = 0; i < count; i++) { var pos = i + startWith; renderPaginationItem.call(this, pagination, pos, pos, "page-" + pos) ._bgEnableAria()._bgSelectAria(pos === current); } - if (count === 0) - { + if (count === 0) { renderPaginationItem.call(this, pagination, 1, 1, "page-" + 1) ._bgEnableAria(false)._bgSelectAria(); } @@ -495,22 +515,19 @@ } } - function renderPaginationItem(list, page, text, markerCss) - { + function renderPaginationItem(list, page, text, markerCss) { var that = this, tpl = this.options.templates, css = this.options.css, - values = getParams.call(this, { css: markerCss, text: text, page: page }), + values = getParams.call(this, {css: markerCss, text: text, page: page}), item = $(tpl.paginationItem.resolve(values)) - .on("click" + namespace, getCssSelector(css.paginationButton), function (e) - { + .on("click" + namespace, getCssSelector(css.paginationButton), function (e) { e.stopPropagation(); e.preventDefault(); var $this = $(this), parent = $this.parent(); - if (!parent.hasClass("active") && !parent.hasClass("disabled")) - { + if (!parent.hasClass("active") && !parent.hasClass("disabled")) { var commandList = { first: 1, prev: that.current - 1, @@ -528,62 +545,53 @@ return item; } - function renderRowCountSelection(actions) - { + function renderRowCountSelection(actions) { var that = this, rowCountList = this.options.rowCount; - function getText(value) - { + function getText(value) { return (value === -1) ? that.options.labels.all : value; } - if ($.isArray(rowCountList)) - { + if ($.isArray(rowCountList)) { var css = this.options.css, tpl = this.options.templates, - dropDown = $(tpl.actionDropDown.resolve(getParams.call(this, { content: getText(this.rowCount) }))), + dropDown = $(tpl.actionDropDown.resolve(getParams.call(this, {content: getText(this.rowCount)}))), menuSelector = getCssSelector(css.dropDownMenu), menuTextSelector = getCssSelector(css.dropDownMenuText), menuItemsSelector = getCssSelector(css.dropDownMenuItems), menuItemSelector = getCssSelector(css.dropDownItemButton); - $.each(rowCountList, function (index, value) - { + $.each(rowCountList, function (index, value) { var item = $(tpl.actionDropDownItem.resolve(getParams.call(that, - { text: getText(value), action: value }))) - ._bgSelectAria(value === that.rowCount) - .on("click" + namespace, menuItemSelector, function (e) - { - e.preventDefault(); - - var $this = $(this), - newRowCount = $this.data("action"); - if (newRowCount !== that.rowCount) - { - // todo: sophisticated solution needed for calculating which page is selected - that.current = 1; // that.rowCount === -1 ---> All - that.rowCount = newRowCount; - $this.parents(menuItemsSelector).children().each(function () - { - var $item = $(this), - currentRowCount = $item.find(menuItemSelector).data("action"); - $item._bgSelectAria(currentRowCount === newRowCount); - }); - $this.parents(menuSelector).find(menuTextSelector).text(getText(newRowCount)); - loadData.call(that); - } - }); + {text: getText(value), action: value}))) + ._bgSelectAria(value === that.rowCount) + .on("click" + namespace, menuItemSelector, function (e) { + e.preventDefault(); + + var $this = $(this), + newRowCount = $this.data("action"); + if (newRowCount !== that.rowCount) { + // todo: sophisticated solution needed for calculating which page is selected + that.current = 1; // that.rowCount === -1 ---> All + that.rowCount = newRowCount; + $this.parents(menuItemsSelector).children().each(function () { + var $item = $(this), + currentRowCount = $item.find(menuItemSelector).data("action"); + $item._bgSelectAria(currentRowCount === newRowCount); + }); + $this.parents(menuSelector).find(menuTextSelector).text(getText(newRowCount)); + loadData.call(that); + } + }); dropDown.find(menuItemsSelector).append(item); }); actions.append(dropDown); } } - function renderRows(rows) - { - if (rows.length > 0) - { + function renderRows(rows) { + if (rows.length > 0) { var that = this, css = this.options.css, tpl = this.options.templates, @@ -591,53 +599,47 @@ allRowsSelected = true, html = ""; - $.each(rows, function (index, row) - { + $.each(rows, function (index, row) { var cells = "", rowAttr = " data-row-id=\"" + ((that.identifier == null) ? index : row[that.identifier]) + "\"", rowCss = ""; - if (that.selection) - { + if (that.selection) { var selected = ($.inArray(row[that.identifier], that.selectedRows) !== -1), selectBox = tpl.select.resolve(getParams.call(that, - { type: "checkbox", value: row[that.identifier], checked: selected })); - cells += tpl.cell.resolve(getParams.call(that, { content: selectBox, css: css.selectCell })); + {type: "checkbox", value: row[that.identifier], checked: selected})); + cells += tpl.cell.resolve(getParams.call(that, {content: selectBox, css: css.selectCell})); allRowsSelected = (allRowsSelected && selected); - if (selected) - { + if (selected) { rowCss += css.selected; rowAttr += " aria-selected=\"true\""; } } var status = row.status != null && that.options.statusMapping[row.status]; - if (status) - { + if (status) { rowCss += status; } - $.each(that.columns, function (j, column) - { - if (column.visible) - { + $.each(that.columns, function (j, column) { + if (column.visible) { var value = ($.isFunction(column.formatter)) ? column.formatter.call(that, column, row) : - column.converter.to(row[column.id]), + column.converter.to(row[column.id]), cssClass = (column.cssClass.length > 0) ? " " + column.cssClass : ""; cells += tpl.cell.resolve(getParams.call(that, { content: (value == null || value === "") ? " " : value, css: ((column.align === "right") ? css.right : (column.align === "center") ? css.center : css.left) + cssClass, - style: (column.width == null) ? "" : "width:" + column.width + ";" })); + style: (column.width == null) ? "" : "width:" + column.width + ";" + })); } }); - if (rowCss.length > 0) - { + if (rowCss.length > 0) { rowAttr += " class=\"" + rowCss + "\""; } - html += tpl.row.resolve(getParams.call(that, { attr: rowAttr, cells: cells })); + html += tpl.row.resolve(getParams.call(that, {attr: rowAttr, cells: cells})); }); // sets or clears multi selectbox state @@ -648,57 +650,49 @@ registerRowEvents.call(this, tbody); } - else - { + else { renderNoResultsRow.call(this); } } - function registerRowEvents(tbody) - { + function registerRowEvents(tbody) { var that = this, selectBoxSelector = getCssSelector(this.options.css.selectBox); - if (this.selection) - { + if (this.selection) { tbody.off("click" + namespace, selectBoxSelector) - .on("click" + namespace, selectBoxSelector, function(e) - { + .on("click" + namespace, selectBoxSelector, function (e) { e.stopPropagation(); var $this = $(this), id = that.converter.from($this.val()); - if ($this.prop("checked")) - { + if ($this.prop("checked")) { that.select([id]); } - else - { + else { that.deselect([id]); } }); } tbody.off("click" + namespace, "> tr") - .on("click" + namespace, "> tr", function(e) - { + .on("click" + namespace, "> tr", function (e) { e.stopPropagation(); var $this = $(this), id = (that.identifier == null) ? $this.data("row-id") : that.converter.from($this.data("row-id") + ""), row = (that.identifier == null) ? that.currentRows[id] : - that.currentRows.first(function (item) { return item[that.identifier] === id; }); + that.currentRows.first(function (item) { + return item[that.identifier] === id; + }); - if (that.selection && that.options.rowSelect) - { - if ($this.hasClass(that.options.css.selected)) - { + if (that.selection && that.options.rowSelect) { + if ($this.hasClass(that.options.css.selected)) { that.deselect([id]); } - else - { + else { that.select([id]); } } @@ -707,16 +701,13 @@ }); } - function renderSearchField() - { - if (this.options.navigation !== 0) - { + function renderSearchField() { + if (this.options.navigation !== 0) { var css = this.options.css, selector = getCssSelector(css.search), searchItems = findFooterAndHeaderItems.call(this, selector); - if (searchItems.length > 0) - { + if (searchItems.length > 0) { var that = this, tpl = this.options.templates, timer = null, // fast keyup detection @@ -726,18 +717,14 @@ searchField = (search.is(searchFieldSelector)) ? search : search.find(searchFieldSelector); - searchField.on("keyup" + namespace, function (e) - { + searchField.on("keyup" + namespace, function (e) { e.stopPropagation(); var newValue = $(this).val(); - if (currentValue !== newValue || (e.which === 13 && newValue !== "")) - { + if (currentValue !== newValue || (e.which === 13 && newValue !== "")) { currentValue = newValue; - if (e.which === 13 || newValue.length === 0 || newValue.length >= that.options.searchSettings.characters) - { + if (e.which === 13 || newValue.length === 0 || newValue.length >= that.options.searchSettings.characters) { window.clearTimeout(timer); - timer = window.setTimeout(function () - { + timer = window.setTimeout(function () { executeSearch.call(that, newValue); }, that.options.searchSettings.delay); } @@ -749,18 +736,21 @@ } } - function executeSearch(phrase) - { - if (this.searchPhrase !== phrase) - { + function executeSearch(phrase) { + if (this.searchPhrase !== phrase) { this.current = 1; this.searchPhrase = phrase; loadData.call(this); } } - function renderTableHeader() - { + function executeSearchByParams() { + this.current = 1; + loadData.call(this); + } + + + function renderTableHeader() { var that = this, headerRow = this.element.find("thead > tr"), css = this.options.css, @@ -768,40 +758,38 @@ html = "", sorting = this.options.sorting; - if (this.selection) - { + if (this.selection) { var selectBox = (this.options.multiSelect) ? - tpl.select.resolve(getParams.call(that, { type: "checkbox", value: "all" })) : ""; - html += tpl.rawHeaderCell.resolve(getParams.call(that, { content: selectBox, - css: css.selectCell })); + tpl.select.resolve(getParams.call(that, {type: "checkbox", value: "all"})) : ""; + html += tpl.rawHeaderCell.resolve(getParams.call(that, { + content: selectBox, + css: css.selectCell + })); } - $.each(this.columns, function (index, column) - { - if (column.visible) - { + $.each(this.columns, function (index, column) { + if (column.visible) { var sortOrder = that.sortDictionary[column.id], iconCss = ((sorting && sortOrder && sortOrder === "asc") ? css.iconUp : (sorting && sortOrder && sortOrder === "desc") ? css.iconDown : ""), - icon = tpl.icon.resolve(getParams.call(that, { iconCss: iconCss })), + icon = tpl.icon.resolve(getParams.call(that, {iconCss: iconCss})), align = column.headerAlign, cssClass = (column.headerCssClass.length > 0) ? " " + column.headerCssClass : ""; html += tpl.headerCell.resolve(getParams.call(that, { column: column, icon: icon, sortable: sorting && column.sortable && css.sortable || "", css: ((align === "right") ? css.right : (align === "center") ? css.center : css.left) + cssClass, - style: (column.width == null) ? "" : "width:" + column.width + ";" })); + style: (column.width == null) ? "" : "width:" + column.width + ";" + })); } }); headerRow.html(html); - if (sorting) - { + if (sorting) { var sortingSelector = getCssSelector(css.sortable); headerRow.off("click" + namespace, sortingSelector) - .on("click" + namespace, sortingSelector, function (e) - { + .on("click" + namespace, sortingSelector, function (e) { e.preventDefault(); setTableHeaderSortDirection.call(that, $(this)); @@ -811,90 +799,72 @@ } // todo: create a own function for that piece of code - if (this.selection && this.options.multiSelect) - { + if (this.selection && this.options.multiSelect) { var selectBoxSelector = getCssSelector(css.selectBox); headerRow.off("click" + namespace, selectBoxSelector) - .on("click" + namespace, selectBoxSelector, function(e) - { + .on("click" + namespace, selectBoxSelector, function (e) { e.stopPropagation(); - if ($(this).prop("checked")) - { + if ($(this).prop("checked")) { that.select(); } - else - { + else { that.deselect(); } }); } } - function setTableHeaderSortDirection(element) - { + function setTableHeaderSortDirection(element) { var css = this.options.css, iconSelector = getCssSelector(css.icon), columnId = element.data("column-id") || element.parents("th").first().data("column-id"), sortOrder = this.sortDictionary[columnId], icon = element.find(iconSelector); - if (!this.options.multiSort) - { + if (!this.options.multiSort) { element.parents("tr").first().find(iconSelector).removeClass(css.iconDown + " " + css.iconUp); this.sortDictionary = {}; } - if (sortOrder && sortOrder === "asc") - { + if (sortOrder && sortOrder === "asc") { this.sortDictionary[columnId] = "desc"; icon.removeClass(css.iconUp).addClass(css.iconDown); } - else if (sortOrder && sortOrder === "desc") - { - if (this.options.multiSort) - { + else if (sortOrder && sortOrder === "desc") { + if (this.options.multiSort) { var newSort = {}; - for (var key in this.sortDictionary) - { - if (key !== columnId) - { + for (var key in this.sortDictionary) { + if (key !== columnId) { newSort[key] = this.sortDictionary[key]; } } this.sortDictionary = newSort; icon.removeClass(css.iconDown); } - else - { + else { this.sortDictionary[columnId] = "asc"; icon.removeClass(css.iconDown).addClass(css.iconUp); } } - else - { + else { this.sortDictionary[columnId] = "asc"; icon.addClass(css.iconUp); } } - function replacePlaceHolder(placeholder, element) - { - placeholder.each(function (index, item) - { + function replacePlaceHolder(placeholder, element) { + placeholder.each(function (index, item) { // todo: check how append is implemented. Perhaps cloning here is superfluous. $(item).before(element.clone(true)).remove(); }); } - function showLoading() - { + function showLoading() { var that = this; - window.setTimeout(function() - { - if (that.element._bgAria("busy") === "true") - { + window.setTimeout(function () { + if (that.element._bgAria("busy") === "true") { var tpl = that.options.templates, thead = that.element.children("thead").first(), tbody = that.element.children("tbody").first(), @@ -902,31 +872,26 @@ padding = (that.element.height() - thead.height()) - (firstCell.height() + 20), count = that.columns.where(isVisible).length; - if (that.selection) - { + if (that.selection) { count = count + 1; } - tbody.html(tpl.loading.resolve(getParams.call(that, { columns: count }))); - if (that.rowCount !== -1 && padding > 0) - { + tbody.html(tpl.loading.resolve(getParams.call(that, {columns: count}))); + if (that.rowCount !== -1 && padding > 0) { tbody.find("tr > td").css("padding", "20px 0 " + padding + "px"); } } }, 250); } - function sortRows() - { + function sortRows() { var sortArray = []; - function sort(x, y, current) - { + function sort(x, y, current) { current = current || 0; var next = current + 1, item = sortArray[current]; - function sortOrder(value) - { + function sortOrder(value) { return (item.order === "asc") ? value : value * -1; } @@ -935,14 +900,11 @@ (sortArray.length > next) ? sort(x, y, next) : 0; } - if (!this.options.ajax) - { + if (!this.options.ajax) { var that = this; - for (var key in this.sortDictionary) - { - if (this.options.multiSort || sortArray.length === 0) - { + for (var key in this.sortDictionary) { + if (this.options.multiSort || sortArray.length === 0) { sortArray.push({ id: key, order: this.sortDictionary[key] @@ -950,13 +912,13 @@ } } - if (sortArray.length > 0) - { + if (sortArray.length > 0) { this.rows.sort(sort); } } } + // GRID PUBLIC CLASS DEFINITION // ==================== @@ -969,8 +931,7 @@ * @param options {Object} The options to override default settings. * @chainable **/ - var Grid = function(element, options) - { + var Grid = function (element, options) { this.element = $(element); this.origin = this.element.clone(); this.options = $.extend(true, {}, Grid.defaults, this.element.data(), options); @@ -997,6 +958,10 @@ this.header = null; this.footer = null; this.xqr = null; + this.searchParams = {}; //The array of search parameters + this.constraints = {}; //The array of column constraints + this.subtree = false; //Whether to display subtrees + this.defaultSort = null; //The modified default sort order // todo: implement cache }; @@ -1087,7 +1052,7 @@ * @for searchSettings **/ delay: 250, - + /** * The characters to type before the search gets executed. * @@ -1178,7 +1143,9 @@ * @for defaults * @since 1.1.0 **/ - requestHandler: function (request) { return request; }, + requestHandler: function (request) { + return request; + }, /** * Transforms the response object into the expected JSON response object. @@ -1189,7 +1156,9 @@ * @for defaults * @since 1.1.0 **/ - responseHandler: function (response) { return response; }, + responseHandler: function (response) { + return response; + }, /** * A list of converters. @@ -1201,13 +1170,21 @@ **/ converters: { numeric: { - from: function (value) { return +value; }, // converts from string to numeric - to: function (value) { return value + ""; } // converts from numeric to string + from: function (value) { + return +value; + }, // converts from string to numeric + to: function (value) { + return value + ""; + } // converts from numeric to string }, string: { // default converter - from: function (value) { return value; }, - to: function (value) { return value; } + from: function (value) { + return value; + }, + to: function (value) { + return value; + } } }, @@ -1335,7 +1312,7 @@ * @for statusMapping **/ 2: "warning", - + /** * Specifies a dangerous or potentially negative action. * @@ -1384,19 +1361,14 @@ * @param rows {Array} An array of rows to append * @chainable **/ - Grid.prototype.append = function(rows) - { - if (this.options.ajax) - { + Grid.prototype.append = function (rows) { + if (this.options.ajax) { // todo: implement ajax PUT } - else - { + else { var appendedRows = []; - for (var i = 0; i < rows.length; i++) - { - if (appendRow.call(this, rows[i])) - { + for (var i = 0; i < rows.length; i++) { + if (appendRow.call(this, rows[i])) { appendedRows.push(rows[i]); } } @@ -1415,14 +1387,11 @@ * @method clear * @chainable **/ - Grid.prototype.clear = function() - { - if (this.options.ajax) - { + Grid.prototype.clear = function () { + if (this.options.ajax) { // todo: implement ajax POST } - else - { + else { var removedRows = $.extend([], this.rows); this.rows = []; this.current = 1; @@ -1440,16 +1409,13 @@ * @method destroy * @chainable **/ - Grid.prototype.destroy = function() - { + Grid.prototype.destroy = function () { // todo: this method has to be optimized (the complete initial state must be restored) $(window).off(namespace); - if (this.options.navigation & 1) - { + if (this.options.navigation & 1) { this.header.remove(); } - if (this.options.navigation & 2) - { + if (this.options.navigation & 2) { this.footer.remove(); } this.element.before(this.origin).remove(); @@ -1463,8 +1429,7 @@ * @method reload * @chainable **/ - Grid.prototype.reload = function() - { + Grid.prototype.reload = function () { this.current = 1; // reset loadData.call(this); @@ -1478,30 +1443,23 @@ * @param [rowsIds] {Array} An array of rows ids to remove * @chainable **/ - Grid.prototype.remove = function(rowIds) - { - if (this.identifier != null) - { + Grid.prototype.remove = function (rowIds) { + if (this.identifier != null) { var that = this; - if (this.options.ajax) - { + if (this.options.ajax) { // todo: implement ajax DELETE } - else - { + else { rowIds = rowIds || this.selectedRows; var id, removedRows = []; - for (var i = 0; i < rowIds.length; i++) - { + for (var i = 0; i < rowIds.length; i++) { id = rowIds[i]; - for (var j = 0; j < this.rows.length; j++) - { - if (this.rows[j][this.identifier] === id) - { + for (var j = 0; j < this.rows.length; j++) { + if (this.rows[j][this.identifier] == id) { removedRows.push(this.rows[j]); this.rows.splice(j, 1); break; @@ -1519,17 +1477,17 @@ }; /** - * Searches in all rows for a specific phrase (but only in visible cells). + * Searches in all rows for a specific phrase (but only in visible cells). * The search filter will be reseted, if no argument is provided. * * @method search * @param [phrase] {String} The phrase to search for * @chainable **/ - Grid.prototype.search = function(phrase) - { + Grid.prototype.search = function (phrase) { phrase = phrase || ""; + if (this.searchPhrase !== phrase) { var selector = getCssSelector(this.options.css.searchField), @@ -1543,6 +1501,194 @@ return this; }; + /** + * Adds a search parameter to a given column. + * + * @method addParams + * @param [phrase] {String} The phrase to search for + * @param [columnNum] {String} The string representation of the columnNumber to search on + * + **/ + Grid.prototype.addParams = function (phrase, columnNum) { + if (this.searchParams.hasOwnProperty(columnNum)) { + if (this.searchParams[columnNum].indexOf(phrase) < 0) { + this.searchParams[columnNum].push(phrase); + executeSearchByParams.call(this); + } + } + else { + this.searchParams[columnNum] = new Array(); + this.searchParams[columnNum].push(phrase); + executeSearchByParams.call(this); + } + return this; + }; + + + /** + * Removes a search parameter (or all search parameters if passed a null phrase) from a given column. + * + * @method removeParams + * @param [phrase] {String} The phrase to search for (or null to remove all) + * @param [columnNum] {String} The string representation of the columnNumber to remove from + * + **/ + Grid.prototype.removeParams = function (phrase, columnNum) { + if(this.searchParams.hasOwnProperty(columnNum)){ + if (phrase == null) { + delete this.searchParams[columnNum]; + } + else { + for (var dex = this.searchParams[columnNum].length - 1; dex >= 0; dex--){ + if (this.searchParams[columnNum][dex] == phrase){ + var tempIndex = this.searchParams[columnNum].indexOf(phrase); + if(tempIndex < 0) break; + this.searchParams[columnNum].splice(tempIndex, 1); + if (this.searchParams[columnNum].length == 0) { + delete this.searchParams[columnNum]; + } + break; + } + } + } + executeSearchByParams.call(this); + } + + return this; + }; + + + /** + * Adds a search constraint to a given column. Currently, only greater, or anything are represented. + * IE. "Greater" is >= and "Anything else" is <=. If you need exactly equals simply add both constraints + * + * @method addConstraint + * @param [constraint] {String} The type of constraint ("greater" or any other string) + * @param [columnNum] {String} The string representation of the columnNumber to apply the constraint + * + **/ + Grid.prototype.addConstraint = function (constraint, columnNum) { + if (constraint != null){ + if (this.constraints.hasOwnProperty(columnNum)){ + if (this.constraints[columnNum].indexOf(constraint) < 0){ + this.constraints[columnNum].push(constraint); + executeSearchByParams.call(this); + } + } + else { + this.constraints[columnNum] = new Array(); + this.constraints[columnNum].push(constraint); + executeSearchByParams.call(this); + } + } + else { + delete this.constraints[columnNum]; + } + + return this; + }; + + + /** + * Prints the parameter array. Usefull when debugging. + * + * @method getParams + * + * + **/ + Grid.prototype.getParams = function () { + for(var i = 0; i < 12; i++){ + if(!(this.searchParams[i] == null)){ + console.log(this.searchParams[i] + " at " + i); + } + } + + return this; + }; + + + /** + * Removes all parameters from all columns + * + * @method clearParams + * + **/ + Grid.prototype.clearParams = function () { + this.searchParams = {}; + executeSearchByParams.call(this); + return this; + }; + + + /** + * Grabs a row of data, given the rows identifier + * + * @method getRowData + * @param [rowId] {String} The rows identifier + * + **/ + Grid.prototype.getRowData = function (rowId) { + for(var i = this.currentRows.length - 1; i >= 0; i--){ + if (this.currentRows[i][this.identifier] == rowId){ + return this.currentRows[i]; + } + } + }; + + /** + * Sets the defualt sorting of the table to a new function + * + * @method setSort + * @param [sortFunction] {function} A function to be called on the elements during the default sort + * The funciton should recieve two rows and return -1, 0, 1 depending + * on the given rows. + * + **/ + Grid.prototype.setSort = function (sortFunction) { + this.defaultSort = sortFunction; + return this; + }; + + + /** + * Sort the rows by a given function just once + * + * @method sortRows + * @param [sortFunction] {function} A function to be called on the elements during the default sort + * The funciton should recieve two rows and return -1, 0, 1 depending + * on the given rows. + * + * + **/ + Grid.prototype.sortRows = function (){ + if (this.defaultSort == null) return this; + this.rows.sort(this.defaultSort); + this.currentRows.sort(this.defaultSort); + loadData.call(this); + return this; + }; + + + /** + * Set subtree capability flag to the table + * + * @method setSubtree + * @param [bool] {String} A string representation of a boolean value. "true" is considered true, + * all other strings are considered false. + * + **/ + Grid.prototype.setSubtree = function (bool) { + if (bool == "true") { + this.subtree = true; + } + else { + this.subtree = false; + } + loadData.call(this); + return this; + }; + + /** * Selects rows by ids. Selects all visible rows if no ids are provided. * In server-side scenarios only visible rows are selectable. @@ -1553,23 +1699,26 @@ **/ Grid.prototype.select = function(rowIds) { - if (this.selection) + if (true) { + console.log("got here"); rowIds = rowIds || this.currentRows.propValues(this.identifier); var id, i, selectedRows = []; - while (rowIds.length > 0 && !(!this.options.multiSelect && selectedRows.length === 1)) + while (rowIds.length > 0 && !(!this.options.multiSelect && selectedRows.length == 1)) { id = rowIds.pop(); - if ($.inArray(id, this.selectedRows) === -1) + if ($.inArray(id, this.selectedRows) == -1) { for (i = 0; i < this.currentRows.length; i++) { - if (this.currentRows[i][this.identifier] === id) + console.log(this.currentRows[i] + " =? " + id); + if (this.currentRows[i][this.identifier] == id) { selectedRows.push(this.currentRows[i]); + console.log(this.currentRows[i]); this.selectedRows.push(id); break; } @@ -1619,7 +1768,7 @@ **/ Grid.prototype.deselect = function(rowIds) { - if (this.selection) + if (true) { rowIds = rowIds || this.currentRows.propValues(this.identifier); diff --git a/dist/jquery.bootgrid.min.js b/dist/jquery.bootgrid.min.js index b84a714..d11b13e 100644 --- a/dist/jquery.bootgrid.min.js +++ b/dist/jquery.bootgrid.min.js @@ -1,6 +1 @@ -/*! - * jQuery Bootgrid v1.3.1 - 09/11/2015 - * Copyright (c) 2014-2015 Rafael Staib (http://www.jquery-bootgrid.com) - * Licensed under MIT http://www.opensource.org/licenses/MIT - */ -!function(a,b,c){"use strict";function d(a){function b(b){return c.identifier&&b[c.identifier]===a[c.identifier]}var c=this;return this.rows.contains(b)?!1:(this.rows.push(a),!0)}function e(b){var c=this.footer?this.footer.find(b):a(),d=this.header?this.header.find(b):a();return a.merge(c,d)}function f(b){return b?a.extend({},this.cachedParams,{ctx:b}):this.cachedParams}function g(){var b={current:this.current,rowCount:this.rowCount,sort:this.sortDictionary,searchPhrase:this.searchPhrase},c=this.options.post;return c=a.isFunction(c)?c():c,this.options.requestHandler(a.extend(!0,b,c))}function h(b){return"."+a.trim(b).replace(/\s+/gm,".")}function i(){var b=this.options.url;return a.isFunction(b)?b():b}function j(){this.element.trigger("initialize"+H),m.call(this),this.selection=this.options.selection&&null!=this.identifier,o.call(this),q.call(this),C.call(this),A.call(this),r.call(this),n.call(this),this.element.trigger("initialized"+H)}function k(a){this.options.highlightRows}function l(a){return a.visible}function m(){var b=this,c=this.element.find("thead > tr").first(),d=!1;c.children().each(function(){var c=a(this),e=c.data(),f={id:e.columnId,identifier:null==b.identifier&&e.identifier||!1,converter:b.options.converters[e.converter||e.type]||b.options.converters.string,text:c.text(),align:e.align||"left",headerAlign:e.headerAlign||"left",cssClass:e.cssClass||"",headerCssClass:e.headerCssClass||"",formatter:b.options.formatters[e.formatter]||null,order:d||"asc"!==e.order&&"desc"!==e.order?null:e.order,searchable:!(e.searchable===!1),sortable:!(e.sortable===!1),visible:!(e.visible===!1),visibleInSelection:!(e.visibleInSelection===!1),width:a.isNumeric(e.width)?e.width+"px":"string"==typeof e.width?e.width:null};b.columns.push(f),null!=f.order&&(b.sortDictionary[f.id]=f.order),f.identifier&&(b.identifier=f.id,b.converter=f.converter),b.options.multiSort||null===f.order||(d=!0)})}function n(){function c(a){for(var b,c=new RegExp(e.searchPhrase,e.options.caseSensitive?"g":"gi"),d=0;d-1)return!0;return!1}function d(a,b){e.currentRows=a,p.call(e,b),e.options.keepSelection||(e.selectedRows=[]),y.call(e,a),t.call(e),v.call(e),e.element._bgBusyAria(!1).trigger("loaded"+H)}var e=this;if(this.element._bgBusyAria(!0).trigger("load"+H),F.call(this),this.options.ajax){var f=g.call(this),h=i.call(this);if(null==h||"string"!=typeof h||0===h.length)throw new Error("Url setting must be a none empty string or a function that returns one.");this.xqr&&this.xqr.abort();var j={url:h,data:f,success:function(b){e.xqr=null,"string"==typeof b&&(b=a.parseJSON(b)),b=e.options.responseHandler(b),e.current=b.current,d(b.rows,b.total)},error:function(a,b,c){e.xqr=null,"abort"!==b&&(u.call(e),e.element._bgBusyAria(!1).trigger("loaded"+H))}};j=a.extend(this.options.ajaxSettings,j),this.xqr=a.ajax(j)}else{var k=this.searchPhrase.length>0?this.rows.where(c):this.rows,l=k.length;-1!==this.rowCount&&(k=k.page(this.current,this.rowCount)),b.setTimeout(function(){d(k,l)},10)}}function o(){if(!this.options.ajax){var b=this,c=this.element.find("tbody > tr");c.each(function(){var c=a(this),e=c.children("td"),f={};a.each(b.columns,function(a,b){f[b.id]=b.converter.from(e.eq(a).text())}),d.call(b,f)}),p.call(this,this.rows.length),G.call(this)}}function p(a){this.total=a,this.totalPages=-1===this.rowCount?1:Math.ceil(this.total/this.rowCount)}function q(){var b=this.options.templates,c=this.element.parent().hasClass(this.options.css.responsiveTable)?this.element.parent():this.element;this.element.addClass(this.options.css.table),0===this.element.children("tbody").length&&this.element.append(b.body),1&this.options.navigation&&(this.header=a(b.header.resolve(f.call(this,{id:this.element._bgId()+"-header"}))),c.before(this.header)),2&this.options.navigation&&(this.footer=a(b.footer.resolve(f.call(this,{id:this.element._bgId()+"-footer"}))),c.after(this.footer))}function r(){if(0!==this.options.navigation){var b=this.options.css,c=h(b.actions),d=e.call(this,c);if(d.length>0){var g=this,i=this.options.templates,j=a(i.actions.resolve(f.call(this)));if(this.options.ajax){var k=i.icon.resolve(f.call(this,{iconCss:b.iconRefresh})),l=a(i.actionButton.resolve(f.call(this,{content:k,text:this.options.labels.refresh}))).on("click"+H,function(a){a.stopPropagation(),g.current=1,n.call(g)});j.append(l)}x.call(this,j),s.call(this,j),E.call(this,d,j)}}}function s(b){if(this.options.columnSelection&&this.columns.length>1){var c=this,d=this.options.css,e=this.options.templates,g=e.icon.resolve(f.call(this,{iconCss:d.iconColumns})),i=a(e.actionDropDown.resolve(f.call(this,{content:g}))),j=h(d.dropDownItem),k=h(d.dropDownItemCheckbox),m=h(d.dropDownMenuItems);a.each(this.columns,function(b,g){if(g.visibleInSelection){var o=a(e.actionDropDownCheckboxItem.resolve(f.call(c,{name:g.id,label:g.text,checked:g.visible}))).on("click"+H,j,function(b){b.stopPropagation();var d=a(this),e=d.find(k);if(!e.prop("disabled")){g.visible=e.prop("checked");var f=c.columns.where(l).length>1;d.parents(m).find(j+":has("+k+":checked)")._bgEnableAria(f).find(k)._bgEnableField(f),c.element.find("tbody").empty(),C.call(c),n.call(c)}});i.find(h(d.dropDownMenuItems)).append(o)}}),b.append(i)}}function t(){if(0!==this.options.navigation){var b=h(this.options.css.infos),c=e.call(this,b);if(c.length>0){var d=this.current*this.rowCount,g=a(this.options.templates.infos.resolve(f.call(this,{end:0===this.total||-1===d||d>this.total?this.total:d,start:0===this.total?0:d-this.rowCount+1,total:this.total})));E.call(this,c,g)}}}function u(){var a=this.element.children("tbody").first(),b=this.options.templates,c=this.columns.where(l).length;this.selection&&(c+=1),a.html(b.noResults.resolve(f.call(this,{columns:c})))}function v(){if(0!==this.options.navigation){var b=h(this.options.css.pagination),c=e.call(this,b)._bgShowAria(-1!==this.rowCount);if(-1!==this.rowCount&&c.length>0){var d=this.options.templates,g=this.current,i=this.totalPages,j=a(d.pagination.resolve(f.call(this))),k=i-g,l=-1*(this.options.padding-g),m=k>=this.options.padding?Math.max(l,1):Math.max(l-this.options.padding+k,1),n=2*this.options.padding+1,o=i>=n?n:i;w.call(this,j,"first","«","first")._bgEnableAria(g>1),w.call(this,j,"prev","<","prev")._bgEnableAria(g>1);for(var p=0;o>p;p++){var q=p+m;w.call(this,j,q,q,"page-"+q)._bgEnableAria()._bgSelectAria(q===g)}0===o&&w.call(this,j,1,1,"page-1")._bgEnableAria(!1)._bgSelectAria(),w.call(this,j,"next",">","next")._bgEnableAria(i>g),w.call(this,j,"last","»","last")._bgEnableAria(i>g),E.call(this,c,j)}}}function w(b,c,d,e){var g=this,i=this.options.templates,j=this.options.css,k=f.call(this,{css:e,text:d,page:c}),l=a(i.paginationItem.resolve(k)).on("click"+H,h(j.paginationButton),function(b){b.stopPropagation(),b.preventDefault();var c=a(this),d=c.parent();if(!d.hasClass("active")&&!d.hasClass("disabled")){var e={first:1,prev:g.current-1,next:g.current+1,last:g.totalPages},f=c.data("page");g.current=e[f]||f,n.call(g)}c.trigger("blur")});return b.append(l),l}function x(b){function c(a){return-1===a?d.options.labels.all:a}var d=this,e=this.options.rowCount;if(a.isArray(e)){var g=this.options.css,i=this.options.templates,j=a(i.actionDropDown.resolve(f.call(this,{content:c(this.rowCount)}))),k=h(g.dropDownMenu),l=h(g.dropDownMenuText),m=h(g.dropDownMenuItems),o=h(g.dropDownItemButton);a.each(e,function(b,e){var g=a(i.actionDropDownItem.resolve(f.call(d,{text:c(e),action:e})))._bgSelectAria(e===d.rowCount).on("click"+H,o,function(b){b.preventDefault();var e=a(this),f=e.data("action");f!==d.rowCount&&(d.current=1,d.rowCount=f,e.parents(m).children().each(function(){var b=a(this),c=b.find(o).data("action");b._bgSelectAria(c===f)}),e.parents(k).find(l).text(c(f)),n.call(d))});j.find(m).append(g)}),b.append(j)}}function y(b){if(b.length>0){var c=this,d=this.options.css,e=this.options.templates,g=this.element.children("tbody").first(),i=!0,j="";a.each(b,function(b,g){var h="",k=' data-row-id="'+(null==c.identifier?b:g[c.identifier])+'"',l="";if(c.selection){var m=-1!==a.inArray(g[c.identifier],c.selectedRows),n=e.select.resolve(f.call(c,{type:"checkbox",value:g[c.identifier],checked:m}));h+=e.cell.resolve(f.call(c,{content:n,css:d.selectCell})),i=i&&m,m&&(l+=d.selected,k+=' aria-selected="true"')}var o=null!=g.status&&c.options.statusMapping[g.status];o&&(l+=o),a.each(c.columns,function(b,i){if(i.visible){var j=a.isFunction(i.formatter)?i.formatter.call(c,i,g):i.converter.to(g[i.id]),k=i.cssClass.length>0?" "+i.cssClass:"";h+=e.cell.resolve(f.call(c,{content:null==j||""===j?" ":j,css:("right"===i.align?d.right:"center"===i.align?d.center:d.left)+k,style:null==i.width?"":"width:"+i.width+";"}))}}),l.length>0&&(k+=' class="'+l+'"'),j+=e.row.resolve(f.call(c,{attr:k,cells:h}))}),c.element.find("thead "+h(c.options.css.selectBox)).prop("checked",i),g.html(j),z.call(this,g)}else u.call(this)}function z(b){var c=this,d=h(this.options.css.selectBox);this.selection&&b.off("click"+H,d).on("click"+H,d,function(b){b.stopPropagation();var d=a(this),e=c.converter.from(d.val());d.prop("checked")?c.select([e]):c.deselect([e])}),b.off("click"+H,"> tr").on("click"+H,"> tr",function(b){b.stopPropagation();var d=a(this),e=null==c.identifier?d.data("row-id"):c.converter.from(d.data("row-id")+""),f=null==c.identifier?c.currentRows[e]:c.currentRows.first(function(a){return a[c.identifier]===e});c.selection&&c.options.rowSelect&&(d.hasClass(c.options.css.selected)?c.deselect([e]):c.select([e])),c.element.trigger("click"+H,[c.columns,f])})}function A(){if(0!==this.options.navigation){var c=this.options.css,d=h(c.search),g=e.call(this,d);if(g.length>0){var i=this,j=this.options.templates,k=null,l="",m=h(c.searchField),n=a(j.search.resolve(f.call(this))),o=n.is(m)?n:n.find(m);o.on("keyup"+H,function(c){c.stopPropagation();var d=a(this).val();(l!==d||13===c.which&&""!==d)&&(l=d,(13===c.which||0===d.length||d.length>=i.options.searchSettings.characters)&&(b.clearTimeout(k),k=b.setTimeout(function(){B.call(i,d)},i.options.searchSettings.delay)))}),E.call(this,g,n)}}}function B(a){this.searchPhrase!==a&&(this.current=1,this.searchPhrase=a,n.call(this))}function C(){var b=this,c=this.element.find("thead > tr"),d=this.options.css,e=this.options.templates,g="",i=this.options.sorting;if(this.selection){var j=this.options.multiSelect?e.select.resolve(f.call(b,{type:"checkbox",value:"all"})):"";g+=e.rawHeaderCell.resolve(f.call(b,{content:j,css:d.selectCell}))}if(a.each(this.columns,function(a,c){if(c.visible){var h=b.sortDictionary[c.id],j=i&&h&&"asc"===h?d.iconUp:i&&h&&"desc"===h?d.iconDown:"",k=e.icon.resolve(f.call(b,{iconCss:j})),l=c.headerAlign,m=c.headerCssClass.length>0?" "+c.headerCssClass:"";g+=e.headerCell.resolve(f.call(b,{column:c,icon:k,sortable:i&&c.sortable&&d.sortable||"",css:("right"===l?d.right:"center"===l?d.center:d.left)+m,style:null==c.width?"":"width:"+c.width+";"}))}}),c.html(g),i){var k=h(d.sortable);c.off("click"+H,k).on("click"+H,k,function(c){c.preventDefault(),D.call(b,a(this)),G.call(b),n.call(b)})}if(this.selection&&this.options.multiSelect){var l=h(d.selectBox);c.off("click"+H,l).on("click"+H,l,function(c){c.stopPropagation(),a(this).prop("checked")?b.select():b.deselect()})}}function D(a){var b=this.options.css,c=h(b.icon),d=a.data("column-id")||a.parents("th").first().data("column-id"),e=this.sortDictionary[d],f=a.find(c);if(this.options.multiSort||(a.parents("tr").first().find(c).removeClass(b.iconDown+" "+b.iconUp),this.sortDictionary={}),e&&"asc"===e)this.sortDictionary[d]="desc",f.removeClass(b.iconUp).addClass(b.iconDown);else if(e&&"desc"===e)if(this.options.multiSort){var g={};for(var i in this.sortDictionary)i!==d&&(g[i]=this.sortDictionary[i]);this.sortDictionary=g,f.removeClass(b.iconDown)}else this.sortDictionary[d]="asc",f.removeClass(b.iconDown).addClass(b.iconUp);else this.sortDictionary[d]="asc",f.addClass(b.iconUp)}function E(b,c){b.each(function(b,d){a(d).before(c.clone(!0)).remove()})}function F(){var a=this;b.setTimeout(function(){if("true"===a.element._bgAria("busy")){var b=a.options.templates,c=a.element.children("thead").first(),d=a.element.children("tbody").first(),e=d.find("tr > td").first(),g=a.element.height()-c.height()-(e.height()+20),h=a.columns.where(l).length;a.selection&&(h+=1),d.html(b.loading.resolve(f.call(a,{columns:h}))),-1!==a.rowCount&&g>0&&d.find("tr > td").css("padding","20px 0 "+g+"px")}},250)}function G(){function a(c,d,e){function f(a){return"asc"===h.order?a:-1*a}e=e||0;var g=e+1,h=b[e];return c[h.id]>d[h.id]?f(1):c[h.id]g?a(c,d,g):0}var b=[];if(!this.options.ajax){for(var c in this.sortDictionary)(this.options.multiSort||0===b.length)&&b.push({id:c,order:this.sortDictionary[c]});b.length>0&&this.rows.sort(a)}}var H=".rs.jquery.bootgrid",I=function(b,c){this.element=a(b),this.origin=this.element.clone(),this.options=a.extend(!0,{},I.defaults,this.element.data(),c);var d=this.options.rowCount=this.element.data().rowCount||c.rowCount||this.options.rowCount;this.columns=[],this.current=1,this.currentRows=[],this.identifier=null,this.selection=!1,this.converter=null,this.rowCount=a.isArray(d)?d[0]:d,this.rows=[],this.searchPhrase="",this.selectedRows=[],this.sortDictionary={},this.total=0,this.totalPages=0,this.cachedParams={lbl:this.options.labels,css:this.options.css,ctx:{}},this.header=null,this.footer=null,this.xqr=null};if(I.defaults={navigation:3,padding:2,columnSelection:!0,rowCount:[10,25,50,-1],selection:!1,multiSelect:!1,rowSelect:!1,keepSelection:!1,highlightRows:!1,sorting:!0,multiSort:!1,searchSettings:{delay:250,characters:1},ajax:!1,ajaxSettings:{method:"POST"},post:{},url:"",caseSensitive:!0,requestHandler:function(a){return a},responseHandler:function(a){return a},converters:{numeric:{from:function(a){return+a},to:function(a){return a+""}},string:{from:function(a){return a},to:function(a){return a}}},css:{actions:"actions btn-group",center:"text-center",columnHeaderAnchor:"column-header-anchor",columnHeaderText:"text",dropDownItem:"dropdown-item",dropDownItemButton:"dropdown-item-button",dropDownItemCheckbox:"dropdown-item-checkbox",dropDownMenu:"dropdown btn-group",dropDownMenuItems:"dropdown-menu pull-right",dropDownMenuText:"dropdown-text",footer:"bootgrid-footer container-fluid",header:"bootgrid-header container-fluid",icon:"icon glyphicon",iconColumns:"glyphicon-th-list",iconDown:"glyphicon-chevron-down",iconRefresh:"glyphicon-refresh",iconSearch:"glyphicon-search",iconUp:"glyphicon-chevron-up",infos:"infos",left:"text-left",pagination:"pagination",paginationButton:"button",responsiveTable:"table-responsive",right:"text-right",search:"search form-group",searchField:"search-field form-control",selectBox:"select-box",selectCell:"select-cell",selected:"active",sortable:"sortable",table:"bootgrid-table table"},formatters:{},labels:{all:"All",infos:"Showing {{ctx.start}} to {{ctx.end}} of {{ctx.total}} entries",loading:"Loading...",noResults:"No results found!",refresh:"Refresh",search:"Search"},statusMapping:{0:"success",1:"info",2:"warning",3:"danger"},templates:{actionButton:'',actionDropDown:'
',actionDropDownItem:'
  • {{ctx.text}}
  • ',actionDropDownCheckboxItem:'
  • ',actions:'
    ',body:"",cell:'{{ctx.content}}',footer:'

    ',header:'

    ',headerCell:'{{ctx.column.text}}{{ctx.icon}}',icon:'',infos:'
    {{lbl.infos}}
    ',loading:'{{lbl.loading}}',noResults:'{{lbl.noResults}}',pagination:'',paginationItem:'
  • {{ctx.text}}
  • ',rawHeaderCell:'{{ctx.content}}',row:"{{ctx.cells}}",search:'
    ',select:''}},I.prototype.append=function(a){if(this.options.ajax);else{for(var b=[],c=0;c0&&(this.options.multiSelect||1!==e.length);)if(c=b.pop(),-1===a.inArray(c,this.selectedRows))for(d=0;d0){var f=h(this.options.css.selectBox),g=this.selectedRows.length>=this.currentRows.length;for(d=0;!this.options.keepSelection&&g&&d tr "+f+":checked").trigger("click"+H),d=0;d tr[data-row-id="'+this.selectedRows[d]+'"]').addClass(this.options.css.selected)._bgAria("selected","true").find(f).prop("checked",!0);this.element.trigger("selected"+H,[e])}}return this},I.prototype.deselect=function(b){if(this.selection){b=b||this.currentRows.propValues(this.identifier);for(var c,d,e,f=[];b.length>0;)if(c=b.pop(),e=a.inArray(c,this.selectedRows),-1!==e)for(d=0;d0){var g=h(this.options.css.selectBox);for(this.element.find("thead "+g).prop("checked",!1),d=0;d tr[data-row-id="'+f[d][this.identifier]+'"]').removeClass(this.options.css.selected)._bgAria("selected","false").find(g).prop("checked",!1);this.element.trigger("deselected"+H,[f])}}return this},I.prototype.sort=function(b){var c=b?a.extend({},b):{};return c===this.sortDictionary?this:(this.sortDictionary=c,C.call(this),G.call(this),n.call(this),this)},I.prototype.getColumnSettings=function(){return a.merge([],this.columns)},I.prototype.getCurrentPage=function(){return this.current},I.prototype.getCurrentRows=function(){return a.merge([],this.currentRows)},I.prototype.getRowCount=function(){return this.rowCount},I.prototype.getSearchPhrase=function(){return this.searchPhrase},I.prototype.getSelectedRows=function(){return a.merge([],this.selectedRows)},I.prototype.getSortDictionary=function(){return a.extend({},this.sortDictionary)},I.prototype.getTotalPageCount=function(){return this.totalPages},I.prototype.getTotalRowCount=function(){return this.total},a.fn.extend({_bgAria:function(a,b){return b?this.attr("aria-"+a,b):this.attr("aria-"+a)},_bgBusyAria:function(a){return null==a||a?this._bgAria("busy","true"):this._bgAria("busy","false")},_bgRemoveAria:function(a){return this.removeAttr("aria-"+a)},_bgEnableAria:function(a){return null==a||a?this.removeClass("disabled")._bgAria("disabled","false"):this.addClass("disabled")._bgAria("disabled","true")},_bgEnableField:function(a){return null==a||a?this.removeAttr("disabled"):this.attr("disabled","disable")},_bgShowAria:function(a){return null==a||a?this.show()._bgAria("hidden","false"):this.hide()._bgAria("hidden","true")},_bgSelectAria:function(a){return null==a||a?this.addClass("active")._bgAria("selected","true"):this.removeClass("active")._bgAria("selected","false")},_bgId:function(a){return a?this.attr("id",a):this.attr("id")}}),!String.prototype.resolve){var J={checked:function(a){return"boolean"==typeof a?a?'checked="checked"':"":a}};String.prototype.resolve=function(b,c){var d=this;return a.each(b,function(b,e){if(null!=e&&"function"!=typeof e)if("object"==typeof e){var f=c?a.extend([],c):[];f.push(b),d=d.resolve(e,f)+""}else{J&&J[b]&&"function"==typeof J[b]&&(e=J[b](e)),b=c?c.join(".")+"."+b:b;var g=new RegExp("\\{\\{"+b+"\\}\\}","gm");d=d.replace(g,e.replace?e.replace(/\$/gi,"$"):e)}}),d}}Array.prototype.first||(Array.prototype.first=function(a){for(var b=0;bc?this.length>d?this.slice(c,d):this.slice(c):[]}),Array.prototype.where||(Array.prototype.where=function(a){for(var b=[],c=0;c tr").first(),i=!1;s.children().each(function(){var s=t(this),n=s.data(),o={id:n.columnId,identifier:null==e.identifier&&n.identifier||!1,converter:e.options.converters[n.converter||n.type]||e.options.converters.string,text:s.text(),align:n.align||"left",headerAlign:n.headerAlign||"left",cssClass:n.cssClass||"",headerCssClass:n.headerCssClass||"",formatter:e.options.formatters[n.formatter]||null,order:i||"asc"!==n.order&&"desc"!==n.order?null:n.order,searchable:!(n.searchable===!1),sortable:!(n.sortable===!1),visible:!(n.visible===!1),visibleInSelection:!(n.visibleInSelection===!1),width:t.isNumeric(n.width)?n.width+"px":"string"==typeof n.width?n.width:null};e.columns.push(o),null!=o.order&&(e.sortDictionary[o.id]=o.order),o.identifier&&(e.identifier=o.id,e.converter=o.converter),e.options.multiSort||null===o.order||(i=!0)})}function p(){function s(t){var e=!1,s=!0,i=!1,o=!1;if(Object.keys(n.searchParams).length>0)for(var r=0;r=0;a--)o=!1,"greater"==n.constraints[r.toString()][a]?isNaN(Number(t[l.id]))||isNaN(Number(n.searchParams[r.toString()][a]))?t[l.id]>=n.searchParams[r.toString()][a]&&(o=!0):Number(t[l.id])>=Number(n.searchParams[r.toString()][a])&&(o=!0):isNaN(Number(t[l.id]))||isNaN(Number(n.searchParams[r.toString()][a]))?t[l.id]<=n.searchParams[r.toString()][a]&&(o=!0):Number(t[l.id])<=Number(n.searchParams[r.toString()][a])&&(o=!0),e=e&&o;else for(a=n.searchParams[r.toString()].length-1;a>=0;a--)if(c=new RegExp(n.searchParams[r.toString()][a],n.options.caseSensitive?"g":"gi"),l.converter.to(t[l.id]).search(c)>-1){e=!0;break}s=s&&e}for(var l,c=new RegExp(n.searchPhrase,n.options.caseSensitive?"g":"gi"),h=0;h-1&&(i=!0);return s&&i}function i(t,e){n.currentRows=t,g.call(n,e),n.options.keepSelection||(n.selectedRows=[]),D.call(n,t),w.call(n),x.call(n),n.element._bgBusyAria(!1).trigger("loaded"+E)}var n=this;if(this.element._bgBusyAria(!0).trigger("load"+E),j.call(this),this.options.ajax){var o=r.call(this),a=l.call(this);if(null==a||"string"!=typeof a||0===a.length)throw new Error("Url setting must be a none empty string or a function that returns one.");this.xqr&&this.xqr.abort();var c={url:a,data:o,success:function(e){n.xqr=null,"string"==typeof e&&(e=t.parseJSON(e)),e=n.options.responseHandler(e),n.current=e.current,i(e.rows,e.total)},error:function(t,e,s){n.xqr=null,"abort"!==e&&(y.call(n),n.element._bgBusyAria(!1).trigger("loaded"+E))}};c=t.extend(this.options.ajaxSettings,c),this.xqr=t.ajax(c)}else{var h=this.searchPhrase.length>0||Object.keys(n.searchParams).length>0?this.rows.where(s):this.rows;if(this.subtree){h.forEach(function(t,e,s){var i=t,n=new RegExp("^"+i[this.identifier]+".*");this.rows.forEach(function(t,e,s){n.test(t[this.identifier])&&h.indexOf(t)<0&&h.push(t)},this)},this);var u=!0;for(var d in this.sortDictionary){u=!1;break}u&&h.sort(this.defaultSort)}var p=h.length;-1!==this.rowCount&&(h=h.page(this.current,this.rowCount)),e.setTimeout(function(){i(h,p)},10)}}function f(){if(!this.options.ajax){var e=this,s=this.element.find("tbody > tr");s.each(function(){var s=t(this),n=s.children("td"),o={};t.each(e.columns,function(t,e){o[e.id]=e.converter.from(n.eq(t).text())}),i.call(e,o)}),g.call(this,this.rows.length),N.call(this)}}function g(t){this.total=t,this.totalPages=-1===this.rowCount?1:Math.ceil(this.total/this.rowCount)}function m(){var e=this.options.templates,s=this.element.parent().hasClass(this.options.css.responsiveTable)?this.element.parent():this.element;this.element.addClass(this.options.css.table),0===this.element.children("tbody").length&&this.element.append(e.body),1&this.options.navigation&&(this.header=t(e.header.resolve(o.call(this,{id:this.element._bgId()+"-header"}))),s.before(this.header)),2&this.options.navigation&&(this.footer=t(e.footer.resolve(o.call(this,{id:this.element._bgId()+"-footer"}))),s.after(this.footer))}function v(){if(0!==this.options.navigation){var e=this.options.css,s=a(e.actions),i=n.call(this,s);if(i.length>0){var r=this,l=this.options.templates,c=t(l.actions.resolve(o.call(this)));if(this.options.ajax){var h=l.icon.resolve(o.call(this,{iconCss:e.iconRefresh})),u=t(l.actionButton.resolve(o.call(this,{content:h,text:this.options.labels.refresh}))).on("click"+E,function(t){t.stopPropagation(),r.current=1,p.call(r)});c.append(u)}S.call(this,c),b.call(this,c),B.call(this,i,c)}}}function b(e){if(this.options.columnSelection&&this.columns.length>1){var s=this,i=this.options.css,n=this.options.templates,r=n.icon.resolve(o.call(this,{iconCss:i.iconColumns})),l=t(n.actionDropDown.resolve(o.call(this,{content:r}))),c=a(i.dropDownItem),h=a(i.dropDownItemCheckbox),d=a(i.dropDownMenuItems);t.each(this.columns,function(e,r){if(r.visibleInSelection){var f=t(n.actionDropDownCheckboxItem.resolve(o.call(s,{name:r.id,label:r.text,checked:r.visible}))).on("click"+E,c,function(e){e.stopPropagation();var i=t(this),n=i.find(h);if(!n.prop("disabled")){r.visible=n.prop("checked");var o=s.columns.where(u).length>1;i.parents(d).find(c+":has("+h+":checked)")._bgEnableAria(o).find(h)._bgEnableField(o),s.element.find("tbody").empty(),_.call(s),p.call(s)}});l.find(a(i.dropDownMenuItems)).append(f)}}),e.append(l)}}function w(){if(0!==this.options.navigation){var e=a(this.options.css.infos),s=n.call(this,e);if(s.length>0){var i=this.current*this.rowCount,r=t(this.options.templates.infos.resolve(o.call(this,{end:0===this.total||-1===i||i>this.total?this.total:i,start:0===this.total?0:i-this.rowCount+1,total:this.total})));B.call(this,s,r)}}}function y(){var t=this.element.children("tbody").first(),e=this.options.templates,s=this.columns.where(u).length;this.selection&&(s+=1),t.html(e.noResults.resolve(o.call(this,{columns:s})))}function x(){if(0!==this.options.navigation){var e=a(this.options.css.pagination),s=n.call(this,e)._bgShowAria(-1!==this.rowCount);if(-1!==this.rowCount&&s.length>0){var i=this.options.templates,r=this.current,l=this.totalPages,c=t(i.pagination.resolve(o.call(this))),h=l-r,u=-1*(this.options.padding-r),d=h>=this.options.padding?Math.max(u,1):Math.max(u-this.options.padding+h,1),p=2*this.options.padding+1,f=l>=p?p:l;C.call(this,c,"first","«","first")._bgEnableAria(r>1),C.call(this,c,"prev","<","prev")._bgEnableAria(r>1);for(var g=0;f>g;g++){var m=g+d;C.call(this,c,m,m,"page-"+m)._bgEnableAria()._bgSelectAria(m===r)}0===f&&C.call(this,c,1,1,"page-1")._bgEnableAria(!1)._bgSelectAria(),C.call(this,c,"next",">","next")._bgEnableAria(l>r),C.call(this,c,"last","»","last")._bgEnableAria(l>r),B.call(this,s,c)}}}function C(e,s,i,n){var r=this,l=this.options.templates,c=this.options.css,h=o.call(this,{css:n,text:i,page:s}),u=t(l.paginationItem.resolve(h)).on("click"+E,a(c.paginationButton),function(e){e.stopPropagation(),e.preventDefault();var s=t(this),i=s.parent();if(!i.hasClass("active")&&!i.hasClass("disabled")){var n={first:1,prev:r.current-1,next:r.current+1,last:r.totalPages},o=s.data("page");r.current=n[o]||o,p.call(r)}s.trigger("blur")});return e.append(u),u}function S(e){function s(t){return-1===t?i.options.labels.all:t}var i=this,n=this.options.rowCount;if(t.isArray(n)){var r=this.options.css,l=this.options.templates,c=t(l.actionDropDown.resolve(o.call(this,{content:s(this.rowCount)}))),h=a(r.dropDownMenu),u=a(r.dropDownMenuText),d=a(r.dropDownMenuItems),f=a(r.dropDownItemButton);t.each(n,function(e,n){var r=t(l.actionDropDownItem.resolve(o.call(i,{text:s(n),action:n})))._bgSelectAria(n===i.rowCount).on("click"+E,f,function(e){e.preventDefault();var n=t(this),o=n.data("action");o!==i.rowCount&&(i.current=1,i.rowCount=o,n.parents(d).children().each(function(){var e=t(this),s=e.find(f).data("action");e._bgSelectAria(s===o)}),n.parents(h).find(u).text(s(o)),p.call(i))});c.find(d).append(r)}),e.append(c)}}function D(e){if(e.length>0){var s=this,i=this.options.css,n=this.options.templates,r=this.element.children("tbody").first(),l=!0,c="";t.each(e,function(e,r){var a="",h=' data-row-id="'+(null==s.identifier?e:r[s.identifier])+'"',u="";if(s.selection){var d=-1!==t.inArray(r[s.identifier],s.selectedRows),p=n.select.resolve(o.call(s,{type:"checkbox",value:r[s.identifier],checked:d}));a+=n.cell.resolve(o.call(s,{content:p,css:i.selectCell})),l=l&&d,d&&(u+=i.selected,h+=' aria-selected="true"')}var f=null!=r.status&&s.options.statusMapping[r.status];f&&(u+=f),t.each(s.columns,function(e,l){if(l.visible){var c=t.isFunction(l.formatter)?l.formatter.call(s,l,r):l.converter.to(r[l.id]),h=l.cssClass.length>0?" "+l.cssClass:"";a+=n.cell.resolve(o.call(s,{content:null==c||""===c?" ":c,css:("right"===l.align?i.right:"center"===l.align?i.center:i.left)+h,style:null==l.width?"":"width:"+l.width+";"}))}}),u.length>0&&(h+=' class="'+u+'"'),c+=n.row.resolve(o.call(s,{attr:h,cells:a}))}),s.element.find("thead "+a(s.options.css.selectBox)).prop("checked",l),r.html(c),P.call(this,r)}else y.call(this)}function P(e){var s=this,i=a(this.options.css.selectBox);this.selection&&e.off("click"+E,i).on("click"+E,i,function(e){e.stopPropagation();var i=t(this),n=s.converter.from(i.val());i.prop("checked")?s.select([n]):s.deselect([n])}),e.off("click"+E,"> tr").on("click"+E,"> tr",function(e){e.stopPropagation();var i=t(this),n=null==s.identifier?i.data("row-id"):s.converter.from(i.data("row-id")+""),o=null==s.identifier?s.currentRows[n]:s.currentRows.first(function(t){return t[s.identifier]===n});s.selection&&s.options.rowSelect&&(i.hasClass(s.options.css.selected)?s.deselect([n]):s.select([n])),s.element.trigger("click"+E,[s.columns,o])})}function A(){if(0!==this.options.navigation){var s=this.options.css,i=a(s.search),r=n.call(this,i);if(r.length>0){var l=this,c=this.options.templates,h=null,u="",d=a(s.searchField),p=t(c.search.resolve(o.call(this))),f=p.is(d)?p:p.find(d);f.on("keyup"+E,function(s){s.stopPropagation();var i=t(this).val();(u!==i||13===s.which&&""!==i)&&(u=i,(13===s.which||0===i.length||i.length>=l.options.searchSettings.characters)&&(e.clearTimeout(h),h=e.setTimeout(function(){R.call(l,i)},l.options.searchSettings.delay)))}),B.call(this,r,p)}}}function R(t){this.searchPhrase!==t&&(this.current=1,this.searchPhrase=t,p.call(this))}function k(){this.current=1,p.call(this)}function _(){var e=this,s=this.element.find("thead > tr"),i=this.options.css,n=this.options.templates,r="",l=this.options.sorting;if(this.selection){var c=this.options.multiSelect?n.select.resolve(o.call(e,{type:"checkbox",value:"all"})):"";r+=n.rawHeaderCell.resolve(o.call(e,{content:c,css:i.selectCell}))}if(t.each(this.columns,function(t,s){if(s.visible){var a=e.sortDictionary[s.id],c=l&&a&&"asc"===a?i.iconUp:l&&a&&"desc"===a?i.iconDown:"",h=n.icon.resolve(o.call(e,{iconCss:c})),u=s.headerAlign,d=s.headerCssClass.length>0?" "+s.headerCssClass:"";r+=n.headerCell.resolve(o.call(e,{column:s,icon:h,sortable:l&&s.sortable&&i.sortable||"",css:("right"===u?i.right:"center"===u?i.center:i.left)+d,style:null==s.width?"":"width:"+s.width+";"}))}}),s.html(r),l){var h=a(i.sortable);s.off("click"+E,h).on("click"+E,h,function(s){s.preventDefault(),I.call(e,t(this)),N.call(e),p.call(e)})}if(this.selection&&this.options.multiSelect){var u=a(i.selectBox);s.off("click"+E,u).on("click"+E,u,function(s){s.stopPropagation(),t(this).prop("checked")?e.select():e.deselect()})}}function I(t){var e=this.options.css,s=a(e.icon),i=t.data("column-id")||t.parents("th").first().data("column-id"),n=this.sortDictionary[i],o=t.find(s);if(this.options.multiSort||(t.parents("tr").first().find(s).removeClass(e.iconDown+" "+e.iconUp),this.sortDictionary={}),n&&"asc"===n)this.sortDictionary[i]="desc",o.removeClass(e.iconUp).addClass(e.iconDown);else if(n&&"desc"===n)if(this.options.multiSort){var r={};for(var l in this.sortDictionary)l!==i&&(r[l]=this.sortDictionary[l]);this.sortDictionary=r,o.removeClass(e.iconDown)}else this.sortDictionary[i]="asc",o.removeClass(e.iconDown).addClass(e.iconUp);else this.sortDictionary[i]="asc",o.addClass(e.iconUp)}function B(e,s){e.each(function(e,i){t(i).before(s.clone(!0)).remove()})}function j(){var t=this;e.setTimeout(function(){if("true"===t.element._bgAria("busy")){var e=t.options.templates,s=t.element.children("thead").first(),i=t.element.children("tbody").first(),n=i.find("tr > td").first(),r=t.element.height()-s.height()-(n.height()+20),a=t.columns.where(u).length;t.selection&&(a+=1),i.html(e.loading.resolve(o.call(t,{columns:a}))),-1!==t.rowCount&&r>0&&i.find("tr > td").css("padding","20px 0 "+r+"px")}},250)}function N(){function t(s,i,n){function o(t){return"asc"===a.order?t:-1*t}n=n||0;var r=n+1,a=e[n];return s[a.id]>i[a.id]?o(1):s[a.id]r?t(s,i,r):0}var e=[];if(!this.options.ajax){for(var s in this.sortDictionary)(this.options.multiSort||0===e.length)&&e.push({id:s,order:this.sortDictionary[s]});e.length>0&&this.rows.sort(t)}}var E=".rs.jquery.bootgrid",M=function(e,s){this.element=t(e),this.origin=this.element.clone(),this.options=t.extend(!0,{},M.defaults,this.element.data(),s);var i=this.options.rowCount=this.element.data().rowCount||s.rowCount||this.options.rowCount;this.columns=[],this.current=1,this.currentRows=[],this.identifier=null,this.selection=!1,this.converter=null,this.rowCount=t.isArray(i)?i[0]:i,this.rows=[],this.searchPhrase="",this.selectedRows=[],this.sortDictionary={},this.total=0,this.totalPages=0,this.cachedParams={lbl:this.options.labels,css:this.options.css,ctx:{}},this.header=null,this.footer=null,this.xqr=null,this.searchParams={},this.constraints={},this.subtree=!1,this.defaultSort=null};if(M.defaults={navigation:3,padding:2,columnSelection:!0,rowCount:[10,25,50,-1],selection:!1,multiSelect:!1,rowSelect:!1,keepSelection:!1,highlightRows:!1,sorting:!0,multiSort:!1,searchSettings:{delay:250,characters:1},ajax:!1,ajaxSettings:{method:"POST"},post:{},url:"",caseSensitive:!0,requestHandler:function(t){return t},responseHandler:function(t){return t},converters:{numeric:{from:function(t){return+t},to:function(t){return t+""}},string:{from:function(t){return t},to:function(t){return t}}},css:{actions:"actions btn-group",center:"text-center",columnHeaderAnchor:"column-header-anchor",columnHeaderText:"text",dropDownItem:"dropdown-item",dropDownItemButton:"dropdown-item-button",dropDownItemCheckbox:"dropdown-item-checkbox",dropDownMenu:"dropdown btn-group",dropDownMenuItems:"dropdown-menu pull-right",dropDownMenuText:"dropdown-text",footer:"bootgrid-footer container-fluid",header:"bootgrid-header container-fluid",icon:"icon glyphicon",iconColumns:"glyphicon-th-list",iconDown:"glyphicon-chevron-down",iconRefresh:"glyphicon-refresh",iconSearch:"glyphicon-search",iconUp:"glyphicon-chevron-up",infos:"infos",left:"text-left",pagination:"pagination",paginationButton:"button",responsiveTable:"table-responsive",right:"text-right",search:"search form-group",searchField:"search-field form-control",selectBox:"select-box",selectCell:"select-cell",selected:"active",sortable:"sortable",table:"bootgrid-table table"},formatters:{},labels:{all:"All",infos:"Showing {{ctx.start}} to {{ctx.end}} of {{ctx.total}} entries",loading:"Loading...",noResults:"No results found!",refresh:"Refresh",search:"Search"},statusMapping:{0:"success",1:"info",2:"warning",3:"danger"},templates:{actionButton:'',actionDropDown:'
    ',actionDropDownItem:'
  • {{ctx.text}}
  • ',actionDropDownCheckboxItem:'
  • ',actions:'
    ',body:"",cell:'{{ctx.content}}',footer:'

    ',header:'

    ',headerCell:'{{ctx.column.text}}{{ctx.icon}}',icon:'',infos:'
    {{lbl.infos}}
    ',loading:'{{lbl.loading}}',noResults:'{{lbl.noResults}}',pagination:'
      ',paginationItem:'
    • {{ctx.text}}
    • ',rawHeaderCell:'{{ctx.content}}',row:"{{ctx.cells}}",search:'
      ',select:''}},M.prototype.append=function(t){if(this.options.ajax);else{for(var e=[],s=0;s=0;s--)if(this.searchParams[e][s]==t){var i=this.searchParams[e].indexOf(t);if(0>i)break;this.searchParams[e].splice(i,1),0==this.searchParams[e].length&&delete this.searchParams[e];break}k.call(this)}return this},M.prototype.addConstraint=function(t,e){return null!=t?this.constraints.hasOwnProperty(e)?this.constraints[e].indexOf(t)<0&&(this.constraints[e].push(t),k.call(this)):(this.constraints[e]=new Array,this.constraints[e].push(t),k.call(this)):delete this.constraints[e],this},M.prototype.getParams=function(){for(var t=0;12>t;t++)null!=this.searchParams[t]&&console.log(this.searchParams[t]+" at "+t);return this},M.prototype.clearParams=function(){return this.searchParams={},k.call(this),this},M.prototype.getRowData=function(t){for(var e=this.currentRows.length-1;e>=0;e--)if(this.currentRows[e][this.identifier]==t)return this.currentRows[e]},M.prototype.setSort=function(t){return this.defaultSort=t,this},M.prototype.sortRows=function(){return null==this.defaultSort?this:(this.rows.sort(this.defaultSort),this.currentRows.sort(this.defaultSort),p.call(this),this)},M.prototype.setSubtree=function(t){return"true"==t?this.subtree=!0:this.subtree=!1,p.call(this),this},M.prototype.select=function(e){console.log("got here"),e=e||this.currentRows.propValues(this.identifier);for(var s,i,n=[];e.length>0&&(this.options.multiSelect||1!=n.length);)if(s=e.pop(),-1==t.inArray(s,this.selectedRows))for(i=0;i0){var o=a(this.options.css.selectBox),r=this.selectedRows.length>=this.currentRows.length;for(i=0;!this.options.keepSelection&&r&&i tr "+o+":checked").trigger("click"+E),i=0;i tr[data-row-id="'+this.selectedRows[i]+'"]').addClass(this.options.css.selected)._bgAria("selected","true").find(o).prop("checked",!0);this.element.trigger("selected"+E,[n])}return this},M.prototype.deselect=function(e){e=e||this.currentRows.propValues(this.identifier);for(var s,i,n,o=[];e.length>0;)if(s=e.pop(),n=t.inArray(s,this.selectedRows),-1!==n)for(i=0;i0){var r=a(this.options.css.selectBox);for(this.element.find("thead "+r).prop("checked",!1),i=0;i tr[data-row-id="'+o[i][this.identifier]+'"]').removeClass(this.options.css.selected)._bgAria("selected","false").find(r).prop("checked",!1);this.element.trigger("deselected"+E,[o])}return this},M.prototype.sort=function(e){var s=e?t.extend({},e):{};return s===this.sortDictionary?this:(this.sortDictionary=s,_.call(this),N.call(this),p.call(this),this)},M.prototype.getColumnSettings=function(){return t.merge([],this.columns)},M.prototype.getCurrentPage=function(){return this.current},M.prototype.getCurrentRows=function(){return t.merge([],this.currentRows)},M.prototype.getRowCount=function(){return this.rowCount},M.prototype.getSearchPhrase=function(){return this.searchPhrase},M.prototype.getSelectedRows=function(){return t.merge([],this.selectedRows)},M.prototype.getSortDictionary=function(){return t.extend({},this.sortDictionary)},M.prototype.getTotalPageCount=function(){return this.totalPages},M.prototype.getTotalRowCount=function(){return this.total},t.fn.extend({_bgAria:function(t,e){return e?this.attr("aria-"+t,e):this.attr("aria-"+t)},_bgBusyAria:function(t){return null==t||t?this._bgAria("busy","true"):this._bgAria("busy","false")},_bgRemoveAria:function(t){return this.removeAttr("aria-"+t)},_bgEnableAria:function(t){return null==t||t?this.removeClass("disabled")._bgAria("disabled","false"):this.addClass("disabled")._bgAria("disabled","true")},_bgEnableField:function(t){return null==t||t?this.removeAttr("disabled"):this.attr("disabled","disable")},_bgShowAria:function(t){return null==t||t?this.show()._bgAria("hidden","false"):this.hide()._bgAria("hidden","true")},_bgSelectAria:function(t){return null==t||t?this.addClass("active")._bgAria("selected","true"):this.removeClass("active")._bgAria("selected","false")},_bgId:function(t){return t?this.attr("id",t):this.attr("id")}}),!String.prototype.resolve){var O={checked:function(t){return"boolean"==typeof t?t?'checked="checked"':"":t}};String.prototype.resolve=function(e,s){var i=this;return t.each(e,function(e,n){if(null!=n&&"function"!=typeof n)if("object"==typeof n){var o=s?t.extend([],s):[];o.push(e),i=i.resolve(n,o)+""}else{O&&O[e]&&"function"==typeof O[e]&&(n=O[e](n)),e=s?s.join(".")+"."+e:e;var r=new RegExp("\\{\\{"+e+"\\}\\}","gm");i=i.replace(r,n.replace?n.replace(/\$/gi,"$"):n)}}),i}}Array.prototype.first||(Array.prototype.first=function(t){for(var e=0;es?this.length>i?this.slice(s,i):this.slice(s):[]}),Array.prototype.where||(Array.prototype.where=function(t){for(var e=[],s=0;s