Passed
Push — master ( 6c55c5...1b6984 )
by Eduardo
03:42 queued 01:33
created

ipcRenderer.sw:results   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 3
nc 1
nop 1
dl 0
loc 4
rs 10
c 0
b 0
f 0
1
var whois = require('../common/whoiswrapper.js'),
2
  parseRawData = require('../common/parse-raw-data.js');
3
4
window.$ = window.jQuery = require('jquery');
5
6
const {
7
  ipcRenderer
8
} = require('electron');
9
10
var singleWhois = {
11
  'input': {
12
    'domain': null
13
  },
14
  'results': null
15
}
16
17
// Single Whois, whois reply processing
18
ipcRenderer.on('sw:results', function(event, domainResults) {
19
  const {
20
    isDomainAvailable
21
  } = whois;
22
  var domainStatus, domainResultsJSON;
23
  //ipcRenderer.send('app:debug', "Whois domain reply:\n {0}".format(domainResults));
24
25
  domainResultsJSON = (function() {
26
    var result;
27
    if (typeof domainResults === 'object') {
28
      JSON.stringify(domainResults, null, 2);
29
      result = domainResults.map(function(data) {
30
        data.data = parseRawData(data.data);
31
        return data;
32
      });
33
    } else {
34
      result = parseRawData(domainResults);
35
    }
36
    return result;
37
  })();
38
39
  // Check domain status
40
  domainStatus = isDomainAvailable(domainResults);
41
42
  switch (domainStatus) {
43
    case 'querylimituniregistry':
44
    case 'error':
45
      $('#swMessageWhoisResults').text("Whois error: {0}\n{1}".format(domainStatus, domainResults));
46
      $('#swMessageError').removeClass('is-hidden');
47
      break;
48
    case 'unavailable':
49
    //console.log(domainResultsJSON);
50
      $('#swMessageUnavailable').removeClass('is-hidden');
51
      $('#swMessageWhoisResults').text(domainResults);
52
53
      $('#swTableDomain').attr('href', "http://" + domainResultsJSON['domainName'] || domainResultsJSON['domain']);
54
      $('#swTableDomain').text(domainResultsJSON['domainName'] || domainResultsJSON['domain']);
55
56
      $('#swTableUpdate').text(domainResultsJSON['updatedDate']);
57
      $('#swTableRegistrar').text(domainResultsJSON['registrar']);
58
      $('#swTableCreation').text(domainResultsJSON['creationDate'] || domainResultsJSON['createdDate'] || domainResultsJSON['created']);
59
      $('#swTableCompany').text(domainResultsJSON['registrantOrganization'] || domainResultsJSON['registrant']);
60
      $('#swTableExpiry').text(domainResultsJSON['registrarRegistrationExpirationDate'] || domainResultsJSON['expires'] || domainResultsJSON['Registry Expiry Date']);
61
      $('#swTableWhoisInfo.is-hidden').removeClass('is-hidden');
62
      break;
63
    case 'available':
64
      $('#swMessageWhoisResults').text(domainResults);
65
      $('#swMessageAvailable').removeClass('is-hidden');
66
      break;
67
    default:
68
      $('#swMessageWhoisResults').text("Whois default error\n{0}".format(domainResults));
69
      $('#swMessageError').removeClass('is-hidden');
70
      break;
71
  }
72
73
  $('#swButtonSearch').removeClass('is-loading');
74
  $('#swInputDomain').removeAttr('readonly');
75
76
});
77
78
// Simple Whois, trigger search by using [ENTER] key
79
$('#swInputDomain').keyup(function(event) {
80
  // Cancel the default action, if needed
81
  event.preventDefault();
82
  // Number 13 is the "Enter" key on the keyboard
83
  if (event.keyCode === 13) {
84
    // Trigger the button element with a click
85
    $('#swButtonSearch').click();
86
  }
87
});
88
89
// Trigger Whois lookup
90
$('#swButtonSearch').click(function() {
91
  if ($(this).hasClass('is-loading')) {
92
    return true;
93
  }
94
  ipcRenderer.send('app:debug', "#swButtonSearch was clicked");
95
96
  singleWhois.input.domain = $('#swInputDomain').val();
97
98
  ipcRenderer.send('app:debug', "Looking up for {0}".format(singleWhois.input.domain));
99
100
  $('#swButtonSearch').addClass('is-loading');
101
  $('#swInputDomain').attr('readonly', '');
102
  $('.notification:not(.is-hidden)').addClass('is-hidden');
103
  $('#swTable:not(.is-hidden)').addClass('is-hidden');
104
  tableReset();
105
  ipcRenderer.send("sw:lookup", singleWhois.input.domain);
106
  return undefined;
107
});
108
109
// Open simple whois model
110
$('.swMessageWhoisOpen').click(function() {
111
  ipcRenderer.send('app:debug', "Opening whois reply");
112
  $('#swMessageWhois').addClass('is-active');
113
});
114
115
// Close simple whois modal
116
$('#swMessageWhoisClose').click(function() {
117
  ipcRenderer.send('app:debug', "Closing whois reply");
118
  $('#swMessageWhois').removeClass('is-active');
119
});
120
121
// Reset registry table contents
122
function tableReset() {
123
  ipcRenderer.send('app:debug', "Resetting whois result table");
124
  $('#swTableDomain').attr('href', "#");
125
  $('#swTableDomain').text('n/a');
126
127
  $('#swTableUpdate').text('n/a');
128
  $('#swTableRegistrar').text('n/a');
129
  $('#swTableCreation').text('n/a');
130
  $('#swTableCompany').text('n/a');
131
  $('#swTableExpiry').text('n/a');
132
}
133