-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.html
391 lines (342 loc) · 11.8 KB
/
app.html
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
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
<!DOCTYPE html>
<html>
<head>
<title>Passbook</title>
<style>
body {
font-family: Arial, sans-serif;
margin: 0;
padding: 0;
background-color: #f7f7f7; /* Light gray background color */
}
#container {
width: 80%;
max-width: 600px;
margin: 50px auto;
padding: 20px;
background-color: #ffffff; /* White container background */
box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
border-radius: 8px;
}
h1 {
margin-top: 0;
text-align: center;
color: #333333;
}
p {
color: #777777;
}
ol {
color: #555555;
margin-left: 20px;
}
input[type="text"] {
width: 100%;
padding: 10px;
margin-bottom: 10px;
border: 1px solid #dddddd;
border-radius: 4px;
box-shadow: none;
}
button {
background-color: #4e90b3; /* New button color */
color: white;
padding: 12px 20px;
border: none;
cursor: pointer;
margin-right: 10px;
border-radius: 4px;
box-shadow: none;
transition: background-color 0.2s;
}
button:hover {
background-color: #367a9f; /* Darker shade on hover */
}
#result {
margin-top: 20px;
color: #555555;
}
/* Toast Styles */
#toast {
position: fixed;
bottom: 20px;
left: 50%;
transform: translateX(-50%);
background-color: #333;
color: #fff;
padding: 10px 20px;
border-radius: 4px;
opacity: 0; /* Initially hidden */
transition: opacity 0.3s;
z-index: 9999;
}
/* Toast animation when shown */
#toast.show {
opacity: 1;
}
/* New CSS for the container holding the input and "Save" button */
#inputAndSaveContainer {
display: flex; /* Use Flexbox to make the input and button align horizontally */
align-items: center; /* Vertically align the elements within the container */
}
/* Adjust the margin between the input and the "Save" button */
#inputAndSaveContainer input[type="text"] {
margin-right: 10px; /* You can adjust the value to control the spacing */
}
/* Toggle Switch Styles */
.toggle-switch-container {
display: flex;
align-items: center; /* Vertically center the toggle switch and label */
margin-bottom: 10px; /* Add some spacing between the toggle switch and label */
}
.toggle-switch {
position: relative;
display: inline-block;
width: 40px; /* Adjust the width to your preference */
height: 24px; /* Adjust the height to your preference */
}
.toggle-switch input {
display: none;
}
.slider {
position: absolute;
cursor: pointer;
top: 0;
left: 0;
right: 0;
bottom: 0;
background-color: #ccc;
border-radius: 34px;
transition: 0.4s;
}
.slider:before {
position: absolute;
content: "";
height: 20px; /* Adjust the height to your preference */
width: 20px; /* Adjust the width to your preference */
left: 2px;
bottom: 2px;
background-color: white;
border-radius: 50%;
transition: 0.4s;
}
input:checked + .slider {
background-color: #4e90b3; /* New button color when tracking is ON */
}
input:checked + .slider:before {
transform: translateX(16px); /* Adjust the position to match the width of the slider */
}
/* CSS to style the tooltip */
.open-passbook-button {
display: inline-block;
color: #4e90b3;
cursor: pointer;
position: relative;
}
</style>
</head>
<body>
<div id="container">
<h1>Passbook</h1>
<p>Welcome to Passbook, your personal Expense Tracker app. Follow the steps below to get started:</p>
<ol>
<li>Make a copy of this Google Sheet if you haven't done it before. This will be your passbook: <a href="https://docs.google.com/spreadsheets/d/1126GAmGR77qNIc1PCH3GkyR-TMkb0uxpIA44F0x5aWk/copy" target="_blank">Copy the Sheet</a></li>
<li>
<div id="inputAndSaveContainer">
<input type="text" id="expenseSheet" placeholder="Enter your expense sheet URL">
<button onclick="saveSheet()">Save</button>
</div>
</li>
<li>
<div id="trackingToggle" class="toggle-switch">
<input type="checkbox" id="toggle" onchange="toggleTracking()">
<span class="slider"></span>
</div>
<label for="toggle">Start Tracking</label>
</li>
<li>
Add your cards below in the below cards/upi section.
</li>
<li>
<div class="open-passbook-button" onclick="displaySheetUrl()">
Open your Passbook
</div>
</li>
</ol>
<div id="result"></div>
<h2>Cards/UPI</h2>
<table id="bankTable">
<tr>
<th>Bank</th>
<th>Card Name</th>
</tr>
<tr>
<td>
<select class="bankDropdown">
<!-- Populate this dropdown with predefined banks -->
<!-- For example: -->
<option value="hdfc_cc">HDFC CC</option>
<option value="hdfc_upi">HDFC UPI</option>
<option value="axis_upi">AXIS UPI</option>
<option value="axis_cc">AXIS CC</option>
<option value="idfc_cc">IDFC CC</option>
<option value="icici_cc">ICICI CC</option>
<option value="icici_food">ICICI Food</option>
<option value="sodexo">Sodexo</option>
<option value="citi">Citi CC</option>
<!-- Add more options as needed -->
</select>
</td>
<td><input type="text" class="cardNameInput" placeholder="Enter card name"></td>
</tr>
</table>
<button onclick="addNewRow()">Add New Bank</button>
<button onclick="saveCards()">Save Bank Cards</button>
<br>
<br>
<br>
<br>
<div>
<input type="text" id="telegramToken" placeholder="Enter your Telegram Bot Token(optional)">
</div>
<div>
<input type="text" id="telegramChatId" placeholder="Enter your Telegram ChatId(optional)">
<button onclick="saveTelegramSettings()">Save</button>
</div>
</div>
<!-- Toast Element -->
<div id="toast"></div>
<script>
function addNewRow() {
var table = document.getElementById('bankTable');
var newRow = table.insertRow(table.rows.length);
var bankCell = newRow.insertCell(0);
var bankDropdown = document.createElement('select');
bankDropdown.className = 'bankDropdown';
// Populate this dropdown with predefined banks or dynamically fetch the banks from user data
bankDropdown.innerHTML = `
<option value="hdfc_cc">HDFC CC</option>
<option value="hdfc_upi">HDFC UPI</option>
<option value="axis_upi">AXIS UPI</option>
<option value="axis_cc">AXIS CC</option>
<option value="idfc_cc">IDFC CC</option>
<option value="icici_cc">ICICI CC</option>
<option value="icici_food">ICICI Food</option>
<option value="sodexo">Sodexo</option>
<option value="citi">Citi CC</option>
`;
bankCell.appendChild(bankDropdown);
var cardNameCell = newRow.insertCell(1);
var cardNameInput = document.createElement('input');
cardNameInput.type = 'text';
cardNameInput.className = 'cardNameInput';
cardNameInput.placeholder = 'Enter card name';
cardNameCell.appendChild(cardNameInput);
}
function saveCards() {
var bankCards = [];
var tableRows = document.querySelectorAll("#bankTable tr");
for (var i = 1; i < tableRows.length; i++) {
var cardId = tableRows[i].querySelector(".bankDropdown").value;
var cardName = tableRows[i].querySelector(".cardNameInput").value;
if (cardName.trim() !== '') {
bankCards.push({cardName: cardName, cardId: cardId });
}
}
// Save the bankCards array as JSON in user properties
var jsonString = JSON.stringify(bankCards);
google.script.run.saveCards(jsonString);
// Optional: Display a toast message to indicate successful save
showToast("Bank Cards saved successfully!");
}
function loadCards() {
google.script.run.withSuccessHandler(function (savedBankCardsJson) {
var savedBankCards = JSON.parse(savedBankCardsJson);
var table = document.getElementById('bankTable');
savedBankCards.forEach(function (bankCard) {
var newRow = table.insertRow(-1); // Add new row at the end of the table
var bankCell = newRow.insertCell(0);
var bankDropdown = document.createElement('select');
bankDropdown.className = 'bankDropdown';
// Populate this dropdown with predefined banks or dynamically fetch the banks from user data
bankDropdown.innerHTML = `
<option value="hdfc_cc">HDFC CC</option>
<option value="hdfc_upi">HDFC UPI</option>
<option value="axis_upi">AXIS UPI</option>
<option value="axis_cc">AXIS CC</option>
<option value="idfc_cc">IDFC CC</option>
<option value="icici_cc">ICICI CC</option>
<option value="icici_food">ICICI Food</option>
<option value="sodexo">Sodexo</option>
<option value="citi">Citi CC</option>
`;
bankDropdown.value = bankCard.cardId; // Set the selected bank based on saved data
bankCell.appendChild(bankDropdown);
var cardNameCell = newRow.insertCell(1);
var cardNameInput = document.createElement('input');
cardNameInput.type = 'text';
cardNameInput.className = 'cardNameInput';
cardNameInput.placeholder = 'Enter card name';
cardNameInput.value = bankCard.cardName; // Set the custom card name based on saved data
cardNameCell.appendChild(cardNameInput);
});
}).getCards();
}
function showToast(message) {
var toastElement = document.getElementById("toast");
toastElement.textContent = message;
toastElement.classList.add("show");
setTimeout(function() {
toastElement.classList.remove("show");
}, 5000);
}
function saveSheet() {
var userInput = document.getElementById("expenseSheet").value;
google.script.run.saveExpenseSheet(userInput);
}
function saveTelegramSettings() {
var telegramToken = document.getElementById("telegramToken").value;
var telegramChatId = document.getElementById("telegramChatId").value;
google.script.run.withSuccessHandler(displayCallback).saveTelegramSettings(telegramToken, telegramChatId);
}
function startTracking() {
google.script.run.withSuccessHandler(displayCallback).startTracking();
}
function stopTracking() {
google.script.run.withSuccessHandler(displayCallback).stopTracking();
}
function displaySheetUrl() {
google.script.run.withSuccessHandler(openExpenseSheet).getExpenseSheet();
}
function displayCallback(data) {
showToast("Message: " + data);
}
function toggleTracking() {
var trackingToggle = document.getElementById("toggle");
if (trackingToggle.checked) {
startTracking();
} else {
stopTracking();
}
}
function getTrackingStatus() {
google.script.run.withSuccessHandler(updateTrackingStatus).getTrackingStatus();
}
function updateTrackingStatus(status) {
var trackingToggle = document.getElementById("toggle");
trackingToggle.checked = status === "STARTED";
}
function openExpenseSheet(expenseSheetUrl) {
if (expenseSheetUrl) {
window.open(expenseSheetUrl, "_blank");
} else {
showToast("Expense Sheet URL is not available.");
}
}
window.onload = function() {
getTrackingStatus();
loadCards();
};
</script>
</body>
</html>