You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
324 lines
7.4 KiB
324 lines
7.4 KiB
/*
|
|
* requires fittingStrings.js to be loaded first
|
|
*/
|
|
|
|
|
|
/*
|
|
* provide alternative Names already existent in DB to given names in
|
|
* input text fields:
|
|
*
|
|
* Arguments:
|
|
* fname / ID of the input text field with firstname
|
|
* sname / ID of the input text field with surname
|
|
* fnameAlt / ID of the list that recieves the alternative firstnames
|
|
* snameAlt / ID of the list that receives the alternative surnames
|
|
* names / Array containing the already existing names and persons.
|
|
*
|
|
* Methods:
|
|
* updField / exact match(no-case) found => update input field
|
|
* genAlternativesList / generate List of alternative Strings
|
|
* altSurnames / fill the list of alternative surnames
|
|
* altFirstnames / fill the list of alternative firstnames
|
|
*/
|
|
function c_personSearch1 (fname, sname, fnameAlt, snameAlt, names, person)
|
|
{
|
|
this.firstname = fname;
|
|
this.surname = sname;
|
|
this.fNameAlt = fnameAlt;
|
|
this.sNameAlt = snameAlt;
|
|
|
|
this.surnames = new Array ();
|
|
this.firstnames = new Array ();
|
|
this.persons = new Array ();
|
|
for (sn in names)
|
|
{
|
|
this.surnames.push (sn);
|
|
this.firstnames[sn] = new Array ();
|
|
this.persons[sn] = new Array ();
|
|
for (d in names[sn])
|
|
{
|
|
this.firstnames[sn].push (names[sn][d][0]);
|
|
this.persons[sn][names[sn][d][0]] = names[sn][d][1];
|
|
}
|
|
}
|
|
this.person = person;
|
|
|
|
this.sNameBest = new Array (-1, -1, null);
|
|
this.fNameBest = new Array (-1, -1, null);
|
|
|
|
this.snameIdx = -1;
|
|
this.fnameIdx = -1;
|
|
this.snameMaxIdx = -1;
|
|
this.fnameMaxIdx = -1;
|
|
this.snameDists = new Array ();
|
|
this.fnameDists = new Array ();
|
|
|
|
this.incSnameIdx = function ()
|
|
{
|
|
if (this.snameIdx < this.snameMaxIdx-1)
|
|
this.snameIdx ++;
|
|
}
|
|
|
|
this.incFnameIdx = function ()
|
|
{
|
|
if (this.fnameIdx < this.fnameMaxIdx-1)
|
|
this.fnameIdx ++;
|
|
}
|
|
|
|
this.decSnameIdx = function ()
|
|
{
|
|
if (this.snameIdx >= 0)
|
|
this.snameIdx --;
|
|
}
|
|
|
|
this.decFnameIdx = function ()
|
|
{
|
|
if (this.fnameIdx >= 0)
|
|
this.fnameIdx --;
|
|
}
|
|
|
|
this.show = function (id)
|
|
{
|
|
var node = document.getElementById (id);
|
|
node.parentNode.style.visibility = 'visible';
|
|
|
|
return false;
|
|
}
|
|
|
|
this.hide = function (id)
|
|
{
|
|
var node = document.getElementById (id);
|
|
var inField =
|
|
node.parentNode.parentNode.getElementsByTagName ('input')[0];
|
|
var idx = -1;
|
|
var dists = new Array ();
|
|
|
|
node.parentNode.style.visibility = 'hidden';
|
|
|
|
switch (inField.getAttribute ('id'))
|
|
{
|
|
case 'personSearch1_fname':
|
|
idx = this.fnameIdx;
|
|
if (idx != -1)
|
|
{
|
|
dists = this.fnameDists[idx].split ('::');
|
|
this.fNameBest = new Array (0, 0, dists[2]);
|
|
inField.value = dists[2];
|
|
}
|
|
break;
|
|
case 'personSearch1_sname':
|
|
idx = this.snameIdx;
|
|
if (idx != -1)
|
|
{
|
|
dists = this.snameDists[idx].split ('::');
|
|
this.sNameBest = new Array (0, 0, dists[2]);
|
|
inField.value = dists[2];
|
|
}
|
|
}
|
|
|
|
if (this.person != null)
|
|
if (this.fNameBest[1] == 0)
|
|
this.person.update (
|
|
this.persons[this.sNameBest[2]][this.fNameBest[2]]);
|
|
else
|
|
this.person.empty ();
|
|
|
|
return false;
|
|
}
|
|
|
|
this.updField = function (field, alternative, altId)
|
|
{
|
|
if (alternative[1] == 0)
|
|
field.value = alternative[2];
|
|
else
|
|
if (alternative[1] >= 0)
|
|
return this.show (altId);
|
|
|
|
return this.hide (altId);
|
|
}
|
|
|
|
this.genAlternativesList = function (bestFit, dists, idx)
|
|
{
|
|
if (dists.length > 0)
|
|
// there are caculated distances for surnames
|
|
{
|
|
var i = 0;
|
|
var bestMatch = dists[0].split ('::'); // infos for best match
|
|
|
|
// reset matches select
|
|
while ((child = bestFit.firstChild) != null)
|
|
bestFit.removeChild (child);
|
|
|
|
for (match in dists)
|
|
// walk through all matches
|
|
{
|
|
// get infos for match
|
|
var sMatch = dists[match].split ('::');
|
|
|
|
// create list entries
|
|
newLi = document.createElement ('li');
|
|
|
|
if (i == idx)
|
|
newLi.className = 'bgc-tt1-selItem';
|
|
|
|
liTxt = document.createTextNode (sMatch[2]);
|
|
newLi.appendChild (liTxt);
|
|
bestFit.appendChild (newLi);
|
|
i=i+1;
|
|
|
|
if (i >= bestMatch[1] && sMatch[1] > bestMatch[1])
|
|
// dont show more than best match distance matches.
|
|
break;
|
|
}
|
|
}
|
|
else
|
|
// there are no caculated distances for surnames
|
|
{
|
|
// reset matches select
|
|
while ((child = bestFit.firstChild) != null)
|
|
bestFit.removeChild (child);
|
|
return new Array (-1, -1, '');
|
|
}
|
|
|
|
return bestMatch;
|
|
}
|
|
|
|
this.altSurnames = function (_event)
|
|
{
|
|
var surname = document.getElementById (this.surname);
|
|
var sNameAlt = document.getElementById (this.sNameAlt);
|
|
|
|
this.snameDists = fittingStrings (surname.value, this.surnames, false);
|
|
if (this.snameDists.length > 0)
|
|
this.snameMaxIdx = this.snameDists[0].split ('::')[1];
|
|
else
|
|
this.snameMaxIdx = -1;
|
|
|
|
this.sNameBest =
|
|
this.genAlternativesList (sNameAlt, this.snameDists, this.snameIdx);
|
|
this.updField (surname, this.sNameBest, this.sNameAlt)
|
|
|
|
if (this.sNameBest[1] == 0)
|
|
{
|
|
var firstname = document.getElementById (this.firstname);
|
|
this.fnameDists = fittingStrings (
|
|
firstname.value, this.firstnames[this.sNameBest[2]], false);
|
|
if (this.fnameDists.length > 0)
|
|
this.fnameMaxIdx = this.fnameDists[0].split ('::')[1];
|
|
else
|
|
this.fnameMaxIdx = -1;
|
|
|
|
if (this.fnameDists.length > 0)
|
|
this.fNameBest = this.fnameDists[0].split ('::');
|
|
|
|
if (this.person != null)
|
|
if (this.fNameBest[1] == 0)
|
|
this.person.update (
|
|
this.persons[this.sNameBest[2]][this.fNameBest[2]]);
|
|
else
|
|
this.person.empty ();
|
|
}
|
|
else
|
|
{
|
|
this.fNameBest = new Array (-1, -1, null);
|
|
if (this.person != null)
|
|
this.person.empty ();
|
|
}
|
|
|
|
return false;
|
|
}
|
|
|
|
this.altFirstnames = function ()
|
|
{
|
|
var firstname = document.getElementById (this.firstname);
|
|
var fNameAlt = document.getElementById (this.fNameAlt);
|
|
|
|
if (this.sNameBest[1] == 0)
|
|
{
|
|
var surname = document.getElementById (this.surname);
|
|
this.fnameDists = fittingStrings (
|
|
firstname.value, this.firstnames[this.sNameBest[2]], false);
|
|
if (this.fnameDists.length > 0)
|
|
this.fnameMaxIdx = this.fnameDists[0].split ('::')[1];
|
|
else
|
|
this.fnameMaxIdx = -1;
|
|
}
|
|
else
|
|
this.fnameDists = new Array ();
|
|
|
|
this.fNameBest =
|
|
this.genAlternativesList (fNameAlt, this.fnameDists, this.fnameIdx);
|
|
this.updField (firstname, this.fNameBest, this.fNameAlt)
|
|
|
|
if (this.person != null)
|
|
if (this.sNameBest[1] == 0 && this.fNameBest[1] == 0)
|
|
this.person.update (
|
|
this.persons[this.sNameBest[2]][this.fNameBest[2]]);
|
|
else
|
|
this.person.empty ();
|
|
|
|
return false;
|
|
}
|
|
}
|
|
|
|
function personSearch1AltFirstnameHandler (_event)
|
|
{
|
|
if (_event == undefined)
|
|
_event = window.event;
|
|
|
|
if (_event.which)
|
|
var keycode = _event.which;
|
|
else if (_event.keyCode)
|
|
var keycode = _event.keyCode;
|
|
|
|
var dists = pSearch1.fnameDists;
|
|
|
|
// pSearch1 wird im php personSearch1.js angelegt.
|
|
switch (keycode)
|
|
{
|
|
case 38:
|
|
pSearch1.decFnameIdx ();
|
|
break;
|
|
case 40:
|
|
pSearch1.incFnameIdx ();
|
|
break;
|
|
case 13:
|
|
pSearch1.hide ('personSearch1_fBestFit');
|
|
break;
|
|
default:
|
|
pSearch1.fnameIdx = -1;
|
|
}
|
|
|
|
pSearch1.altFirstnames ();
|
|
}
|
|
|
|
function personSearch1AltSurnameHandler (_event)
|
|
{
|
|
if (_event == undefined)
|
|
_event = window.event;
|
|
|
|
if (_event.which)
|
|
var keycode = _event.which;
|
|
else if (_event.keyCode)
|
|
var keycode = _event.keyCode;
|
|
|
|
var dists = pSearch1.snameDists;
|
|
|
|
// pSearch1 wird im php personSearch1.js angelegt.
|
|
switch (keycode)
|
|
{
|
|
case 38:
|
|
pSearch1.decSnameIdx ();
|
|
break;
|
|
case 40:
|
|
pSearch1.incSnameIdx ();
|
|
break;
|
|
case 13:
|
|
pSearch1.hide ('personSearch1_sBestFit');
|
|
break;
|
|
default:
|
|
pSearch1.snameIdx = -1;
|
|
}
|
|
|
|
pSearch1.altSurnames ();
|
|
}
|