Passed
Push — master ( b5b832...6c55c5 )
by Eduardo
02:11
created

auxiliary.js ➔ setExportOptions   B

Complexity

Conditions 5
Paths 5

Size

Total Lines 32
Code Lines 27

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 5
eloc 27
c 0
b 0
f 0
nc 5
dl 0
loc 32
rs 8.7653
nop 1
1
var {
2
  resetObject
3
} = require('../../common/resetobj.js');
4
5
// Reset table
6
function tableReset(dLength = 0, tLength = 0) {
7
  $('#bwTableProcessingProcessed').text(0);
8
  $('#bwTableProcessingWaiting').text(0);
9
  $('#bwTableProcessingTotal').text(dLength * tLength);
10
11
  $('#bwTableProcessingDomAvail').text(0);
12
  $('#bwTableProcessingDomUnavail').text(0);
13
  $('#bwTableProcessingDomError').text(0);
14
}
15
16
// Get export options from the form
17
function getExportOptions() {
18
  var options = {};
0 ignored issues
show
Unused Code introduced by
The assignment to variable options seems to be never used. Consider removing it.
Loading history...
19
  options = {
20
    'filetype': $('#bweSelectFiletype').val(),
21
    'domains': $('#bweSelectDomains').val(),
22
    'errors': $('#bweSelectErrors').val(),
23
    'information': $('#bweSelectInformation').val(),
24
    'whoisreply': $('#bweSelectWhoisreply').val()
25
  }
26
  return options;
27
}
28
29
function setExportOptions(preset) {
30
  switch (preset) {
31
    case ('none'):
32
      unlockFields();
33
      break;
34
    case ('availableonly'):
35
      unlockFields();
36
      //$('#bweSelectFiletype').val('csv');
37
      $('#bweSelectDomains').val('available');
38
      $('#bweSelectErrors').val('no');
39
      $('#bweSelectInformation').val('domain');
40
      $('#bweSelectWhoisreply').val('no');
41
      break;
42
    case ('allbutnoreply'):
43
      unlockFields();
44
      //$('#bweSelectFiletype').val('csv');
45
      $('#bweSelectDomains').val('both');
46
      $('#bweSelectErrors').val('yes');
47
      $('#bweSelectInformation').val('domain+basic');
48
      $('#bweSelectWhoisreply').val('no');
49
      break;
50
    case ('import'):
51
      lockFields();
52
      $('#bweSelectFiletype').val('csv');
53
      $('#bweSelectDomains').val('both');
54
      $('#bweSelectErrors').val('yes');
55
      $('#bweSelectInformation').val('domain+basic+debug');
56
      $('#bweSelectWhoisreply').val('yes+block');
57
      break;
58
  }
59
60
}
61
62
function setExportOptionsEx(filetype) {
63
  switch (filetype) {
64
    case 'txt':
65
      lockFields(true);
66
      break;
67
    case 'csv':
68
      unlockFields(true);
69
      break;
70
  }
71
}
72
73
function lockFields(isTxt = false) {
74
  if (isTxt === false) {
75
    $('#bweSelectFiletype').prop("disabled", true);
76
    $('#bweSelectDomains').prop("disabled", true);
77
    $('#bweSelectErrors').prop("disabled", true);
78
  }
79
  if ($('#bweSelectWhoisreply').prop("disabled") === false) {
80
    $('#bweSelectInformation').prop("disabled", true);
81
    $('#bweSelectWhoisreply').prop("disabled", true);
82
  }
83
}
84
85
function unlockFields(isTxt = false) {
86
  if (isTxt === true) {
87
    $('#bweSelectFiletype').prop("disabled", false);
88
  }
89
  if ($('#bweSelectWhoisreply').prop("disabled") === true && $('#bweSelectFiletype').val() == 'csv') {
90
    $('#bweSelectFiletype').prop("disabled", false);
91
    $('#bweSelectDomains').prop("disabled", false);
92
    $('#bweSelectErrors').prop("disabled", false);
93
    $('#bweSelectInformation').prop("disabled", false);
94
    $('#bweSelectWhoisreply').prop("disabled", false);
95
  }
96
}
97
98
module.exports = {
99
  tableReset: tableReset,
100
  tblReset: tableReset,
101
  getExportOptions: getExportOptions,
102
  getExprtOptns: getExportOptions,
103
  setExportOptions: setExportOptions,
104
  setExprtOptns: setExportOptions,
105
  setExportOptionsEx: setExportOptionsEx
106
}
107