forked from umangv/mergethisemail
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Javascript.html
94 lines (81 loc) · 2.57 KB
/
Javascript.html
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
<script src="//ajax.googleapis.com/ajax/libs/jquery/3.1.0/jquery.min.js"></script>
<script>
var di = 0;
var numdatarows = 1;
var ddd;
var step1;
$(function () {
ddd = $("#draftdropdown");
step1 = $(".step1");
$("#fetch").click(function () {
step1.hide();
ddd.empty();
ddd.append($("<option value='-1'>Loading...</option>"));
ddd.show();
showSample();
google.script.run.withFailureHandler(fail).withSuccessHandler(showDrafts).getDrafts();
return;
});
google.script.run.withFailureHandler(fail).withSuccessHandler(function(n) { numdatarows = n; }).getNumDataRows();
ddd.change(showSample);
$("#prevsample").click(function () {updateRowIndex(-1); });
$("#nextsample").click(function () { updateRowIndex(1); });
$("#send").click(function () {
$("#send").prop("disabled", true);
google.script.run.withFailureHandler(fail).withSuccessHandler(google.script.host.close).sendEmails(ddd.val());
});
});
function showDrafts(drafts) {
ddd.empty();
ddd.append($("<option value='-1'>Select</option>"));
for (var i = 0; i < drafts.length; i++) {
d = drafts[i];
op = $("<option>");
op.attr("value", d["id"]);
op.html(d["subject"]);
ddd.append(op);
}
showSample();
}
function showSample()
{
id = ddd.val();
var dSample = $("#sampleemail");
if (id == "-1") {
dSample.html("Select a draft from the drop-down above.");
$("#rownavigation").hide();
}
else
{
$("#sampleemail").css("color", "#999"); //grey out email until new email is populated
google.script.run.withFailureHandler(fail).withSuccessHandler(populateSample).getSampleEmail(id, di);
}
$("#sample").show();
}
function populateSample(content)
{
$("#sampleemail").html(content);
$("#sampleemail").css("color", "#000"); //don't grey out email anymore
$("#rowindex").html(String(di+1) + "/" + String(numdatarows));
$("#rownavigation").show();
}
function updateRowIndex(change)
{
change = change || 0;
var tempdi = Math.max(Math.min(di + change, numdatarows - 1), 0);
$("#prevsample").prop("disabled", tempdi == 0);
$("#nextsample").prop("disabled", tempdi == numdatarows -1);
if (tempdi != di)
{
di = tempdi;
showSample();
}
}
function fail(e)
{
$("#explanation").text(e.message);
$("#showerror").click(function () { $("#explanation").show(); $("#showerror").prop("disabled", true); });
$("#error").show();
$("#main").hide();
}
</script>