-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathIndex.html
More file actions
310 lines (261 loc) · 13.3 KB
/
Index.html
File metadata and controls
310 lines (261 loc) · 13.3 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
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
<!DOCTYPE html>
<html>
<head>
<base target="_top">
<script src="https://cdn.jsdelivr.net/npm/qrcodejs@1.0.0/qrcode.min.js"></script>
<style>
body { font-family: Arial, sans-serif; background-color: #f0f2f5; margin: 0; }
.header { background-color: #1C2790; padding: 20px; text-align: center; color: white; }
.header img { width: 800px; margin-bottom: 10px; }
.container { max-width: 700px; margin: 20px auto; background: #fff; padding: 30px; border-radius: 8px; box-shadow: 0 4px 8px rgba(0,0,0,0.1); border-top: 5px solid #CDAE2C; }
.form-group { margin-bottom: 20px; position: relative; }
.form-section-title { font-size: 1.2em; font-weight: bold; color: #1C2790; border-bottom: 2px solid #eee; padding-bottom: 10px; margin-bottom: 20px; margin-top: 30px; }
label { display: block; margin-bottom: 8px; font-weight: bold; color: #333; }
input[type="text"], input[type="email"], select { width: 100%; padding: 12px; border: 1px solid #ccc; border-radius: 4px; box-sizing: border-box; }
button { padding: 12px; border: none; border-radius: 4px; cursor: pointer; font-size: 16px; font-weight: bold; }
/* Buttons */
#submitButton { width: 100%; margin-top: 20px; background-color: #1C2790; color: white; }
#submitButton:disabled { background-color: #cccccc; cursor: not-allowed; }
#add-doc-btn { width: 100%; background-color: #28a745; color: white; margin-top: 10px; }
/* Document Entry */
.document-entry { background-color: #f9f9f9; border: 1px solid #e0e0e0; border-radius: 6px; padding: 20px; margin-bottom: 15px; position: relative; }
.remove-btn { position: absolute; top: 10px; right: 10px; background-color: #dc3545; color: white; width: 30px; height: 30px; padding: 0; font-size: 14px; line-height: 30px; text-align: center; }
/* AUTOCOMPLETE LIST */
.autocomplete-items {
position: absolute;
border: 1px solid #d4d4d4;
border-bottom: none;
border-top: none;
z-index: 99;
top: 100%;
left: 0;
right: 0;
max-height: 200px;
overflow-y: auto;
background-color: #fff;
}
.autocomplete-items div {
padding: 10px;
cursor: pointer;
background-color: #fff;
border-bottom: 1px solid #d4d4d4;
}
.autocomplete-items div:hover {
background-color: #e9e9e9;
}
.autocomplete-active {
background-color: #1C2790 !important;
color: #ffffff;
}
/* --- ALIGNED PRINT SLIP STYLES (MATCHING OLD SYSTEM) --- */
.slip-content {
box-sizing: border-box; padding: 4mm; color: #000;
text-align: left; border: 1px solid #000; font-size: 9pt; width: 105mm; /* A6 Width */
}
.slip-header { border-bottom: 1px solid #ccc; padding-bottom: 2mm; margin-bottom: 2mm; text-align: center; }
.header-text { font-size: 9pt; font-weight: bold; margin: 0; }
/* Flexbox for Side-by-Side */
.slip-body { display: flex; align-items: flex-start; gap: 2mm; }
.slip-left-panel { flex-grow: 1; }
.slip-right-panel { flex-shrink: 0; text-align: center; }
/* Table Styles */
.meta-table { width: 100%; font-size: 8pt; margin-bottom: 3mm; border-collapse: collapse; }
.meta-table td { padding: 1px 0; vertical-align: top; }
.ref-number-cell { font-size: 12pt; font-weight: bold; } /* Big Font for ID */
.docs-table { width: 100%; font-size: 7pt; border-collapse: collapse; margin-top: 2mm; border-top: 1px solid #000; }
.docs-table th { text-align: left; font-weight: bold; border-bottom: 1px solid #ccc; padding: 2px; }
.docs-table td { border-bottom: 1px solid #eee; padding: 2px; vertical-align: top; }
@media print {
.header, #formContainer { display: none !important; }
#successContainer { display: flex !important; justify-content: center; padding-top: 5mm; border: none; box-shadow: none; margin: 0; max-width: 100%; }
.slip-content { width: 100%; border: none; }
}
</style>
</head>
<body>
<div class="header">
<img src="https://i.imgur.com/jaEbfAR.png" alt="DAP Logo">
<h2>Finance Department - Office of the Department Manager</h2>
</div>
<div class="container" id="formContainer">
<form id="submissionForm">
<div class="form-group autocomplete">
<label>Liaison / Admin Coordinator Name</label>
<input type="text" id="contactPerson" placeholder="Type name to search..." autocomplete="off">
<div class="autocomplete-items"></div>
</div>
<div class="form-group"><label>Center/Department</label><input type="text" id="centerDept" required></div>
<div class="form-group"><label>Office/Unit</label><input type="text" id="officeUnit"></div>
<div class="form-group"><label>Liaison Email Address</label><input type="email" id="email" required></div>
<div class="form-section-title">Documents in this Transaction</div>
<div id="documents-container"></div>
<button type="button" id="add-doc-btn">+ Add Another Document</button>
<button type="submit" id="submitButton">Submit Transaction</button>
</form>
</div>
<div class="container" id="successContainer" style="display: none;">
<div class="slip-content">
<div class="slip-header"><p class="header-text">Finance Department - Office of the Department Manager</p></div>
<div class="slip-body">
<div class="slip-left-panel">
<table class="meta-table">
<tr><td style="width: 50px;">Ref #:</td><td class="ref-number-cell" id="slipTxId"></td></tr>
<tr><td>Liaison:</td><td id="slipContact"></td></tr>
<tr><td>Date:</td><td id="slipTimestamp"></td></tr>
</table>
<table class="docs-table">
<thead>
<tr>
<th style="width:30%">Owner</th>
<th style="width:25%">Type</th>
<th style="width:45%">Title</th>
</tr>
</thead>
<tbody id="slip-documents-list"></tbody>
</table>
</div>
<div class="slip-right-panel">
<div id="qrcode"></div>
</div>
</div>
</div>
</div>
<script>
const docTypes = <?!= JSON.stringify(docTypes) ?>;
const directory = <?!= JSON.stringify(directory) ?>;
function createDocEntryHTML() {
let options = `<option value="" disabled selected>Select a type...</option>`;
docTypes.forEach(t => options += `<option value="${t}">${t}</option>`);
return `
<button type="button" class="remove-btn" onclick="removeEntry(this)">X</button>
<div class="form-group autocomplete">
<label>Document Owner / Principal</label>
<input type="text" class="principal-search" placeholder="Type name to search directory..." autocomplete="off">
<input type="hidden" class="principal-email">
<div class="autocomplete-items"></div>
</div>
<div class="form-group">
<label>Document Type</label>
<select class="doc-type-select" required>${options}</select>
</div>
<div class="form-group">
<label>Document Title</label>
<input type="text" class="doc-title-input" required>
</div>
`;
}
function addDocumentEntry() {
const container = document.getElementById('documents-container');
const entryDiv = document.createElement('div');
entryDiv.className = 'document-entry';
entryDiv.innerHTML = createDocEntryHTML();
container.appendChild(entryDiv);
const input = entryDiv.querySelector('.principal-search');
attachAutocomplete(input, false);
}
function removeEntry(btn) {
const container = document.getElementById('documents-container');
if (container.children.length > 1) { btn.parentElement.remove(); }
else { alert("You must include at least one document."); }
}
function attachAutocomplete(inp, isLiaison) {
const listContainer = inp.parentNode.querySelector('.autocomplete-items');
const targetEmailField = isLiaison
? document.getElementById('email')
: inp.parentNode.querySelector('.principal-email');
inp.addEventListener("input", function(e) {
const val = this.value;
listContainer.innerHTML = '';
if (!val) return false;
const matches = directory.filter(d => d.name.toLowerCase().includes(val.toLowerCase()));
matches.slice(0, 8).forEach(match => {
const item = document.createElement("div");
const regex = new RegExp(`(${val})`, "gi");
const highlightedName = match.name.replace(regex, "<strong>$1</strong>");
item.innerHTML = `${highlightedName} <span style='font-size:11px;color:#888;'>(${match.email})</span>`;
item.innerHTML += `<input type='hidden' value='${match.name}' data-email='${match.email}'>`;
item.addEventListener("click", function(e) {
inp.value = this.getElementsByTagName("input")[0].value;
const selectedEmail = this.getElementsByTagName("input")[0].getAttribute('data-email');
if (targetEmailField) { targetEmailField.value = selectedEmail; }
listContainer.innerHTML = '';
});
listContainer.appendChild(item);
});
});
document.addEventListener("click", function (e) {
if (e.target !== inp) { listContainer.innerHTML = ''; }
});
}
document.addEventListener('DOMContentLoaded', function() {
attachAutocomplete(document.getElementById('contactPerson'), true);
addDocumentEntry();
document.getElementById('add-doc-btn').addEventListener('click', addDocumentEntry);
document.getElementById('submissionForm').addEventListener('submit', function(event) {
event.preventDefault();
const submitButton = document.getElementById('submitButton');
const submissionObject = {
transactionDetails: {
contactPerson: document.getElementById('contactPerson').value,
centerDept: document.getElementById('centerDept').value,
officeUnit: document.getElementById('officeUnit').value,
email: document.getElementById('email').value
},
documents: []
};
const documentEntries = document.querySelectorAll('.document-entry');
documentEntries.forEach(entry => {
let pName = entry.querySelector('.principal-search').value;
let pEmail = entry.querySelector('.principal-email').value;
submissionObject.documents.push({
docType: entry.querySelector('.doc-type-select').value,
docTitle: entry.querySelector('.doc-title-input').value,
principalName: pName,
principalEmail: pEmail
});
});
submitButton.disabled = true;
submitButton.textContent = 'Submitting...';
google.script.run.withSuccessHandler(onSuccess).withFailureHandler(onFailure).processForm(submissionObject);
});
function onSuccess(returnData) {
const txId = returnData.transactionId;
const fullLink = `${returnData.appUrl}?action=update&id=${txId}`;
const details = returnData.details;
document.getElementById('slipTxId').textContent = txId;
document.getElementById('slipContact').textContent = details.ContactPerson;
document.getElementById('slipTimestamp').textContent = details.Timestamp;
const tableBody = document.getElementById('slip-documents-list');
tableBody.innerHTML = '';
details.documents.forEach(doc => {
tableBody.innerHTML += `
<tr>
<td style="font-weight:bold;">${doc.owner}</td>
<td>${doc.type}</td>
<td>${doc.title}</td>
</tr>`;
});
const qrcodeContainer = document.getElementById('qrcode');
qrcodeContainer.innerHTML = "";
// --- QR CODE FIX ---
// 1. width/height increased to 150 for better resolution
// 2. correctLevel set to L (Low) to make dots bigger and scannable
new QRCode(qrcodeContainer, {
text: fullLink,
width: 150,
height: 150,
correctLevel: QRCode.CorrectLevel.L
});
document.getElementById('formContainer').style.display = 'none';
document.getElementById('successContainer').style.display = 'flex';
setTimeout(() => { window.print(); }, 500);
}
function onFailure(error) {
alert('Error: ' + error.message);
document.getElementById('submitButton').disabled = false;
document.getElementById('submitButton').textContent = 'Submit Transaction';
}
});
</script>
</body>
</html>