-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexcellogic.js
144 lines (140 loc) · 6.49 KB
/
excellogic.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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
const table = document.querySelector('#excel_table');
const Excel = require('exceljs');
const { ipcRenderer } = require('electron');
var workbook = new Excel.Workbook();
const form = document.querySelector("#excel_file");
form.addEventListener('change',submitForm);
function submitForm(e){
e.preventDefault();
var filesel = document.querySelector('#excel_file').files[0];
if(filesel){
excel_file_path = document.querySelector('#excel_file').files[0].path;
workbook.xlsx.readFile(excel_file_path)
.then(function() {
document.getElementById('excelerrmsg').innerHTML = "";
document.querySelector('#excel-div').classList.remove("d-none");
document.querySelector('#buttons').classList.remove("d-none");
document.getElementById('email_column_sel').disabled = false;
document.getElementById('placeholdercol').disabled = false;
table.innerHTML = '';
var ws = workbook.getWorksheet(1);
var cell = ws.getCell('A1').value;
console.log(cell);
rowCount = ws.actualRowCount;
ws.eachRow(function(row, rowNumber) {
// console.log('Row ' + rowNumber + ' = ' + JSON.stringify(row.values));
const tr = document.createElement('tr');
var RowArray = row.values//JSON.stringify(row.values);
if(rowNumber==1){
var tr_con = "<td style='font-weight:bold; position:sticky;top:0;background-color:#f2f5fa;'>Sr. no</td>";
var sel1 = document.getElementById('email_column_sel');
var sel2 = document.getElementById('placeholdercol');
sel1.innerHTML = '';
sel2.innerHTML = '';
RowArray.forEach((item,index)=>{
tr_con += "<td style='font-weight:bold; position:sticky;top:0;background-color:#f2f5fa;'>"+item+"</td>";
rowValHeader.push({'text':item, 'value':index});
sel1.appendChild(new Option(item,index));
sel2.appendChild(new Option(item,item));
})
tr_con += "<td style='font-weight:bold; position:sticky;top:0;z-index:2;right:0;background-color:#f2f5fa;'>Select</td>";
}else{
var tr_con = "<td>"+(rowNumber-1)+"</td>";
RowArray.forEach((item,index)=>{
tr_con += "<td>"+item+"</td>";
})
tr_con += `<td style='position:sticky; text-align:center;z-index:1;right:0;background-color:rgba(200,200,200,0.5);'>
<input class='form-check-input' type='checkbox' id='sel_em[${(rowNumber-1)}]' name='sel_em[]' checked />
</td>`;
}
// console.log(tr_con);
tr.innerHTML= tr_con;
// tr.addEventListener('click',checkone);
tr.addEventListener('click', myFunc, false);
tr.index_no = rowNumber-2;
tr.setAttribute("name", "rows[]");
table.appendChild(tr);
});
})
.catch((error)=>{
console.log("Unable to read file");
document.getElementById('excelerrmsg').innerHTML = "Unable to load the file!"
});
}
else{
//
}
}
document.getElementById('select-all').onclick = function() {
var checkboxes = document.getElementsByName('sel_em[]');
for (var checkbox of checkboxes) {
checkbox.checked = true;
}
}
document.getElementById('de-select-all').onclick = function() {
var checkboxes = document.getElementsByName('sel_em[]');
for (var checkbox of checkboxes) {
checkbox.checked = false;
}
}
// document.getElementById('subcheck').onclick = function() {
// var checkboxes = document.getElementsByName('sel_em[]');
// var res = [];
// for(let checkbox of checkboxes){
// res.push(checkbox.checked);
// }
// alert(res);
// }
document.getElementById('lockbutton').onclick = function() {
console.log(document.getElementsByName('sel_em[]')[1].checked);
var lock = document.getElementById('locklayer');
var selectall = document.getElementById('select-all');
var deselectall = document.getElementById('de-select-all');
var excel_div = document.getElementById('excel-div');
if(lock.classList.contains('d-none')){
excel_div.classList.add('unscrollable');
excel_div.classList.remove('scrollable');
lock.classList.remove('d-none');
selectall.classList.add('d-none');
deselectall.classList.add('d-none');
this.innerText = 'Unlock';
}else{
excel_div.classList.remove('unscrollable');
excel_div.classList.add('scrollable');
lock.classList.add('d-none');
selectall.classList.remove('d-none');
deselectall.classList.remove('d-none');
this.innerText = 'Lock';
}
}
var myFunc = function(evt) {
var checkbox = document.getElementsByName('sel_em[]')[evt.currentTarget.index_no];
checkbox.checked = checkbox.checked? false:true;
}
ipcRenderer.on('openexcel',function(){
document.querySelector("#excel_file").click();
})
ipcRenderer.on('email_status',function(e,item){
rowCount1++;
console.log(rowCount,rowCount1);
if(rowCount1 == rowCount-1){
loadingSpinner(false);
}
var row = document.getElementsByName('rows[]')[item.rowNumber-1];
if(item.status==1){
row.classList.add('greenbg');
row.classList.remove('redbg');
}
if(item.status==0){
console.log(item.status,item.rowNumber);
console.log(item);
row.classList.add('redbg');
row.classList.remove('greenbg');
}
})
// loadingSpinner(true);
//setTimeout(loadingSpinner,1000,false);
// document.addEventListener('DOMContentLoaded', function() {
// var elems = document.querySelectorAll('email_column_sel');
// var instances = M.FormSelect.init(elems,rowValHeader);
// });