client/index.xhtml
author Mark Hammond <mhammond@skippinet.com.au>
Fri, 20 Mar 2009 16:26:49 +1100
branchtwisty
changeset 110 20979788066de01860cf050a0d0c43498d640624
parent 70 557ef1b824258f490a54d08545b90b9d88cf746b
child 166 194c2a8c0d184bb7590d12112cb74cbcad7cba07
permissions -rw-r--r--
get imap and twitter working in the new world order

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
  <title>Junius</title>
  <script type="text/javascript" charset="utf-8"><![CDATA[
    if (window.console === undefined)
      console = {log: function() {}};
  ]]></script>
  <script src="/_utils/script/json2.js"></script>
  <script src="/_utils/script/jquery.js?1.2.6"></script>
  <script src="jquery.couch.js"></script>
  <script src="xbl-src.js"></script>
  <script src="md5.js"></script>
  <link rel="stylesheet" href="bindings.css" type="text/css"></link>
  <link rel="stylesheet" href="autocomplete.css" type="text/css"></link>
  <link rel="stylesheet" href="bubbles.css" type="text/css"></link>
  <link rel="stylesheet" href="searchResults.css" type="text/css"></link>
  <script src="cloda.js"></script>
  <script src="cloda-completers.js"></script>
  <script src="utils.js"></script>
  <script type="text/javascript" charset="utf-8"><![CDATA[
    function funkyInit() {
      var autocompleter = document.getElementById("autocomplete");
      console.log("autocompleter", autocompleter);
      autocompleter.addCompleter(TagCompleter);
      console.log("tag completer registered");
      autocompleter.addCompleter(ContactCompleter);
      console.log("contact completer registered");

      var query = document.getElementById("query");

      var constraints = document.getElementById("constraints");
      autocompleter.addActionListener(function (item) {
        console.log("!!!Action Listener!!!", item);
        var itemType = item.getType();
        console.log(".type:", itemType);
        if (itemType == "contact") {
          console.log("..contact case");
          var contact = item.getContact();
          constraints.addContact(contact);
          console.log("added contact", contact);
        }
        else if (itemType == "tag") {
          console.log("..tag case");
          var tagName = item.getTagName();
          constraints.addTagName(tagName);
          console.log("added tag name", tagName);
        }
        else
          return;
        query.updateConstraints(constraints);
      });
      console.log("constrainer registered");

      ru = new RainUtil();
      ru.addStaticMailbox("Inbox","inbox");
      ru.addStaticMailbox("Drafts","drafts");
      ru.addStaticMailbox("Archives","archives");
      ru.addStaticMailbox("Sent","sent");
      ru.addStaticMailbox("Trash","trash");
      ru.addStaticMailbox("Junk","junk");
      
      ru.addDynamicMailbox("People","people-by-frecency");
      ru.addDynamicMailbox("Search","searches");
      ru.addDynamicMailbox("Discussion","discussion");
      
      
      var dbMessages = $.couch.db("raindrop");
      dbMessages.view("raindrop!mailing_lists!all/by_list_id", {
        include_docs: false,
        group : true,
        success: function(json) {
          var parent = $("#discussion");
          json.rows.forEach(function(row) {
            var li = $(document.createElement("li")).addClass("discussion-list");
            parent.append(li
                          .append($(document.createElement("a"))
                                            .addClass("discussion-list")
                                            .attr("title", row.value["name"] + " (" + row.value["count"] + ")\n" + row.value["id"])
                                            .attr("href","#/discussion/" + row.key)
                                            .mousedown(function() { 
                                                          var c = document.getElementById("constraints"); 
                                                          c.clear(); 
                                                          c.addDiscussion(row.value);
                                                          var query = document.getElementById("query");
                                                          query.updateConstraints(c);
                                                        }
                                                      )
                                            .text(row.value["id"] + " ")
                                            .append($(document.createElement("span"))
                                                              .addClass("count")
                                                              .text("(" + row.value["count"] + ")")
                                                  )
                                            )
                                  );
          });
        }
      });
      
    }

    $(function() {
      window.setTimeout(funkyInit, 1000);
      //DocumentXBL.prototype.loadBindingDocument.call(document, "messages.xml");
      /*
      var dbMessages = $.couch.db("messages");
      dbMessages.view("by_timestamp/by_timestamp", {
        include_docs: true,
        success: function(json) {
          var parent = $("#messages");
          json.rows.forEach(function(row) {
            var node = document.createElement("div");
            node.setAttribute("class", "message");
            parent.append(node);
            ElementXBL.prototype.addBinding.call(node, "messages.xml#message");
            node.setMessage(row.doc);
            //fDocumentXBL_addBindings(node);
            return node;
          });
        }
      })
      */
    });

  function RainUtil() { }
  RainUtil.prototype = {
    addStaticMailbox: function(aTitle, aQuery) {
      var a = document.createElement("a");
      $("#static-mailboxes").append($(a).addClass("sMailbox").attr("href","#" + aQuery).text(aTitle));
    },
    addDynamicMailbox: function(aTitle, aQuery) {
      $("#dynamic-mailboxes").append(this._dynamicMailbox(aTitle,aQuery));
    },
    _dynamicMailbox: function(aTitle,aQuery) {
      var d = document.createElement("div"), 
          dt = document.createElement("div"),
          span = document.createElement("span"),
          ul = document.createElement("ul"),
          li = document.createElement("li");
      return $(d).addClass("dMailbox").append(
              $(dt).addClass("title").text(aTitle).append(
                $(span).addClass("toggle")
                       .text("-")
                       .click(function() { $(ul).slideToggle(); })),
                        $(ul).addClass("results").attr("id", aQuery));
    },
  
  };
  ]]></script>  
</head>
<body>
  <div id="autocomplete"></div>
  <div id="constraints"/>
  <div id="query"/>

  <div id="mc">
    <div id="left">
      <div id="static-mailboxes">
      </div>
      <div id="dynamic-mailboxes">
      </div>
    </div>
    <div id="right">
      <div id="conversations">
      </div>
    </div>
  </div>
</body>
</html>