generated from caltechlibrary/template
-
Notifications
You must be signed in to change notification settings - Fork 0
/
form-utilities.js.html
43 lines (40 loc) · 1.98 KB
/
form-utilities.js.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
<script>
// @file form-utilities.js.html (shown as form-utilities in GAS editor)
// @brief Common JS code used in Boffo HTML files
// @created 2023-08-01
// @license Please see the file named LICENSE in the project directory
// @website https://github.com/caltechlibrary/boffo
//
// The need to name this file form-utilities.js.html instead of
// form-utilities.js is because HTMLService in Google Apps Script doesn't
// recognize files that don't have a .html suffix.
// Log messages in browser console and in GAS execution log.
function log(msg) {
console.log(msg);
google.script.run.log(msg);
}
// Call host.close() after a delay. Needed for 2 reasons:
//
// 1) It seems that calls made after gs.host.close() are not executed,
// which is a critical problem for what we need to do. In particular,
// one of the things done here is to call a subsequent function after
// interacting with the user and closing the dialog. Since calling
// gs.host.close() seems to prevent anything else from happening, we
// can't just call gs.host.close() to close the dialog and then make
// our call; conversely, we can't make our call first and afterwards
// close the dialog, because then the dialog stays visible the whole
// time our code is working on (e.g.) looking up barcodes. Solution:
// we put the gs.host.close() on a timer, which lets us make our call
// while the timer runs in parallel and (after a delay) calls close().
//
// 2) It seems that even calls made right *before* gs.host.close() also
// don't get executed (or at least, if I call Logger.log right before
// it, the log statement doesn't show in Google's cloud log.) Once
// again, a delay between the call and gs.host.close() solves it.
//
// Problem #2 is why other code never calls gs.host.close()
// directly, even in cases where problem #1 is not at stake.
function delayedClose(duration = 300) {
setTimeout(() => { google.script.host.close(); }, duration);
}
</script>