Mercurial > eldonilo > lightstring
annotate plugins/vcard.js @ 108:5cb4733c5189
many api changes
author | Sonny Piers <sonny@fastmail.net> |
---|---|
date | Fri, 13 Jul 2012 15:26:18 +0200 |
parents | 90fdbe5454c4 |
children |
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) |
94
90fdbe5454c4
makes vcard plugin actually works
Sonny Piers <sonny.piers@gmail.com>
parents:
93
diff
changeset
|
29 return "<iq type='get' to='" + aTo + "'><vCard xmlns='" + |
90fdbe5454c4
makes vcard plugin actually works
Sonny Piers <sonny.piers@gmail.com>
parents:
93
diff
changeset
|
30 Lightstring.ns.vcard + "'/></iq>"; |
49
e25dfe389dab
Fix vCard-temp plugin.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
35
diff
changeset
|
31 else |
93 | 32 return "<iq type='get'><vCard xmlns='" + Lightstring.ns.vcard + "'/></iq>"; |
33 }, | |
94
90fdbe5454c4
makes vcard plugin actually works
Sonny Piers <sonny.piers@gmail.com>
parents:
93
diff
changeset
|
34 set: function(aFields) { |
90fdbe5454c4
makes vcard plugin actually works
Sonny Piers <sonny.piers@gmail.com>
parents:
93
diff
changeset
|
35 var iq = "<iq type='set'><vCard xmlns='" + Lightstring.ns.vcard + "'>"; |
90fdbe5454c4
makes vcard plugin actually works
Sonny Piers <sonny.piers@gmail.com>
parents:
93
diff
changeset
|
36 aFields.forEach(function(field) { |
90fdbe5454c4
makes vcard plugin actually works
Sonny Piers <sonny.piers@gmail.com>
parents:
93
diff
changeset
|
37 iq += field; |
90fdbe5454c4
makes vcard plugin actually works
Sonny Piers <sonny.piers@gmail.com>
parents:
93
diff
changeset
|
38 }); |
90fdbe5454c4
makes vcard plugin actually works
Sonny Piers <sonny.piers@gmail.com>
parents:
93
diff
changeset
|
39 iq += "</vCard></iq>"; |
90fdbe5454c4
makes vcard plugin actually works
Sonny Piers <sonny.piers@gmail.com>
parents:
93
diff
changeset
|
40 return iq; |
49
e25dfe389dab
Fix vCard-temp plugin.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
35
diff
changeset
|
41 } |
e25dfe389dab
Fix vCard-temp plugin.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
35
diff
changeset
|
42 }, |
e25dfe389dab
Fix vCard-temp plugin.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
35
diff
changeset
|
43 methods: { |
94
90fdbe5454c4
makes vcard plugin actually works
Sonny Piers <sonny.piers@gmail.com>
parents:
93
diff
changeset
|
44 //FIXME: we should return a JSON vcard, not an XML one |
93 | 45 get: function(aTo, aOnSuccess, aOnError) { |
94
90fdbe5454c4
makes vcard plugin actually works
Sonny Piers <sonny.piers@gmail.com>
parents:
93
diff
changeset
|
46 this.send(Lightstring.stanzas['vcard'].get(aTo), |
90fdbe5454c4
makes vcard plugin actually works
Sonny Piers <sonny.piers@gmail.com>
parents:
93
diff
changeset
|
47 // on success |
90fdbe5454c4
makes vcard plugin actually works
Sonny Piers <sonny.piers@gmail.com>
parents:
93
diff
changeset
|
48 function(stanza) { |
90fdbe5454c4
makes vcard plugin actually works
Sonny Piers <sonny.piers@gmail.com>
parents:
93
diff
changeset
|
49 var fields = stanza.DOM.firstChild; |
90fdbe5454c4
makes vcard plugin actually works
Sonny Piers <sonny.piers@gmail.com>
parents:
93
diff
changeset
|
50 if (aOnSuccess && fields) |
90fdbe5454c4
makes vcard plugin actually works
Sonny Piers <sonny.piers@gmail.com>
parents:
93
diff
changeset
|
51 aOnSuccess(fields); |
90fdbe5454c4
makes vcard plugin actually works
Sonny Piers <sonny.piers@gmail.com>
parents:
93
diff
changeset
|
52 }, |
90fdbe5454c4
makes vcard plugin actually works
Sonny Piers <sonny.piers@gmail.com>
parents:
93
diff
changeset
|
53 //on error |
90fdbe5454c4
makes vcard plugin actually works
Sonny Piers <sonny.piers@gmail.com>
parents:
93
diff
changeset
|
54 function(stanza) { |
90fdbe5454c4
makes vcard plugin actually works
Sonny Piers <sonny.piers@gmail.com>
parents:
93
diff
changeset
|
55 if (aOnError) |
90fdbe5454c4
makes vcard plugin actually works
Sonny Piers <sonny.piers@gmail.com>
parents:
93
diff
changeset
|
56 aOnError(sanza); |
90fdbe5454c4
makes vcard plugin actually works
Sonny Piers <sonny.piers@gmail.com>
parents:
93
diff
changeset
|
57 } |
90fdbe5454c4
makes vcard plugin actually works
Sonny Piers <sonny.piers@gmail.com>
parents:
93
diff
changeset
|
58 ); |
93 | 59 }, |
94
90fdbe5454c4
makes vcard plugin actually works
Sonny Piers <sonny.piers@gmail.com>
parents:
93
diff
changeset
|
60 set: function(aFields, aOnSuccess, aOnError) { |
90fdbe5454c4
makes vcard plugin actually works
Sonny Piers <sonny.piers@gmail.com>
parents:
93
diff
changeset
|
61 this.send(Lightstring.stanzas['vcard'].set(aFields), |
90fdbe5454c4
makes vcard plugin actually works
Sonny Piers <sonny.piers@gmail.com>
parents:
93
diff
changeset
|
62 //on success |
90fdbe5454c4
makes vcard plugin actually works
Sonny Piers <sonny.piers@gmail.com>
parents:
93
diff
changeset
|
63 function(stanza) { |
90fdbe5454c4
makes vcard plugin actually works
Sonny Piers <sonny.piers@gmail.com>
parents:
93
diff
changeset
|
64 if (aOnSuccess) |
90fdbe5454c4
makes vcard plugin actually works
Sonny Piers <sonny.piers@gmail.com>
parents:
93
diff
changeset
|
65 aOnSuccess(stanza.DOM.firstChild); |
90fdbe5454c4
makes vcard plugin actually works
Sonny Piers <sonny.piers@gmail.com>
parents:
93
diff
changeset
|
66 }, |
90fdbe5454c4
makes vcard plugin actually works
Sonny Piers <sonny.piers@gmail.com>
parents:
93
diff
changeset
|
67 //on error |
90fdbe5454c4
makes vcard plugin actually works
Sonny Piers <sonny.piers@gmail.com>
parents:
93
diff
changeset
|
68 function(stanza) { |
90fdbe5454c4
makes vcard plugin actually works
Sonny Piers <sonny.piers@gmail.com>
parents:
93
diff
changeset
|
69 if (aOnError) |
90fdbe5454c4
makes vcard plugin actually works
Sonny Piers <sonny.piers@gmail.com>
parents:
93
diff
changeset
|
70 aOnError(stanza); |
90fdbe5454c4
makes vcard plugin actually works
Sonny Piers <sonny.piers@gmail.com>
parents:
93
diff
changeset
|
71 } |
90fdbe5454c4
makes vcard plugin actually works
Sonny Piers <sonny.piers@gmail.com>
parents:
93
diff
changeset
|
72 ); |
49
e25dfe389dab
Fix vCard-temp plugin.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
35
diff
changeset
|
73 } |
30
1506992c33e2
Split plugins.js into multiple plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
74 } |
1506992c33e2
Split plugins.js into multiple plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
75 }; |