advanced.XML.html

<HTML>

<HEAD>

<script>var dFrameFilePath = '../../../'</script>

<script language="Javascript" src="../../../lib/dFrameAPI.js"></script>

<script language="Javascript">

//Global

var baseAll, dFrameDetail, dFrameList

var dbDomTree

var gCurrentContactOrdinal = 0;

var gCurrentContact

//additional library

DynAPI.setLibraryPath('../../../dynapi/src/lib/');

DynAPI.include("dynapi.gui.list.js")

//Style

if (window.parent && window.parent != self && window.parent.getDFrameValues) {

//Setup mainPage

window.parent.getDFrameValues()

dFrameStyle = mainPage.dFrameStyle

} else DFrameAPI.include('styles/blue/styleBlue.js')

//XML for <SCRIPT>

DFrameAPI.include('ext/xml_for_script-2.0/jsXMLParser/xmldom.js')

DFrameAPI.onLoad = function(){

baseAll = new DFrame([3, 3, 97, 97], 'advanced.XML.html', dFrameStyle);

baseAll.setTitleBar(false)

//Create at one the DFrame that will receive the list

//and insert a "blank" document in it to create a IFrame

dFrameList = new DFrame(['10', '10', '350', 97], 'Contacts list',dFrameStyle, baseAll)

dFrameList.setTitleBar(false)

dFrameList.setURL('./advanced.XML/blank.html')

DFrameAPI.getContent('./advanced.XML/contacts_XML.html', 'load1')

}

DFrameAPI.onContentLoad = function(contentValue, key) {

if (key == 'load1') {

XMLString = contentValue.slice(1)

dbDom = new XMLDoc(XMLString, xmlError);

dbDomTree = dbDom.docNode;

displayContactsAsAList()

}

}

function displayContactsAsAList() {

contactList = new List()

contactList.moveTo(10,10)

contactList.setWidth(dFrameList.getWidth()-40)

contactList.setBgColor('#000000')

contactList.boldOnSelect(true)

var l = new EventListener(contactList);

l.onmousedown = function(e) {

var o = e.getTarget();

var i = o.getSelectedIndex()

showContactDetail(i)

}

contactList.addEventListener(l)

objUser = navigateUserList("first");

while(objUser != null) {

firstName = trim(objUser.getElements(cTCC("FIRSTNAME"))[0].getText(),true, true);

lastName = trim(objUser.getElements(cTCC("LASTNAME"))[0].getText(), true, true);

contactList.add(lastName + ' ' + firstName,1)

objUser = navigateUserList("next");

}

DynDoc = dFrameList.createDynAPIDocument()

DynDoc.addChild(contactList)

}

function displayContacts(direction) {

objUser = navigateUserList(direction);

if (objUser!= null) {

displayUserData(objUser);

contactList.select(contactList.items[gCurrentContactOrdinal])

}

}

function showContactDetail(i) {

objUser = getContactByOrdinalValue(i)

if (objUser!= null) {

displayUserData(objUser);

gCurrentContact = objUser

}

}

function displayUserData(objUser) {

var txt = formatXML(objUser)

if (!dFrameDetail) {

var position = [0, '10', 97, 97]

position[0] = [dFrameList, 'Right', 10]

dFrameDetail = new DFrame(position, 'Contact detail',dFrameStyle, baseAll)

dFrameDetail.setTitleBar(false)

dFrameDetail.addButton('First', 'displayContacts("first")')

dFrameDetail.addButton('Previous', 'displayContacts("previous")')

dFrameDetail.addButton('Next', 'displayContacts("next")')

dFrameDetail.addButton('Last', 'displayContacts("last")')

if (baseAll.getParentDFrame() != null && baseAll.getParentDFrame().addSelectButton) {

dFrameDetail.addBar().addButton('Select', 'selectContact()')

}

dFrameDetail.setDragEnabled(true)

}

//dFrameDetail.alert('<form><textarea>' + txt + '</textarea></form>')

dFrameDetail.alert(txt)

dFrameDetail.show(true)

}

function formatXML(objUser) {

firstName = trim(objUser.getElements(cTCC("FIRSTNAME"))[0].getText(),true, true);

lastName = trim(objUser.getElements(cTCC("LASTNAME"))[0].getText(), true, true);

address = trim(objUser.getElements(cTCC("ADDRLOC"))[0].getText(), true, true);

city = trim(objUser.getElements(cTCC("CITY"))[0].getText(), true, true);

state = trim(objUser.getElements(cTCC("STATE"))[0].getText(), true, true);

zip = trim(objUser.getElements(cTCC("ZIPCODE"))[0].getText(), true, true);

var br = '<br>'

var txt = '<b>' + firstName + ' ' + lastName + '</b>'+br + address + br + city + ' ' + state + ' ' + zip

return txt

}

function selectContact() {

baseAll.getParentDFrame().receiveData(gCurrentContact)

}

function cTCC(string) {

//cTCC: convertToCorrectCase = lowerCase for NS6

if (is.ns6) return string.toLowerCase()

else return string

}

/************************************************************************

From formFunction.js of XML for <SCRIPT>

************************************************************************/

function xmlError(e) {

alert("There has been an error accessing the XML Database. The error is:\n" + e)

}

function navigateUserList(direction) {

var objUser;

switch (direction) {

case "next":

objUser = getContactByOrdinalValue(gCurrentContactOrdinal + 1);

break;

case "previous":

objUser = getContactByOrdinalValue(gCurrentContactOrdinal - 1);

break;

case "first":

objUser = getContactByOrdinalValue(0);

break;

case "last":

objUser = getContactByOrdinalValue(dbDomTree.getElements(cTCC("CONTACT")).length -1);

break;

case "current":

objUser = getContactByOrdinalValue(gCurrentContactOrdinal);

break;

} // end switch

//set the global currently displayed user

gCurrentContact = objUser;

return (objUser)

}

function getContactByOrdinalValue(value){

var tmpNode = dbDomTree.getElements(cTCC("CONTACT"))[value];

gCurrentContactOrdinal = value;

return tmpNode;

}

</script>

</HEAD>

</HTML>