view plugins/vcard.js @ 93:26d372c9e270

fix the vcard plugin
author Sonny Piers <sonny.piers@gmail.com>
date Thu, 19 Apr 2012 16:49:46 +0200
parents e25dfe389dab
children 90fdbe5454c4
line wrap: on
line source

'use strict';

/**
  Copyright (c) 2011, Sonny Piers <sonny at fastmail dot net>

  Permission to use, copy, modify, and/or distribute this software for any
  purpose with or without fee is hereby granted, provided that the above
  copyright notice and this permission notice appear in all copies.

  THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
  WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
  MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
  ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
  WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
  ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
  OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/

/////////
//vCard//
/////////
Lightstring.plugins['vcard'] = {
  namespaces: {
    vcard: 'vcard-temp'
  },
  stanzas: {
    get: function(aTo) {
      if (aTo)
        return "<iq type='get' to='" + aTo + "'><vCard xmlns='" + Lightstring.ns.vcard + "'/></iq>";
      else
        return "<iq type='get'><vCard xmlns='" + Lightstring.ns.vcard + "'/></iq>";
    },
    set: function(aTo) {
      if (aTo)
        return "<iq type='get' to='" + aTo + "'><vCard xmlns='" + Lightstring.ns.vcard + "'/></iq>";
      else
        return "<iq type='get'><vCard xmlns='" + Lightstring.ns.vcard + "'/></iq>";
    }
  },
  //FIXME: we should return a JSON vcard, not an XML one
  methods: {
    get: function(aTo, aOnSuccess, aOnError) {
      this.send(Lightstring.stanzas['vcard'].get(aTo), function(stanza) {
        var fields = stanza.DOM.firstChild.childNodes;
        if (aOnSuccess && fields)
          aOnSuccess(fields);
      }, aOnError);
    },
    set: function(aTo, aFields, aOnSuccess, aOnError) {
      this.send(Lightstring.stanzas['vcard'].set(aTo, aFields), function(stanza) {
        if (aOnSuccess)
          aOnSuccess();
        //~ var vcard = stanza.DOM.firstChild;
        //~ if (vcard)
          //~ aResult(vcard);
      }, aError);
    }
  }
};