]> git.argeo.org Git - gpl/argeo-slc.git/blob - org.argeo.slc.webapp/src/main/webapp/source/class/org/argeo/slc/web/util/RequestManager.js
Canonical view
[gpl/argeo-slc.git] / org.argeo.slc.webapp / src / main / webapp / source / class / org / argeo / slc / web / util / RequestManager.js
1 qx.Class.define("org.argeo.slc.web.util.RequestManager",
2 {
3 type : "singleton",
4 extend : qx.core.Object,
5
6 construct : function(){
7 this.base(arguments);
8 },
9
10 members : {
11
12 setStopCommand : function(stopCommand){
13 this.command = stopCommand;
14 },
15
16 getRequest : function(url, method, responseType){
17 var request = new qx.io.remote.Request(url, method, responseType);
18 /*
19 request.addListener("sending", function(event){
20 this.requestCreated(request);
21 }, this);
22 request.addListener("aborted", function(event){
23 this.requestAborted(request);
24 }, this);
25 request.addListener("failed", function(event){
26 this.requestFailed(request);
27 }, this);
28 request.addListener("timeout", function(event){
29 this.requestTimeout(request);
30 }, this);
31 request.addListener("completed", function(event){
32 this.requestCompleted(request);
33 }, this);
34 */
35 this.enableCommand(request);
36 return request;
37 },
38
39 requestCreated : function(req){
40 this.enableCommand(req);
41 },
42
43 requestAborted : function(req){
44 this.disableCommand();
45 },
46
47 requestFailed : function(req){
48 this.disableCommand();
49 },
50
51 requestTimeout : function(req){
52 this.disableCommand();
53 },
54
55 requestCompleted : function(req){
56 this.disableCommand();
57 },
58
59 disableCommand : function(){
60 this.command.setEnabled(false);
61 var manager = qx.event.Registration.getManager(this.command);
62 manager.removeAllListeners(this.command);
63 },
64
65 enableCommand : function(request){
66 this.command.setEnabled(true);
67 qx.ui.core.queue.Manager.flush();
68 this.command.addListener("execute", function(){
69 request.abort();
70 });
71 }
72 }
73 });