source: Dev/branches/rest-dojo-ui/client/dojox/xmpp/UserService.js @ 256

Last change on this file since 256 was 256, checked in by hendrikvanantwerpen, 13 years ago

Reworked project structure based on REST interaction and Dojo library. As
soon as this is stable, the old jQueryUI branch can be removed (it's
kept for reference).

File size: 3.0 KB
Line 
1dojo.provide("dojox.xmpp.UserService");
2
3dojo.declare("dojox.xmpp.UserService", null, {
4        constructor: function(xmppService){
5                this.session= xmppService;
6        },
7
8        getPersonalProfile: function(){
9                var req={
10                        id: this.session.getNextIqId(),
11                        type: 'get'
12                }
13                var request = new dojox.string.Builder(dojox.xmpp.util.createElement("iq",req,false));
14                request.append(dojox.xmpp.util.createElement("query",{xmlns:"jabber:iq:private"},false));
15                request.append(dojox.xmpp.util.createElement("sunmsgr",{xmlsns:'sun:xmpp:properties'},true));
16                request.append("</query></iq>");
17
18                var def = this.session.dispatchPacket(request.toString(),"iq",req.id);
19                def.addCallback(this, "_onGetPersonalProfile");
20        },
21
22        setPersonalProfile: function(props){
23                var req={
24                        id: this.session.getNextIqId(),
25                        type: 'set'
26                }
27               
28                var request = new dojox.string.Builder(dojox.xmpp.util.createElement("iq",req,false));
29                request.append(dojox.xmpp.util.createElement("query",{xmlns:"jabber:iq:private"},false));
30                request.append(dojox.xmpp.util.createElement("sunmsgr",{xmlsns:'sun:xmpp:properties'},false));
31
32                for (var key in props){
33                        request.append(dojox.xmpp.util.createElement("property",{name: key},false));
34                        request.append(dojox.xmpp.util.createElement("value",{},false));
35                        request.append(props[key]);
36                        request.append("</value></props>");
37                }
38               
39                request.append("</sunmsgr></query></iq>");
40
41                var def = this.session.dispatchPacket(request.toString(), "iq", req.id);
42                def.addCallback(this, "_onSetPersonalProfile");
43        },
44
45        _onSetPersonalProfile: function(response){
46                if(response.getAttribute('type')=='result'){
47                        this.onSetPersonalProfile(response.getAttribute('id'));
48                }else if(response.getAttribute('type')=='error'){
49                        var err = this.session.processXmppError(response);
50                        this.onSetPersonalProfileFailure(err);
51                }
52        },
53
54        onSetPersonalProfile: function(id){},
55        onSetPersonalProfileFailure: function(err){},
56
57        _onGetPersonalProfile: function(profile){
58                if (profile.getAttribute('type')=='result'){
59                        var props = {};
60
61                        if (profile.hasChildNodes()){
62                                var queryNode = profile.firstChild;
63                                if ((queryNode.nodeName=="query")&&(queryNode.getAttribute('xmlns')=='jabber:iq:private')){
64                                        var sunNode = queryNode.firstChild;
65                                        if ((sunNode.nodeName=='query')&&(sunNode.getAttributes('xmlns')=='sun:xmpp:properties')){
66                                                for (var i=0; i<sunNode.childNodes.length;i++){
67                                                        var n = sunNode.childNodes[i];
68                                                        if(n.nodeName == 'property'){
69                                                                var name = n.getAttribute('name');
70                                                                var val = n.firstChild || "";
71                                                                props[name]=val;
72                                                        }
73                                                }
74                                        }
75                                }
76                                this.onGetPersonalProfile(props);
77                        }
78                }else if (profile.getAttribute('type')=='error'){
79                        var err = this.session.processXmppError(profile);
80                        this.onGetPersonalProfileFailure(err);
81                }
82
83                return profile;
84        },
85
86        onGetPersonalProfile: function(profile){
87                //console.log("UserService::onGetPersonalProfile() ", profile);
88        },
89
90        onGetPersonalProfileFailure: function(err){
91                //console.log("UserService::onGetPersonalProfileFailure() ", err);
92        }
93});
Note: See TracBrowser for help on using the repository browser.