1
  
2
  
3
  
4
  
5
  
6
  
7
  
8
  
9
  
10
  
11
  
12
  
13
  
14
  
15
  
16
  
17
  
18
  
19
  
20
  
21
  
22
  
23
  
24
  
25
  
26
  
27
  
28
  
29
  
30
  
31
  
32
  
33
  
34
  
35
  
36
  
37
  
38
  
39
  
40
  
41
  
42
  
43
  
44
  
45
  
46
  
47
  
48
  
49
  
50
  
51
  
52
  
// jshint esversion: 5 
/* 
  This is a consolidation of the the two scripts dbs/ajax_optimizeall.js 
  and dbs/ajax_repairall.js 
 
  This script is referenced in dbs/db_optimizeall.html and dbs/db_repairall.html 
*/ 
 
(function(window, document, R) { 
  'use strict'; 
 
  var resTarget   = document.querySelector('#result'), 
    resTargetText = resTarget.querySelector('.text'), 
    href          = resTarget.dataset.dbHref, 
    action        = resTarget.dataset.dbAction, 
    wizid         = resTarget.dataset.wizid, 
    typeStr       = resTarget.dataset.progressMsg, 
    args          = []; 
 
  if (!href) { 
    resTarget.innerHTML = 
      '<div class="notify error">No <code>data-db-href</code> attribute' + 
      ' found on the result target. Something is really wrong!</div>'; 
 
    return; 
  } 
 
  if (action) { 
    args.push('action=' + action); 
  } 
 
  if (wizid) { 
    args.push(wizid); 
  } 
 
  if (args.length) { 
    href += '?' + args.join('&'); 
  } 
 
  resTargetText.innerHTML = typeStr || 'Doing things...'; 
 
  R.wget(href, 
    function(res) { 
      resTarget.innerHTML = res; 
    }, 
    function(err) { 
      resTarget.innerHTML = 
        '<div class="notify error">' + err + '</div>'; 
    }); 
 
}(window, document, rxnlib));