-
Notifications
You must be signed in to change notification settings - Fork 1
/
init.gs
49 lines (49 loc) · 1.39 KB
/
init.gs
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
//////////////////////////////////
// SCOPE VARIABLES AND ALERT FUNCTION
var documentProperties = PropertiesService.getDocumentProperties();
var APIkey;
var ui = SpreadsheetApp.getUi();
function alertFunction(msg) {ui.alert(msg)}
// RUN ON INSTALL
function onInstall() {
documentProperties.setProperty("APIkey", "")
onOpen();
}
// RUN ON OPEN
function onOpen() {
var item = ui.createMenu("Wise").addItem("Import borderless statement", 'runApp');
item.addToUi();
}
// RUN APP
function runApp() {
function runHtml() {
html = HtmlService.createTemplateFromFile("sidebar")
.evaluate()
.setTitle("Wise Borderless Statement Import");
ui.showSidebar(html);
}
var documentKey = documentProperties.getProperty("APIkey");
if (documentKey == null || documentKey == "") {
var result = ui.prompt(
'Let\'s connect',
'Please enter your Wise.com API key with Read permissions',
ui.ButtonSet.OK_CANCEL);
APIkey = result.getResponseText();
documentProperties.setProperty('APIkey', APIkey);
var idRequestSuccess = requestIdData();
if (idRequestSuccess == true) {
runHtml()
} else {
documentProperties.setProperty("APIkey", "")
var result = ui.alert(
'Authentication failed.',
'Try again?',
ui.ButtonSet.YES_NO);
if (result == ui.Button.YES) {
runApp();
}
}
} else {
runHtml()
}
}