]> git.sur5r.net Git - bacula/bacula/blob - gui/bweb/html/bweb.js
ebl fix postgresql date
[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 up_icon         = "/bweb/up.gif";
23  var down_icon       = "/bweb/down.gif";
24  var prev_icon       = "/bweb/left.gif";
25  var next_icon       = "/bweb/right.gif";
26  var rew_icon        = "/bweb/first.gif";
27  var fwd_icon        = "/bweb/last.gif";
28
29  var jobstatus = {
30  'C': 'created but not yet running',
31  'R': 'running',
32  'B': 'blocked',
33  'T': 'terminated normally',
34  'E': 'Job terminated in error',
35  'e': 'Non-fatal error',
36  'f': 'Fatal error',
37  'D': 'Verify differences',
38  'A': 'canceled by user',
39  'F': 'waiting on File daemon',
40  'S': 'waiting on the Storage daemon',
41  'm': 'waiting for new media',
42  'M': 'waiting for Mount',
43  's': 'Waiting for storage resource',
44  'j': 'Waiting for job resource',
45  'c': 'Waiting for Client resource',
46  'd': 'Waiting for maximum jobs',
47  't': 'Waiting for start time',
48  'p': 'Waiting for higher priority jobs to finish'
49 };
50
51 var joblevel = {
52  'F': 'Full backup',
53  'I': 'Incr (since last backup)',
54  'D': 'Diff (since last full backup)',
55  'C': 'verify from catalog',
56  'V': 'verify save (init DB)',
57  'O': 'verify Volume to catalog entries',
58  'd': 'verify Disk attributes to catalog',
59  'A': 'verify data on volume',
60  'B': 'Base level job'
61 };
62
63
64 var refresh_time = 60000;
65
66 function bweb_refresh() {
67   location.reload(true)
68 }
69 function bweb_add_refresh(){
70         window.setInterval("bweb_refresh()",refresh_time);
71 }
72
73 function human_size(val)
74 {   
75    if (!val) {
76       return '';
77    }
78    var unit = ['b', 'Kb', 'Mb', 'Gb', 'Tb'];
79    var i=0;
80    var format;
81    while (val /1024 > 1) {
82       i++;
83       val /= 1024;
84    }
85
86    var format = (i>0)?1:0;
87    return val.toFixed(format) + ' ' + unit[i];
88 }
89
90 function human_sec(val)
91 {
92    if (!val) {
93       val = 0;
94    }
95    val /= 60;                   // sec -> min
96    
97    if ((val / 60) <= 1) {
98       return val.toFixed(0) + ' mins';
99    }
100
101    val /= 60;                   // min -> hour
102
103    if ((val / 24) <= 1) { 
104       return val.toFixed(0) + ' hours';
105    }
106
107    val /= 24;                   // hour -> day
108
109    if ((val / 365) < 2) { 
110       return val.toFixed(0) + ' days';
111    }
112
113    val /= 365;
114
115    return val.toFixed(0) + ' years';
116 }
117
118
119 //
120 // percent_display("row2", [ { nb: 1, name: "Full"   },
121 //                         { nb: 2, name: "Error"  },
122 //                         { nb: 5, name: "Append" },
123 //                         { nb: 2, name: "Purged" },
124 //                         {}                               # last element must be {}
125 //                       ]);
126
127 function percent_get_img(type)
128 {
129    var img=document.createElement('img');
130    if (type) {
131       img.className="pSlice" + type ;
132    } else {
133       img.className="pSlice";
134    }
135    img.src="/bweb/pix.png";
136    img.alt="";
137    return img;
138 }
139
140 var percent_display_nb_slice = 20;
141 var percent_usage_nb_slice = 5;
142
143 function percent_display(hash_values, parent)
144 {
145    var nb_elt=percent_display_nb_slice;
146    var tips= "";
147
148    if (!parent) {
149       parent = document.createElement('DIV');
150    }
151
152    if (typeof parent != "object") {
153       parent = document.getElementById(parent);
154    } 
155
156    if (!parent) {
157        alert("E : display_percent(): Can't find parent " + parent);
158        return;
159    }
160
161    hash_values.pop(); // drop last element {}
162
163    var nb_displayed = 0;
164    var nb_max = 0;
165
166    for(var i=0;i<hash_values.length;i++) {
167         nb_max += hash_values[i]['nb'];
168    }
169
170    for(var i=0;i<hash_values.length;i++) {
171         var elt = hash_values[i];
172         var cur_nb = (elt['nb'] * nb_elt)/nb_max;
173         var cur_name = elt['name'];
174         cur_name.replace(/-/,"_");
175
176         tips = tips + " " + elt['nb'] + " " + cur_name;
177
178         while ((nb_displayed < nb_elt) && (cur_nb >=1)) {
179             nb_displayed++;
180             cur_nb--;
181
182             var img= percent_get_img(cur_name);
183             parent.appendChild(img);
184         }       
185    }
186
187    while (nb_displayed < nb_elt) {
188       nb_displayed++;
189       var img= percent_get_img();
190       parent.appendChild(img);
191   }     
192
193   parent.title = tips;
194
195   return parent;
196 }
197
198 function percent_usage(value, parent)
199 {
200    var nb_elt=percent_usage_nb_slice;
201    var type;
202   
203    if (!parent) {
204       parent = document.createElement('DIV');
205    }   
206
207    if (typeof parent != "object") {
208       parent = document.getElementById(parent);
209    } 
210
211    if (!parent) {
212        alert("E : display_percent(): Can't find parent " + parent);
213        return;
214    }
215
216    if (value <= 0.001) {
217       type = "Empty";
218       value = 0;      
219    } else if (value <= 40) {
220       type = "Ok";
221    } else if (value <= 75) {
222       type = "Warn";
223    } else if (value <= 85) {
224       type = "Crit";
225    } else {
226       type = "Crit";
227    }
228
229    var nb = parseInt(value*nb_elt/100, 10);
230    parent.title = parseInt(value*100,10)/100 + "% used (approximate)";
231
232    for(var i=0; i<nb; i++) {
233       var img= percent_get_img(type);
234       parent.appendChild(img);
235    }
236
237    for(nb;nb < nb_elt;nb++) {
238       var img= percent_get_img("Empty");
239       parent.appendChild(img);       
240    } 
241
242    return parent;
243 }
244
245 function search_media()
246 {
247  var what = document.getElementById('searchbox').value;
248  if (what) {
249    document.search.action.value='media';
250    document.search.re_media.value=what;
251    document.search.submit();
252  }
253 }
254
255 function search_client()
256 {
257  var what = document.getElementById('searchbox').value;
258  if (what) {
259    document.search.action.value='client';
260    document.search.re_client.value=what;
261    document.search.submit();
262  }
263 }
264
265 sfHover = function() {
266  var sfEls = document.getElementById("menu").getElementsByTagName("LI");
267  for (var i=0; i<sfEls.length; i++) {
268     sfEls[i].onmouseover=function() {
269        this.className+=" sfhover";
270     }
271     sfEls[i].onmouseout=function() {
272        this.className=this.className.replace(new RegExp(" sfhover\\b"), "");
273     }
274  }
275 }
276
277 if (window.attachEvent) window.attachEvent("onload", sfHover);