Fleshing out the contacts listing. Not quite working yet.
authorJames Burke <jrburke@mozillamessaging.com>
Fri, 28 May 2010 17:40:17 -0700
changeset 1761 c9501bd56590a23ccf17f560e3cb10fe30565a69
parent 1759 3535eb15ec1aaa9372b7c6accfe10253011196bc
child 1762 723a13b3e86cde7ecf644d76cf8150771ae01682
push id966
push userjrburke@gmail.com
push dateSat, 29 May 2010 00:40:59 +0000
Fleshing out the contacts listing. Not quite working yet.
client/api/contacts.html
client/api/scripts/rdapi.js
--- a/client/api/contacts.html
+++ b/client/api/contacts.html
@@ -1,17 +1,76 @@
 <!DOCTYPE html>
 <html>
 <head>
     <title>Contact Listing</title>
+    <style type="text/css">
+        #contactList,
+        #identityDisplay {
+            float: left;
+        }
+        
+        #identityDisplay {
+            border: 1px solid black;
+        }
+    </style>
     <script src="scripts/requireplugins-jquery-1.4.2.js" charset="utf-8"></script>
     <script>
-        require(["jquery", "rdapi", "json2"], function ($, rdapi) {
+        "use strict";
+        /*global require: false, console: false */
+        require(["jquery", "rdapi", "blade/jig", "json2"], function ($, rdapi, jig) {
+            $('body').delegate('a.person', 'click', function (evt) {
+                evt.preventDefault();
+                var data = rdapi.data(evt.target.parentNode.getAttribute('data-blade-jig'));
+                rdapi('_design/raindrop!content!all/_view/identities_by_contact', {
+                    data: {
+                        startkey: JSON.stringify([data.id[1]]),
+                        endkey: JSON.stringify([data.id[1], {}])
+                    },
+                    success: function (json) {
+                        var idKeys = [];
+                        if (json.rows) {
+                            json.rows.forEach(function (row) {
+                                idKeys.push(['key-schema_id', [row.value.rd_key, 'rd.identity']]);
+                            });
+                        }
 
+                        console.log(json);
+                        rdapi('_design/raindrop!content!all/_view/megaview?reduce=false&include_docs=true', {
+                            data: JSON.stringify({
+                                keys: idKeys
+                            }),
+                            processData: false,
+                            type: 'POST',
+                            success: function (json) {
+                                var identities = [], html = '', options = rdapi.normalizeOptions({
+                                    templateId: 'identities'
+                                });
+                                if (json.rows) {
+                                    json.rows.forEach(function (row) {
+                                        identities.push(row.doc);
+                                    });
+                                }
+                                if (identities.length) {
+                                    html = jig(options.template, identities, options);
+                                }
+                                $('#identityDisplay').html(html);
+                            }
+                        });
+                    }
+                });
+            });
         });
     </script>
 </head>
 <body>
-    <ul class="contacts templateContainer">
-        <li class="template" data-api="inflow/contacts/by_name"><a href="#{id[1]}">{displayName}</a></li>
+    <ul id="contactList" class="contacts templateContainer">
+        <li class="template" data-api="inflow/contacts/by_name"><a class="person" href="#{id[1]}">{displayName}</a></li>
     </ul>
+    <div id="identityDisplay">
+    </div>
+
+    <div class="template" data-id="identities">
+        {name}
+    </div>
+
 </body>
 </html>
--- a/client/api/scripts/rdapi.js
+++ b/client/api/scripts/rdapi.js
@@ -219,16 +219,18 @@ require.def('rdapi', ['jquery', 'blade/o
     rdapi.data = function (id) {
         return jig.data(id);
     };
 
     rdapi.identity = function (id) {
         return idRegistry[id.toString()] || {};
     };
 
+    rdapi.normalizeOptions = normalize;
+
     $(function () {
         var prop, tmpl;
 
         //Build up lists of templates to use.
         $('.template').each(function (index, node) {
             var sNode = $(node),
                 dataProp = sNode.attr('data-prop'),
                 id = sNode.attr('data-id') || ('id' + (idCounter++)),