/adei/trunk

To get this branch, use:
bzr branch http://darksoft.org/webbzr/adei/trunk
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
  function DLMANAGER() {  
    this.config = new CONFIG();
    this.tm = null;
    this.rate = 2000;
    this.defopts = "target=dlmanager_run";  
    this.download = 0;
    this.finalizing = false;
    this.starting = false;
    this.stop = false;
    this.idleruns = 0;   ;
  }

  function dlmanagerstart() {        
    //if(dlmanager.tm == null) dlmanager.tm = window.setInterval("dlmanager.Request()", dlmanager.rate); 
    dlmanager.idleruns = 0;
    dlmanager.Request();
  }

  DLMANAGER.prototype.Request = function(opts) {       
    if(!opts) var opts = this.defopts;    
    new Ajax.Request(
	adei.GetServiceURL("download", opts),
	{
	    method: 'post',
	    onSuccess: dlUpdaterRequest(this),
	    onFailure: function() {		
		adei.SetStatus(translate("Downloadmanager updater POST request failed"), 0);
		this.Stop();
	    }
	}
    );      
  }  

  function dlUpdaterRequest(updater) { 
    return function(transport) {	
	var error = false;
	var result;
	var res = transport.responseXML;
	
        if (res) {
	    var values = res.getElementsByTagName("result");
	    if (values.length > 1) {
		error = translate("download service returned multiple result nodes");
	    } else if (values.length == 0) {
		var errors = res.getElementsByTagName("error");
		if (errors.length > 0) {
		    error = errors[0].firstChild.data;
		} else {
	    	    error = translate("download service returned no result or error nodes", url);
		}
	    } else {
		result = values[0];
	    }
	}
	if (error) adeiReportError(error);

	var job = result.getAttribute('job');
    
	switch (job) {
	  case 'Showprogress':	
	      updater.idleruns = 0;
	      var download = result.getAttribute('dl_id');
	      var filediv = "fcount" + download;
	      var frem = result.getAttribute('frem');
	      var prog = result.getAttribute('progress');	      
	      var finalizing = result.getAttribute('finalizing');
	      var bar = "progress" + download;
 	      con = new CONFIG();  
 	      if(con.GetModule() == 'download') setTimeout("dlmanager.Request()", updater.rate);
	      if(finalizing != 1) updater.finalizing = false;
	      if(finalizing == 1) {
		updater.finalizing = true;
		$(bar).style.width = "100%";
		$(bar).innerHTML = "Finalizing file...";
	      } else if(prog < 100 && prog != "") {
		$(bar).style.width = prog + "%";
		$(bar).innerHTML = prog + "%";
		$(filediv).innerHTML = "Data groups left: "+frem;
	      }	      	     
	  break;
	  case 'Idle':	
		var finalizing = result.getAttribute('finalizing')
		updater.idleruns = updater.idleruns + 1;
		if ((finalizing)||(updater.finalizing)) {
		  updater.finalizing = false;
		  adei.updater.Update();
		} else {
		  if(updater.idleruns < 4) setTimeout("dlmanager.Request()", updater.rate);
		}
	  break;	  
	  case 'Done':
	      adei.updater.Update();
	  break;
	
	}      
     }    
    
  }  
  
   DLMANAGER.prototype.RemoveDownload = function(download) {
     var doIt = confirm('Are you sure you want to delete download?');
     if(doIt) {
       var opts = "target=dlmanager_remove&dl_id=" + download;
       this.Request(opts);   
     }	
     else return;
   }
   
  DLMANAGER.prototype.AddDownload = function(opts) {
    opts += "&target=dlmanager_add";  
    //alert(opts);
    this.Request(opts);
    if(this.config.GetModule() != 'download') {
      adei.OpenModule('download');
    }            
  }
  
  DLMANAGER.prototype.Stop = function() {   
    window.clearInterval(this.tm);
  }
  
  DLMANAGER.prototype.SortBy = function(user) {
    var opts = "target=dlmanager_sort&sortby=" + user;
    this.Request(opts);
  }

  DLMANAGER.prototype.ToggleAutodelete = function(download) {
    var opts = "target=dlmanager_toggleautodelete&dl_id=" + download;
    this.Request(opts);
  }