]>
git.argeo.org Git - gpl/argeo-slc.git/blob - server/org.argeo.slc.ria/src/argeo-ria-src/class/org/argeo/ria/remote/RemoteNotifier.js
be97aee069b2a29d0b60a903a68c7845cae62cd5
2 * This can be triggered at the end of a IO Request. In that case, it contains
3 * a data type as an identifier, and the request response itself.
4 * Can be used this way to listen for data changes from various parts of the application.
6 qx
.Class
.define("org.argeo.ria.remote.RemoteNotifier",
8 extend
: qx
.core
.Object
,
10 construct : function(uri
, pollService
, addService
, removeService
){
13 this.setPollService(pollService
);
14 this.setAddService(addService
);
15 this.setRemoveService(removeService
);
21 pollService
: {check
: "String"},
22 addService
: {check
: "String"},
23 removeService
: {check
: "String"},
24 eventParamName
: {check
: "String", init
:"eventType"},
25 eventXPath
: {check
: "String", init
:"//event"},
26 eventTypeXPath
: {check
: "String", init
:"@type"},
27 eventDataXPath
: {check
: "String", init
:"@data"},
28 answerStatusXPath
: {check
: "String", init
:"slc:execution-answer/slc:status"},
41 addListener : function(eventType
, eventParamName
){
42 var req
= this._getRequest(this.getAddService());
43 req
.setParameter(this.getEventParamName(), eventType
);
46 removeListener : function(eventType
, eventParamName
){
47 var req
= this._getRequest(this.getRemoveService());
48 req
.setParameter(this.getEventParamName(), eventType
);
51 startPolling : function(){
52 this.setInterrupt(false);
53 var req
= this._getRequest(this.getPollService());
54 req
.setParameter("timeout", "10");
55 req
.addListener("completed", this._pollHandler
, this);
58 stopPolling : function(){
59 this.setInterrupt(true);
62 if(this.getInterrupt()) return;
63 var req
= this._getRequest(this.getPollService());
64 req
.setParameter("timeout", this.getTimeout());
65 req
.setTimeout(this.getTimeout() + 5000);
66 req
.addListener("completed", this._pollHandler
, this);
67 req
.addListener("failed", this._errorHandler
, this);
68 req
.addListener("timeout", this._errorHandler
, this);
69 req
.addListener("aborted", this._errorHandler
, this);
72 _pollHandler : function(response
){
74 var status
= org
.argeo
.ria
.util
.Element
.getSingleNodeText(response
.getContent(), this.getAnswerStatusXPath());
75 if(status
&& status
== "ERROR"){
79 var messages
= org
.argeo
.ria
.util
.Element
.selectNodes(response
.getContent(), this.getEventXPath());
81 for(var i
=0;i
<messages
.length
;i
++){
83 var eventType
= org
.argeo
.ria
.util
.Element
.getSingleNodeText(messages
[i
], this.getEventTypeXPath());
84 var eventData
= org
.argeo
.ria
.util
.Element
.getSingleNodeText(messages
[i
], this.getEventDataXPath());
85 org
.argeo
.ria
.event
.UIBus
.getInstance().dispatchEvent(eventType
, eventData
);
93 _errorHandler : function(){
94 // Wait an try again later
95 qx
.event
.Timer
.once(this._poll
, this, this.getErrorTimeout());
97 _getRequest : function(service
, method
, type
){
98 return new qx
.io
.remote
.Request(
99 this.getUri()+service
,
101 type
||"application/xml"