]> git.sur5r.net Git - bacula/bacula/blob - gui/bweb/html/bweb.js
ebl fix delete jobid
[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 //
74 // percent_display("row2", [ { nb: 1, name: "Full"   },
75 //                         { nb: 2, name: "Error"  },
76 //                         { nb: 5, name: "Append" },
77 //                         { nb: 2, name: "Purged" },
78 //                         {}                               # last element must be {}
79 //                       ]);
80
81 function percent_get_img(type)
82 {
83    var img=document.createElement('img');
84    if (type) {
85       img.className="pSlice" + type ;
86    } else {
87       img.className="pSlice";
88    }
89    img.src="/bweb/pix.png";
90    img.alt="";
91    return img;
92 }
93
94 var percent_display_nb_slice = 20;
95 var percent_usage_nb_slice = 5;
96
97 function percent_display(hash_values, parent)
98 {
99    var nb_elt=percent_display_nb_slice;
100    var tips= "";
101
102    if (!parent) {
103       parent = document.createElement('DIV');
104    }
105
106    if (typeof parent != "object") {
107       parent = document.getElementById(parent);
108    } 
109
110    if (!parent) {
111        alert("E : display_percent(): Can't find parent " + parent);
112        return;
113    }
114
115    hash_values.pop(); // drop last element {}
116
117    var nb_displayed = 0;
118    var nb_max = 0;
119
120    for(var i=0;i<hash_values.length;i++) {
121         nb_max += hash_values[i]['nb'];
122    }
123
124    for(var i=0;i<hash_values.length;i++) {
125         var elt = hash_values[i];
126         var cur_nb = (elt['nb'] * nb_elt)/nb_max;
127         var cur_name = elt['name'];
128         cur_name.replace(/-/,"_");
129
130         tips = tips + " " + elt['nb'] + " " + cur_name;
131
132         while ((nb_displayed < nb_elt) && (cur_nb >=1)) {
133             nb_displayed++;
134             cur_nb--;
135
136             var img= percent_get_img(cur_name);
137             parent.appendChild(img);
138         }       
139    }
140
141    while (nb_displayed < nb_elt) {
142       nb_displayed++;
143       var img= percent_get_img();
144       parent.appendChild(img);
145   }     
146
147   parent.title = tips;
148
149   return parent;
150 }
151
152 function percent_usage(value, parent)
153 {
154    var nb_elt=percent_usage_nb_slice;
155    var type;
156   
157    if (!parent) {
158       parent = document.createElement('DIV');
159    }   
160
161    if (typeof parent != "object") {
162       parent = document.getElementById(parent);
163    } 
164
165    if (!parent) {
166        alert("E : display_percent(): Can't find parent " + parent);
167        return;
168    }
169
170    if (value <= 0) {
171       type = "Empty";
172       value = 0;      
173    } else if (value <= 40) {
174       type = "Ok";
175    } else if (value <= 75) {
176       type = "Warn";
177    } else if (value <= 85) {
178       type = "Crit";
179    } else {
180       type = "Crit";
181    }
182
183    var nb = parseInt(value*nb_elt/100, 10);
184    parent.title = parseInt(value*100,10)/100 + "% used (approximate)";
185
186    for(var i=0; i<nb; i++) {
187       var img= percent_get_img(type);
188       parent.appendChild(img);
189    }
190
191    for(nb;nb < nb_elt;nb++) {
192       var img= percent_get_img("Empty");
193       parent.appendChild(img);       
194    } 
195
196    return parent;
197 }
198
199 function search_media()
200 {
201  var what = document.getElementById('searchbox').value;
202  if (what) {
203    document.search.action.value='media';
204    document.search.re_media.value=what;
205    document.search.submit();
206  }
207 }
208
209 function search_client()
210 {
211  var what = document.getElementById('searchbox').value;
212  if (what) {
213    document.search.action.value='client';
214    document.search.re_client.value=what;
215    document.search.submit();
216  }
217 }
218
219 sfHover = function() {
220  var sfEls = document.getElementById("menu").getElementsByTagName("LI");
221  for (var i=0; i<sfEls.length; i++) {
222     sfEls[i].onmouseover=function() {
223        this.className+=" sfhover";
224     }
225     sfEls[i].onmouseout=function() {
226        this.className=this.className.replace(new RegExp(" sfhover\\b"), "");
227     }
228  }
229 }
230
231 if (window.attachEvent) window.attachEvent("onload", sfHover);