aboutsummaryrefslogtreecommitdiff
path: root/new-connection.js
blob: 2493c25385b58965815df562b4a2fd4ce4063004 (plain)
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
"use strict";

const { remote, ipcRenderer } = require("electron");
const $ = window.jQuery = require("jquery");

function cancel() {
  let confirm = remote.dialog.showMessageBox(remote.getCurrentWindow(), {
    type: "question",
    buttons: ["Yes", "No"],
    title: "Confirm",
    message: "Remove this connection?"
  });

  if (confirm === 0) {
    remote.getCurrentWindow().close();
  }
}

function parseForm() {
  let formData = {};

  $("form").serializeArray().forEach((input) => {
    formData[input.name] = input.value;
  });
    
  return formData;
}

function createConnection() {
  let connectionProps = parseForm();
  ipcRenderer.send("newConnection.createConnection", connectionProps);
}

$(document).ready(() => {
  $("#create-connection").click(() => {
    createConnection();
  });
  
  $("#test-connection").click(() => {
    //TODO
  });

  $("#cancel").click(() => {
    cancel();
  });
});