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