]> git.sur5r.net Git - bacula/bacula/blob - gui/bweb/html/bweb.js
Merge branch 'bwebII'
[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 Kern Sibbald.
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 var joblevelname = {
77  'F': 'Full',
78  'I': 'Incremental',
79  'D': 'Differential',
80 };
81
82
83 var refresh_time = 60000;
84
85 function bweb_refresh() {
86   location.reload(true)
87 }
88 function bweb_add_refresh(){
89         window.setInterval("bweb_refresh()",refresh_time);
90 }
91 function human_size(val)
92 {   
93    if (!val) {
94       return '';
95    }
96    val = parseInt(val);
97    var unit = ['B', 'KB', 'MB', 'GB', 'TB'];
98    var i=0;
99    var format;
100    while (val /1024 > 1) {
101       i++;
102       val /= 1024;
103    }
104
105    var format = (i>0)?1:0;
106    return val.toFixed(format) + ' ' + unit[i];
107 }
108
109 function human_enabled(val)
110 {   
111    if (!val) {
112       return 'no';
113    }
114
115    if (val == 'yes' || val == '1') {
116       return 'yes';
117
118    } else if (val == 'archived' || val == '2') {
119       return 'archived';
120    } else {
121       return 'no';
122    }
123 }
124
125 function human_sec(val)
126 {
127    if (!val) {
128       val = 0;
129    }
130    val = parseInt(val);
131    val /= 60;                   // sec -> min
132    
133    if ((val / 60) <= 1) {
134       return val.toFixed(0) + ' mins';
135    }
136
137    val /= 60;                   // min -> hour
138
139    if ((val / 24) <= 1) { 
140       return val.toFixed(0) + ' hours';
141    }
142
143    val /= 24;                   // hour -> day
144
145    if ((val / 365) < 2) { 
146       return val.toFixed(0) + ' days';
147    }
148
149    val /= 365;
150
151    return val.toFixed(0) + ' years';
152 }
153
154
155 //
156 // percent_display("row2", [ { nb: 1, name: "Full"   },
157 //                         { nb: 2, name: "Error"  },
158 //                         { nb: 5, name: "Append" },
159 //                         { nb: 2, name: "Purged" },
160 //                         {}                               # last element must be {}
161 //                       ]);
162
163 function percent_get_img(type)
164 {
165    var img=document.createElement('img');
166    if (type) {
167       img.className="pSlice" + type ;
168    } else {
169       img.className="pSlice";
170    }
171    img.src="/bweb/pix.png";
172    img.alt="";
173    return img;
174 }
175
176 var percent_display_nb_slice = 20;
177 var percent_usage_nb_slice = 5;
178
179 function percent_display(hash_values, parent)
180 {
181    var nb_elt=percent_display_nb_slice;
182    var tips= "";
183
184    if (!parent) {
185       parent = document.createElement('DIV');
186    }
187
188    if (typeof parent != "object") {
189       parent = document.getElementById(parent);
190    } 
191
192    if (!parent) {
193        alert("E : display_percent(): Can't find parent " + parent);
194        return;
195    }
196
197    hash_values.pop(); // drop last element {}
198
199    var nb_displayed = 0;
200    var nb_max = 0;
201
202    for(var i=0;i<hash_values.length;i++) {
203         nb_max += hash_values[i]['nb'];
204    }
205
206    for(var i=0;i<hash_values.length;i++) {
207         var elt = hash_values[i];
208         var cur_nb = (elt['nb'] * nb_elt)/nb_max;
209         var cur_name = elt['name'];
210         cur_name.replace(/-/,"_");
211
212         tips = tips + " " + elt['nb'] + " " + cur_name;
213
214         while ((nb_displayed < nb_elt) && (cur_nb >=1)) {
215             nb_displayed++;
216             cur_nb--;
217
218             var img= percent_get_img(cur_name);
219             parent.appendChild(img);
220         }       
221    }
222
223    while (nb_displayed < nb_elt) {
224       nb_displayed++;
225       var img= percent_get_img();
226       parent.appendChild(img);
227   }     
228
229   parent.title = tips;
230
231   return parent;
232 }
233
234 function percent_finish(value, corr, parent)
235 {
236    var type;
237
238    var nb = parseInt(value*300/100, 10);
239    var nbp = parseInt(value*100,10)/100;
240    if (nbp > 500) {
241       return;
242    }
243    parent.title = nbp + "% finished (approximate " + (corr).toFixed(2) + ")" ;
244    var img=document.createElement('img');
245    img.className="pSliceFinished";
246    img.src="/bweb/pix.png";
247    img.width=nb;
248    parent.appendChild(img);
249
250    if (value >= 100) {
251       return;
252    }
253
254    nb = parseInt((100-value)*300/100, 10);
255    img=document.createElement('img');
256    img.className="pSliceNotFinished";
257    img.src="/bweb/pix.png";
258    img.width=nb;
259    parent.appendChild(img);       
260 }
261
262 function percent_usage(value, parent)
263 {
264    var nb_elt=percent_usage_nb_slice;
265    var type;
266   
267    if (!parent) {
268       parent = document.createElement('DIV');
269    }   
270
271    if (typeof parent != "object") {
272       parent = document.getElementById(parent);
273    } 
274
275    if (!parent) {
276        alert("E : display_percent(): Can't find parent " + parent);
277        return;
278    }
279
280    if (value >= 500) {
281       return;
282    } else if (value <= 0.001) {
283       type = "Empty";
284       value = 0;      
285    } else if (value <= 40) {
286       type = "Ok";
287    } else if (value <= 75) {
288       type = "Warn";
289    } else if (value <= 85) {
290       type = "Crit";
291    } else {
292       type = "Crit";
293    }
294
295    var nb = parseInt(value*nb_elt/100, 10);
296    parent.title = parseInt(value*100,10)/100 + "% used (approximate)";
297
298    for(var i=0; i<nb; i++) {
299       var img= percent_get_img(type);
300       parent.appendChild(img);
301    }
302
303    for(nb;nb < nb_elt;nb++) {
304       var img= percent_get_img("Empty");
305       parent.appendChild(img);       
306    } 
307
308    return parent;
309 }
310
311 function bweb_get_job_img(status, errors, type)
312 {
313   var ret;
314
315   if (status == "T") {
316      if (errors > 0) {
317         ret = "W.png";
318
319      } else {
320         if (type == 'B' || type == 'R') { // Backup or Restore
321            ret = "T.png";
322
323         } else if (type == 'C') {
324            ret = "CT.png";
325
326         } else {
327            ret = "AT.png";      // Admin, migration, copy etc...
328         }
329      }
330   } else {
331      ret = status + ".png";
332   }
333
334   return bweb_root + ret;
335 }
336
337 function toggle_display(id, arrow) 
338 {
339    var a = document.getElementById(arrow);
340    var e = document.getElementById(id);
341    if(e.style.display == 'block') {
342       e.style.display = 'none';
343       a.src = '/bweb/right.gif';
344    } else {
345       e.style.display = 'block';
346       a.src = '/bweb/down.gif';
347    }
348 }
349
350 function search_media()
351 {
352  var what = document.getElementById('searchbox').value;
353  if (what) {
354    document.search.action.value='media';
355    document.search.re_media.value=what;
356    document.search.submit();
357  }
358 }
359
360 function search_client()
361 {
362  var what = document.getElementById('searchbox').value;
363  if (what) {
364    document.search.action.value='client';
365    document.search.re_client.value=what;
366    document.search.submit();
367  }
368 }
369
370 sfHover = function() {
371  var sfEls = document.getElementById("menu").getElementsByTagName("LI");
372  for (var i=0; i<sfEls.length; i++) {
373     sfEls[i].onmouseover=function() {
374        this.className+=" sfhover";
375     }
376     sfEls[i].onmouseout=function() {
377        this.className=this.className.replace(new RegExp(" sfhover\\b"), "");
378     }
379  }
380 }
381
382 if (window.attachEvent) window.attachEvent("onload", sfHover);