-
Notifications
You must be signed in to change notification settings - Fork 1
/
PollDetails.gs
50 lines (42 loc) · 1.25 KB
/
PollDetails.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
50
function PollDetails() {
this.init = function() {
this.poll_data = {
poll_formation_status: POLL_FORMATION_STATUS.READY,
poller: "",
options: {
single_choice: true,
anonymous: true,
expiration_time_in_seconds: 0.0
},
question: "",
choices: []
};
}
this.clear = function() {
this.poll_data = null;
}
this.get = function() {
return this.poll_data;
}
this.load = function() {
// Deserialize any pending poll details from user properties
let user_properties = PropertiesService.getUserProperties();
let poll_data = user_properties.getProperty('POLL_DATA');
// log.info(`LOAD: ${poll_data}`);
if (poll_data == null)
this.init();
else
this.poll_data = JSON.parse(poll_data);
}
this.save = function() {
let user_properties = PropertiesService.getUserProperties();
// Serialize poll details (if any) back into user properties
if (this.poll_data == null)
user_properties.deleteProperty("POLL_DATA");
else {
let serialized_poll_data = JSON.stringify(this.poll_data);
// log.info(`SAVE: ${serialized_poll_data}`);
user_properties.setProperty("POLL_DATA", serialized_poll_data);
}
}
}