client/bubbles.xml
author Mark Hammond <mhammond@skippinet.com.au>
Mon, 20 Apr 2009 11:06:46 +1000
changeset 210 9056db5cd8ef1ea86be7232e338c0b3025f250c3
parent 39 939023071b01c2414c30a84bb9fdddc4cd7f8ccb
permissions -rw-r--r--
fix error retries by passing the old revision info around

<?xml version="1.0" encoding="UTF-8"?>
<xbl:xbl
  xmlns="http://www.w3.org/1999/xhtml"
  xmlns:xbl="http://www.w3.org/ns/xbl">

  <xbl:binding id="constraint-list">
    <xbl:template>
      <div id="holder">
      </div>
    </xbl:template>
    <xbl:implementation><![CDATA[
      ({
        _nConstraints: null,
        addContact: function(aContact) {
          var node = $("<div/>").addClass("bubble").attr("type", "contact")[0];
          ElementXBL.prototype.addBinding.call(node, "bubbles.xml#constraint-contact");
          node.setContact(aContact);
          $(this._nConstraints).append(node);
          console.log("Contact", aContact, "added");
        },
        addTagName: function(aTagName) {
          var node = $("<div/>").addClass("bubble").attr("type", "tag")[0];
          ElementXBL.prototype.addBinding.call(node, "bubbles.xml#constraint-tag");
          node.setTagName(aTagName);
          $(this._nConstraints).append(node);
          console.log("Tag name constraint", aTagName, "added");
        },
        addDiscussion: function(aDiscussion) {
          var node = $("<div/>").addClass("bubble").attr("type", "discussion")[0];
          ElementXBL.prototype.addBinding.call(node, "bubbles.xml#constraint-discussion");
          node.setDiscussion(aDiscussion);
          $(this._nConstraints).append(node);
          console.log("Discussion constraint", aDiscussion, "added");        
        },
        getContacts: function() {
          var contacts = [];
          $(this._nConstraints).children().map(function (index, item) {
            if (item.getType() == "contact") {
              contacts.push(item.getContact());
            }
          });
          return contacts;
        },
        getTagNames: function() {
          var tagNames = [];
          $(this._nConstraints).children().map(function (index, item) {
            if (item.getType() == "tag") {
              tagNames.push(item.getTagName());
            }
          });
          return tagNames;
        },
        getDiscussions: function() {
          var discussions = [];
          $(this._nConstraints).children().map(function (index, item) {
            if (item.getType() == "discussion") {
              discussions.push(item.getDiscussion());
            }
          });
          return discussions;
        },
        clear: function() {
          $(this._nConstraints).empty();
        },
        xblBindingAttached: function () {
          this._nConstraints = this.shadowTree.getElementById("holder");
        },
      })
    ]]></xbl:implementation>
  </xbl:binding>

  <xbl:binding id="constraint-contact">
    <xbl:template>
      <img id="picture" height="18" width="18" class="con_contactpic"/>
      <span id="name"></span>
    </xbl:template>
    <xbl:resources>
      <xbl:style><![CDATA[
        .con_contactpic {
          width: 18;
          height: 18;
        }
      ]]></xbl:style>
    </xbl:resources>
    <xbl:implementation><![CDATA[
      ({
        getType: function() { return "contact"; },
        contact: null,
        getContact: function() {
          return this.contact;
        },
        setContact: function(aContact) {
          this.contact = aContact;
          console.log("setContact", this);
          this.shadowTree.getElementById("name").textContent = this.contact.name;
          var bestEmail = null;
          var emailText = this.contact.identities.forEach(function (identity) {
            if (identity.kind == "email")
              bestEmail = identity.value;
          });
          if (bestEmail) {
            this.shadowTree.getElementById("picture").setAttribute("src",
              "http://www.gravatar.com/avatar/" + hex_md5(bestEmail) +
              ".jpg?r=pg&d=identicon&s=18");
          }
        },
      })
    ]]></xbl:implementation>
  </xbl:binding>
  <!-- Tag -->
  <xbl:binding id="constraint-tag">
    <xbl:template>
      <span id="tagname"></span>
    </xbl:template>
    <xbl:implementation><![CDATA[
      ({
        getType: function() { return "tag"; },
        tagname: null,
        getTagName: function() {
          return this.tagname;
        },
        setTagName: function(aTagName) {
          this.tagname = aTagName;
          this.shadowTree.getElementById("tagname").textContent = aTagName;
        }
      })
    ]]></xbl:implementation>
  </xbl:binding>
  <!-- Discussion -->
  <xbl:binding id="constraint-discussion">
    <xbl:template>
      <span id="discussion"></span>
    </xbl:template>
    <xbl:implementation><![CDATA[
      ({
        getType: function() { return "discussion"; },
        _discussion: null,
        getDiscussion: function() {
          return this._discussion;
        },
        _getAttr : function(attr) {
          return this._discussion[attr];
        },
        getName: function() {
          return this._getAttr("name");
        },
        getListId: function() {
          /* fake the real "List-Id" since we've done some clean up before */
          return this.getName() + " " + "<" + this._getAttr("id") + ">";
        },
        setDiscussion: function(aDiscussion) {
          this._discussion = aDiscussion;
          this.shadowTree.getElementById("discussion").textContent = this.getListId();
        }
      })
    ]]></xbl:implementation>
  </xbl:binding>
</xbl:xbl>