mirror of
https://github.com/processwire/processwire.git
synced 2025-08-17 12:10:45 +02:00
Update InputfieldSelector to support new text search operators
This commit is contained in:
@@ -474,6 +474,7 @@ var InputfieldSelector = {
|
||||
var op = $op.val();
|
||||
var $value = $op.next('.input-value');
|
||||
var value = $value.val();
|
||||
var fieldPrefix = '';
|
||||
|
||||
if(op && op.indexOf('"') > -1) {
|
||||
// handle: 'is empty' or 'is not empty' operators
|
||||
@@ -483,24 +484,33 @@ var InputfieldSelector = {
|
||||
$value.removeAttr('disabled');
|
||||
}
|
||||
|
||||
if(op.indexOf('!') === 0 && op !== '!=') {
|
||||
fieldPrefix = '!';
|
||||
op = op.substring(1);
|
||||
}
|
||||
|
||||
if(typeof value != "undefined") if(value.length) {
|
||||
|
||||
if($value.hasClass("input-value-subselect") && InputfieldSelector.valueHasOperator(value)) {
|
||||
// value needs to be identified as a sub-selector
|
||||
value = '[' + value + ']';
|
||||
|
||||
} else if(value.indexOf(',') > -1 && fieldName != '_custom') {
|
||||
// } else if(value.indexOf(',') > -1 && fieldName != '_custom') {
|
||||
} else if(fieldName != '_custom') {
|
||||
// value needs to be quoted
|
||||
if(value.indexOf('"') > -1) {
|
||||
if(value.indexOf("'") == -1) value = "'" + value + "'";
|
||||
else value = '"' + value.replace(/"/g, '') + '"'; // remove quote
|
||||
} else {
|
||||
if(value.indexOf("'") === -1) {
|
||||
value = "'" + value + "'";
|
||||
} else {
|
||||
value = '"' + value.replace(/"/g, '') + '"'; // remove quote
|
||||
}
|
||||
} else if(!value.match(/^[-_a-zA-Z0-9]*$/)) {
|
||||
value = '"' + value + '"';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
var testField = ',' + fieldName + '~' + op + '~';
|
||||
var testField = ',' + fieldPrefix + fieldName + '~' + op + '~';
|
||||
var testValue = '~' + op + '~' + value + ',';
|
||||
var mayOrValue = value && value.length > 0 && test.indexOf(testField) > -1;
|
||||
var mayOrField = value && value.length > 0 && test.indexOf(testValue) > -1;
|
||||
@@ -526,6 +536,7 @@ var InputfieldSelector = {
|
||||
}
|
||||
|
||||
selectors[n++] = {
|
||||
not: fieldPrefix === '!',
|
||||
field: fieldName,
|
||||
operator: op,
|
||||
value: value,
|
||||
@@ -535,11 +546,11 @@ var InputfieldSelector = {
|
||||
useOrField: useOrField,
|
||||
isOrGroup: isOrGroup,
|
||||
checkbox: $orCheckbox
|
||||
};
|
||||
};
|
||||
|
||||
if(mayOrField || mayOrValue) showOrNotes = true;
|
||||
test += ',' + fieldName + '~' + op + '~' + value + ',';
|
||||
selector += ',' + fieldName + op + value; // this gets rebuilt later, but is here for querying
|
||||
test += ',' + fieldPrefix + fieldName + '~' + op + '~' + value + ',';
|
||||
selector += ',' + fieldPrefix + fieldName + op + value; // this gets rebuilt later, but is here for querying
|
||||
|
||||
}); // each row
|
||||
|
||||
@@ -621,6 +632,7 @@ var InputfieldSelector = {
|
||||
selector += s.field + '="' + $.trim(s.value) + '"';
|
||||
}
|
||||
} else {
|
||||
if(s.not) selector += '!';
|
||||
selector += s.field + s.operator + $.trim(s.value);
|
||||
}
|
||||
}
|
||||
|
File diff suppressed because one or more lines are too long
@@ -356,39 +356,41 @@ class InputfieldSelector extends Inputfield implements ConfigurableModule {
|
||||
*/
|
||||
public function setup() {
|
||||
|
||||
$this->operators = array(
|
||||
'=' => $this->_('Equals'),
|
||||
'!=' => $this->_('Not Equals'),
|
||||
'>' => $this->_('Greater Than'),
|
||||
'<' => $this->_('Less Than'),
|
||||
'>=' => $this->_('Greater Than or Equal'),
|
||||
'<=' => $this->_('Less Than or Equal'),
|
||||
'%=' => $this->_('Contains Text'),
|
||||
'*=' => $this->_('Contains Phrase'),
|
||||
'~=' => $this->_('Contains Words'),
|
||||
'^=' => $this->_('Starts With'),
|
||||
'$=' => $this->_('Ends With'),
|
||||
'!%=' => $this->_('Does Not Contain Text'),
|
||||
'!*=' => $this->_('Does Not Contain Phrase'),
|
||||
'!~=' => $this->_('Does Not Contain Words'),
|
||||
'!^=' => $this->_('Does Not Start With'),
|
||||
'!$=' => $this->_('Does Not End With'),
|
||||
'.=' => $this->_('Ascending By'),
|
||||
'.=-' => $this->_('Descending By'),
|
||||
$notLabel = $this->_('Not: %s');
|
||||
$findOperators = array();
|
||||
$findNotOperators = array();
|
||||
|
||||
$operators = Selectors::getOperators(array(
|
||||
'getIndexType' => 'operator',
|
||||
'getValueType' => 'verbose',
|
||||
));
|
||||
|
||||
foreach($operators as $operator => $info) {
|
||||
$this->operators[$operator] = $info['label'];
|
||||
if($info['compareType'] & Selector::compareTypeFind) {
|
||||
$findOperators[$operator] = $info['label'];
|
||||
$findNotOperators["!$operator"] = sprintf($notLabel, $info['label']);
|
||||
}
|
||||
}
|
||||
|
||||
$this->operators = array_merge($this->operators, $findNotOperators, array(
|
||||
'.=' => $this->_('Ascending By'),
|
||||
'.=-' => $this->_('Descending By'),
|
||||
'@=' => $this->_('Has'),
|
||||
'@!=' => $this->_('Does Not Have'),
|
||||
'#=' => $this->_('Matches'),
|
||||
'#!=' => $this->_('Does Not Match'),
|
||||
'=""' => $this->_('Is Empty'),
|
||||
'!=""' => $this->_('Is Not Empty'),
|
||||
);
|
||||
'=""' => $this->_('Is Empty'),
|
||||
'!=""' => $this->_('Is Not Empty'),
|
||||
//'#=' => $this->_('Matches'),
|
||||
//'#!=' => $this->_('Does Not Match'),
|
||||
));
|
||||
|
||||
// operators by input type
|
||||
// this is a backup and/or for system fields, as these may also be specified
|
||||
// with fieldtype's getSelectorInfo() method, which takes precedence
|
||||
$this->operatorsByType = array(
|
||||
'name' => array('=', '!=', '%='),
|
||||
'text' => array('%=', '!%=', '*=', '!*=', '~=', '!~=', '^=', '!^=', '$=', '!$=', '=', '!=', '=""', '!=""'),
|
||||
// 'text' => array('%=', '!%=', '*=', '!*=', '~=', '!~=', '^=', '!^=', '$=', '!$=', '=', '!=', '=""', '!=""'),
|
||||
'text' => array_merge($findOperators, array('=', '!=', '<', '<=', '>', '>='), $findNotOperators),
|
||||
'autocomplete' => array('=', '!='),
|
||||
'number' => array('=', '!=', '<', '>', '<=', '>=', '=""', '!=""'),
|
||||
'datetime' => array('=', '!=', '<', '>', '<=', '>='),
|
||||
@@ -402,7 +404,7 @@ class InputfieldSelector extends Inputfield implements ConfigurableModule {
|
||||
|
||||
// chars that are trimmed off operators before being used
|
||||
// enables different contexts for the same operator
|
||||
$this->operatorTrimChars = '.@#';
|
||||
$this->operatorTrimChars = '.@';
|
||||
|
||||
$templates = array();
|
||||
foreach($this->wire('templates') as $template) {
|
||||
|
Reference in New Issue
Block a user