]> git.sur5r.net Git - bacula/bacula/blob - gui/bweb/html/bweb.js
ebl fix joberrors display
[bacula/bacula] / gui / bweb / html / bweb.js
1 // Copyright (C) 2006 Eric Bollengier
2 //     All rights reserved.
3 //
4 // This program is free software; you can redistribute it and/or modify
5 // it under the terms of the GNU General Public License as published by
6 // the Free Software Foundation; either version 2 of the License, or
7 // any later version.
8 //
9 // This program is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12 // GNU General Public License for more details.
13 //
14 // You should have received a copy of the GNU General Public License
15 // along with this program; if not, write to the Free Software
16 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
17
18  var even_cell_color = "#FFFFFF";
19  var odd_cell_color  = "#EEEEEE";
20  var header_color    = "#E1E0DA";
21  var rows_per_page   = 20;
22  var bweb_root       = "/bweb/";
23  var up_icon         = "/bweb/up.gif";
24  var down_icon       = "/bweb/down.gif";
25  var prev_icon       = "/bweb/left.gif";
26  var next_icon       = "/bweb/right.gif";
27  var rew_icon        = "/bweb/first.gif";
28  var fwd_icon        = "/bweb/last.gif";
29
30  var jobstatus = {
31  'C': 'created but not yet running',
32  'R': 'running',
33  'B': 'blocked',
34  'T': 'terminated normally',
35  'E': 'Job terminated in error',
36  'e': 'Non-fatal error',
37  'f': 'Fatal error',
38  'D': 'Verify differences',
39  'A': 'canceled by user',
40  'F': 'waiting on File daemon',
41  'S': 'waiting on the Storage daemon',
42  'm': 'waiting for new media',
43  'M': 'waiting for Mount',
44  's': 'Waiting for storage resource',
45  'j': 'Waiting for job resource',
46  'c': 'Waiting for Client resource',
47  'd': 'Waiting for maximum jobs',
48  't': 'Waiting for start time',
49  'p': 'Waiting for higher priority jobs to finish'
50 };
51
52 var joblevel = {
53  'F': 'Full backup',
54  'I': 'Incr (since last backup)',
55  'D': 'Diff (since last full backup)',
56  'C': 'verify from catalog',
57  'V': 'verify save (init DB)',
58  'O': 'verify Volume to catalog entries',
59  'd': 'verify Disk attributes to catalog',
60  'A': 'verify data on volume',
61  'B': 'Base level job'
62 };
63
64
65 var refresh_time = 60000;
66
67 function bweb_refresh() {
68   location.reload(true)
69 }
70 function bweb_add_refresh(){
71         window.setInterval("bweb_refresh()",refresh_time);
72 }
73
74 function human_size(val)
75 {   
76    if (!val) {
77       return '';
78    }
79    var unit = ['b', 'Kb', 'Mb', 'Gb', 'Tb'];
80    var i=0;
81    var format;
82    while (val /1024 > 1) {
83       i++;
84       val /= 1024;
85    }
86
87    var format = (i>0)?1:0;
88    return val.toFixed(format) + ' ' + unit[i];
89 }
90
91 function human_sec(val)
92 {
93    if (!val) {
94       val = 0;
95    }
96    val /= 60;                   // sec -> min
97    
98    if ((val / 60) <= 1) {
99       return val.toFixed(0) + ' mins';
100    }
101
102    val /= 60;                   // min -> hour
103
104    if ((val / 24) <= 1) { 
105       return val.toFixed(0) + ' hours';
106    }
107
108    val /= 24;                   // hour -> day
109
110    if ((val / 365) < 2) { 
111       return val.toFixed(0) + ' days';
112    }
113
114    val /= 365;
115
116    return val.toFixed(0) + ' years';
117 }
118
119
120 //
121 // percent_display("row2", [ { nb: 1, name: "Full"   },
122 //                         { nb: 2, name: "Error"  },
123 //                         { nb: 5, name: "Append" },
124 //                         { nb: 2, name: "Purged" },
125 //                         {}                               # last element must be {}
126 //                       ]);
127
128 function percent_get_img(type)
129 {
130    var img=document.createElement('img');
131    if (type) {
132       img.className="pSlice" + type ;
133    } else {
134       img.className="pSlice";
135    }
136    img.src="/bweb/pix.png";
137    img.alt="";
138    return img;
139 }
140
141 var percent_display_nb_slice = 20;
142 var percent_usage_nb_slice = 5;
143
144 function percent_display(hash_values, parent)
145 {
146    var nb_elt=percent_display_nb_slice;
147    var tips= "";
148
149    if (!parent) {
150       parent = document.createElement('DIV');
151    }
152
153    if (typeof parent != "object") {
154       parent = document.getElementById(parent);
155    } 
156
157    if (!parent) {
158        alert("E : display_percent(): Can't find parent " + parent);
159        return;
160    }
161
162    hash_values.pop(); // drop last element {}
163
164    var nb_displayed = 0;
165    var nb_max = 0;
166
167    for(var i=0;i<hash_values.length;i++) {
168         nb_max += hash_values[i]['nb'];
169    }
170
171    for(var i=0;i<hash_values.length;i++) {
172         var elt = hash_values[i];
173         var cur_nb = (elt['nb'] * nb_elt)/nb_max;
174         var cur_name = elt['name'];
175         cur_name.replace(/-/,"_");
176
177         tips = tips + " " + elt['nb'] + " " + cur_name;
178
179         while ((nb_displayed < nb_elt) && (cur_nb >=1)) {
180             nb_displayed++;
181             cur_nb--;
182
183             var img= percent_get_img(cur_name);
184             parent.appendChild(img);
185         }       
186    }
187
188    while (nb_displayed < nb_elt) {
189       nb_displayed++;
190       var img= percent_get_img();
191       parent.appendChild(img);
192   }     
193
194   parent.title = tips;
195
196   return parent;
197 }
198
199 function percent_usage(value, parent)
200 {
201    var nb_elt=percent_usage_nb_slice;
202    var type;
203   
204    if (!parent) {
205       parent = document.createElement('DIV');
206    }   
207
208    if (typeof parent != "object") {
209       parent = document.getElementById(parent);
210    } 
211
212    if (!parent) {
213        alert("E : display_percent(): Can't find parent " + parent);
214        return;
215    }
216
217    if (value <= 0.001) {
218       type = "Empty";
219       value = 0;      
220    } else if (value <= 40) {
221       type = "Ok";
222    } else if (value <= 75) {
223       type = "Warn";
224    } else if (value <= 85) {
225       type = "Crit";
226    } else {
227       type = "Crit";
228    }
229
230    var nb = parseInt(value*nb_elt/100, 10);
231    parent.title = parseInt(value*100,10)/100 + "% used (approximate)";
232
233    for(var i=0; i<nb; i++) {
234       var img= percent_get_img(type);
235       parent.appendChild(img);
236    }
237
238    for(nb;nb < nb_elt;nb++) {
239       var img= percent_get_img("Empty");
240       parent.appendChild(img);       
241    } 
242
243    return parent;
244 }
245
246 function bweb_get_job_img(status, errors)
247 {
248   var ret;
249
250   if (status == "T") {
251      if (errors > 0) {
252         ret = "W.png";
253
254      } else {
255         ret = "T.png";
256      }
257
258   } else {
259      ret = status + ".png";
260   }
261
262   return bweb_root + ret;
263 }
264
265 function search_media()
266 {
267  var what = document.getElementById('searchbox').value;
268  if (what) {
269    document.search.action.value='media';
270    document.search.re_media.value=what;
271    document.search.submit();
272  }
273 }
274
275 function search_client()
276 {
277  var what = document.getElementById('searchbox').value;
278  if (what) {
279    document.search.action.value='client';
280    document.search.re_client.value=what;
281    document.search.submit();
282  }
283 }
284
285 sfHover = function() {
286  var sfEls = document.getElementById("menu").getElementsByTagName("LI");
287  for (var i=0; i<sfEls.length; i++) {
288     sfEls[i].onmouseover=function() {
289        this.className+=" sfhover";
290     }
291     sfEls[i].onmouseout=function() {
292        this.className=this.className.replace(new RegExp(" sfhover\\b"), "");
293     }
294  }
295 }
296
297 if (window.attachEvent) window.attachEvent("onload", sfHover);