From a6ebf372ccc90d4b566d0e7856264ab197514c66 Mon Sep 17 00:00:00 2001 From: "hangas%netscape.com" Date: Mon, 7 Jun 1999 18:50:20 +0000 Subject: [PATCH] Added code to update the cardview pane with data from datasource --- .../addrbook/resources/content/addressbook.js | 166 +++++++++++------- .../resources/content/addressbook.xul | 8 +- .../addrbook/resources/skin/addressbook.css | 3 + 3 files changed, 113 insertions(+), 64 deletions(-) diff --git a/mailnews/addrbook/resources/content/addressbook.js b/mailnews/addrbook/resources/content/addressbook.js index 796c43029166..6782432e205d 100644 --- a/mailnews/addrbook/resources/content/addressbook.js +++ b/mailnews/addrbook/resources/content/addressbook.js @@ -1,15 +1,60 @@ +var rdf; +var cvData; + +function OnLoadAddressBook() +{ + // This should be in an onload for the card view window, but that is not currently working + rdf = Components.classes["component://netscape/rdf/rdf-service"].getService(); + rdf = rdf.QueryInterface(Components.interfaces.nsIRDFService); + + var doc = frames["cardViewFrame"].document; + + /* data for address book, prefixes: "cvb" = card view box + "cvh" = crad view header + "cv" = card view (normal fields) */ + cvData = new Object; + + /* Card View - Title */ + cvData.CardTitle = doc.getElementById("CardTitle"); + /* Name section */ + cvData.cvhName = doc.getElementById("cvhName"); + cvData.cvNickname = doc.getElementById("cvNickname"); + cvData.cvEmail1 = doc.getElementById("cvEmail1"); + cvData.cvEmail2 = doc.getElementById("cvEmail2"); + /* Home section */ + cvData.cvhHome = doc.getElementById("cvhHome"); + cvData.cvHomeAddress = doc.getElementById("cvHomeAddress"); + cvData.cvHomeCityStZip = doc.getElementById("cvHomeCityStZip"); + /* Other section */ + cvData.cvhOther = doc.getElementById("cvhOther"); + cvData.cvNotes = doc.getElementById("cvNotes"); + /* Phone section */ + cvData.cvhPhone = doc.getElementById("cvhPhone"); + cvData.cvPhWork = doc.getElementById("cvPhWork"); + cvData.cvPhHome = doc.getElementById("cvPhHome"); + cvData.cvPhFax = doc.getElementById("cvPhFax"); + cvData.cvPhCellular = doc.getElementById("cvPhCellular"); + cvData.cvPhPager = doc.getElementById("cvPhPager"); + /* Work section */ + cvData.cvhWork = doc.getElementById("cvhWork"); + cvData.cvJobTitle = doc.getElementById("cvJobTitle"); + cvData.cvOrganization = doc.getElementById("cvOrganization"); + cvData.cvWorkAddress = doc.getElementById("cvWorkAddress"); + cvData.cvWorkCityStZip = doc.getElementById("cvWorkCityStZip"); +} + function ChangeDirectoryByDOMNode(dirNode) { - var uri = dirNode.getAttribute('id'); - dump(uri + "\n"); - ChangeDirectoryByURI(uri); + var uri = dirNode.getAttribute('id'); + dump(uri + "\n"); + ChangeDirectoryByURI(uri); } function ChangeDirectoryByURI(uri) { - var tree = frames[0].frames[1].document.getElementById('resultTree'); - tree.childNodes[7].setAttribute('id', uri); + var tree = frames[0].frames[1].document.getElementById('resultTree'); + tree.childNodes[7].setAttribute('id', uri); } @@ -48,66 +93,69 @@ function EditCardCancelButton() dump("Cancel Hit\n"); } -function DisplayCardViewPane(messageNode) +function DisplayCardViewPane(abNode) { - /* Setup vars - this should move to a global var */ - /* data for address book, prefixes: "cvb" = card view box - "cvh" = crad view header - "cv" = card view (normal fields) */ - - var doc = parent.frames["cardViewFrame"].document; - - /* Card View - Title */ - var CardTitle = doc.getElementById("CardTitle"); - /* Name section */ - var cvbName = doc.getElementById("cvbName"); - var cvhName = doc.getElementById("cvhName"); - var cvNickname = doc.getElementById("cvNickname"); - var cvEmail1 = doc.getElementById("cvEmail1"); - var cvEmail2 = doc.getElementById("cvEmail2"); - /* Home section */ - var cvbHome = doc.getElementById("cvbHome"); - var cvHomeAddress = doc.getElementById("cvHomeAddress"); - var cvHomeCityStZip = doc.getElementById("cvHomeCityStZip"); - /* Other section */ - var cvbOther = doc.getElementById("cvbOther"); - var cvNotes = doc.getElementById("cvNotes"); - /* Phone section */ - var cvbPhone = doc.getElementById("cvbPhone"); - var cvPhWork = doc.getElementById("cvPhWork"); - var cvPhHome = doc.getElementById("cvPhHome"); - var cvPhFax = doc.getElementById("cvPhFax"); - var cvPhCellular = doc.getElementById("cvPhCellular"); - var cvPhPager = doc.getElementById("cvPhPager"); - /* Work section */ - var cvbWork = doc.getElementById("cvbWork"); - var cvJobTitle = doc.getElementById("cvJobTitle"); - var cvOrganization = doc.getElementById("cvOrganization"); - var cvWorkAddress = doc.getElementById("cvWorkAddress"); - var cvWorkCityStZip = doc.getElementById("cvWorkCityStZip"); - + var uri = abNode.getAttribute('id'); + var cardResource = parent.parent.rdf.GetResource(uri); + var card = cardResource.QueryInterface(Components.interfaces.nsIAbCard); + + var data = parent.parent.cvData; + var visible; + var name = card.personName; + /* set fields in card view pane */ - CardTitle.childNodes[0].nodeValue = "Card for Winnie the Pooh"; + visible = cvSetNode(data.CardTitle, "Card for " + name); + + // FIX ME! + // Code needs to be fixed to make the entire box visible or not. Current hack just hides + // the header of the section that should be visible. /* Name section */ - cvhName.childNodes[0].nodeValue = "Winnie the Pooh"; - cvNickname.childNodes[0].nodeValue = "\"Pooh\""; - cvEmail1.childNodes[0].nodeValue = "wpooh@netscape.com"; - cvEmail2.childNodes[0].nodeValue = "poohbear@netscape.net"; + cvSetNode(data.cvhName, name); + cvSetNode(data.cvNickname, "\"" + card.nickname + "\""); + cvSetNode(data.cvEmail1, card.email); + cvSetNode(data.cvEmail2, "poohbear@netscape.net"); /* Home section */ - cvHomeAddress.childNodes[0].nodeValue = "123 Treehouse Lane"; - cvHomeCityStZip.childNodes[0].nodeValue = "Hundred Acre Wood, CA 94087"; + visible = cvSetNode(data.cvHomeAddress, "123 Treehouse Lane"); + visible = cvSetNode(data.cvHomeCityStZip, "Hundred Acre Wood, CA 94087") && visible; + cvSetVisible(data.cvhHome, visible); /* Other section */ - cvNotes.childNodes[0].nodeValue = "This data is fake. It is inserted into the DOM from JavaScript."; + visible = cvSetNode(data.cvNotes, "This data is fake. It is inserted into the DOM from JavaScript."); + cvSetVisible(data.cvhOther, visible); /* Phone section */ - cvPhWork.childNodes[0].nodeValue = "Work: (650) 937-1234"; - cvPhHome.childNodes[0].nodeValue = "Home: (408) 732-1212"; - cvPhFax.childNodes[0].nodeValue = "Fax: (650) 937-3434"; - cvPhCellular.childNodes[0].nodeValue = "Cellular: (408) 734-9090"; - cvPhPager.childNodes[0].nodeValue = "Pager: (408) 732-6545"; + visible = cvSetNode(data.cvPhWork, "Work: " + card.workPhone); + visible = cvSetNode(data.cvPhHome, "Home: (408) 732-1212") && visible; + visible = cvSetNode(data.cvPhFax, "Fax: (650) 937-3434") && visible; + visible = cvSetNode(data.cvPhCellular, "Cellular: (408) 734-9090") && visible; + visible = cvSetNode(data.cvPhPager, "Pager: (408) 732-6545") && visible; + cvSetVisible(data.cvhPhone, visible); /* Work section */ - cvJobTitle.childNodes[0].nodeValue = "Interaction Designer"; - cvOrganization.childNodes[0].nodeValue = "Netscape Communications Corp."; - cvWorkAddress.childNodes[0].nodeValue = "501 E Middlefield Road"; - cvWorkCityStZip.childNodes[0].nodeValue = "Mountain View, CA 94043"; + visible = cvSetNode(data.cvJobTitle, "Interaction Designer"); + visible = cvSetNode(data.cvOrganization, card.organization) && visible; + visible = cvSetNode(data.cvWorkAddress, "501 E Middlefield Road") && visible; + visible = cvSetNode(data.cvWorkCityStZip, card.city + ", CA 94043") && visible; + cvSetVisible(data.cvhWork, visible); +} + +function cvSetNode(node, text) +{ + node.childNodes[0].nodeValue = text; + if ( text == "" ) + { + node.style.display = "none"; + return false; + } + else + { + node.style.display = "block"; + return true; + } +} + +function cvSetVisible(node, visible) +{ + if ( visible ) + node.style.display = "block"; + else + node.style.display = "none"; } diff --git a/mailnews/addrbook/resources/content/addressbook.xul b/mailnews/addrbook/resources/content/addressbook.xul index a16bef7df720..957ca5abbe47 100644 --- a/mailnews/addrbook/resources/content/addressbook.xul +++ b/mailnews/addrbook/resources/content/addressbook.xul @@ -106,12 +106,10 @@ + style="width:100%;height:100%" + onload="OnLoadAddressBook()"> - - - - + diff --git a/mailnews/addrbook/resources/skin/addressbook.css b/mailnews/addrbook/resources/skin/addressbook.css index ae30689ca3ba..6bb0845c31c1 100644 --- a/mailnews/addrbook/resources/skin/addressbook.css +++ b/mailnews/addrbook/resources/skin/addressbook.css @@ -27,11 +27,13 @@ div[class="CardViewHeading"] { color: white; background-color: #5050ff; font-weight: bold; + display: none; } div[class="CardViewText"] { padding-left: 20px; padding-right: 2px; + display: none; } box[class="CardView"] { @@ -39,6 +41,7 @@ box[class="CardView"] { padding-top: 12px; padding-bottom: 4px; border: none; + display: block; } spring[class="CardViewHeadingSpace"] {