initial import from onelab svn codebase
[plewww.git] / misc / update.js
1 // $Id: update.js 144 2007-03-28 07:52:20Z thierry $
2
3 if (isJsEnabled()) {
4   addLoadEvent(function() {
5     if ($('edit-has_js')) {
6       $('edit-has_js').value = 1;
7     }
8
9     if ($('progress')) {
10       // Success: redirect to the summary.
11       var updateCallback = function (progress, status, pb) {
12         if (progress == 100) {
13           pb.stopMonitoring();
14           window.location = window.location.href.split('op=')[0] +'op=finished';
15         }
16       }
17
18       // Failure: point out error message and provide link to the summary.
19       var errorCallback = function (pb) {
20         var div = document.createElement('p');
21         div.className = 'error';
22         div.innerHTML = 'An unrecoverable error has occured. You can find the error message below. It is advised to copy it to the clipboard for reference. Please continue to the <a href="update.php?op=error">update summary</a>';
23         $('progress').insertBefore(div, $('progress').firstChild);
24         $('wait').style.display = 'none';
25       }
26
27       var progress = new progressBar('updateprogress', updateCallback, HTTPPost, errorCallback);
28       progress.setProgress(-1, 'Starting updates');
29       $('progress').appendChild(progress.element);
30       progress.startMonitoring('update.php?op=do_update', 0);
31     }
32   });
33 }