-
Notifications
You must be signed in to change notification settings - Fork 0
/
MenuHandlers.gs
64 lines (56 loc) · 1.89 KB
/
MenuHandlers.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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
function prevMonthTreasurer() {
let d = new Date();
d.setMonth(d.getMonth() - 1);
main_(d.getMonth() + 1, d.getFullYear());
}
function curMonthTreasurer() {
let d = new Date();
main_(d.getMonth() + 1, d.getFullYear());
}
function customMonthTreasurer() {
let html = HtmlService.createHtmlOutputFromFile('CustomMonthDialog')
.setWidth(260)
.setHeight(65);
SpreadsheetApp.getUi()
.showModalDialog(html, 'Enter Month');
}
function customMonthDialogHandler(dateForm) {
let date = dateForm['dateInput'];
const month = parseInt(date.split('-')[1]);
const year = parseInt(date.split('-')[0]);
main_(month, year);
}
function autoUpdate() {
const ui = SpreadsheetApp.getUi();
try {
let isAutoUpdateInstalled = isAutoUpdateEnabled_();
let alertText = formAutoUpdateAlertText_(isAutoUpdateInstalled);
let result = ui.alert('Auto Update', alertText, ui.ButtonSet.YES_NO);
if (result == ui.Button.YES) {
if (isAutoUpdateInstalled) disableAutoUpdate_();
else enableAutoUpdate_();
}
console.log('Successfully handled auto update');
} catch(e) {
console.error('Failed in handling auto update due to ', e.stack);
ui.alert('Some error occured. Please try again later');
}
}
function formAutoUpdateAlertText_(isAutoUpdateInstalled) {
let alertText;
if (isAutoUpdateInstalled) {
alertText = 'Auto update is enabled. Do you want to disable auto update of sheet on 1st of every month ?';
} else {
alertText = 'Auto update is disabled. Do you want to enable auto update of sheet on 1st of every month ?';
}
return alertText;
}
function isAutoUpdateEnabled_() {
let isAutoUpdateInstalled = false;
let allTriggers = ScriptApp.getProjectTriggers();
for (let i = 0; i < allTriggers.length; i++) {
if (allTriggers[i].getHandlerFunction() === 'lastMonthTreasurer')
isAutoUpdateInstalled = true;
}
return isAutoUpdateInstalled;
}