Hooking up saving of identities from contacts addon, adjusted api paths used for rdapi.js
authorJames Burke <jrburke@mozillamessaging.com>
Thu, 27 May 2010 16:04:47 -0700
changeset 1746 c35832728283303597a98b912a1643f8d16a7f38
parent 1745 693888347eed07ca6581f1a58d4cb28d323049e0
child 1747 003ddc6d09c9be77670f59061a57b9041c38e672
push id953
push userjrburke@gmail.com
push dateThu, 27 May 2010 23:04:50 +0000
Hooking up saving of identities from contacts addon, adjusted api paths used for rdapi.js
client/api/rdapi.html
client/api/scripts/rdapi.js
client/api/vgrid.html
client/peeps/index.html
--- a/client/api/rdapi.html
+++ b/client/api/rdapi.html
@@ -35,17 +35,16 @@
                 var parent, scrollY, targetTop,
                     inflow = $('.inflow'),
                     widgets = $('.widgets'),
                     convDisplay = $('#convDisplay'),
                     top = inflow[0].getBoundingClientRect().top,
                     inflowPaddingTop = parseInt(window.getComputedStyle(inflow[0], null).paddingTop, 10),
                     showingConversation = false;
 
-
                 $('html').live('keyup', function (evt) {
                     //Keyboard nav for selecting different conversations
                     var keyCode = evt.keyCode, highlighted, newHighlight,
                         rect, isMessageNav = false;
                     if (keyCode === 74) {
                         //j
                         highlighted = $('.inflow > .highlight');
                         if (highlighted.length) {
@@ -110,17 +109,17 @@
                     }
 
                     //Get data for current selected conversation, highlight it.
                     parent = $(evt.target).parents('[data-blade-motif]').first();
                     parent.addClass('highlight');
 
                     //Load the conversation data
                     var data = rdapi.data(parent.attr('data-blade-motif'));
-                    rdapi('conversations/by_id?key=' + encodeURIComponent(JSON.stringify(data.id)) + '&schemas=%5B%22*%22%5D', {
+                    rdapi('inflow/conversations/by_id?key=' + encodeURIComponent(JSON.stringify(data.id)) + '&schemas=%5B%22*%22%5D', {
                         templateId: 'fullConversation',
                         containerNode: document.getElementById('convDisplay'),
                         onTemplateDone: function () {
                             showingConversation = true;
                         }
                     });
 
                     //Hide widgets area and fix the conversations.
@@ -174,17 +173,17 @@
       </div>
       <div class="c3 logo">
 
       </div>
     </div>
   </div>
 
   <div class="inflow templateContainer">
-    <div class="row template" data-api="conversations/personal">
+    <div class="row template" data-api="inflow/conversations/personal">
       {. first messages[0].schemas['rd.msg.body']}
       {. from rdapi.identity(first.from)}
       <div class="c3">
         <span class="date">{first.timestamp} - via email</span>
 
         <span class="actions">hide delete</span>
       </div>
       <div class="c1">
--- a/client/api/scripts/rdapi.js
+++ b/client/api/scripts/rdapi.js
@@ -5,17 +5,17 @@
 require.def('rdapi', ['jquery', 'blade/object', 'blade/motif'], function ($, object, motif) {
 
     var rdapi,
         idCounter = 0,
         templateRegistry = {},
         idRegistry = {},
         config = {
             baseUrl: '/raindrop/',
-            apiPath: '_api/inflow/',
+            apiPath: '_api/',
             saveTemplateData: true
         };
 
     function getHtml(node) {
         var temp = document.createElement('div'),
             parent = node.parentNode,
             sibling = node.nextSibling, html;
 
--- a/client/api/vgrid.html
+++ b/client/api/vgrid.html
@@ -39,17 +39,17 @@
                   delay: 20,
                   fadeIn: { time: 500,
                             delay: 50 }
                   });
 
                   $("#zoomTarget").fancyZoom({ width:600, height:300 });
                   $(".subject").click(function() {
                       var data = rdapi.data($(this.parentNode).attr('data-blade-motif'));
-                      rdapi('conversations/by_id?key=' + encodeURIComponent(JSON.stringify(data.id)) + '&schemas=%5B%22*%22%5D', {
+                      rdapi('inflow/conversations/by_id?key=' + encodeURIComponent(JSON.stringify(data.id)) + '&schemas=%5B%22*%22%5D', {
                           templateId: 'fullConversation',
                           containerNode: document.getElementById('convoDisplay'),
                           onTemplateDone: function () {
                             $("#zoomTarget").click();
                           }
                       });
                   })
                 }
@@ -62,17 +62,17 @@
   <div class="header">
     <img style="float:left; margin-top:15px;" src="i/search.png">
     <div style="margin-left:20px; display:inline;"><li>Compose</li><li>Edit</li></div>
     <img style="float:right; margin-top:15px;" src="i/logo.png">
   </div> 
 
   <div id="grid-content" class="inflow templateContainer">
 
-    <div class="row template" data-api="conversations/personal">
+    <div class="row template" data-api="inflow/conversations/personal">
       <a class="subject" href="#convoDisplay">{subject}</a>
       <div class="date">sent on {messages[0].schemas['rd.msg.body'].timestamp}</div>
       <div class="name">{from_display[0]}</div>
       <div class="messageBody">{messages[0].schemas['rd.msg.body'].body_preview}</div>
       <div class="viewAll">View all messages ({messages[1:].length})</div>
     </div>
 
   </div>
--- a/client/peeps/index.html
+++ b/client/peeps/index.html
@@ -1,41 +1,78 @@
 <!DOCTYPE html>
 <html>
 <head>
     <title>Peeps</title>
     <link type="text/css" rel="stylesheet" href="peeps.css">
     <script src="../api/scripts/requireplugins-jquery-1.4.2.js" charset="utf-8"></script>
     <script>
         "use strict";
+        /*jslint plusplus: false */
         /*global require: false, window: false, console: false */
         //http://people.mozilla.com/~mhanson/contacts/
 
         require(["jquery", "rdapi"], function ($, rdapi) {
 
             function onPeople(people) {
                 //Only care about people who have an email, phone number or an URL.
-                var useful = people.filter(function (person) {
-                    return !!(person.emails || person.phoneNumbers || person.urls || person.addresses);
+                var contact, identities, type, i, item,
+                    props = {
+                        'emails': 'email',
+                        'urls': 'url',
+                        'phoneNumbers': 'phoneNumber'
+                    };
+
+                people.forEach(function (person) {
+                    if (person.accounts) {
+                        console.log(person);
+                    }
+                    var prop;
+                    contact = {
+                        displayName: person.displayName
+                    };
+                    identities = [];
+
+                    //Pull out possible identity info.
+                    for (prop in props) {
+                        if (props.hasOwnProperty(prop)) {
+                            type = props[prop];
+                            if (person[prop]) {
+                                for (i = 0; (item = person[prop][i]); i++) {
+                                    identities.push([[type, item.value], type]);
+                                }
+                            }
+                        }
+                    }
+
+                    //If there are new identities to send, do that now for this contact.
+                    if (identities.length) {
+                        rdapi('model/contacts/create_identity_relationships', {
+                            type: 'POST',
+                            processData: false,
+                            data: JSON.stringify({
+                                contact_properties: contact,
+                                relationships: identities
+                            })
+                        });
+                    }
                 });
-
-                console.log(useful);
             }
 
             function onPeopleError(err) {
                 console.log(err);
                 if (err.message.indexOf('permission denied') !== -1) {
                     $('permissionDenied').removeClass('hidden');
                 }
             }
 
             function importContacts() {
                 navigator.people.find(
                     {},
-                    ["displayName", "accounts", "emails", "phoneNumbers", "urls", "photos", "addresses"],
+                    ["displayName", "emails", "phoneNumbers", "accounts", "urls", "photos", "addresses"],
                     onPeople,
                     onPeopleError
                 );
             }
 
             $(function () {
                 if (window.navigator.people) {
                     $('#import').removeClass('hidden');