annotate 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
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
30
1506992c33e2 Split plugins.js into multiple plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
1 'use strict';
1506992c33e2 Split plugins.js into multiple plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
2
1506992c33e2 Split plugins.js into multiple plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
3 /**
1506992c33e2 Split plugins.js into multiple plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
4 Copyright (c) 2011, Sonny Piers <sonny at fastmail dot net>
1506992c33e2 Split plugins.js into multiple plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
5
1506992c33e2 Split plugins.js into multiple plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
6 Permission to use, copy, modify, and/or distribute this software for any
1506992c33e2 Split plugins.js into multiple plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
7 purpose with or without fee is hereby granted, provided that the above
1506992c33e2 Split plugins.js into multiple plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
8 copyright notice and this permission notice appear in all copies.
1506992c33e2 Split plugins.js into multiple plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
9
1506992c33e2 Split plugins.js into multiple plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
10 THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
1506992c33e2 Split plugins.js into multiple plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
11 WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
1506992c33e2 Split plugins.js into multiple plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
12 MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
1506992c33e2 Split plugins.js into multiple plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
13 ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
1506992c33e2 Split plugins.js into multiple plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
14 WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
1506992c33e2 Split plugins.js into multiple plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
15 ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
1506992c33e2 Split plugins.js into multiple plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
16 OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
1506992c33e2 Split plugins.js into multiple plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
17 */
1506992c33e2 Split plugins.js into multiple plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
18
1506992c33e2 Split plugins.js into multiple plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
19 /////////
1506992c33e2 Split plugins.js into multiple plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
20 //vCard//
1506992c33e2 Split plugins.js into multiple plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
21 /////////
49
e25dfe389dab Fix vCard-temp plugin.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 35
diff changeset
22 Lightstring.plugins['vcard'] = {
e25dfe389dab Fix vCard-temp plugin.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 35
diff changeset
23 namespaces: {
e25dfe389dab Fix vCard-temp plugin.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 35
diff changeset
24 vcard: 'vcard-temp'
e25dfe389dab Fix vCard-temp plugin.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 35
diff changeset
25 },
e25dfe389dab Fix vCard-temp plugin.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 35
diff changeset
26 stanzas: {
e25dfe389dab Fix vCard-temp plugin.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 35
diff changeset
27 get: function(aTo) {
e25dfe389dab Fix vCard-temp plugin.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 35
diff changeset
28 if (aTo)
93
26d372c9e270 fix the vcard plugin
Sonny Piers <sonny.piers@gmail.com>
parents: 49
diff changeset
29 return "<iq type='get' to='" + aTo + "'><vCard xmlns='" + Lightstring.ns.vcard + "'/></iq>";
49
e25dfe389dab Fix vCard-temp plugin.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 35
diff changeset
30 else
93
26d372c9e270 fix the vcard plugin
Sonny Piers <sonny.piers@gmail.com>
parents: 49
diff changeset
31 return "<iq type='get'><vCard xmlns='" + Lightstring.ns.vcard + "'/></iq>";
26d372c9e270 fix the vcard plugin
Sonny Piers <sonny.piers@gmail.com>
parents: 49
diff changeset
32 },
26d372c9e270 fix the vcard plugin
Sonny Piers <sonny.piers@gmail.com>
parents: 49
diff changeset
33 set: function(aTo) {
26d372c9e270 fix the vcard plugin
Sonny Piers <sonny.piers@gmail.com>
parents: 49
diff changeset
34 if (aTo)
26d372c9e270 fix the vcard plugin
Sonny Piers <sonny.piers@gmail.com>
parents: 49
diff changeset
35 return "<iq type='get' to='" + aTo + "'><vCard xmlns='" + Lightstring.ns.vcard + "'/></iq>";
26d372c9e270 fix the vcard plugin
Sonny Piers <sonny.piers@gmail.com>
parents: 49
diff changeset
36 else
26d372c9e270 fix the vcard plugin
Sonny Piers <sonny.piers@gmail.com>
parents: 49
diff changeset
37 return "<iq type='get'><vCard xmlns='" + Lightstring.ns.vcard + "'/></iq>";
49
e25dfe389dab Fix vCard-temp plugin.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 35
diff changeset
38 }
e25dfe389dab Fix vCard-temp plugin.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 35
diff changeset
39 },
93
26d372c9e270 fix the vcard plugin
Sonny Piers <sonny.piers@gmail.com>
parents: 49
diff changeset
40 //FIXME: we should return a JSON vcard, not an XML one
49
e25dfe389dab Fix vCard-temp plugin.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 35
diff changeset
41 methods: {
93
26d372c9e270 fix the vcard plugin
Sonny Piers <sonny.piers@gmail.com>
parents: 49
diff changeset
42 get: function(aTo, aOnSuccess, aOnError) {
49
e25dfe389dab Fix vCard-temp plugin.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 35
diff changeset
43 this.send(Lightstring.stanzas['vcard'].get(aTo), function(stanza) {
93
26d372c9e270 fix the vcard plugin
Sonny Piers <sonny.piers@gmail.com>
parents: 49
diff changeset
44 var fields = stanza.DOM.firstChild.childNodes;
26d372c9e270 fix the vcard plugin
Sonny Piers <sonny.piers@gmail.com>
parents: 49
diff changeset
45 if (aOnSuccess && fields)
26d372c9e270 fix the vcard plugin
Sonny Piers <sonny.piers@gmail.com>
parents: 49
diff changeset
46 aOnSuccess(fields);
26d372c9e270 fix the vcard plugin
Sonny Piers <sonny.piers@gmail.com>
parents: 49
diff changeset
47 }, aOnError);
26d372c9e270 fix the vcard plugin
Sonny Piers <sonny.piers@gmail.com>
parents: 49
diff changeset
48 },
26d372c9e270 fix the vcard plugin
Sonny Piers <sonny.piers@gmail.com>
parents: 49
diff changeset
49 set: function(aTo, aFields, aOnSuccess, aOnError) {
26d372c9e270 fix the vcard plugin
Sonny Piers <sonny.piers@gmail.com>
parents: 49
diff changeset
50 this.send(Lightstring.stanzas['vcard'].set(aTo, aFields), function(stanza) {
26d372c9e270 fix the vcard plugin
Sonny Piers <sonny.piers@gmail.com>
parents: 49
diff changeset
51 if (aOnSuccess)
26d372c9e270 fix the vcard plugin
Sonny Piers <sonny.piers@gmail.com>
parents: 49
diff changeset
52 aOnSuccess();
26d372c9e270 fix the vcard plugin
Sonny Piers <sonny.piers@gmail.com>
parents: 49
diff changeset
53 //~ var vcard = stanza.DOM.firstChild;
26d372c9e270 fix the vcard plugin
Sonny Piers <sonny.piers@gmail.com>
parents: 49
diff changeset
54 //~ if (vcard)
26d372c9e270 fix the vcard plugin
Sonny Piers <sonny.piers@gmail.com>
parents: 49
diff changeset
55 //~ aResult(vcard);
49
e25dfe389dab Fix vCard-temp plugin.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 35
diff changeset
56 }, aError);
e25dfe389dab Fix vCard-temp plugin.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 35
diff changeset
57 }
30
1506992c33e2 Split plugins.js into multiple plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
58 }
1506992c33e2 Split plugins.js into multiple plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
59 };