I get how the first two work and when they are called. But don't understand when and how the third option (realValue != null ) works, can someone plz explain or give me a link with an explenation because I don't seem to find it.
- Code: Select all
/**
* Called when the valuelist needs data, it has 3 modes.
* real and display params both null: return the whole list
* only display is specified, called by a typeahead, return a filtered list
* only real value is specified, called when the list doesnt contain the real value for the give record value, this will insert this value into the existing list
*
* @param {String} displayValue The value of a lookupfield that a user types
* @param realValue The real value for a lookupfield where a display value should be get for
* @param {JSRecord} record The current record for the valuelist.
* @param {String} valueListName The valuelist name that triggers the method. (This is the FindRecord in find mode, which is like JSRecord has all the columns/dataproviders, but doesn't have its methods)
* @param {Boolean} findMode True if foundset of this record is in find mode
* @param {Boolean} rawDisplayValue The raw displayValue without being converted to lower case
*
* @return {JSDataSet} A dataset with 1 or 2 columns display[,real]
*
* @properties={typeid:24,uuid:"AA41BF59-E584-4A46-B446-B1A8BFA5E2C4"}
*/
function getDataSetForValueList( displayValue, realValue, record, valueListName, findMode, rawDisplayValue ) {
var args = null;
var query = datasources.db.example_data.employees.createSelect( );
/** @type {JSDataSet} */
var result = null;
if ( displayValue == null && realValue == null ) {
// TODO think about caching this result. can be called often!
// return the complete list
query.result.add( query.columns.firstname.concat( ' ' ).concat( query.columns.lastname ) ).add( query.columns.employeeid );
result = databaseManager.getDataSetByQuery( query, 100 );
}
else if ( displayValue != null ) {
// TYPE_AHEAD filter call, return a filtered list
args = [displayValue + "%", displayValue + "%"];
query.result.add( query.columns.firstname.concat( ' ' ).concat( query.columns.lastname ) ).add( query.columns.employeeid ).root.where.add( query.or.add( query.columns.firstname.lower.like( args[0] + '%' ) ).add( query.columns.lastname.lower.like( args[1] + '%' ) ) );
result = databaseManager.getDataSetByQuery( query, 100 );
}
else if ( realValue != null ) {
// TODO think about caching this result. can be called often!
// real object not found in the current list, return 1 row with display,realvalue that will be added to the current list
// dont return a complete list in this mode because that will be added to the list that is already there
args = [realValue];
query.result.add( query.columns.firstname.concat( ' ' ).concat( query.columns.lastname ) ).add( query.columns.employeeid ).root.where.add( query.columns.employeeid.eq( args[0] ) );
result = databaseManager.getDataSetByQuery( query, 1 );
}
return result;
}