-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathapp-database.js
83 lines (67 loc) · 2.71 KB
/
app-database.js
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
$(document).on('click', '.back', function(event) {
event.preventDefault();
$(this).parents('.step').addClass('d-none');
var href= $(this).attr('href');
$(href).removeClass('d-none');
});
$(document).on('submit', 'form', function(event) {
event.preventDefault();
var form = $(this);
var body = $('#form-connect').serialize();
body = body + '&' + $('#form-mappings').serialize();
if ('form-mappings' == form.attr('id')) {
$('#step-mappings').addClass('d-none');
$('#step-loading').removeClass('d-none');
}
fetch(form.attr('action'), {
'credentials': 'include',
'headers': {
'Content-Type': 'application/x-www-form-urlencoded',
},
'method': 'post',
'body': body
}).then(function(response) {
return response.json();
}).then(function(json) {
if (true == json.exception) {
createToast(json.message);
if ('form-mappings' == form.attr('id')) {
$('#step-loading').addClass('d-none');
$('#step-mappings').removeClass('d-none');
}
} else {
if ('form-connect' == form.attr('id')) {
var columns = '<option value="">-</option>';
for (var key in json.columns) {
var column = json.columns[key];
columns += '<option value="' + column + '">' + column + '</option>';
}
$(document).find('.select-column').each(function() {
$(this).html(columns);
var field = $(this).data('field');
if (json.columns.includes(field)) {
$(this).val(field);
}
});
$('#step-connect').addClass('d-none');
$('#step-mappings').removeClass('d-none');
}
if ('form-mappings' == form.attr('id')) {
$('#step-completed h3 .badge').text(json.documents);
$('#step-mappings').addClass('d-none');
$('#step-loading').addClass('d-none');
$('#step-completed').removeClass('d-none');
$('#errors').addClass('d-none');
$('#step-completed tbody').html('');
if (0 < (json.errors).length) {
for (var key in json.errors) {
var error = json.errors[key];
$('#step-completed tbody').append(`<tr><td>${error['_id']}</td><td>${error['status']}</td><td>${error['message']}</td></tr>`);
}
$('#errors').removeClass('d-none');
}
}
}
}).catch(function() {
});
});