mirror of
https://github.com/processwire/processwire.git
synced 2025-08-09 16:26:59 +02:00
Add support for OR-groups in "custom (field=value)" selections in InputfieldSelector. Simply use the existing "or" checkbox to apply the custom selector as an OR group.
This commit is contained in:
@@ -480,6 +480,7 @@ var InputfieldSelector = {
|
|||||||
var $orCheckbox = $row.find(".input-or");
|
var $orCheckbox = $row.find(".input-or");
|
||||||
var useOrValue = mayOrValue && $orCheckbox.is(":checked");
|
var useOrValue = mayOrValue && $orCheckbox.is(":checked");
|
||||||
var useOrField = mayOrField && $orCheckbox.is(":checked");
|
var useOrField = mayOrField && $orCheckbox.is(":checked");
|
||||||
|
var isOrGroup = (useOrField || useOrValue) && fieldName == '_custom';
|
||||||
|
|
||||||
if(useOrValue) { // && !$row.is('.has-or-value')) {
|
if(useOrValue) { // && !$row.is('.has-or-value')) {
|
||||||
$row.addClass('has-or-value');
|
$row.addClass('has-or-value');
|
||||||
@@ -505,6 +506,7 @@ var InputfieldSelector = {
|
|||||||
mayOrField: mayOrField,
|
mayOrField: mayOrField,
|
||||||
useOrValue: useOrValue,
|
useOrValue: useOrValue,
|
||||||
useOrField: useOrField,
|
useOrField: useOrField,
|
||||||
|
isOrGroup: isOrGroup,
|
||||||
checkbox: $orCheckbox
|
checkbox: $orCheckbox
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -560,7 +562,9 @@ var InputfieldSelector = {
|
|||||||
if(i === n) continue;
|
if(i === n) continue;
|
||||||
var si = selectors[i];
|
var si = selectors[i];
|
||||||
if(si === null || typeof si == "undefined" || typeof si.value == "undefined") continue;
|
if(si === null || typeof si == "undefined" || typeof si.value == "undefined") continue;
|
||||||
if(si.mayOrField && si.value == s.value) {
|
if(si.field == '_custom' && si.isOrGroup) {
|
||||||
|
s.isOrGroup = true;
|
||||||
|
} else if(si.mayOrField && si.value == s.value) {
|
||||||
si.checkbox.show();
|
si.checkbox.show();
|
||||||
if(si.useOrField) {
|
if(si.useOrField) {
|
||||||
s.field += '|' + si.field;
|
s.field += '|' + si.field;
|
||||||
@@ -582,7 +586,12 @@ var InputfieldSelector = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if(s.field == '_custom') {
|
if(s.field == '_custom') {
|
||||||
selector += s.value;
|
if(s.isOrGroup) {
|
||||||
|
s.value = s.value.replace('(', '').replace(')', '');
|
||||||
|
selector += s.field + '=' + '(' + s.value + ')';
|
||||||
|
} else {
|
||||||
|
selector += s.value;
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
selector += s.field + s.operator + $.trim(s.value);
|
selector += s.field + s.operator + $.trim(s.value);
|
||||||
}
|
}
|
||||||
|
File diff suppressed because one or more lines are too long
@@ -492,8 +492,7 @@ class InputfieldSelector extends Inputfield implements ConfigurableModule {
|
|||||||
'label' => $this->_('Custom (field=value)'),
|
'label' => $this->_('Custom (field=value)'),
|
||||||
'operators' => array(),
|
'operators' => array(),
|
||||||
'placeholder' => $this->_('field=value'),
|
'placeholder' => $this->_('field=value'),
|
||||||
),
|
),
|
||||||
|
|
||||||
//'parent' => $this->_('parent'),
|
//'parent' => $this->_('parent'),
|
||||||
);
|
);
|
||||||
|
|
||||||
@@ -1125,12 +1124,12 @@ class InputfieldSelector extends Inputfield implements ConfigurableModule {
|
|||||||
$options[$item->id] = $inputfield->getPageLabel($item); // $item->get('title|name');
|
$options[$item->id] = $inputfield->getPageLabel($item); // $item->get('title|name');
|
||||||
}
|
}
|
||||||
if(count($options) < 2
|
if(count($options) < 2
|
||||||
&& ($field->parent_id || $field->template_id)
|
&& ($field->get('parent_id') || $field->get('template_id'))
|
||||||
&& ($field->findPagesCode || $field->findPagesSelector)) {
|
&& ($field->get('findPagesCode') || $field->get('findPagesSelector'))) {
|
||||||
// see if we can locate options purely with the parent or template
|
// see if we can locate options purely with the parent or template
|
||||||
$findSelector = array("include=unpublished, limit=500, sort=title, sort=name, ");
|
$findSelector = array("include=unpublished, limit=500, sort=title, sort=name, ");
|
||||||
if($field->parent_id) $findSelector[] = "parent_id=" . (int) $field->parent_id;
|
if($field->get('parent_id')) $findSelector[] = "parent_id=" . (int) $field->get('parent_id');
|
||||||
if($field->template_id) $findSelector[] = "templates_id=" . (int) $field->template_id;
|
if($field->get('template_id')) $findSelector[] = "templates_id=" . (int) $field->get('template_id');
|
||||||
foreach($this->wire('pages')->find(implode(', ', $findSelector)) as $item) {
|
foreach($this->wire('pages')->find(implode(', ', $findSelector)) as $item) {
|
||||||
$options[$item->id] = $inputfield->getPageLabel($item); // $item->get('title|name');
|
$options[$item->id] = $inputfield->getPageLabel($item); // $item->get('title|name');
|
||||||
}
|
}
|
||||||
@@ -1400,35 +1399,35 @@ class InputfieldSelector extends Inputfield implements ConfigurableModule {
|
|||||||
$hasPageListSelect = strpos($field->get('inputfield'), 'PageListSelect') !== false;
|
$hasPageListSelect = strpos($field->get('inputfield'), 'PageListSelect') !== false;
|
||||||
|
|
||||||
// determine autocomplete state based on field settings and quantity of pages involved
|
// determine autocomplete state based on field settings and quantity of pages involved
|
||||||
if($field->findPagesSelector) {
|
if($field->get('findPagesSelector')) {
|
||||||
// user-specified selector determines which pages match
|
// user-specified selector determines which pages match
|
||||||
$selector = trim($field->findPagesSelector, ', ');
|
$selector = trim($field->get('findPagesSelector'), ', ');
|
||||||
if(strpos($selector, 'page.') !== false) {
|
if(strpos($selector, 'page.') !== false) {
|
||||||
// remove page.something impossible reference, if present
|
// remove page.something impossible reference, if present
|
||||||
$selector = preg_replace('/[_a-zA-Z0-9]+[=<>!]+page\.[_a-zA-Z0-9]+[\s,]*/', '', $selector);
|
$selector = preg_replace('/[_a-zA-Z0-9]+[=<>!]+page\.[_a-zA-Z0-9]+[\s,]*/', '', $selector);
|
||||||
//$selector = preg_replace('/(^|,)\s*page\.[_a-zA-Z0-9][=<>!]+[^,]*/', '', $selector);
|
//$selector = preg_replace('/(^|,)\s*page\.[_a-zA-Z0-9][=<>!]+[^,]*/', '', $selector);
|
||||||
}
|
}
|
||||||
if($field->parent_id) $selector .= ",has_parent=" . (int) $field->parent_id;
|
if($field->get('parent_id')) $selector .= ",has_parent=" . (int) $field->get('parent_id');
|
||||||
} else if($field->parent_id) {
|
} else if($field->get('parent_id')) {
|
||||||
if($hasPageListSelect) {
|
if($hasPageListSelect) {
|
||||||
$selector = "has_parent=" . (int) $field->parent_id;
|
$selector = "has_parent=" . (int) $field->get('parent_id');
|
||||||
} else {
|
} else {
|
||||||
$selector = "parent_id=" . (int) $field->parent_id;
|
$selector = "parent_id=" . (int) $field->get('parent_id');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if($field->template_id) {
|
if($field->get('template_id')) {
|
||||||
$selector .= ",templates_id=";
|
$selector .= ",templates_id=";
|
||||||
if(is_array($field->template_id)) {
|
if(is_array($field->get('template_id'))) {
|
||||||
if(count($field->template_id)) $selector .= implode('|', $field->template_id);
|
if(count($field->get('template_id'))) $selector .= implode('|', $field->get('template_id'));
|
||||||
} else {
|
} else {
|
||||||
$selector .= (int) $field->template_id;
|
$selector .= (int) $field->get('template_id');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if(empty($selector)) {
|
if(empty($selector)) {
|
||||||
// if it's using a runtime code to determine, then we can't use autocomplete
|
// if it's using a runtime code to determine, then we can't use autocomplete
|
||||||
if($field->findPagesCode) return '';
|
if($field->get('findPagesCode')) return '';
|
||||||
// otherwise just populate a selector that can match anything
|
// otherwise just populate a selector that can match anything
|
||||||
$selector = "id>0";
|
$selector = "id>0";
|
||||||
}
|
}
|
||||||
@@ -1717,8 +1716,8 @@ class InputfieldSelector extends Inputfield implements ConfigurableModule {
|
|||||||
|
|
||||||
// render a row for each value in the selector (usually 1)
|
// render a row for each value in the selector (usually 1)
|
||||||
foreach($values as $valueNum => $value) {
|
foreach($values as $valueNum => $value) {
|
||||||
if($valueNum > 0) $rowClass .= " has-or-value";
|
if($valueNum > 0 || $quote == '(') $rowClass .= " has-or-value";
|
||||||
if($fieldNum > 0 || $valueNum > 0) $orChecked = true;
|
if($fieldNum > 0 || $valueNum > 0 || $quote == '(') $orChecked = true;
|
||||||
if(!strlen($value) && $quote) $value = "$quote{$value}$quote";
|
if(!strlen($value) && $quote) $value = "$quote{$value}$quote";
|
||||||
$operator = $selector->operator;
|
$operator = $selector->operator;
|
||||||
// convert to not operator when finding a not selector
|
// convert to not operator when finding a not selector
|
||||||
|
Reference in New Issue
Block a user