-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathnewRule_Dialog.html
More file actions
169 lines (141 loc) · 5.1 KB
/
Copy pathnewRule_Dialog.html
File metadata and controls
169 lines (141 loc) · 5.1 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
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
<link rel="stylesheet" href="https://ssl.gstatic.com/docs/script/css/add-ons1.css">
<style>
table,tr,select,input{
width:100%;
}
td{width:50%;border:none;padding-right: 30px;}
input[type="button"]{cursor:pointer;}
</style>
<b>1. When all these conditions are met</b>
<br>
<table>
<tbody>
<tr>
<td>
<!-- Select dropdown -->
<div class="block form-group">
<label for="select">Label</label>
<select id="labelList">
<option selected disabled hidden>Loading..</option>
</select>
</div>
</td>
<td>
<div class="block form-group">
<label for="fromEmail">From</label>
<input type="text" id="fromEmail" style="width: 100%;">
</div>
</td>
</tr>
<!--2nd row-->
<tr>
<td>
<div class="block form-group">
<label for="subject">Subject</label>
<input type="text" id="subject" style="width: 100%;">
</div>
</td>
<td>
<div class="block form-group">
<label for="advancedCriteria">Advanced Criteria</label>
<input type="text" id="advancedCriteria" placeholder="e.g., has:attachment to:me" style="width: 100%;">
</div>
</td>
</tr>
</tbody>
</table>
<!-- DivTable.com -->
<br>
<b>2. Do the following</b>
<table>
<tbody>
<tr>
<td>
<div class="block form-group">
<label for="forwardTo">To</label>
<input type="email" id="forwardTo" style="width: 100%;" required>
</div>
</td>
<td>
<div class="block form-group">
<label for="select">Sender's Alias</label>
<select id="aliasEmail">
<option selected disabled hidden>Loading..</option>
</select>
</div>
</td>
</tr>
</tbody>
</table>
<div id="message123" style="height:18px"></div>
<button class="action" onClick="submitData()">Create Forwarding Rule</button>
<button onClick="manageRules()">Manage Rules</button>
<!-- Javascript Code -->
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.1/jquery.min.js"></script>
<script>
// The code in this function runs when the page is loaded.
$(function() {
google.script.run.withSuccessHandler(buildOptionList)
.getData();
});
function buildOptionList(data) {
var labelList = $('#labelList');
var aliasList = $('#aliasEmail');
labelList.empty();
aliasList.empty();
var labels = data.labels;
labelList.append(new Option("Select Gmail Label..", ""));
for (var i = 0; i < labels.length; i++) {
labelList.append(new Option(labels[i], labels[i]));
}
var emailAddresses = data.emailAddresses;
for (i = 0; i < emailAddresses.length; ++i) {
var emailID = emailAddresses[i];
aliasList.append(new Option(emailID, emailID));
}
}
function submitData() {
var formInput = {
'label': $("select#labelList option:checked").val(),
'from': $("#fromEmail").val(),
'subject': $("#subject").val(),
'advancedSearch': $("#advancedCriteria").val(),
'forwardTo': $("#forwardTo").val(),
'aliasEmail': $("#aliasEmail :selected").text()
}
var valid = true;
// Validation
//if any of the 4 fields is not null, the if-block is executed
if (formInput.label || formInput.from || formInput.subject || formInput.advancedSearch) {
if (!(formInput.forwardTo && validateEmail(formInput.forwardTo))) {
$('#message123').html("<p style='color:red'>Invalid email address</p>");
valid = false;
}
if (!formInput.forwardTo) {
$('#message123').html("<p style='color:red'>Can\x27t leave forward to field empty!</p>");
valid = false;
}
if (valid) {
google.script.run.addRule(formInput);
$("#message123").html("<p><img style='width:20px;height:20px;' src='https://www.wallies.com/filebin/images/loading_apple.gif'/> Creating new rule, please wait..</p>")
setTimeout(function(){
$('#message123').html("<p style='color:green'>Rule created successfully!</p>");
}, 800);
}
} else {
$('#message123').html("<p style='color:red'>Atleast one condition is required</p>");
valid = false;
}
}
function validateEmail(sEmail) {
var filter = /^([\w-\.]+)@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([\w-]+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$/;
if (filter.test(sEmail)) {
return true;
} else {
return false;
}
}
function manageRules(){
google.script.run.manage_rules();
}
</script>