Fix filter type "group" when 500+ options are available (#5141)
When 500 options or more are presented in a group filter, PHP `max_input_vars` limits may prevent the filter from working. This fix passes selected options through as a JSON string to get around the limits.
This commit is contained in:
parent
70eac9b0e2
commit
517c588ef7
|
|
@ -208,7 +208,8 @@ class Filter extends WidgetBase
|
|||
|
||||
switch ($scope->type) {
|
||||
case 'group':
|
||||
$active = $this->optionsFromAjax(post('options.active'));
|
||||
$data = json_decode(post('options'), true);
|
||||
$active = $this->optionsFromAjax($data ?: null);
|
||||
$this->setScopeValue($scope, $active);
|
||||
break;
|
||||
|
||||
|
|
@ -223,7 +224,8 @@ class Filter extends WidgetBase
|
|||
break;
|
||||
|
||||
case 'date':
|
||||
$dates = $this->datesFromAjax(post('options.dates'));
|
||||
$data = json_decode(post('options'), true);
|
||||
$dates = $this->datesFromAjax($data['dates'] ?? null);
|
||||
|
||||
if (!empty($dates)) {
|
||||
list($date) = $dates;
|
||||
|
|
@ -236,7 +238,8 @@ class Filter extends WidgetBase
|
|||
break;
|
||||
|
||||
case 'daterange':
|
||||
$dates = $this->datesFromAjax(post('options.dates'));
|
||||
$data = json_decode(post('options'), true);
|
||||
$dates = $this->datesFromAjax($data['dates'] ?? null);
|
||||
|
||||
if (!empty($dates)) {
|
||||
list($after, $before) = $dates;
|
||||
|
|
@ -251,7 +254,8 @@ class Filter extends WidgetBase
|
|||
break;
|
||||
|
||||
case 'number':
|
||||
$numbers = $this->numbersFromAjax(post('options.numbers'));
|
||||
$data = json_decode(post('options'), true);
|
||||
$numbers = $this->numbersFromAjax($data['numbers'] ?? null);
|
||||
|
||||
if (!empty($numbers)) {
|
||||
list($number) = $numbers;
|
||||
|
|
@ -264,7 +268,8 @@ class Filter extends WidgetBase
|
|||
break;
|
||||
|
||||
case 'numberrange':
|
||||
$numbers = $this->numbersFromAjax(post('options.numbers'));
|
||||
$data = json_decode(post('options'), true);
|
||||
$numbers = $this->numbersFromAjax($data['numbers'] ?? null);
|
||||
|
||||
if (!empty($numbers)) {
|
||||
list($min, $max) = $numbers;
|
||||
|
|
|
|||
|
|
@ -23,6 +23,7 @@
|
|||
|
||||
this.options = options || {}
|
||||
this.scopeValues = {}
|
||||
this.scopeAvailable = {}
|
||||
this.$activeScope = null
|
||||
this.activeScopeName = null
|
||||
this.isActiveScopeDirty = false
|
||||
|
|
@ -286,23 +287,24 @@
|
|||
|
||||
var
|
||||
itemId = $item.data('item-id'),
|
||||
items = this.scopeValues[this.activeScopeName],
|
||||
fromItems = isDeselect ? items.active : items.available,
|
||||
toItems = isDeselect ? items.available : items.active,
|
||||
testFunc = function(item){ return item.id == itemId },
|
||||
active = this.scopeValues[this.activeScopeName],
|
||||
available = this.scopeAvailable[this.activeScopeName],
|
||||
fromItems = isDeselect ? active : available,
|
||||
toItems = isDeselect ? available : active,
|
||||
testFunc = function(active){ return active.id == itemId },
|
||||
item = $.grep(fromItems, testFunc).pop(),
|
||||
filtered = $.grep(fromItems, testFunc, true)
|
||||
|
||||
if (isDeselect)
|
||||
this.scopeValues[this.activeScopeName].active = filtered
|
||||
this.scopeValues[this.activeScopeName] = filtered
|
||||
else
|
||||
this.scopeValues[this.activeScopeName].available = filtered
|
||||
this.scopeAvailable[this.activeScopeName] = filtered
|
||||
|
||||
if (item)
|
||||
toItems.push(item)
|
||||
|
||||
this.toggleFilterButtons(items)
|
||||
this.updateScopeSetting(this.$activeScope, items.active.length)
|
||||
this.toggleFilterButtons(active)
|
||||
this.updateScopeSetting(this.$activeScope, isDeselect ? filtered.length : active.length)
|
||||
this.isActiveScopeDirty = true
|
||||
this.focusSearch()
|
||||
}
|
||||
|
|
@ -310,10 +312,17 @@
|
|||
FilterWidget.prototype.displayPopover = function($scope) {
|
||||
var self = this,
|
||||
scopeName = $scope.data('scope-name'),
|
||||
data = this.scopeValues[scopeName],
|
||||
data = null,
|
||||
isLoaded = true,
|
||||
container = false
|
||||
|
||||
if (typeof this.scopeAvailable[scopeName] !== "undefined" && this.scopeAvailable[scopeName]) {
|
||||
data = $.extend({}, data, {
|
||||
available: this.scopeAvailable[scopeName],
|
||||
active: this.scopeValues[scopeName]
|
||||
})
|
||||
}
|
||||
|
||||
// If the filter is running in a modal, popovers should be
|
||||
// attached to the modal container. This prevents z-index issues.
|
||||
var modalParent = $scope.parents('.modal-dialog')
|
||||
|
|
@ -390,7 +399,8 @@
|
|||
if (!data.active) data.active = []
|
||||
if (!data.available) data.available = []
|
||||
|
||||
this.scopeValues[scopeName] = data
|
||||
this.scopeValues[scopeName] = data.active;
|
||||
this.scopeAvailable[scopeName] = data.available;
|
||||
|
||||
// Do not render if scope has changed
|
||||
if (scopeName != this.activeScopeName)
|
||||
|
|
@ -424,9 +434,9 @@
|
|||
/*
|
||||
* Ensure any active items do not appear in the search results
|
||||
*/
|
||||
if (items.active.length) {
|
||||
if (items.length) {
|
||||
var activeIds = []
|
||||
$.each(items.active, function (key, obj) {
|
||||
$.each(items, function (key, obj) {
|
||||
activeIds.push(obj.id)
|
||||
})
|
||||
|
||||
|
|
@ -457,7 +467,7 @@
|
|||
buttonContainer = $('#controlFilterPopover .filter-buttons')
|
||||
|
||||
if (data) {
|
||||
data.active.length > 0 ? buttonContainer.show() : buttonContainer.hide()
|
||||
data.length > 0 ? buttonContainer.show() : buttonContainer.hide()
|
||||
} else {
|
||||
items.children().length > 0 ? buttonContainer.show() : buttonContainer.hide()
|
||||
}
|
||||
|
|
@ -473,7 +483,7 @@
|
|||
var self = this,
|
||||
data = {
|
||||
scopeName: scopeName,
|
||||
options: this.scopeValues[scopeName]
|
||||
options: JSON.stringify(this.scopeValues[scopeName])
|
||||
}
|
||||
|
||||
$.oc.stripeLoadIndicator.show()
|
||||
|
|
@ -541,6 +551,7 @@
|
|||
|
||||
if (isReset) {
|
||||
this.scopeValues[scopeName] = null
|
||||
this.scopeAvailable[scopeName] = null
|
||||
this.updateScopeSetting(this.$activeScope, 0)
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -3044,6 +3044,7 @@ $.fn.toolbar.noConflict=function(){$.fn.toolbar=old
|
|||
return this}
|
||||
$(document).on('render',function(){$('[data-control=toolbar]').toolbar()})}(window.jQuery);+function($){"use strict";var FilterWidget=function(element,options){this.$el=$(element);this.options=options||{}
|
||||
this.scopeValues={}
|
||||
this.scopeAvailable={}
|
||||
this.$activeScope=null
|
||||
this.activeScopeName=null
|
||||
this.isActiveScopeDirty=false
|
||||
|
|
@ -3148,18 +3149,19 @@ $item.addClass('animate-enter').prependTo($otherContainer).one('webkitAnimationE
|
|||
if(!this.scopeValues[this.activeScopeName])
|
||||
return
|
||||
var
|
||||
itemId=$item.data('item-id'),items=this.scopeValues[this.activeScopeName],fromItems=isDeselect?items.active:items.available,toItems=isDeselect?items.available:items.active,testFunc=function(item){return item.id==itemId},item=$.grep(fromItems,testFunc).pop(),filtered=$.grep(fromItems,testFunc,true)
|
||||
itemId=$item.data('item-id'),active=this.scopeValues[this.activeScopeName],available=this.scopeAvailable[this.activeScopeName],fromItems=isDeselect?active:available,toItems=isDeselect?available:active,testFunc=function(active){return active.id==itemId},item=$.grep(fromItems,testFunc).pop(),filtered=$.grep(fromItems,testFunc,true)
|
||||
if(isDeselect)
|
||||
this.scopeValues[this.activeScopeName].active=filtered
|
||||
this.scopeValues[this.activeScopeName]=filtered
|
||||
else
|
||||
this.scopeValues[this.activeScopeName].available=filtered
|
||||
this.scopeAvailable[this.activeScopeName]=filtered
|
||||
if(item)
|
||||
toItems.push(item)
|
||||
this.toggleFilterButtons(items)
|
||||
this.updateScopeSetting(this.$activeScope,items.active.length)
|
||||
this.toggleFilterButtons(active)
|
||||
this.updateScopeSetting(this.$activeScope,isDeselect?filtered.length:active.length)
|
||||
this.isActiveScopeDirty=true
|
||||
this.focusSearch()}
|
||||
FilterWidget.prototype.displayPopover=function($scope){var self=this,scopeName=$scope.data('scope-name'),data=this.scopeValues[scopeName],isLoaded=true,container=false
|
||||
FilterWidget.prototype.displayPopover=function($scope){var self=this,scopeName=$scope.data('scope-name'),data=null,isLoaded=true,container=false
|
||||
if(typeof this.scopeAvailable[scopeName]!=="undefined"&&this.scopeAvailable[scopeName]){data=$.extend({},data,{available:this.scopeAvailable[scopeName],active:this.scopeValues[scopeName]})}
|
||||
var modalParent=$scope.parents('.modal-dialog')
|
||||
if(modalParent.length>0){container=modalParent[0]}
|
||||
if(!data){data={loading:true}
|
||||
|
|
@ -3181,8 +3183,7 @@ FilterWidget.prototype.fillOptions=function(scopeName,data){if(this.scopeValues[
|
|||
return
|
||||
if(!data.active)data.active=[]
|
||||
if(!data.available)data.available=[]
|
||||
this.scopeValues[scopeName]=data
|
||||
if(scopeName!=this.activeScopeName)
|
||||
this.scopeValues[scopeName]=data.active;this.scopeAvailable[scopeName]=data.available;if(scopeName!=this.activeScopeName)
|
||||
return
|
||||
var container=$('#controlFilterPopover .filter-items > ul').empty()
|
||||
this.addItemsToListElement(container,data.available)
|
||||
|
|
@ -3194,8 +3195,8 @@ if(!this.scopeValues[this.activeScopeName])
|
|||
return
|
||||
var
|
||||
self=this,filtered=[],items=this.scopeValues[scopeName]
|
||||
if(items.active.length){var activeIds=[]
|
||||
$.each(items.active,function(key,obj){activeIds.push(obj.id)})
|
||||
if(items.length){var activeIds=[]
|
||||
$.each(items,function(key,obj){activeIds.push(obj.id)})
|
||||
filtered=$.grep(available,function(item){return $.inArray(item.id,activeIds)===-1})}
|
||||
else{filtered=available}
|
||||
var container=$('#controlFilterPopover .filter-items > ul').empty()
|
||||
|
|
@ -3204,10 +3205,10 @@ FilterWidget.prototype.addItemsToListElement=function($ul,items){$.each(items,fu
|
|||
$ul.append(item)})}
|
||||
FilterWidget.prototype.toggleFilterButtons=function(data)
|
||||
{var items=$('#controlFilterPopover .filter-active-items > ul'),buttonContainer=$('#controlFilterPopover .filter-buttons')
|
||||
if(data){data.active.length>0?buttonContainer.show():buttonContainer.hide()}else{items.children().length>0?buttonContainer.show():buttonContainer.hide()}}
|
||||
if(data){data.length>0?buttonContainer.show():buttonContainer.hide()}else{items.children().length>0?buttonContainer.show():buttonContainer.hide()}}
|
||||
FilterWidget.prototype.pushOptions=function(scopeName){if(!this.isActiveScopeDirty||!this.options.updateHandler)
|
||||
return
|
||||
var self=this,data={scopeName:scopeName,options:this.scopeValues[scopeName]}
|
||||
var self=this,data={scopeName:scopeName,options:JSON.stringify(this.scopeValues[scopeName])}
|
||||
$.oc.stripeLoadIndicator.show()
|
||||
this.$el.request(this.options.updateHandler,{data:data}).always(function(){$.oc.stripeLoadIndicator.hide()}).done(function(){self.$el.find('[data-scope-name="'+scopeName+'"]').trigger('change.oc.filterScope')})}
|
||||
FilterWidget.prototype.checkboxToggle=function($el){var isChecked=$el.is(':checked'),$scope=$el.closest('.filter-scope'),scopeName=$scope.data('scope-name')
|
||||
|
|
@ -3224,6 +3225,7 @@ this.$el.request(this.options.updateHandler,{data:data}).always(function(){$.oc.
|
|||
$scope.toggleClass('active',!!switchValue)}
|
||||
FilterWidget.prototype.filterScope=function(isReset){var scopeName=this.$activeScope.data('scope-name')
|
||||
if(isReset){this.scopeValues[scopeName]=null
|
||||
this.scopeAvailable[scopeName]=null
|
||||
this.updateScopeSetting(this.$activeScope,0)}
|
||||
this.pushOptions(scopeName);this.isActiveScopeDirty=true;this.$activeScope.data('oc.popover').hide()}
|
||||
FilterWidget.prototype.getLang=function(name,defaultValue){if($.oc===undefined||$.oc.lang===undefined){return defaultValue}
|
||||
|
|
|
|||
Loading…
Reference in New Issue