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