-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathemail_content.js
238 lines (199 loc) · 7.71 KB
/
email_content.js
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
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
///////////////////////////////////// email_content.js //////////////////////////////////////
//
// VeRsIoN: 0.1
// Last updated: 03/27/2017
// Full Path: /email_content.js
//
// Description: Main content script for email pages.
//
// Notes:
//
///////////////////////////////////////////////////////////////////////////////////////////////////////
logTrace('email_content.js initializing.');
// General
var popUpWidth;
var popUpHeight;
// Email Page Specific Options
var disableOriginalSendButtons;
var forceCAEmail;
var includeToInfo;
var includeSubjet;
var includeEmailBody;
logTrace('email_content.js collecting settings.');
var requestVars = JSON.stringify(['disableOriginalSendButtons','forceCAEmail','includeToInfo','includeSubjet','includeEmailBody']);
getVars(requestVars,init_email);
logTrace('email_content.js finished assigning vars.');
// Per-case vars
var fiveHunID;
/*
chrome.storage.sync.get(
{
// General
'popUpWidth': '800',
'popUpHeight': '675',
// Email Page Specific Options
'disableOriginalSendButtons': false,
'forceCAEmail': true,
'includeToInfo': true,
'includeSubjet': true,
'includeEmailBody': true
},
function(items) {
logTrace('email_content.js settings collected, listing:');
for (var key in items)
{
logTrace("var: " + key + " = " + items[key]);
}
logTrace('email_content.js assigning vars.');
//General
popUpWidth = items.popUpWidth;
popUpHeight = items.popUpHeight;
// Email Page Specific Options
disableOriginalSendButtons = items.disableOriginalSendButtons;
forceCAEmail = items.forceCAEmail;
includeToInfo = items.includeToInfo;
includeSubjet = items.includeSubjet;
includeEmailBody = items.includeEmailBody;
}
);
*/
function init_email() {
// Collect 500 id
try {
fiveHunID = $("#cancelURL").val().split("/")[1].split("?")[0].slice(0,-3);
logTrace("Generate Email Comments: 500 ID = " + fiveHunID);
}
catch(e) {
logError("Generate Email Comments: Error: Unable to get 500 ID...");
}
var caseNum = null;
// BEGIN: Post comment on Email
// Make a new button with the prefills passed in the header
var newSendBtn = '<input id="send-gce" value="Send + Comment" class="btn" name="send-gce" title="Send + Comment" type="button">';
$(newSendBtn).prependTo("#topButtonRow");
var newBotSendBtn = '<input id="send-gce-bot" value="Send + Comment" class="btn" name="send-gce-bot" title="Send + Comment" type="button">';
$(newBotSendBtn).prependTo("#bottomButtonRow");
//$(newSendBtn).clone.prependTo("#topButtonRow");
// Hide the old buttons?
if (disableOriginalSendButtons)
{
$("input[name=send]").css('display', 'none');
}
// Modify new Send buttons onclick functionality
document.getElementById("send-gce").addEventListener('click', emailSendModified, false);
document.getElementById("send-gce-bot").addEventListener('click', emailSendModified, false);
// end post comment on email
if (forceCAEmail) { $("#p26").val("0D2a0000000L0ak:[email protected]:CA Technical Support"); } // if forceCAEmail enabled, change email
// BEGIN: Send & dismiss code
/*
if (window.location.href.indexOf("&dismiss=1") > -1) // if dismiss was passed
{
$("<input id='send-dismiss' value='Send & Dismiss' title='Send & Dismiss' type='button' class='btn'></input>")
.click(
function() {
var fiveHunID = $("#cancelURL").val().replace("/","").split("?")[0];
var caseNum = $("#p3_lkold").val();
//alert(caseNum);
popIt("framePOP", "https://ca--c.na13.visual.force.com/apex/Dismiss_selected_Callbacks?caseId=" + fiveHunID, "Dismiss Callbacks");
//$("input[value='Cancel']").click();
$("input[value=' Send ']").click();
}
).appendTo("#topButtonRow").clone().appendTo("#bottomButtonRow");
}
// END: Send & dismiss code
*/
logTrace('email_content.js finished.');
}
function emailSendModified() {
// New lines are really 2 chars when SC counts... treat them that way!
var nlen = 2;
// Collect total length (so we don't overrun the 4000 char comment limit)
var currLength = 0;
currLength += commentStart.length + nlen;
// Start Generating URI String
var myURI = 'https://ca.my.salesforce.com/00a/e?parent_id=' + fiveHunID + '&retURL=/' + fiveHunID + '&isdtp=vw' + '&email2Comment=true';
if (includeToInfo)
{ //alert('a');
// Collect To
var emailTo = $("#p2").val();
if (emailTo !== '')
{
myURI += '&emailTo=' + lzw_encode(emailTo);
currLength += emailTo.length + labelTo.length + nlen;
}
// Collect AdditionalTo
var emailADD = $("#p24").val();
if (emailADD !== '')
{
myURI += '&emailADD=' + lzw_encode(emailADD);
currLength += emailADD.length + labelADD.length + nlen;
}
// Collect CC
var emailCC = $("#p4").val();
if (emailCC !== '')
{
myURI += '&emailCC=' + lzw_encode(emailCC);
currLength += emailCC.length + labelCC.length + nlen;
}
// Collect BCC
var emailBCC = $("#p5").val();
if (emailBCC !== '')
{
myURI += '&emailBCC=' + lzw_encode(emailBCC);
currLength += emailBCC.length + labelBCC.length + nlen;
}
}
if (includeSubjet)
{
// Collect Subject
var emailSub = $("#p6").val();
if (emailSub !== '')
{
if (emailSub.length <= 100)
{
myURI += '&emailSub=' + lzw_encode(emailSub);
currLength += emailSub.length + labelSub.length + nlen;
} else {
alert("Subject is longer than SC allows (>100 chars). Please shorten before sending.");
return;
}
}
}
if (includeEmailBody)
{
// Collect Email Body, truncate?
var emailBody = $("#p7").val();
if (emailBody.length > 0)
{
var numLineReturns = emailBody.split("\n").length;
currLength += labelBody.length + nlen;
if (emailBody.length + numLineReturns > 3995 - currLength)
{
currLength += truncatedMessage.length + nlen;
emailBody = emailBody.substr(0, (3995 - currLength));
numLineReturns = emailBody.split("\n").length;
if (emailBody.length + numLineReturns >= 3995 - currLength)
{
emailBody = emailBody.substr(0, (3995 - currLength - numLineReturns));
numLineReturns = emailBody.split("\n").length;
}
emailBody += "\n" + truncatedMessage;
}
myURI += '&emailBody=' + lzw_encode(emailBody);
}
else
{
// Email Body is empty... Confirm the email should be sent
var response = confirm("Are you sure you want to send a blank email!?");
// If yes clicked (WHO WOULD SEND A BLANK EMAIL ON PURPOSE?!), continue...
if (response === true) {}
// else break out of this function to stop email & comment from being genereated
else { return; }
}
}
// POP IT!
popIt("framePOP", encodeURI(myURI), "Adding email comment...", "Comments", false);
// Click Send to send email
//$("input[name='cancel']").click(); // Click Cancel (for testing)
$("input[name='send']").first().click(); // Click send
}