Fix the startup trouble the search code was causing (moved DB call into init() function rather than constructor) -- sorry about that
This commit is contained in:
parent
504ebf8996
commit
d7ed7c256c
1 changed files with 104 additions and 87 deletions
|
@ -400,6 +400,9 @@ Scholar.SearchConditions = new function(){
|
||||||
this.getStandardConditions = getStandardConditions;
|
this.getStandardConditions = getStandardConditions;
|
||||||
this.hasOperator = hasOperator;
|
this.hasOperator = hasOperator;
|
||||||
|
|
||||||
|
var _initialized = false;
|
||||||
|
var _conditions = [];
|
||||||
|
var _standardConditions = [];
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Define the advanced search operators
|
* Define the advanced search operators
|
||||||
|
@ -424,100 +427,102 @@ Scholar.SearchConditions = new function(){
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Define the advanced search conditions
|
* Define and set up the available advanced search conditions
|
||||||
*/
|
*/
|
||||||
var _conditions = [
|
function _init(){
|
||||||
//
|
_conditions = [
|
||||||
// Special conditions
|
//
|
||||||
//
|
// Special conditions
|
||||||
|
//
|
||||||
// Context (i.e. collection id to search within)
|
|
||||||
{
|
// Context (i.e. collection id to search within)
|
||||||
name: 'context'
|
{
|
||||||
},
|
name: 'context'
|
||||||
|
},
|
||||||
// Search recursively
|
|
||||||
{
|
// Search recursively
|
||||||
name: 'recursive',
|
{
|
||||||
operators: {
|
name: 'recursive',
|
||||||
true: true,
|
operators: {
|
||||||
false: true
|
true: true,
|
||||||
|
false: true
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
// Join mode
|
||||||
|
{
|
||||||
|
name: 'joinMode',
|
||||||
|
operators: {
|
||||||
|
any: true,
|
||||||
|
all: true
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
//
|
||||||
|
// Standard conditions
|
||||||
|
//
|
||||||
|
|
||||||
|
{
|
||||||
|
name: 'title',
|
||||||
|
operators: {
|
||||||
|
contains: true,
|
||||||
|
doesNotContain: true
|
||||||
|
},
|
||||||
|
table: 'items',
|
||||||
|
field: 'title'
|
||||||
|
},
|
||||||
|
|
||||||
|
{
|
||||||
|
name: 'itemType',
|
||||||
|
operators: {
|
||||||
|
is: true,
|
||||||
|
isNot: true
|
||||||
|
},
|
||||||
|
table: 'items',
|
||||||
|
field: 'itemTypeID'
|
||||||
|
},
|
||||||
|
|
||||||
|
{
|
||||||
|
name: 'field',
|
||||||
|
operators: {
|
||||||
|
is: true,
|
||||||
|
isNot: true,
|
||||||
|
contains: true,
|
||||||
|
doesNotContain: true
|
||||||
|
},
|
||||||
|
table: 'itemData',
|
||||||
|
field: 'value',
|
||||||
|
aliases: Scholar.DB.columnQuery("SELECT fieldName FROM fields"),
|
||||||
|
template: true // mark for special handling
|
||||||
}
|
}
|
||||||
},
|
];
|
||||||
|
|
||||||
// Join mode
|
// Index conditions by name and aliases
|
||||||
{
|
for (var i in _conditions){
|
||||||
name: 'joinMode',
|
_conditions[_conditions[i]['name']] = _conditions[i];
|
||||||
operators: {
|
if (_conditions[i]['aliases']){
|
||||||
any: true,
|
for (var j in _conditions[i]['aliases']){
|
||||||
all: true
|
_conditions[_conditions[i]['aliases'][j]] = _conditions[i];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
},
|
_conditions[_conditions[i]['name']] = _conditions[i];
|
||||||
|
delete _conditions[i];
|
||||||
//
|
|
||||||
// Standard conditions
|
|
||||||
//
|
|
||||||
|
|
||||||
{
|
|
||||||
name: 'title',
|
|
||||||
operators: {
|
|
||||||
contains: true,
|
|
||||||
doesNotContain: true
|
|
||||||
},
|
|
||||||
table: 'items',
|
|
||||||
field: 'title'
|
|
||||||
},
|
|
||||||
|
|
||||||
{
|
|
||||||
name: 'itemType',
|
|
||||||
operators: {
|
|
||||||
is: true,
|
|
||||||
isNot: true
|
|
||||||
},
|
|
||||||
table: 'items',
|
|
||||||
field: 'itemTypeID'
|
|
||||||
},
|
|
||||||
|
|
||||||
{
|
|
||||||
name: 'field',
|
|
||||||
operators: {
|
|
||||||
is: true,
|
|
||||||
isNot: true,
|
|
||||||
contains: true,
|
|
||||||
doesNotContain: true
|
|
||||||
},
|
|
||||||
table: 'itemData',
|
|
||||||
field: 'value',
|
|
||||||
aliases: Scholar.DB.columnQuery("SELECT fieldName FROM fields"),
|
|
||||||
template: true // mark for special handling
|
|
||||||
}
|
}
|
||||||
];
|
|
||||||
|
// Separate standard conditions for menu display
|
||||||
// Index conditions by name and aliases
|
for (var i in _conditions){
|
||||||
for (var i in _conditions){
|
// Standard conditions a have associated tables
|
||||||
_conditions[_conditions[i]['name']] = _conditions[i];
|
if (_conditions[i]['table'] &&
|
||||||
if (_conditions[i]['aliases']){
|
// If a template condition, not the original (e.g. 'field')
|
||||||
for (var j in _conditions[i]['aliases']){
|
(!_conditions[i]['template'] || i!=_conditions[i]['name'])){
|
||||||
_conditions[_conditions[i]['aliases'][j]] = _conditions[i];
|
_standardConditions.push({
|
||||||
|
name: i,
|
||||||
|
operators: _conditions[i]['operators']
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
_conditions[_conditions[i]['name']] = _conditions[i];
|
|
||||||
delete _conditions[i];
|
_initialized = true;
|
||||||
}
|
|
||||||
|
|
||||||
var _standardConditions = [];
|
|
||||||
|
|
||||||
// Separate standard conditions for menu display
|
|
||||||
for (var i in _conditions){
|
|
||||||
// Standard conditions a have associated tables
|
|
||||||
if (_conditions[i]['table'] &&
|
|
||||||
// If a template condition, not the original (e.g. 'field')
|
|
||||||
(!_conditions[i]['template'] || i!=_conditions[i]['name'])){
|
|
||||||
_standardConditions.push({
|
|
||||||
name: i,
|
|
||||||
operators: _conditions[i]['operators']
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -525,6 +530,10 @@ Scholar.SearchConditions = new function(){
|
||||||
* Get condition data
|
* Get condition data
|
||||||
*/
|
*/
|
||||||
function get(condition){
|
function get(condition){
|
||||||
|
if (!_initialized){
|
||||||
|
_init();
|
||||||
|
}
|
||||||
|
|
||||||
return _conditions[condition];
|
return _conditions[condition];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -535,6 +544,10 @@ Scholar.SearchConditions = new function(){
|
||||||
* Does not include special conditions, only ones that would show in a drop-down list
|
* Does not include special conditions, only ones that would show in a drop-down list
|
||||||
*/
|
*/
|
||||||
function getStandardConditions(){
|
function getStandardConditions(){
|
||||||
|
if (!_initialized){
|
||||||
|
_init();
|
||||||
|
}
|
||||||
|
|
||||||
// TODO: return copy instead
|
// TODO: return copy instead
|
||||||
return _standardConditions;
|
return _standardConditions;
|
||||||
}
|
}
|
||||||
|
@ -544,6 +557,10 @@ Scholar.SearchConditions = new function(){
|
||||||
* Check if an operator is valid for a given condition
|
* Check if an operator is valid for a given condition
|
||||||
*/
|
*/
|
||||||
function hasOperator(condition, operator){
|
function hasOperator(condition, operator){
|
||||||
|
if (!_initialized){
|
||||||
|
_init();
|
||||||
|
}
|
||||||
|
|
||||||
if (!_conditions[condition]){
|
if (!_conditions[condition]){
|
||||||
throw ("Invalid condition '" + condition + "' in hasOperator()");
|
throw ("Invalid condition '" + condition + "' in hasOperator()");
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue