[Bedework-commit] carddav r142 - in trunk/clients/javascript/bwAddrbookClient: . config config/lang resources

svnadmin at bedework.org svnadmin at bedework.org
Sat Oct 2 22:48:03 EDT 2010


Author: johnsa
Date: 2010-10-02 22:48:03 -0400 (Sat, 02 Oct 2010)
New Revision: 142

Modified:
   trunk/clients/javascript/bwAddrbookClient/config/config.js
   trunk/clients/javascript/bwAddrbookClient/config/lang/en_US.js
   trunk/clients/javascript/bwAddrbookClient/index.html
   trunk/clients/javascript/bwAddrbookClient/resources/addressbook.css
   trunk/clients/javascript/bwAddrbookClient/resources/addressbook.js
Log:
javascript client:  build menus from configured books; make them selectable 

Modified: trunk/clients/javascript/bwAddrbookClient/config/config.js
===================================================================
--- trunk/clients/javascript/bwAddrbookClient/config/config.js	2010-10-03 00:02:37 UTC (rev 141)
+++ trunk/clients/javascript/bwAddrbookClient/config/config.js	2010-10-03 02:48:03 UTC (rev 142)
@@ -40,9 +40,8 @@
  *                         For the present this client assumes books 
  *                         that are not personal are read-only. 
  * default:       Boolean - if this is the default address book.
- *                         There should be only one of these, but
- *                         if more than one is defined, the client
- *                         will take the first in the array.                        
+ *                         There should be only one of these and 
+ *                         it is only used on the personal books.                        
  * label:         String - the display title for the book
  * vcards:        Array  - an empty array; this will be filled with
  *                         vcard objects when the client connects to 

Modified: trunk/clients/javascript/bwAddrbookClient/config/lang/en_US.js
===================================================================
--- trunk/clients/javascript/bwAddrbookClient/config/lang/en_US.js	2010-10-03 00:02:37 UTC (rev 141)
+++ trunk/clients/javascript/bwAddrbookClient/config/lang/en_US.js	2010-10-03 02:48:03 UTC (rev 142)
@@ -28,4 +28,5 @@
 var bwAbDispListEmail = "Email";
 var bwAbDispListTitle = "Title";
 var bwAbDispListOrg = "Organization";
-var bwAbDispListUrl = "Webpage";
\ No newline at end of file
+var bwAbDispListUrl = "Webpage";
+var bwAbDispListNone = "none";
\ No newline at end of file

Modified: trunk/clients/javascript/bwAddrbookClient/index.html
===================================================================
--- trunk/clients/javascript/bwAddrbookClient/index.html	2010-10-03 00:02:37 UTC (rev 141)
+++ trunk/clients/javascript/bwAddrbookClient/index.html	2010-10-03 02:48:03 UTC (rev 142)
@@ -66,27 +66,14 @@
     </div>
     <div id="booksAndGroups" class="ui-layout-west">
       <h3>personal address book</h3>
-      <ul class="books">
-        <li>
-          <a href="#" id="mainUserBook" class="selected">personal</a>
-          <ul class="groups">
-            <li>
-              group a
-            </li>
-            <li>
-              group b
-            </li>
-          </ul>
-        </li>
+      <ul class="books" id="bwBooks">
+        <!-- Books will be built here if any exist  -->
+        <li>loading...</li>
       </ul>
       <h3>subscribed address books</h3>
-      <ul class="subscriptions">
-        <li>
-          some public book
-        </li>
-        <li>
-          some user book
-        </li>
+      <ul class="subscriptions" id="bwSubscriptions">
+        <!-- Books will be built here if any exist -->
+        <li>loading...</li>
       </ul>
       
       <button style="margin: 20em 0 0 2em;" onclick="showPage('bw-test');">show test pane</button>
@@ -256,11 +243,6 @@
           <h3>Add Location</h3>
         </li>
         <li id="bw-test" class="invisible content-block">
-          <p>
-            <button id="auth" type="button">Authenticate/Test</button>
-            <button id="report" type="button">Report</button>
-          </p>
-          <hr/>
           <h3>Delete Contact (by UID)</h3>
           <div id="deleteForm">
             UID: <input type="text" size="60" value="" id="DUID"/><br/>

Modified: trunk/clients/javascript/bwAddrbookClient/resources/addressbook.css
===================================================================
--- trunk/clients/javascript/bwAddrbookClient/resources/addressbook.css	2010-10-03 00:02:37 UTC (rev 141)
+++ trunk/clients/javascript/bwAddrbookClient/resources/addressbook.css	2010-10-03 02:48:03 UTC (rev 142)
@@ -51,6 +51,9 @@
   position: relative;
   white-space: nowrap;
 }
+ul.books {
+	margin-bottom: 1em;
+}
 ul.books li {
   list-style-image: url("icons/silk/book.png");
 }
@@ -166,7 +169,7 @@
   border-bottom: 1px solid #eee;
 }
 #bwAddrBookTable th {
-  padding: 0.5em 0 0.5em 1em;
+  padding: 0.5em 1em;
   background-color: #eee;
   color: #999;
   border-right: 1px solid #ddd;
@@ -184,6 +187,11 @@
 	background-color: white;
 	color: black;
 }
+#bwAddrBookTable tr.none td {
+  background-color: white;
+  color: black;
+  border: none;
+}
 #bwAddrBookTable img {
 	margin: 0 1em 0 0;
 	vertical-align: middle;

Modified: trunk/clients/javascript/bwAddrbookClient/resources/addressbook.js
===================================================================
--- trunk/clients/javascript/bwAddrbookClient/resources/addressbook.js	2010-10-03 00:02:37 UTC (rev 141)
+++ trunk/clients/javascript/bwAddrbookClient/resources/addressbook.js	2010-10-03 02:48:03 UTC (rev 142)
@@ -71,6 +71,41 @@
     }
   };
   
+  this.buildMenus = function() {
+    var personalBooks = "";
+    var subscriptions = "";
+    
+    // iterate over the books and build up the menus
+    // We need to iterate over groups within the books and add them as children
+    for (var i=0; i < bwAddressBook.books.length; i++) {
+      var book = bwAddressBook.books[i];
+      var bookId = "bwBook-" + i;
+      if (book.personal) {
+        if (book.default) {
+          // this is the default book; mark it as such.  We will replace the title with the user's id
+          personalBooks += '<li class="bwBook" id="' + bookId + '"><a href="#" class="selected">' + book.label + '</a></li>';
+        } else {
+          personalBooks += '<li class="bwBook" id="' + bookId + '"><a href="#">' + book.label + '</a></li>';
+        }
+      } else {
+        subscriptions += '<li class="bwBook" id="' + bookId + '"><a href="#">' + book.label + '</a></li>';
+      }
+    }
+    
+    // check for empty menus
+    if (personalBooks == "") {
+      personalBooks = '<li class="empty">no books found</li>'; 
+    }
+    if (subscriptions == "") {
+      subscriptions = '<li class="empty">no books found</li>'; 
+    }
+    
+    // write the menus back to the browser
+    $("#bwBooks").html(personalBooks);
+    $("#bwSubscriptions").html(subscriptions);
+    
+  };
+  
   this.displayList = function(bookIndex) {
     var book = new Array();
     var index = bookIndex;
@@ -102,54 +137,69 @@
     listing += "<th>" + bwAbDispListOrg + "</th>";
     listing += "<th>" + bwAbDispListUrl + "</th>";
     listing += "</tr>";
-    for (var i=0; i < book.vcards.length; i++) {
-      var curCard = jQuery.parseJSON(book.vcards[i]);
-      var rowClass = "";
-      if (i%2 == 1) {
-        rowClass = "odd"; 
-      }
-      // determine the kind of vcard - if not available, assume "individual"
-      var kind = "individual";
-      var kindIcon = "resources/icons/silk/user.png";
-      if (curCard.KIND != undefined && curCard.KIND.value != "") {
-        kind = curCard.KIND.value;
-        switch(kind) {
-          case "group" :  
-            kindIcon = "resources/icons/silk/group.png";
-            break;
-          case "location" :
-            kindIcon = "resources/icons/silk/building.png";
-            break;
+    
+    // if we have no cards, tell the user
+    if (book.vcards.length == 0) {
+      listing += '<tr class="none"><td>' +  bwAbDispListNone + '</td><td></td><td></td><td></td><td></td><td></td></tr>'; 
+    } else {
+    // we have cards: build the list
+      for (var i=0; i < book.vcards.length; i++) {
+        var curCard = jQuery.parseJSON(book.vcards[i]);
+        var rowClass = "";
+        if (i%2 == 1) {
+          rowClass = "odd"; 
         }
+        // determine the kind of vcard - if not available, assume "individual"
+        var kind = "individual";
+        var kindIcon = "resources/icons/silk/user.png";
+        if (curCard.KIND != undefined && curCard.KIND.value != "") {
+          kind = curCard.KIND.value;
+          switch(kind) {
+            case "group" :  
+              kindIcon = "resources/icons/silk/group.png";
+              break;
+            case "location" :
+              kindIcon = "resources/icons/silk/building.png";
+              break;
+          }
+        }
+        
+        // check for the existence of the properties
+        var fn ="";
+        if(curCard.FN != undefined) { 
+          fn = curCard.FN[0].value; 
+        }
+        var tel ="";
+        if(curCard.TEL != undefined) { 
+          tel = curCard.TEL[0].values[0].number; 
+        }
+        var email ="";
+        if(curCard.EMAIL != undefined) { 
+          email = curCard.EMAIL[0].value; 
+        }
+        var title = "";
+        if(curCard.TITLE != undefined) { 
+          title = curCard.TITLE[0].value; 
+        }
+        var org = "";
+        if(curCard.ORG != undefined) { 
+          org = curCard.ORG[0].values[0].organization_name; 
+        }
+        var url = "";
+        if(curCard.URL != undefined) { 
+          url = curCard.URL[0].value; 
+        }
+        
+        listing += "<tr class=\"" + rowClass + "\">"
+        listing += "<td><img src=\"" + kindIcon + "\" width=\"16\" height=\"16\" alt=\"" + kind + "\"/>";
+        listing += fn + "</td>";
+        listing += "<td>" + tel + /*"<span class=\"typeNote\">(kind)</span>" + */ "</td>";
+        listing += "<td><a href=\"mailto:" + email + "\">" + email + "</a></td>";
+        listing += "<td>" + title + "</td>";
+        listing += "<td>" + org + "</td>";
+        listing += "<td>" + url + "</td>";
+        listing += "</tr>"
       }
-      
-      // check for the existence of other properties (will need to do all)
-      var title = "";
-      if(curCard.TITLE != undefined) { 
-        title = curCard.TITLE[0].value; 
-      }
-      var org = "";
-      if(curCard.ORG != undefined) { 
-        org = curCard.ORG[0].values[0].organization_name; 
-      }
-      var tel = "";
-      if(curCard.TEL != undefined) { 
-        tel = curCard.TEL[0].values[0].number; 
-      }
-      var url = "";
-      if(curCard.URL != undefined) { 
-        url = curCard.URL[0].value; 
-      }
-      
-      listing += "<tr class=\"" + rowClass + "\">"
-      listing += "<td><img src=\"" + kindIcon + "\" width=\"16\" height=\"16\" alt=\"" + kind + "\"/>";
-      listing += curCard.FN[0].value + "</td>";
-      listing += "<td>" + tel + /*"<span class=\"typeNote\">(kind)</span>" + */ "</td>";
-      listing += "<td><a href=\"mailto:" + curCard.EMAIL[0].value + "\">" + curCard.EMAIL[0].value + "</a></td>";
-      listing += "<td>" + title + "</td>";
-      listing += "<td>" + org + "</td>";
-      listing += "<td>" + url + "</td>";
-      listing += "</tr>"
     }
     listing += "</table>"
       
@@ -209,6 +259,9 @@
   // bwBooks is defined in addressbookProps.js
   bwAddrBook.init(bwBooks);
   
+  // generate the personal and subscribed books menus
+  bwAddrBook.buildMenus();
+  
   // display the default listing
   bwAddrBook.displayList();
   
@@ -259,8 +312,18 @@
     showPage("bw-modLocation");
   });
 
-  $("#mainUserBook").click(function() {
-    bwAddrBook.displayList(0);
+  $(".bwBook").click(function() {
+    // extract the book array index from the id
+    var bookIndex = $(this).attr("id").substr($(this).attr("id").indexOf("-")+1);
+    
+    // remove highlighting from all books
+    $(".bwBook a").each(function(index){
+      $(this).removeClass("selected");
+    });
+    // now highlight the one just selected
+    $(this).find("a:first-child").addClass("selected");
+    
+    bwAddrBook.displayList(bookIndex);
   });
   
   // submit a vcard to the server
@@ -348,35 +411,6 @@
     }  
   );
   
-  /* Testing Features */
-  // setting the user is for testing
-  $("#setuser").click(function() {
-    var newid = $("#userid").val();
-    if (newid != "") {
-      userid = newid;
-      alert("User set to " + userid);
-    }
-  });
-  
-  // Click to auth is for testing only
-  // In production, the user will likely be already authed.
-  // If not, the server will prompt for auth when the report query is sent on first load of the page.
-  $("#auth").click(function() {
-    var addrBookUrl = carddavUrl + userpath + userid + userBookName;
-    $.ajax({
-      type: "get",
-      url: addrBookUrl,
-      dataType: "html",
-      success: function(responseData, status){
-        alert(status + "\n" + responseData);            
-      },
-      error: function(msg) {
-        // there was a problem
-        alert(msg.statusText);
-      }
-    });
-  });
-    
 });
 
 /****************************



More information about the Bedework-commit mailing list