View Single Post
Old 08-26-2008, 10:41 AM   PM User | #6
tosbourn
Regular Coder

 
Join Date: Aug 2008
Location: Northern Ireland
Posts: 167
Thanks: 12
Thanked 6 Times in 6 Posts
tosbourn is on a distinguished road
Here is my code, sorry there is so much of it, but I don't want to guess at what is 100% working correctly and then miss something out.

Basically this code when initiated should open up a window containing users, once a user is clicked, their details should be automatically fed into the previous form.

The link that starts it all off..
Code:
<a href="javascript:newChangePerson(1)" id="findperson" >
The newChangePerson() function
Code:
function newChangePerson  (mode, witness){                   
			a = $("selectPID");

			b = $("myid");
			if (!a) a = {"value":""};
			if (!b) b = {"value":""};
			if (!witness) witness = "";
			TS.person(a.value, b.value, mode, witness);
TS.person (if (modals) is commented out because I wanted to see if I could get it working making it follow the wraptabs route.
Code:
TS.person      = function( ind, accid, mode, dstField ){
	if (accid!="") accid   = "&accident="+accid;
	if (ind  !="") ind     = "&current="+ind;
	if (mode ==1 ) mode    = "find"  ;
	if (mode ==2 ) mode    = "new"   ;
	if (mode ==0 ) mode    = "choose";
	if (dstField=="") dstField = "selectPID";
	jsdst = dstField;
	dstField = "&dest="+dstField;
	/*if (modals){
		var width  = window.innerWidth  || document.body.clientWidth;
		var height = window.innerHeight || document.body.clientHeight;
		$(jsdst).value = window.showModalDialog("person.php?"+mode+ind+accid+dstField, "", "dialogWidth: "+(width-80)+"px; dialogHeight: "+(height-80)+"px; center:1");
		goFindPerson(jsdst);
	} else */
	
	TS.wrapTabs("person.php?"+mode+ind+accid+dstField, "Person");
}
TS.wrapTabs then brings up the new window.

Once you select the user you want, these are the next two methods that get used.
Code:
function Person_callback  ( ){                                // [l] responder to above 
	if (req.readyState == 4) {          
		if (req.status == 200) {        
			eval(req.responseText);
			if (peopleChoice == null){
				alert("No one with that name was found in the database, \n\nCreate a new person by filling out the remainder of these fields");
			} else if (peopleChoice.length==1) {
				// $('fname'    ).value = peopleChoice[0].fname ; // Already populated so why?
				// $('sname'    ).value = peopleChoice[0].sname ;                        
				//$('selectPID').value = peopleChoice[0].dbid  ;   
				peopleChoice[0].add = unescape(peopleChoice[0].add);
				add = peopleChoice[0].add.split("\n");
				{
					$(pLookDest+"hnum").value = unescape(add[0]);
					$(pLookDest+"hpcd").value = unescape(add[4]);
					$(pLookDest+"hstr").value = unescape(add[1]);
					$(pLookDest+"hcou").value = unescape(add[2]);
					$(pLookDest+"hcty").value = unescape(add[3]);
				}
				$(pLookDest+'fname'    ).value = unescape(peopleChoice[0].fname  );                           
				$(pLookDest+'sname'    ).value = unescape(peopleChoice[0].sname  );                           
				$(pLookDest+'phone'    ).value = unescape(peopleChoice[0].phone  );                           
				$(pLookDest+'age'      ).value = unescape(peopleChoice[0].age    );                            
				dd_select(pLookDest+"gender",    unescape(peopleChoice[0].gender));                          
				dd_select(pLookDest+"pcat",      unescape(peopleChoice[0].catid ));                          
			} 
		}// status 200
	} //readystate
}//person callback
function applyPerson      ( ){                                // [l] fill fields with result 
	num = $("personpicker").options[$("personpicker").selectedIndex].value;
	$('selectPID').value = peopleChoice[num].dbid  ;   
	peopleChoice[num].add = unescape(peopleChoice[num].add);
	add = peopleChoice[num].add.split("\n");
	{
		$("hnum").value = add[1];
		$("hpcd").value = add[5];
		$("hstr").value = add[2];
		$("hcou").value = add[3];
		$("hcty").value = add[4];
	}
	$('fname'    ).value =          peopleChoice[num].fname; 
	$('sname'    ).value =          peopleChoice[num].sname; 
	$('phone'    ).value =          peopleChoice[num].phone ; 
	$('age'      ).value = unescape(peopleChoice[num].age);   
	dd_select("gender",             peopleChoice[num].gender);
	dd_select("pcat",               peopleChoice[num].catid );
	$("attentionPhrase"  ).innerText = "";
	//innerHTML fix
	var newdiv = document.createElement("div");
	newdiv.innerHTML = "";
	$("attentionContents").appendChild(newdiv);
	$("attentionActions").appendChild(newdiv);

	//$("attentionContents").innerHTML = "";
	//$("attentionActions" ).innerHTML = "";
	$("attention").style.display="none";
}
I don't think I have missed anything out, and again, apologies for the incredibly long post!

Last edited by tosbourn; 08-26-2008 at 10:43 AM.. Reason: Tidying up code to make it a little more condensed.
tosbourn is offline   Reply With Quote