-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathScripts.gs
192 lines (174 loc) · 4.65 KB
/
Scripts.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
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
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
/**
* INIT CLASSES
*/
class mySidebar {
/**
* Класс mySidebar позволяет создавать sidebars удобным способом с заранее сформулированными методами и свойства
* @param {object} json
* @param {string} title - Sidebar name настроек которые надо удалить
*/
constructor(json, title = "Sidebar") {
this.title = title
this.json = json
this.html = ""
const obj = []
Object.keys ( json ).forEach ( (value, key) => {
//console.log ( `json[${ key }].${ json[value].type }:`, json[value] )
switch (json[value].type) {
case "input":
obj[key] = new Input ( json[value] )
break
case "button":
obj[key] = new Button ( json[value] )
break
}
obj[key].log ()
this.html += obj[key].getHtml () + "<br>\n"
//console.log ( this.html )
} )
}
log() {
console.log (
`title: ${ this.title },
json: ${ JSON.stringify ( this.json ) },`
)
}
/**
* Метод позволяет сделать тест открытия 'sidebar'.
* https://developers.google.com/apps-script/reference/base/ui#showsidebaruserinterface
*/
test() {
const html = HtmlService.createTemplate (
"Hello, world! <input type=\"button\" value=\"Close\" onclick=\"google.script.host.close()\" />"
)
.evaluate ()
.setTitle ( "Test sidebar" )
SpreadsheetApp.getUi ()
.showSidebar ( HtmlService.createHtmlOutput ( html ) )
}
/**
* Метод открывает 'sidebar'.
* https://developers.google.com/apps-script/reference/base/ui#showsidebaruserinterface
*/
show() {
SpreadsheetApp.getUi ().showSidebar ( HtmlService
.createHtmlOutput ( this.html )
.setTitle ( this.title ) ); // создаем HtmlOutput
}
}
class Button {
/**
* Button class
* @param title
* @param listener
* @param url
* @param child
*/
constructor({
title = 'undefined_button',
listener,
url = 'undefined_url',
}) {
this.title = title
this.listener = listener
this.url = url
}
getHtml() {
return HtmlService.createTemplate (
`<input type=\"button\" value=\"${ this.title }\" ${ this.listener } \\>`
).evaluate ().getContent ()
}
log() {
console.log (
`
title: ${ this.title },
url: ${ this.url },
listener: ${ this.listener },
`
)
}
}
class Input {
/**
* Input class
* @param title
* @param listener
* @param child
*/
constructor({
title = "input",
listener
}) {
this.title = title
this.listener = listener
}
getHtml() {
return HtmlService.createTemplate (
`<input type=\"input\" value=\"${ this.title }\" ${ this.listener } \\>`
).evaluate ().getContent ()
}
log() {
console.log (
`
title: ${ this.title },
listener: ${ this.listener },
`
)
}
}
/**
* TESTS
*/
const test = () => {
const json = [
{
type: "input",
title: "test_input"
},
{
type: "button",
title: "test_button",
listener: "onclick=\"google.script.host.close()\"",
url: "https://#"
},
{
type: "input",
title: "test_input"
},
{
type: "input",
title: "test_input"
},
{
type: "button",
title: "test_button",
listener: "onclick=\"google.script.host.close()\"",
url: "https://#"
},
{
type: "button",
title: "test_button",
listener: "onclick=\"google.script.host.close()\"",
url: "https://#"
},
{
type: "input",
title: "test_input",
spell: "fire"
},
]
const Sidebar1 = new mySidebar ( json )
return Sidebar1.show ()
}
/**
* ANOTHER FUNCTION
*/
/**
* Include external files
* @param filename
* @returns {string}
*/
const include = (filename) => {
return HtmlService.createHtmlOutputFromFile ( filename )
.getContent ();
}