diff --git a/public/js/extensions/cookie/bootstrap-table-cookie.js b/public/js/extensions/cookie/bootstrap-table-cookie.js index 3192bde38bec..c3a746a4b75e 100755 --- a/public/js/extensions/cookie/bootstrap-table-cookie.js +++ b/public/js/extensions/cookie/bootstrap-table-cookie.js @@ -1,7 +1,7 @@ /** * @author: Dennis Hernández * @webSite: http://djhvscf.github.io/Blog - * @version: v1.2.0 + * @version: v1.2.2 * * @update zhixin wen */ @@ -64,11 +64,27 @@ } cookieName = that.options.cookieIdTable + '.' + cookieName; - if (!cookieName || /^(?:expires|max\-age|path|domain|secure)$/i.test(cookieName)) { - return false; + + switch(that.options.cookieStorage) { + case 'cookieStorage': + document.cookie = [ + cookieName, '=', cookieValue, + '; expires=' + that.options.cookieExpire, + that.options.cookiePath ? '; path=' + that.options.cookiePath : '', + that.options.cookieDomain ? '; domain=' + that.options.cookieDomain : '', + that.options.cookieSecure ? '; secure' : '' + ].join(''); + break; + case 'localStorage': + localStorage.setItem(cookieName, cookieValue); + break; + case 'sessionStorage': + sessionStorage.setItem(cookieName, cookieValue); + break; + default: + return false; } - document.cookie = encodeURIComponent(cookieName) + '=' + encodeURIComponent(cookieValue) + calculateExpiration(that.options.cookieExpire) + (that.options.cookieDomain ? '; domain=' + that.options.cookieDomain : '') + (that.options.cookiePath ? '; path=' + that.options.cookiePath : '') + (that.cookieSecure ? '; secure' : ''); return true; }; @@ -83,28 +99,44 @@ cookieName = tableName + '.' + cookieName; - return decodeURIComponent(document.cookie.replace(new RegExp('(?:(?:^|.*;)\\s*' + encodeURIComponent(cookieName).replace(/[\-\.\+\*]/g, '\\$&') + '\\s*\\=\\s*([^;]*).*$)|^.*$'), '$1')) || null; - }; - - var hasCookie = function (cookieName) { - if (!cookieName) { - return false; + switch(that.options.cookieStorage) { + case 'cookieStorage': + return decodeURIComponent(document.cookie.replace(new RegExp('(?:(?:^|.*;)\\s*' + encodeURIComponent(cookieName).replace(/[\-\.\+\*]/g, '\\$&') + '\\s*\\=\\s*([^;]*).*$)|^.*$'), '$1')) || null; + case 'localStorage': + return localStorage.getItem(cookieName); + case 'sessionStorage': + return sessionStorage.getItem(cookieName); + default: + return null; } - return (new RegExp('(?:^|;\\s*)' + encodeURIComponent(cookieName).replace(/[\-\.\+\*]/g, '\\$&') + '\\s*\\=')).test(document.cookie); }; - var deleteCookie = function (tableName, cookieName, sPath, sDomain) { + var deleteCookie = function (that, tableName, cookieName) { cookieName = tableName + '.' + cookieName; - if (!hasCookie(cookieName)) { - return false; + + switch(that.options.cookieStorage) { + case 'cookieStorage': + document.cookie = [ + encodeURIComponent(cookieName), '=', + '; expires=Thu, 01 Jan 1970 00:00:00 GMT', + that.options.cookiePath ? '; path=' + that.options.cookiePath : '', + that.options.cookieDomain ? '; domain=' + that.options.cookieDomain : '', + ].join(''); + break; + case 'localStorage': + localStorage.removeItem(cookieName); + break; + case 'sessionStorage': + sessionStorage.removeItem(cookieName); + break; + } - document.cookie = encodeURIComponent(cookieName) + '=; expires=Thu, 01 Jan 1970 00:00:00 GMT' + (sDomain ? '; domain=' + sDomain : '') + (sPath ? '; path=' + sPath : ''); return true; }; var calculateExpiration = function(cookieExpire) { var time = cookieExpire.replace(/[0-9]*/, ''); //s,mi,h,d,m,y - cookieExpire = cookieExpire.replace(/[A-Za-z]/, ''); //number + cookieExpire = cookieExpire.replace(/[A-Za-z]{1,2}}/, ''); //number switch (time.toLowerCase()) { case 's': @@ -123,7 +155,7 @@ cookieExpire = cookieExpire * 30 * 24 * 60 * 60; break; case 'y': - cookieExpire = cookieExpire * 365 * 30 * 24 * 60 * 60; + cookieExpire = cookieExpire * 365 * 24 * 60 * 60; break; default: cookieExpire = undefined; @@ -133,6 +165,38 @@ return cookieExpire === undefined ? '' : '; max-age=' + cookieExpire; }; + var initCookieFilters = function (bootstrapTable) { + setTimeout(function () { + var parsedCookieFilters = JSON.parse(getCookie(bootstrapTable, bootstrapTable.options.cookieIdTable, cookieIds.filterControl)); + + if (!bootstrapTable.options.filterControlValuesLoaded && parsedCookieFilters) { + bootstrapTable.options.filterControlValuesLoaded = true; + + var cachedFilters = {}, + header = getCurrentHeader(bootstrapTable), + searchControls = getCurrentSearchControls(bootstrapTable), + + applyCookieFilters = function (element, filteredCookies) { + $(filteredCookies).each(function (i, cookie) { + $(element).val(cookie.text); + cachedFilters[cookie.field] = cookie.text; + }); + }; + + header.find(searchControls).each(function () { + var field = $(this).closest('[data-field]').data('field'), + filteredCookies = $.grep(parsedCookieFilters, function (cookie) { + return cookie.field === field; + }); + + applyCookieFilters(this, filteredCookies); + }); + + bootstrapTable.initColumnSearch(cachedFilters); + } + }, 250); + }; + $.extend($.fn.bootstrapTable.defaults, { cookie: false, cookieExpire: '2h', @@ -140,17 +204,30 @@ cookieDomain: null, cookieSecure: null, cookieIdTable: '', - cookiesEnabled: ['bs.table.sortOrder', 'bs.table.sortName', 'bs.table.pageNumber', 'bs.table.pageList', 'bs.table.columns', 'bs.table.searchText', 'bs.table.filterControl'], + cookiesEnabled: [ + 'bs.table.sortOrder', 'bs.table.sortName', + 'bs.table.pageNumber', 'bs.table.pageList', + 'bs.table.columns', 'bs.table.searchText', + 'bs.table.filterControl' + ], + cookieStorage: 'cookieStorage', //localStorage, sessionStorage //internal variable filterControls: [], filterControlValuesLoaded: false }); + $.fn.bootstrapTable.methods.push('getCookies'); $.fn.bootstrapTable.methods.push('deleteCookie'); + $.extend($.fn.bootstrapTable.utils, { + setCookie: setCookie, + getCookie: getCookie + }); + var BootstrapTable = $.fn.bootstrapTable.Constructor, _init = BootstrapTable.prototype.init, _initTable = BootstrapTable.prototype.initTable, + _initServer = BootstrapTable.prototype.initServer, _onSort = BootstrapTable.prototype.onSort, _onPageNumber = BootstrapTable.prototype.onPageNumber, _onPageListChange = BootstrapTable.prototype.onPageListChange, @@ -167,9 +244,10 @@ this.options.filterControls = []; this.options.filterControlValuesLoaded = false; - this.options.cookiesEnabled = typeof this.options.cookiesEnabled === 'string' ? - this.options.cookiesEnabled.replace('[', '').replace(']', '').replace(/ /g, '').toLowerCase().split(',') : this.options.cookiesEnabled; + this.options.cookiesEnabled.replace('[', '').replace(']', '') + .replace(/ /g, '').toLowerCase().split(',') : + this.options.cookiesEnabled; if (this.options.filterControl) { var that = this; @@ -191,36 +269,46 @@ } setCookie(that, cookieIds.filterControl, JSON.stringify(that.options.filterControls)); - }).on('post-body.bs.table', function () { - setTimeout(function () { - if (!that.options.filterControlValuesLoaded) { - that.options.filterControlValuesLoaded = true; - var filterControl = JSON.parse(getCookie(that, that.options.cookieIdTable, cookieIds.filterControl)); - if (filterControl) { - var field = null, - result = [], - header = getCurrentHeader(that), - searchControls = getCurrentSearchControls(that); - - header.find(searchControls).each(function (index, ele) { - field = $(this).parent().parent().parent().data('field'); - result = $.grep(filterControl, function (valueObj) { - return valueObj.field === field; - }); - - if (result.length > 0) { - $(this).val(result[0].text); - that.onColumnSearch({currentTarget: $(this)}); - } - }); - } - } - }, 250); - }); + }).on('post-body.bs.table', initCookieFilters(that)); } _init.apply(this, Array.prototype.slice.apply(arguments)); }; + BootstrapTable.prototype.initServer = function () { + var bootstrapTable = this, + selectsWithoutDefaults = [], + + columnHasSelectControl = function (column) { + return column.filterControl && column.filterControl === 'select'; + }, + + columnHasDefaultSelectValues = function (column) { + return column.filterData && column.filterData !== 'column'; + }, + + cookiesPresent = function() { + var cookie = JSON.parse(getCookie(bootstrapTable, bootstrapTable.options.cookieIdTable, cookieIds.filterControl)); + return bootstrapTable.options.cookie && cookie; + }; + + selectsWithoutDefaults = $.grep(bootstrapTable.columns, function(column) { + return columnHasSelectControl(column) && !columnHasDefaultSelectValues(column); + }); + + // reset variable to original initServer function, so that future calls to initServer + // use the original function from this point on. + BootstrapTable.prototype.initServer = _initServer; + + // early return if we don't need to populate any select values with cookie values + if (this.options.filterControl && cookiesPresent() && selectsWithoutDefaults.length === 0) { + return; + } + + // call BootstrapTable.prototype.initServer + _initServer.apply(this, Array.prototype.slice.apply(arguments)); + }; + + BootstrapTable.prototype.initTable = function () { _initTable.apply(this, Array.prototype.slice.apply(arguments)); this.initCookie(); @@ -233,7 +321,6 @@ if ((this.options.cookieIdTable === '') || (this.options.cookieExpire === '') || (!cookieEnabled())) { throw new Error("Configuration error. Please review the cookieIdTable, cookieExpire properties, if those properties are ok, then this browser does not support the cookies"); - return; } var sortOrderCookie = getCookie(this, this.options.cookieIdTable, cookieIds.sortOrder), @@ -310,15 +397,31 @@ setCookie(this, cookieIds.columns, JSON.stringify(visibleColumns)); }; - + BootstrapTable.prototype.selectPage = function (page) { _selectPage.apply(this, Array.prototype.slice.apply(arguments)); setCookie(this, cookieIds.pageNumber, page); }; BootstrapTable.prototype.onSearch = function () { - _onSearch.apply(this, Array.prototype.slice.apply(arguments)); - setCookie(this, cookieIds.searchText, this.searchText); + var target = Array.prototype.slice.apply(arguments); + _onSearch.apply(this, target); + + if ($(target[0].currentTarget).parent().hasClass('search')) { + setCookie(this, cookieIds.searchText, this.searchText); + } + }; + + BootstrapTable.prototype.getCookies = function () { + var bootstrapTable = this; + var cookies = {}; + $.each(cookieIds, function(key, value) { + cookies[key] = getCookie(bootstrapTable, bootstrapTable.options.cookieIdTable, value); + if (key === 'columns') { + cookies[key] = JSON.parse(cookies[key]); + } + }); + return cookies; }; BootstrapTable.prototype.deleteCookie = function (cookieName) { @@ -326,6 +429,6 @@ return; } - deleteCookie(this.options.cookieIdTable, cookieIds[cookieName], this.options.cookiePath, this.options.cookieDomain); + deleteCookie(this, this.options.cookieIdTable, cookieIds[cookieName]); }; })(jQuery); diff --git a/public/js/extensions/cookie/bootstrap-table-cookie.min.js b/public/js/extensions/cookie/bootstrap-table-cookie.min.js index 0a3c25717590..425ef8b6f62c 100755 --- a/public/js/extensions/cookie/bootstrap-table-cookie.min.js +++ b/public/js/extensions/cookie/bootstrap-table-cookie.min.js @@ -1,7 +1,7 @@ /* -* bootstrap-table - v1.9.1 - 2015-10-25 +* bootstrap-table - v1.11.1 - 2017-02-22 * https://github.com/wenzhixin/bootstrap-table -* Copyright (c) 2015 zhixin wen +* Copyright (c) 2017 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",filterControl:"bs.table.filterControl"},c=function(a){var b=a.$header;return a.options.height&&(b=a.$tableHeader),b},d=function(a){var b="select, input";return a.options.height&&(b="table select, table input"),b},e=function(){return!!navigator.cookieEnabled},f=function(a,b){for(var c=-1,d=0;d0&&(a(this).val(i[0].text),e.onColumnSearch({currentTarget:a(this)}))})}}},250)})}m.apply(this,Array.prototype.slice.apply(arguments))},l.prototype.initTable=function(){n.apply(this,Array.prototype.slice.apply(arguments)),this.initCookie()},l.prototype.initCookie=function(){if(this.options.cookie){if(""===this.options.cookieIdTable||""===this.options.cookieExpire||!e())throw new Error("Configuration error. Please review the cookieIdTable, cookieExpire properties, if those properties are ok, then this browser does not support the cookies");var c=h(this,this.options.cookieIdTable,b.sortOrder),d=h(this,this.options.cookieIdTable,b.sortName),f=h(this,this.options.cookieIdTable,b.pageNumber),g=h(this,this.options.cookieIdTable,b.pageList),i=JSON.parse(h(this,this.options.cookieIdTable,b.columns)),j=h(this,this.options.cookieIdTable,b.searchText);this.options.sortOrder=c?c:this.options.sortOrder,this.options.sortName=d?d:this.options.sortName,this.options.pageNumber=f?+f:this.options.pageNumber,this.options.pageSize=g?g===this.options.formatAllRows()?g:+g:this.options.pageSize,this.options.searchText=j?j:"",i&&a.each(this.columns,function(b,c){c.visible=-1!==a.inArray(c.field,i)})}},l.prototype.onSort=function(){o.apply(this,Array.prototype.slice.apply(arguments)),g(this,b.sortOrder,this.options.sortOrder),g(this,b.sortName,this.options.sortName)},l.prototype.onPageNumber=function(){p.apply(this,Array.prototype.slice.apply(arguments)),g(this,b.pageNumber,this.options.pageNumber)},l.prototype.onPageListChange=function(){q.apply(this,Array.prototype.slice.apply(arguments)),g(this,b.pageList,this.options.pageSize)},l.prototype.onPageFirst=function(){r.apply(this,Array.prototype.slice.apply(arguments)),g(this,b.pageNumber,this.options.pageNumber)},l.prototype.onPagePre=function(){s.apply(this,Array.prototype.slice.apply(arguments)),g(this,b.pageNumber,this.options.pageNumber)},l.prototype.onPageNext=function(){t.apply(this,Array.prototype.slice.apply(arguments)),g(this,b.pageNumber,this.options.pageNumber)},l.prototype.onPageLast=function(){u.apply(this,Array.prototype.slice.apply(arguments)),g(this,b.pageNumber,this.options.pageNumber)},l.prototype.toggleColumn=function(){v.apply(this,Array.prototype.slice.apply(arguments));var c=[];a.each(this.columns,function(a,b){b.visible&&c.push(b.field)}),g(this,b.columns,JSON.stringify(c))},l.prototype.selectPage=function(a){w.apply(this,Array.prototype.slice.apply(arguments)),g(this,b.pageNumber,a)},l.prototype.onSearch=function(){x.apply(this,Array.prototype.slice.apply(arguments)),g(this,b.searchText,this.searchText)},l.prototype.deleteCookie=function(a){""!==a&&e()&&j(this.options.cookieIdTable,b[a],this.options.cookiePath,this.options.cookieDomain)}}(jQuery); \ No newline at end of file +!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",filterControl:"bs.table.filterControl"},c=function(a){var b=a.$header;return a.options.height&&(b=a.$tableHeader),b},d=function(a){var b="select, input";return a.options.height&&(b="table select, table input"),b},e=function(){return!!navigator.cookieEnabled},f=function(a,b){for(var c=-1,d=0;d + @if (!isset($simple_view)) - @@ -36,31 +36,27 @@ function buildTable($el) { classes: 'table table-responsive table-no-bordered', undefinedText: '', iconsPrefix: 'fa', - - @if (isset($search)) - search: true, - @endif - - + search: {{ (isset($search)) ? 'true' : 'false' }}, paginationVAlign: 'both', sidePagination: '{{ (isset($clientSearch)) ? 'client' : 'server' }}', sortable: true, + pageSize: 20, + pagination: true, + cookie: true, + cookieExpire: '2y', + cookieIdTable: '{{ Route::currentRouteName() }}', @if (!isset($simple_view)) showRefresh: true, - pagination: true, - pageSize: 20, - cookie: true, - cookieExpire: '2y', showExport: true, stickyHeader: true, stickyHeaderOffsetY: stickyHeaderOffsetY + 'px', - @if (isset($showFooter)) showFooter: true, @endif + showColumns: true, trimOnSearch: false, @@ -287,13 +283,9 @@ function itemTypeFormatter(value, row) { // We need a special formatter for license seats, since they don't work exactly the same // - function licenseSeatInOutFormatter (value, row) { + function licenseSeatInOutFormatter(value, row) { - if ((row.available_actions.checkout == true) && (row.user_can_checkout == true) && (!row.assigned_to)) { - return '{{ trans('general.checkout') }}'; - } else { - } } function genericCheckinCheckoutFormatter(destination) {