-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathstudentmatrix-mailer.js
More file actions
75 lines (66 loc) · 2.83 KB
/
studentmatrix-mailer.js
File metadata and controls
75 lines (66 loc) · 2.83 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
/**
* @file
* StudentActions for sending e-mails to students based on templates and master sheet content.
*/
StudentMatrix.plugins.mailer = {
name : 'E-mail sender',
description : 'Allows sending e-mails to students based on templates and content in master sheet.',
version : '1.0',
updateUrl : 'https://raw.github.com/Itangalo/studentmatrix/3.x/studentmatrix-mailer.js',
cell : 'D10',
dependencies : {
core : '3.1',
modules : {
studentActions : '1.0',
},
},
studentActions : {
sendTemplateMail : {
name : 'Send e-mail to students based on a template',
group : 'E-mail sender',
description : 'Uses a Google document as template for e-mails, allowing place holder tokens to be replaced by data from the master sheet.',
processor : function(row, options) {
Logger.log(options);
var studentMail = StudentMatrix.components.fetchers.studentColumnValue(row, 'studentMail');
var mailContent = DocumentApp.openById(options.fileId).getBody().getText();
mailContent = StudentMatrix.replaceColumnTokens(mailContent, row);
MailApp.sendEmail(studentMail, options.subject, mailContent);
},
validator : function() {
},
options : {
fileId : true,
subject : 'E-mail from your teacher',
},
optionsBuilder : function(handler, container) {
var app = UiApp.getActiveApplication();
var fileHandler = StudentMatrix.addPluginHandler('mailer', 'showFilePicker');
container.add(app.createButton('Select template', fileHandler));
container.add(app.createAnchor('no file selected', '').setId('fileLink').setVisible(false));
var fileId = app.createTextBox().setId('fileId').setName('fileId').setVisible(false);
container.add(fileId);
handler.addCallbackElement(fileId);
container.add(app.createLabel('Email subject'));
var subject = app.createTextBox().setId('subject').setName('subject');
container.add(subject);
handler.addCallbackElement(subject);
return app;
},
},
},
handlers : {
showFilePicker : function(eventInfo) {
var app = UiApp.getActiveApplication();
var handler = StudentMatrix.addPluginHandler('mailer', 'closeFilePicker');
app.createDocsListDialog().setDialogTitle('Select document to use as email template').setInitialView(UiApp.FileType.DOCUMENTS).addSelectionHandler(handler).showDocsPicker();
return app;
},
closeFilePicker : function(eventInfo) {
var app = UiApp.getActiveApplication();
app.getElementById('fileId').setText(eventInfo.parameter.items[0].id);
app.getElementById('fileLink').setVisible(true).setText(eventInfo.parameter.items[0].name).setHref(eventInfo.parameter.items[0].url);
Logger.log(eventInfo.parameter.items[0].id);
return app;
},
},
};