-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSignup.js
More file actions
80 lines (64 loc) · 2.15 KB
/
Signup.js
File metadata and controls
80 lines (64 loc) · 2.15 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
function createSignupForm(model){
const title = model.title + " sign-up"
const file = DriveApp.getFileById(templateSignupForm)
.makeCopy(title, DriveApp.getFolderById(targetFolder))
const form = FormApp.openById(file.getId())
form.setTitle(title)
model.formUrl = form.getPublishedUrl()
model.formId = form.getId()
console.log("Form created: " + form.getPublishedUrl())
return form
}
function createResponsesSheet(model, form)
{
const title = model.title + " responses"
const file = DriveApp.getFileById(templateResponsesSheet)
.makeCopy(title, DriveApp.getFolderById(targetFolder))
form.setDestination(FormApp.DestinationType.SPREADSHEET, file.getId())
model.responsesUrl = file.getUrl()
file.setSharing(DriveApp.Access.ANYONE_WITH_LINK, DriveApp.Permission.VIEW)
return file
}
function updateResponsesSheet(model)
{
const ss = SpreadsheetApp.openByUrl(model.responsesUrl)
const static = ss.getSheetByName("Static")
let i = 1
for(let k in model) {
static.getRange(i, 1).setValue(k)
static.getRange(i++, 2).setValue(model[k])
}
static.hideSheet()
const responseSheet = ss.getSheets().filter(s => !!s.getFormUrl())[0]
console.log("Found response sheet:", responseSheet.getName())
responseSheet.hideSheet()
const projection = ss.getSheetByName("All responses")
projection.getRange(1,1).setFormula(`{'${responseSheet.getName()}'!1:1000}`)
return ss
}
function moveToTargetFolder(doc)
{
const file = DriveApp.getFileById(doc.getId());
DriveApp.getFolderById(targetFolder).addFile(file);
DriveApp.getRootFolder().removeFile(file);
}
function removeSignupForm(id)
{
try {
const file = DriveApp.getFileById(id)
Drive.Files.remove(file.getId())
} catch(e) {
console.warn("Cannot remove signup form", id)
}
}
function removeResponsesSheet(url)
{
try {
console.info("Removing signup sheet", url)
const file = DriveApp.getFileById(SpreadsheetApp.openByUrl(url).getId())
console.info("Found file", file.getName(), file.isTrashed(), file.getId())
Drive.Files.remove(file.getId())
} catch(e) {
console.warn("Cannot remove responses sheet", url)
}
}