-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCode.gs
More file actions
120 lines (99 loc) · 3.94 KB
/
Code.gs
File metadata and controls
120 lines (99 loc) · 3.94 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
/**
* Creates a menu entry in the Google Docs UI when the document is opened.
*/
function onOpen(e) {
DocumentApp.getUi().createAddonMenu()
.addItem('Start', 'showSidebar')
.addToUi();
}
/**
* Runs when the add-on is installed.
*/
function onInstall(e) {
onOpen(e);
}
/**
* Opens a sidebar in the document containing the add-on's user interface.
*/
function showSidebar() {
var ui = HtmlService.createHtmlOutputFromFile('Sidebar')
.setTitle('SOW')
.setSandboxMode(HtmlService.SandboxMode.IFRAME);
DocumentApp.getUi().showSidebar(ui);
file();
}
/**
* Replaces {{client}} {{date}} {{project}} {{integration}} {{location}}
*/
function main(client_actual,integration_actual,location_actual){
var client_lv = "\{\{client\}\}";
var date_lv = "\{\{date\}\}";
var project_lv = "\{\{project\}\}";
var integration_lv = "\{\{integration\}\}";
var location_lv = "\{\{location\}\}";
var body = DocumentApp.getActiveDocument().getBody();
var heading = DocumentApp.getActiveDocument().getHeader();
var project_num = DocumentApp.getActiveDocument().getName().split(' ')[0];
var today = Utilities.formatDate(new Date(), "PST", "M/dd/yyyy");
//checks the heading of the document
if (heading !== null){
if (heading.findText(date_lv)!== null){heading.replaceText(date_lv, today);}
if (heading.findText(project_lv)!== null){heading.replaceText(project_lv, project_num);}
if (heading.findText(client_lv)!== null){heading.replaceText(client_lv, client_actual);}
//if (heading.findText(integration_lv)!== null){heading.replaceText(integration_lv, integration_actual);}
//if (heading.findText(location_lv)!== null){heading.replaceText(location_lv, location_actual);}
}
//chcks the body of the document
if (body !== null){
if (body.findText(date_lv)!== null){body.replaceText(date_lv, today);}
if (body.findText(project_lv)!== null){body.replaceText(project_lv, project_num);}
if (body.findText(client_lv)!== null){body.replaceText(client_lv, client_actual);}
if (body.findText(integration_lv)!== null){body.replaceText(integration_lv, integration_actual);}
if (body.findText(location_lv)!== null){body.replaceText(location_lv, location_actual);}
}
curly();
pound();
}
//halfsies (no date/client/project)
function halfsies(integration_actual,location_actual){
var integration_lv = "\{\{integration\}\}";
var location_lv = "\{\{location\}\}";
var body = DocumentApp.getActiveDocument().getBody();
//chcks the body of the document
if (body !== null){
if (body.findText(integration_lv)!== null){body.replaceText(integration_lv, integration_actual);}
if (body.findText(location_lv)!== null){body.replaceText(location_lv, location_actual);}
}
pound();
}
//checks for curly brackets in body
function curly(){
var body = DocumentApp.getActiveDocument().getBody();
var heading = DocumentApp.getActiveDocument().getHeader();
if (body !== null){
if (body.findText("\{")!== null){DocumentApp.getUi().alert("there is a {");}
if (body.findText("\}")!== null){DocumentApp.getUi().alert("there is a }");}
}
if (heading !== null){
if (heading.findText("\{")!== null){DocumentApp.getUi().alert("there is a {");}
if (heading.findText("\}")!== null){DocumentApp.getUi().alert("there is a }");}
}
}
//adds file to the Compelted SOWs folder
//removes file from the templates folder
function file(){
var doc = DocumentApp.getActiveDocument()
var file = DriveApp.getFileById(doc.getId());
var completed = DriveApp.getFolderById("0B1T9Y1DTvgk9a0xONlQ5WEFFcU0");
var templates = DriveApp.getFolderById("0B1T9Y1DTvgk9d0ZyeU5NZkNzSkU");
completed.addFile(file);
templates.removeFile(file);
}
//checks for ## signs
function pound(){
var body = DocumentApp.getActiveDocument().getBody();
if (body !== null){
if (body.findText("##")!== null){DocumentApp.getUi().alert("there is a ##!");}
//else {DocumentApp.getUi().alert("you good girl");}
}
}