This repository was archived by the owner on Jul 24, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMain.js
More file actions
128 lines (104 loc) · 3.57 KB
/
Main.js
File metadata and controls
128 lines (104 loc) · 3.57 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
// Import for local javascript development --> Comment on Google Apps Script
// import "google-apps-script";
// Widgets: https://developers.google.com/apps-script/reference/card-service/text-input
function onHomepage(event) {
console.log(event);
return CardService.newCardBuilder()
.addSection(buildStep1())
.addSection(buildStep2())
.addSection(buildStep3())
.build();
}
function getCurrentChipnumber() {
const email = Session.getActiveUser().getEmail();
const userdata = AdminDirectory.Users.get(email, {
"projection": "full",
});
if (!userdata.hasOwnProperty("customSchemas")) {
return "";
}
const customSchemas = userdata["customSchemas"];
if (!customSchemas.hasOwnProperty("fuks")) {
return "";
}
const fuks = customSchemas["fuks"];
if (fuks.hasOwnProperty("KIT_Card_Chipnummer")) {
return fuks["KIT_Card_Chipnummer"];
}
return "";
}
function buildStep1() {
var text = CardService.newTextParagraph()
.setText("The fuks office door can be opened by your KIT-Card. "
+ "You must be a member of the \"aktive@fuks.org\" workspace group to gain access. "
+ "Follow the next steps to add your KIT-Card chip number to the system.");
return CardService.newCardSection()
.setHeader("Step 1: Read this")
.addWidget(text);
}
function buildStep2() {
var goto = CardService.newDecoratedText()
.setText("Go to https://my.scc.kit.edu > Anmelden > Konto/KIT-Account > KIT-Card")
.setWrapText(true)
.setOpenLink(CardService.newOpenLink()
.setUrl("https://my.scc.kit.edu/shib/accountinformationen.php")
.setOpenAs(CardService.OpenAs.OVERLAY)
.setOnClose(CardService.OnClose.NOTHING));
return CardService.newCardSection()
.setHeader("Step 2: Find your chipnumber")
.addWidget(goto);
}
function buildStep3() {
var input = CardService.newTextInput()
.setFieldName("KIT_Card_Chipnummer")
.setTitle("KIT-Card Chipnummer")
.setValue(getCurrentChipnumber())
.setMultiline(false);
var save = CardService.newTextButton()
.setText('Save')
.setOnClickAction(CardService.newAction()
.setFunctionName('onSave'))
.setTextButtonStyle(CardService.TextButtonStyle.FILLED);
return CardService.newCardSection()
.setHeader("Step 3: Save your chipnumber")
.addWidget(input)
.addWidget(save);
}
function onSave(event) {
const input = event.formInput["KIT_Card_Chipnummer"];
const chipnumber = parseInt(input);
const ok = chipnumber > 0;
if (ok) {
const email = Session.getActiveUser().getEmail();
const userdata = AdminDirectory.Users.get(email, {
"projection": "full",
});
if (!userdata.hasOwnProperty("customSchemas")) {
userdata.customSchemas = {};
}
userdata.customSchemas["fuks"] = {
"KIT_Card_Chipnummer": input
};
AdminDirectory.Users.update(userdata, email);
console.log({
"email": email,
"input": event.formInput,
"customSchemas": userdata.customSchemas,
"parsed": chipnumber,
});
}
var status = CardService.newDecoratedText()
.setTopLabel(ok
? "Success"
: "Error")
.setText(ok
? "Saved '" + input + "' as chipnumber"
: "The input '" + input + "' not a valid chipnumber")
.setEndIcon(CardService.newIconImage().setIconUrl(ok
? "https://www.gstatic.com/images/icons/material/system/1x/check_black_48dp.png"
: "https://www.gstatic.com/images/icons/material/system/1x/error_black_48dp.png"))
.setWrapText(true);
return CardService.newCardBuilder()
.addSection(CardService.newCardSection().addWidget(status))
.build();
}