/*******************************
adrForm.js
-doProcessText generic -- with the exception of curparams[1]
-doUpdateField generic -- with the exception of curparams[1]
-doValidate specific to the form/database association
-clk generic
-setId generic
-setFormField generic
-fillForm generic
*******************************/
// global vars
//var jsrsTrace = true; // sets vs. resets a trace -- set in jsrsClient.js
var activeFld = '';
var activeForm = '';
// activated by onkeyup
function doProcessText(form,fld){
var curparams = new Array(); // buildSearchQry args:
curparams[0] = form.elements[fld].value; // baseTerm
curparams[1] = 'adresse'; // table
curparams[2] = fld; // field
curparams[3] = form.elements['id'].value; // id
if (jsrsTrace)
alert('doProcessText: '+form.name+'--'+fld+'--'+form.elements[fld].value+'-- id:'+curparams[3]);
activeFld = fld;
activeForm = form;
jsrsExecute( 'adr-form-process.php', fillForm, 'buildSearchQry', curparams, '');
} // end doProcessText
function doUpdateField(form,fld){
var curparams = new Array(); // buildSearchQry args:
curparams[0] = form.elements[fld].value; // baseTerm
curparams[1] = 'adresse'; // table
curparams[2] = fld; // field
curparams[3] = form.elements['id'].value; // id
if (jsrsTrace)
alert('doUpdateField: '+form.name+'--'+fld+'--'+form.elements[fld].value+'-- id:'+curparams[3]);
activeFld = fld;
activeForm = form;
jsrsExecute( 'adr-form-process.php', setFormField, 'incrDbRecord', curparams, '');
} // end doUpdateField
function doValidate(form){
var args = new Array(); // buildSearchQry args:
var val = new Array();
var str_args;
var str_val;
var curparams = new Array();
var i=0;
args[i] = 'id'; // baseTerm
args[i++] = 'table'; // 'adresse'
// liste de tous les champs pour les m-a-j, sauf 'id' (voir adr-form.xml)
//args[i++] = 'tble'; // table
args[i++] = 'aux_designations';
args[i++] = 'numero';
args[i++] = 'lieu_dit';
args[i++] = 'rue';
args[i++] = 'commune';
args[i++] = 'code';
args[i++] = 'departement';
args[i++] = 'pays';
args[i++] = 'type_lieu';
str_args = args.join('~');
activeForm = form;
val[0] = activeForm.elements['id'].value;
val[1] = 'adresse';
for(i=2; i< args.length;i++){
var xobj = activeForm.elements[args[i]];
if (xobj == undefined){
val[i] = '';
continue;
}
var x = xobj.value;
val[i] = (x == undefined)?'':x;
}
str_val = val.join('~');
curparams[0] = activeForm.elements['id'].value;
curparams[1] = str_args;
curparams[2] = str_val;
if (jsrsTrace)
alert('exec doValidate:'+str_val);
jsrsExecute( 'adr-form-process.php', setId, 'db_record', curparams, '');
} // end doValidate()
// callback invoked upon iframe being loaded ...
// each sql returned row is being imploded by join( $row, '~')
// all the rows are separated by "|"
function clk(form,fld, s){
form.elements[fld].value = s;
sel = form.elements['aux_saisie'];
psel = sel.parentNode;
psel.removeChild(sel);
doUpdateField(form,fld);
} // clk
function setId(sqlQryReturnStr){
if (jsrsTrace)alert('setId:'+sqlQryReturnStr);
activeForm.elements['id'].value = sqlQryReturnStr;
sel = activeForm.elements['id'];
psel = sel.parentNode;
div2 = psel.getElementsByTagName("div")[0];
if (div2 != undefined)
psel.removeChild(div2);
div2 = document.createElement("div");
div2.innerHTML = sqlQryReturnStr;
psel.appendChild(div2);
} // setId
function setFormField(sqlQryReturnStr){
if (jsrsTrace)
alert('setFormField:'+sqlQryReturnStr);
var params = sqlQryReturnStr.split('|');
activeForm.elements[params[0]].value = params[1];
} // setFormField
function fillForm( sqlQryReturnStr ){
if (jsrsTrace) alert('fillForm:');
if (sqlQryReturnStr.length == 0)return;
var aOptions = sqlQryReturnStr.split('|'); //sqlQryReturnStr.split('|');
aOptions.sort();
for(i=aOptions.length-1; i>0 ;i--){
if (aOptions[i].length == 0)aOptions.splice(i,1);
if (aOptions[i-1] == aOptions[i])aOptions.splice(i-1,1);
}
var opts = '<select name="aux_saisie" size="5" maxlength="70">\n';
for(i=0; i< aOptions.length;i++){
opts = opts+ '<option value="'+i+'" onclick="clk(this.form,\''+activeFld+'\', \''+aOptions[i]+'\')">'+aOptions[i]+'\n';
//opts = opts+ '<option value="'+i+'" >'+aOptions[i]+'\n';
}
opts = opts+ '</select>\n';
if (jsrsTrace) alert(opts);
saux = activeForm.elements['aux_saisie'];
if (saux != undefined)saux.parentNode.removeChild(saux);
sel = document.createElement("span");
sel.innerHTML = opts;
active_el = activeForm.elements[activeFld];
td_el = active_el.parentNode;
td_el.insertBefore(sel,active_el);
} // end fillForm
|