-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSidebar.html
More file actions
139 lines (131 loc) · 4.52 KB
/
Sidebar.html
File metadata and controls
139 lines (131 loc) · 4.52 KB
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
<!DOCTYPE html>
<html>
<head>
<base target="_top">
<link rel="stylesheet" href="https://ssl.gstatic.com/docs/script/css/add-ons1.css">
<style>
@keyframes spinner {
to {transform: rotate(360deg);}
}
.spinner:before {
content: '';
box-sizing: border-box;
position: absolute;
top: 50%;
left: 50%;
width: 50px;
height: 50px;
margin-top: -10px;
margin-left: -10px;
border-radius: 50%;
border-top: 4px solid #07d;
border-right: 4px solid transparent;
animation: spinner .9s linear infinite;
z-index: 20;
}
.overlay {
background: #b4b4b4;
display: none;
position: absolute;
top: 0;
right: 0;
bottom: 0;
left: 0;
opacity: 0.5;
}
</style>
</head>
<body>
<h1>Paste here:</h1>
<textarea style="width: 100%;" id="toImport" rows="25"></textarea>
<button class="blue" id="importDataBtn">Import</button>
<button class="" id="ClearBtn">Clear</button>
<div id="nextSteps"></div>
<div id="mySpinner" class=""></div>
<div class="overlay"></div>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<script>
$(function() {
$('#importDataBtn').click(runImportData);
$('#ClearBtn').click(function () {
$('#toImport').val('');
$('#toImport').attr({rows: '25'});
$('#nextSteps').html('');
});
});
function displayErrors(retData) {
if (retData === undefined) {
retData = 'item1,10:item2,220'.split(':'); //{'item1', 10},{'item2', 220};
retData.forEach(function(item, index, array) {
array[index] = array[index].split(',');
});
}
if (retData.length == 0) {
$('#nextSteps').append('<h3>Successfully imported!</h3>');
return;
}
var nonImportTotal = 0;
var i = 0;
$('#nextSteps').append('<h3>No match for these:</h3>');
retData.forEach(function(item, index, array) {
nonImportTotal = Number(nonImportTotal) + Number(item[1]);
let thisRowNumber = i;
let btnID = 'btn-' + i;
let lblID = 'lbl-' + i;
let $newLbl = $('<label />')
.attr({id: lblID, for: btnID, class: 'error'})
.text('New expense "' + item[0] + '" for $' + Number(item[1]).toFixed(2) + '?');
let $newBtn = $('<button />')
.attr({id: btnID, style: 'margin: 5px;margin-bottom: 2px'})
.text('Add')
.click(function () {addRow(thisRowNumber)});
let $newDiv = $('<div />')
.attr({id: 'row-' + i})
.data('category', item[0])
.data('amount', item[1]);
$newDiv.append($newBtn, $newLbl);
$('#nextSteps').append($newDiv);
i++;
});
$('#nextSteps').append('<h4>Not imported total: $' + nonImportTotal.toFixed(2) + '</h4>');
}
function runImportData() {
var MyData;
$('.overlay').show();
$('#mySpinner').addClass('spinner');
$('#nextSteps').html('');
MyData = $('#toImport').val();
if (MyData.indexOf('\t') > 0) {
MyData = MyData.split(',').join('');
MyData = MyData.split('\t').join(',');
}
MyData = MyData.split('\n');
MyData.forEach(function(item, index, array) {
array[index] = array[index].split(',');
});
google.script.run.withSuccessHandler(onImportReturn)
.importData(MyData);
}
function onImportReturn(MyData) {
displayErrors(MyData);
$('#toImport').attr({rows: '5'});
$('.overlay').hide();
$('#mySpinner').removeClass('spinner');
}
function addRow(param) {
var category = $('#row-' + param).data('category');
var amount = $('#row-' + param).data('amount')
$('#nextSteps').append(param + ': clicked ' + category + ' : ' + amount + '</p>');
$('.overlay').show();
$('#mySpinner').addClass('spinner');
google.script.run.withSuccessHandler(onAddRowReturn)
.InsertNewExpense(category, amount, param);
}
function onAddRowReturn (param) {
$('#row-' + param).remove();
$('.overlay').hide();
$('#mySpinner').removeClass('spinner');
}
</script>
</body>
</html>