-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathsalesforce_case_helper.tamper.js
840 lines (815 loc) · 38.8 KB
/
salesforce_case_helper.tamper.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
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
// ==UserScript==
// @name new_salesforce_case_helper
// @namespace salesforce.com
// @include https://bazaarvoice1.my.salesforce.com/*
// @include https://bazaarvoice1--e2cp.na3.visual.force.com/*
// @include https://bazaarvoice1--c.na3.visual.force.com/*
// @require http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js
// @resource Customcss case_helper.css
// @version 2.1
// @grant GM_addStyle
// @grant GM_getResourceText
// ==/UserScript==
/*
Define your signature in the userSignature variable
Define your SoftServe Signature in the sendToSoftserve variable
\n is a carriage return (Enter/Return)
*/
//if (document.getElementById('cas2_ileinner')){
//var caseNumber = document.getElementById('cas2_ileinner').innerText.substring(0,8);
//console.log('caseNumber: ',caseNumber);
//}
//if(document.getElementsByClassName('bPageTitle')[0]){
//var caseNumber = document.getElementsByClassName('bPageTitle')[0].innerText.split('').splice(6,8).join('');
//}
// business day calculator
function businessDaysFromDate(businessDays) {
var counter = 0, tmp = new Date(), origTime = tmp.getTime();
var yr = tmp.getFullYear();
var easter = computus(yr);
var goodFriday = easter;
goodFriday.setDate(goodFriday.getDate()-2);
var gfM = goodFriday.getMonth()+1;
var gfD = goodFriday.getDate();
var gfStr = gfM + '/'+gfD;
var easterMonday = goodFriday;
easterMonday.setDate(easterMonday.getDate()+3);
var emM = easterMonday.getMonth()+1;
var emD = easterMonday.getDate();
var emStr = emM+'/'+emD;
var ascensionThursday = easterMonday;
ascensionThursday.setDate(ascensionThursday.getDate()+38);
var atM = ascensionThursday.getMonth()+1;
var atD = ascensionThursday.getDate();
var atStr = atM+'/'+atD;
var whitMonday = ascensionThursday;
whitMonday.setDate(whitMonday.getDate()+11);
var wmM = whitMonday.getMonth()+1;
var wmD = whitMonday.getDate();
var wmStr = wmM+'/'+wmD;
var corpusChristi = whitMonday;
corpusChristi.setDate(corpusChristi.getDate()+10);
var ccM = corpusChristi.getMonth()+1;
var ccD = corpusChristi.getDate();
var ccStr = ccM+'/'+ccD;
while( businessDays>=0 ) {
console.log('businessDays: ',businessDays);
tmp.setTime( origTime + counter * 86400000 );
if(isBusinessDay (tmp,gfStr,emStr,atStr,wmStr,ccStr)) {
--businessDays;
}
++counter;
}
return tmp;
}
function isBusinessDay (date,gfStr,emStr,atStr,wmStr,ccStr) {
var dayOfWeek = date.getDay();
if(dayOfWeek === 0 || dayOfWeek === 6) {
// Weekend
console.log('weekend - return false');
return false;
}
// Uncomment out the holiday of your country - it is United States by default
// United States
// comment this out if you are chossing another country
var holidays = [
'12/31+5', // New Year's Day on a saturday celebrated on previous friday
'1/1', // New Year's Day
'1/2+1', // New Year's Day on a sunday celebrated on next monday
'1-3/1', // Birthday of Martin Luther King, third Monday in January
'2-3/1', // Washington's Birthday, third Monday in February
'5~1/1', // Memorial Day, last Monday in May
'7/3+5', // Independence Day
'7/4', // Independence Day
'7/5+1', // Independence Day
'9-1/1', // Labor Day, first Monday in September
'11-4/4', // Thanksgiving Day, fourth Thursday in November
'11-4/5', // Day after Thanksgiving, fourth Friday in November
'12/23+5', // Christmas Eve
'12/24', // Christmas Eve
'12/25+1', // Christmas Eve
'12/24+5', // Christmas Day
'12/25', // Christmas Day
'12/26+1', // Christmas Day
];
// United Kingdom
/*
holidays = [
'12/31+5', // New Year's Day on a saturday celebrated on previous friday
'1/1', // New Year's Day
'1/2+1', // New Year's Day on a sunday celebrated on next monday
'5-1/1', // Early May Bank Holiday, first Monday in May
'5~1/1', // Spring Bank Holiday, last Monday in May
'8~1/1', // Summer Bank Holiday, last Monday in August
'12/24+5', // Christmas Day
'12/25', // Christmas Day
'12/26+1', // Christmas Day
'12/25+5', // Boxing Day
'12/26', // Boxing Day
'12/27+1', // Boxing Day
];
holidays[12] = gfStr;
holidays[13] = emStr;
*/
// France
/*
holidays = [
'12/31+5', // New Year's Day on a saturday celebrated on previous friday
'1/1', // New Year's Day
'1/2+1', // New Year's Day on a sunday celebrated on next monday
'5/1', // Labor Day, May 1st
'5/8', // Victory in Europe Day (May 8th, 1945)
'8/15', // Assumption (August 15th)
'11/1', // All Saint's Day
'12/24+5', // Christmas Day
'12/25', // Christmas Day
'12/26+1', // Christmas Day
];
holidays[10] = emStr;
holidays[11] = atStr;
*/
// Germany
/*
holidays = [
'12/31+5', // New Year's Day on a saturday celebrated on previous friday
'1/1', // New Year's Day
'1/2+1', // New Year's Day on a sunday celebrated on next monday
'5/1', // Labor Day, May 1st
'8/15', // Assumption (August 15th)
'10/3', // Day of German Unity
'11/1', // All Saint's Day
'12/24+5', // Christmas Day
'12/25', // Christmas Day
'12/26+1', // Christmas Day
'12/25+5', // Second Day of Christmas
'12/26', // Second Day of Christmas
'12/27+1', // Second Day of Christmas
];
holidays[13] = gfStr;
holidays[14] = emStr;
holidays[15] = atStr;
holidays[16] = wmStr;
holidays[17] = ccStr;
*/
// Netherlands
/*
holidays = [
'12/31+5', // New Year's Day on a saturday celebrated on previous friday
'1/1', // New Year's Day
'1/2+1', // New Year's Day on a sunday celebrated on next monday
'4/27', // King’s Day
'12/24+5', // Christmas Day
'12/25', // Christmas Day
'12/26+1', // Christmas Day
'12/25+5', // Boxing Day
'12/26', // Boxing Day
'12/27+1', // Boxing Day
];
holidays[10] = emStr;
holidays[11] = atStr;
holidays[12] = wmStr;
*/
// Northern Ireland
/*
holidays = [
'12/31+5', // New Year's Day on a saturday celebrated on previous friday
'1/1', // New Year's Day
'1/2+1', // New Year's Day on a sunday celebrated on next monday
'3/19+1', // St. Patrick’s Day on a saturday celebrated on next monday
'3/17', // St. Patrick’s Day
'3/18+1', // St. Patrick’s Day on a sunday celebrated on next monday
'5-1/1', // Early May Bank Holiday, first Monday in May
'5~1/1', // Spring Bank Holiday, last Monday in May
'7/12', // Battle of the Boyne
'8~1/1', // August Bank Holiday, last Monday in August
'12/24+5', // Christmas Day
'12/25', // Christmas Day
'12/26+1', // Christmas Day
'12/25+5', // Boxing Day
'12/26', // Boxing Day
'12/27+1', // Boxing Day
];
holidays[16] = gfStr;
holidays[17] = emStr;
*/
// Australia
/*
holidays = [
'12/31+5', // New Year's Day on a saturday celebrated on previous friday
'1/1', // New Year's Day
'1/2+1', // New Year's Day on a sunday celebrated on next monday
'1/28+1', // Australia Day on a saturday celebrated on next monday
'1/26', // Australia Day
'1/27+1', // Australia Day on a sunday celebrated on next monday
'4/25', // ANZAC Day
'6-2/1', // Queen’s Birthday (2nd Monday in June)
'8-1/1', // Bank Holiday (1st Monday in August)
'10-1/1', // Labour Day (1st Monday in October)
'12/24+5', // Christmas Day
'12/25', // Christmas Day
'12/26+1', // Christmas Day
'12/25+5', // Boxing Day
'12/26', // Boxing Day
'12/27+1', // Boxing Day
];
holidays[16] = gfStr;
holidays[17] = emStr;
*/
var dayOfMonth = date.getDate(),
month = date.getMonth() + 1,
monthDay = month + '/' + dayOfMonth;
if(holidays.indexOf(monthDay)>-1){
return false;
}
var monthDayDay = monthDay + '+' + dayOfWeek;
if(holidays.indexOf(monthDayDay)>-1){
return false;
}
var weekOfMonth = Math.floor((dayOfMonth - 1) / 7) + 1,
monthWeekDay = month + '-' + weekOfMonth + '/' + dayOfWeek;
if(holidays.indexOf(monthWeekDay)>-1){
return false;
}
var lastDayOfMonth = new Date(date);
lastDayOfMonth.setMonth(lastDayOfMonth.getMonth() + 1);
lastDayOfMonth.setDate(0);
var negWeekOfMonth = Math.floor((lastDayOfMonth.getDate() - dayOfMonth - 1) / 7) + 1,
monthNegWeekDay = month + '~' + negWeekOfMonth + '/' + dayOfWeek;
if(holidays.indexOf(monthNegWeekDay)>-1){
return false;
}
return true;
}
function computus( y ) {
var date, a, b, c, m, d;
// Instantiate the date object.
date = new Date();
// Set the timestamp to midnight.
date.setHours( 0, 0, 0, 0 );
// Set the year.
date.setFullYear( y );
// Find the golden number.
a = y % 19;
// Choose which version of the algorithm to use based on the given year.
b = ( 2200 <= y && y <= 2299 ) ?
( ( 11 * a ) + 4 ) % 30 :
( ( 11 * a ) + 5 ) % 30;
// Determine whether or not to compensate for the previous step.
c = ( ( b === 0 ) || ( b === 1 && a > 10 ) ) ?
( b + 1 ) :
b;
// Use c first to find the month: April or March.
m = ( 1 <= c && c <= 19 ) ? 3 : 2;
// Then use c to find the full moon after the northward equinox.
d = ( 50 - c ) % 31;
// Mark the date of that full moon—the "Paschal" full moon.
date.setMonth( m, d );
// Count forward the number of days until the following Sunday (Easter).
date.setMonth( m, d + ( 7 - date.getDay() ) );
// Gregorian Western Easter Sunday
return date;
}
var closeDate = businessDaysFromDate(5);
var options = { weekday: 'long', year: 'numeric', month: 'long', day: 'numeric' };
// UnComment out your country - it is United States by default
// United States
// Comment this out if you are choosing another country
var days = ["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"];
var months = ["January","February","March","April","May","June","July","August","September","October","November","December"];
var suffixes = ["st","nd","rd","th","th","th","th","th","th","th","th","th","th","th","th","th","th","th","th","th","st","nd","rd","th","th","th","th","th","th","th","st"];
var closeDateNice = days[closeDate.getDay()]+' '+months[closeDate.getMonth()]+' '+closeDate.getDate()+suffixes[closeDate.getDate()-1];
closeDate = closeDateNice;
// United Kingdom
//closeDate = closeDate.toLocaleDateString('en-GB', options);
// Northern Ireland
//closeDate = closeDate.toLocaleDateString('en-IE', options);
// France
//closeDate = closeDate.toLocaleDateString('fr-FR', options);
// Germany
//closeDate = closeDate.toLocaleDateString('de-DE', options);
// Netherlands
//closeDate = closeDate.toLocaleDateString('nl-NL', options);
// Australia
//closeDate = closeDate.toLocaleDateString('en-AU', options);
var userSignature = "\nBest regards,\nXXXX | Technical Success Manager | 512.551.XXXX\n\n———\nIf you have a critical issue at any time of day or night - defined as a total outage of submission or display on production - please call our support hotline at 888-984-1381 (toll free) and someone will assist you.";
var sendToSoftserve = "Hello SoftServe,\n\nbenchname, PRR/C13, Cluster Prod/Staging, Display code (if applicable)\n\nExternal Communication no\n\nThanks!";
var newCSS = GM_getResourceText ("Customcss");
//this block runs on all salesforce case pages and all new comments page. Fixes word wrap issue, adds signature buttons and floats WorkIt!
GM_addStyle (newCSS);
if($('.pageType').html()) {
if($('.pageType').html().substring(0,10) == 'Close Case') {
$("#00N50000002D2N9").addClass("status_negative");
$("#00N50000002AgSu").addClass("status_negative");
var closeTextArea = document.getElementById("cas16");
closeTextArea.style.minWidth = "410px";
closeTextArea.style.height = "150px";
alert("Before closing, make sure that you fill out the Nature of Issue and Solution Type fields with correct information as these may have changed during course of the case!");
}
}
//https://bazaarvoice1--c.na3.visual.force.com
//https://bazaarvoice1--e2cp.na3.visual.force.com
console.log('Hello World!');
console.log('document.location.origin: ',document.location.origin);
if(document.location.origin === 'https://bazaarvoice1--c.na3.visual.force.com'){
window.addEventListener("load", Greasemonkey_main1, false);
}
function Greasemonkey_main1(){
//$('.slds-form-element ').attr('id', 'commentButtons');
var caseNumber = 0;
$("[data-aura-rendered-by='18:0']").attr('id', 'caseNumber');
caseNumber = $("#caseNumber").text();
//caseNumber = document.getElementById('caseNumber').innerText;
console.log('caseNumber: ',caseNumber);
var closeSignature = "I will go ahead and mark this ticket as resolved. It will stay open until "+closeDate+", just in case you have any questions. It was great working with you. Have a wonderful day!\n\nThanks,\nXXXX\nTechnical Success Manager\no: 512.551.XXXX\n\nNote on Closed cases: replies to Closed cases do not alert the case owner. If you have any follow up questions please open a new case and reference this case number ("+caseNumber+").";
$("[data-aura-rendered-by='195:0']").attr('id', 'dataSelect');
var viewportWidth = $(window).width();
console.log('viewportWidth: ',viewportWidth);
$("[data-aura-rendered-by='8:0']").width(viewportWidth-243);
//$("[data-aura-rendered-by='203:0']").hide();
var addCommentDivWidth = $("[data-aura-rendered-by='179:0']").width();
$("[data-aura-rendered-by='279:0']").width(addCommentDivWidth-30);
//$("[data-aura-rendered-by='347:0']").find('input[type=checkbox]').each(function () {
//$(this).prop("checked",true);
//this.checked = true;
//});
//var radioCounter = 0;
//$("[data-aura-rendered-by='347:0']").find('input[type=radio]').each(function () {
//console.log('$(this).val() = ',$(this).val());
//if(radioCounter%2==0){
//this.checked = true;
//$(this).prop("checked",true);
//this.val('true');
//}
//radioCounter++;
//});
var commentRow = document.getElementById('dataSelect');
//var commentRow = document.getElementById('pg:addCommentF:addCommentPB:rptOrder:0:addCommentPBS:cannedPBSI:cannedOP');
var signatureButton = document.createElement('input');
signatureButton.id = 'signatureButton';
signatureButton.setAttribute('class','btn');
signatureButton.setAttribute('type','button');
signatureButton.setAttribute('name','signatureButton');
signatureButton.setAttribute('value','Add Signature');
var softserveButton = document.createElement('input');
softserveButton.id = 'softserveButton';
softserveButton.setAttribute('class','btn');
softserveButton.setAttribute('type','button');
softserveButton.setAttribute('name','sendToSoftserve');
softserveButton.setAttribute('value','SS Signature');
var closeButton = document.createElement('input');
closeButton.id = 'closeButton';
closeButton.setAttribute('class','btn');
closeButton.setAttribute('type','button');
closeButton.setAttribute('name','closeButton');
closeButton.setAttribute('value','Closing Signature');
$("[data-aura-rendered-by='279:0']").attr('id', 'textAreaTarget');
//var textAreaTarget = document.getElementById('textAreaTarget');
commentRow.insertBefore(signatureButton,null);
commentRow.insertBefore(softserveButton,null);
commentRow.insertBefore(closeButton,null);
//$("[data-aura-rendered-by='320:0']").attr('id', 'textAreaTarget');
document.getElementById('softserveButton').onclick = function(){
console.log('ss button clicked');
document.getElementById("textAreaTarget").value += sendToSoftserve;
//document.getElementById("pg:addCommentF:addCommentPB:rptOrder:0:addCommentPBS:addCommentPBSI:Comment_TextArea").value += sendToSoftserve;
//if (document.getElementById("pg:addCommentF:addCommentPB:rptOrder:0:addCommentPBS:publicPBSI:IsPublic_Checkbox").value == "on"){
//document.getElementById("pg:addCommentF:addCommentPB:rptOrder:0:addCommentPBS:publicPBSI:IsPublic_Checkbox").click();
//}
//document.getElementById("pg:addCommentF:addCommentPB:rptOrder:1:customFieldsPBS:j_id90:0:j_id91").value = "Awaiting TSE Assignment";
};
document.getElementById('signatureButton').onclick = function(){
if(userSignature.indexOf('XXXX')>-1){
alert("You haven't changed the default user signature yet!");
}
console.log('signature button clicked');
document.getElementById("textAreaTarget").value += userSignature;
//document.getElementById("pg:addCommentF:addCommentPB:rptOrder:0:addCommentPBS:addCommentPBSI:Comment_TextArea").value += userSignature;
};
document.getElementById('closeButton').onclick = function(){
if(closeSignature.indexOf('XXXX')>-1){
alert("You haven't changed the default close signature yet!");
}
console.log('close signature button clicked');
document.getElementById("textAreaTarget").value += closeSignature;
//document.getElementById("pg:addCommentF:addCommentPB:rptOrder:0:addCommentPBS:addCommentPBSI:Comment_TextArea").value += closeSignature;
//document.getElementById("pg:addCommentF:addCommentPB:rptOrder:1:customFieldsPBS:j_id90:0:j_id91").value = "Resolved";
};
}
//end block
// AddComment improved text
var commentDescriptionDiv = document.getElementById("pg:addCommentF:csPB:csPBS");
if(commentDescriptionDiv){
var commentTextArea = document.getElementById("pg:addCommentF:addCommentPB:rptOrder:0:addCommentPBS:addCommentPBSI:Comment_TextArea");
commentTextArea.style.width = window.innerWidth - 849 + "px";
commentTextArea.style.minWidth = "425px";
commentTextArea.style.height = "300px";
commentDescriptionDiv.style.maxWidth = window.innerWidth - 316 + "px";
commentDescriptionDiv.style.width = window.innerWidth - 316 + "px";
commentDescriptionDiv.style.wordBreak = "break-all";
commentDescriptionDiv.style.wordWrap = "break-word";
commentDescriptionDiv.style.fontSize = "small";
$(window).resize(function () {
commentDescriptionDiv.style.maxWidth = window.innerWidth - 316 + "px";
commentDescriptionDiv.style.width = window.innerWidth - 316 + "px";
commentTextArea.style.width = window.innerWidth - 849 + "px";
});
} else {
console.log('Add Comment Description element not present');
}
//This block will run on all Support Case Types
if(document.getElementById('RecordType_ileinner')){
console.log('Record Type Field is present');
if(document.getElementById('RecordType_ileinner').innerHTML.substr(0,12) === "Support Team"||document.getElementById('RecordType_ileinner').innerHTML.substr(0,15) === "Product Support"){
window.addEventListener("load", Greasemonkey_main, false);
}
} else {
console.log('Record Type Field is not present');
}
function Greasemonkey_main() {
//load Open Sans font
var head= document.getElementsByTagName('head')[0];
var script= document.createElement('link');
script.rel = 'stylesheet';
script.type= 'text/css';
script.href= 'https://fonts.googleapis.com/css?family=Open+Sans:400,600';
head.appendChild(script); //end font
// Select Font size listener
console.log('checking for font-size selector');
if(document.getElementsByClassName('pageType')[0]) {
if(document.getElementsByClassName('pageType')[0].innerHTML == 'Close Case') {
alert("Make sure you correctly fill out Nature of Issue and Solution Type fields with correct information before closing!");
}
}
document.body.addEventListener( 'change', function ( event ) {
if( event.srcElement.id == 'selectFontSize' ) {
var newSize = document.getElementById('selectFontSize').value;
$('.beautified_comment').css('font-size',newSize);
}
} );
//This function updates the important fields with color depending on their values
function checkImportantFields(){
var status = document.getElementById("cas7_ileinner");
var natureOfIssueField = document.getElementById('00N50000002D2N9_ileinner');
var rootCauseField = document.getElementById('00N50000002AgSu_ileinner');
var relatedProductField = document.getElementById('00N50000002D2Rp_ileinner');
var accountSupportGroupField = document.getElementById('00N50000003fP3z_ileinner');
var primaryTSMConversationsField = document.getElementById('00N50000009s6XR_ileinner');
var primaryTSMPRRField = document.getElementById('00N50000009s6XW_ileinner');
var caseOriginField = document.getElementById('cas11_ileinner');
var caseNotes = document.getElementById('00N50000002AHM3_ileinner');
var supportNotes = document.getElementById('00N50000001yx07_ileinner');
var testNegField = document.getElementById('fakeFake');
//update nature of issue, root cause, and related product fields
console.log('Checking fields . . .');
// Nature of Issue
if (natureOfIssueField){
console.log('Nature of issue Field is present');
if (natureOfIssueField.innerHTML === " ") {
$("#00N50000002D2N9_ileinner").addClass("status_negative");
}else{
//$("#00N50000002D2N9_ileinner").addClass("status_positive");
}
} else {
console.log('Nature of issue Field not present');
}
// Root Cause
if (rootCauseField){
console.log('Root Cause Field is present');
if (rootCauseField.innerHTML === " ") {
$('#00N50000002AgSu_ileinner').addClass("status_negative");
} else {
//$('#00N50000002AgSu_ileinner').addClass("status_positive");
}
} else {
console.log('Root Cause Field not present');
}
// Case Origin
if (caseOriginField){
console.log('Case Origin Field is present');
if (caseOriginField.innerHTML === " ") {
$("#cas11_ileinner").addClass("status_negative");
} else {
console.log('Case Origin is present');
}
} else {
console.log('Case Origin Field not present');
}
// Primary TSM CV2
if (primaryTSMConversationsField){
console.log('Primary TSM CV2 Field is present');
if (primaryTSMConversationsField.innerHTML === "" || primaryTSMConversationsField.innerHTML === " " || primaryTSMConversationsField.innerHTML === " ") {
console.log('No Primary Conversations TSM');
} else {
$('#00N50000009s6XR_ileinner').addClass("status_positive");
}
} else {
console.log('Primary TSM CV2 Field not present');
}
// Primary TSM PRR
if (primaryTSMPRRField){
console.log('Primary TSM PRR Field is present');
if (primaryTSMPRRField.innerHTML === "" || primaryTSMPRRField.innerHTML === " " || primaryTSMPRRField.innerHTML === " ") {
console.log('No Primary PRR TSM');
} else {
$('#00N50000009s6XW_ileinner').addClass("status_positive");
}
} else {
console.log('Primary TSM PRR Field not present');
}
// Account Support Group
if (accountSupportGroupField){
console.log('Account Support Group Field is present');
if (accountSupportGroupField.innerHTML === "") {
accountSupportGroupField.innerHTML = " ";
$("#00N50000003fP3z_ileinner").addClass("status_negative");
} else {
$("#00N50000003fP3z_ileinner").addClass("status_positive");
}
} else {
console.log('Account Support Group Field not present');
}
// Status
if (status){
console.log('Status Field is present');
if (status.innerHTML === "New" || status.innerHTML === "In Progress" || status.innerHTML === "Assigned") {
$('#cas7_ileinner').addClass("status_negative");
} else if(status.innerHTML.substr(0,7) === "Pending") {
$('#cas7_ileinner').addClass("pending");
} else {
$('#cas7_ileinner').addClass("status_positive");
}
} else {
console.log('Status Field not present');
}
// Case Notes
if (caseNotes){
console.log('Case Notes Field is present');
if (caseNotes.innerHTML !== " "){
$('#00N50000002AHM3_ileinner').addClass("status_important");
}
} else {
console.log('Case Notes Field not present');
}
//update Support notes
if (supportNotes){
console.log('Support Notes Field is present');
if (supportNotes.innerHTML !== ""){
$('#00N50000001yx07_ileinner').addClass("status_important");
var alertText = $('#00N50000001yx07_ileinner').text();
alert(alertText);
}
} else {
console.log('Support Notes Field not present');
}
//update last comment, contact name, description
$("#cas3_ileinner").addClass("beautified_comment");
$("#cas15_ileinner").addClass("beautified_comment");
var maxWidth = window.innerWidth - 466;
var maxWidthStr = maxWidth+"px";
// Move Description to it's own table
var descTD = document.getElementById("cas15_ilecell");
var rowIndex = descTD.cellIndex;
var descRow = descTD.parentElement;
var labelTD = descRow.cells[rowIndex-1];
var TDTR = descTD.parentElement;
var TRTB = TDTR.parentElement;
var TBTable = TRTB.parentElement;
var TableDiv = TBTable.parentElement;
// create a new table and append to original
var tableDesc = document.createElement('table');
tableDesc.classList.add('detailList');
TableDiv.appendChild(tableDesc);
var row = tableDesc.insertRow();
var cell1 = row.insertCell(0);
var cell2 = row.insertCell(1);
cell1.classList.add("addedFieldCol");
$(".addedFieldCol").replaceWith(labelTD);
cell2.classList.add("addedValueCol");
$(".addedValueCol").replaceWith(descTD);
TBTable.parentNode.insertBefore(tableDesc, TBTable.nextSibling);
// Fix container breaking
document.getElementById('ep').style.maxWidth = window.innerWidth - 416 + "px";
document.getElementById('bodyCell').style.maxWidth = window.innerWidth - 416 + "px";
document.getElementById('cas15_ileinner').style.maxWidth = window.innerWidth - 525 + "px";
document.getElementById('cas15_ileinner').style.width = window.innerWidth - 525 + "px";
document.getElementById('cas15_ileinner').style.minWidth = "465px";
document.getElementById('cas15_ileinner').style.wordWrap = "break-word";
$(window).resize(function () {
document.getElementById('ep').style.maxWidth = window.innerWidth - 416 + "px";
document.getElementById('bodyCell').style.maxWidth = window.innerWidth - 416 + "px";
document.getElementById('cas15_ileinner').style.maxWidth = window.innerWidth - 525 + "px";
document.getElementById('cas15_ileinner').style.width = window.innerWidth - 525 + "px";
document.getElementById('cas15_ileinner').style.minWidth = "465px";
});
}
var placeDiv = true;
function descriptionImage(){
var description = document.getElementById('cas15_ileinner').innerHTML;
var creationDate = document.getElementById('CreatedDate_ileinner').innerHTML;
if(description.indexOf('[cid:')!= -1){
var descnumOccurs = description.split('[cid:').length -1;
for(var z = 0; z <= descnumOccurs; z++){
var dateString = 0;
var descimagePos = description.indexOf('[cid:');
var descimagePosEnd = description.indexOf(']',descimagePos);
var descstr = description.substr(descimagePos,descimagePosEnd-descimagePos+1);//this is the full html that needs to be replaced
var descimageName = descstr.substr(descstr.indexOf(':')+1,descstr.indexOf('@')-descstr.indexOf(':')-1);
var adjusteddescimageName = descimageName.split('<a href=\"mailto:').pop();
var descanchors = document.getElementsByClassName('actionLink');
for(var w = 0; w < descanchors.length; w++){
if(descanchors[w].title.indexOf(adjusteddescimageName) != -1 && descanchors[w].target === "_blank" && descanchors[w].parentNode.parentNode.children[4].innerHTML === creationDate){
console.log('something fit this desc');
var descimageSrc = descanchors[w].href;
document.getElementById('cas15_ileinner').innerHTML = document.getElementById('cas15_ileinner').innerHTML.replace(descstr,"<div style='max-width:100%'><a target='_blank' href='"+descimageSrc+"'><img style='max-width:100%' src='"+descimageSrc+"'></a></div>");
}
}
}
}
}
//updates case comments to be more readable
function updateComments() {
var viewImages = "javascript:RelatedList.get('" + document.location.pathname.substr(1) + "_RelatedAttachmentList').showXMore(100)";
console.log('viewImages: ',viewImages);
var hiddenBtn = document.createElement('a');
hiddenBtn.id = "hiddenBtn";
hiddenBtn.href = viewImages;
hiddenBtn.style.visibility = "hidden";
if(placeDiv === true){
document.getElementById('sessiontimeout').insertBefore(hiddenBtn,null);
placeDiv = false;
}
var comments = document.getElementsByClassName("dataCell");
//beautify comments & add images
for (var i = 0; i < comments.length; i++){
if (comments[i].innerHTML.substr(0,14) === "<b>Created By:"){
comments[i].className += " beautified_comment";
//get Date of Comment
var dateStart = comments[i].innerHTML.indexOf('(')+1;
var dateLength = comments[i].innerHTML.indexOf(')') - dateStart;
var commentDate = comments[i].innerHTML.substr(dateStart,dateLength);
if(comments[i].innerHTML.indexOf('[cid:')!= -1){ //change to while?
var numOccurs = comments[i].innerHTML.split('[cid:').length -1;
for(var k = 0; k <= numOccurs; k++){
var imagePos = comments[i].innerHTML.indexOf('[cid:');
var imagePosEnd = comments[i].innerHTML.indexOf(']',imagePos);
var str = comments[i].innerHTML.substr(imagePos,imagePosEnd-imagePos+1);
var imageName = str.substr(str.indexOf(':')+1,str.indexOf('@')-str.indexOf(':')-1);
console.log(imageName);
var anchors = document.getElementsByClassName('actionLink');
for(var j = 0; j < anchors.length; j++){
if(anchors[j].title.indexOf(imageName) != -1 && anchors[j].target === "_blank" && anchors[j].parentNode.parentNode.children[4].innerHTML === commentDate){
document.getElementById('hiddenBtn').click();console.log('click');
var imageSrc = anchors[j].href;
comments[i].innerHTML = comments[i].innerHTML.replace(str,"<div style='max-width:100%'><a target='_blank' href='"+imageSrc+"'><img style='max-width:100%' src='"+imageSrc+"'></a></div>");
}
}
}
}
}
}
}
//create infobar container
var infoBar = document.createElement("div");
infoBar.id = "infoBar";
document.getElementsByTagName('body')[0].appendChild(infoBar);
infoBar.style.width = "99%";
infoBar.style.height = "55px";
//create and add JIRA button
var jiraButton = document.createElement("input");
jiraButton.id = "jiraButton";
jiraButton.setAttribute("class","btn");
jiraButton.setAttribute("type","button");
jiraButton.setAttribute("name","JIRA");
jiraButton.setAttribute("value","New JIRA");
jiraButton.setAttribute("onclick","window.open(\"https://bits.bazaarvoice.com/jira/secure/Dashboard.jspa\",\"_blank\");");
document.getElementById("topButtonRow").insertBefore(jiraButton,null);
//populate infobar
function createInfoBar(){
var contactPhone, cluster, csdName, tamName, caseCreationDate;
var currentLocalDate = new Date();
var contactPhoneField = document.getElementById('cas9_ileinner');
var clusterField = document.getElementById('00N50000001yzHK_ileinner');
var CSDField = document.getElementById('00N50000001yTBP_ileinner');
var TAMField = document.getElementById('00N50000002D3bq_ileinner');
var clientName = document.getElementById('cas4_ileinner').childNodes[0].innerHTML;
var caseTitle = document.getElementById('cas14_ileinner').innerHTML;
var slaStatus = document.getElementById('00N50000002Cffz_ileinner').innerHTML;
var bvTime = document.getElementById('00N50000002yQKN_ileinner').innerHTML;
var contactName = document.getElementById('cas3_ileinner').children[0].innerHTML;
// Contact Phone field
if (contactPhoneField){
console.log('Contact Phone Field is present');
if (contactPhoneField.innerHTML !== " "){
contactPhone = contactPhoneField.innerHTML;
} else {
contactPhone = "No Contact Number in SF";
}
} else {
console.log('Contact Phone Field not present');
}
// Cluster field
if (clusterField){
console.log('Cluster Field is present');
if(clusterField.innerHTML !== " "){
cluster = clusterField.innerHTML.toUpperCase();
} else {
cluster = "No Cluster Info in SF";
}
} else {
console.log('Cluster Field not present');
}
// CSD field
if (CSDField){
console.log('CSD Field is present');
if(CSDField.innerHTML !== " "){
csdName = CSDField.innerHTML;
} else {
csdName = "No CSD Info in SF";
}
} else {
console.log('CSD Field not present');
}
// TAM field
if (TAMField){
console.log('Tam Field is present');
if(TAMField.innerHTML !== ""){
tamName = TAMField.innerHTML;
} else {
tamName = "No TAM Info in SF";
}
} else {
console.log('TAM Field not present');
}
//check for milestone
var iDateDiff, milestoneTTCR, TTCRStatus, milestoneTTFR, TTFRStatus, milestoneTTSR, TTSRStatus, TTCRInfo, TTFRInfo, TTSRInfo, milestoneBodyID;
var timeTitle = [];
var timeRemain = [];
var timeStatus = [];
var milestoneArray = [];
var milestoneListID = document.getElementsByClassName('listHoverLinks')[0].children[0].id;
milestoneBodyID = milestoneListID.substr(0,milestoneListID.length-4);
milestoneBodyID += "body";
if(document.getElementById(milestoneBodyID).children[0].children[0].children[0].children[0].innerHTML !== "No records to display"){
var children = document.getElementById(milestoneBodyID).children[0].children[0].children;
for (var i = 0,len=children.length; i < len; i++) {
milestoneArray[i] = children[i];
// Do stuff
console.log('Milestone: ',milestoneArray[i].children[1].innerText,' Time Remaining: ',milestoneArray[i].children[3].innerHTML);
timeTitle[i] = milestoneArray[i].children[1].innerText;
timeRemain[i] = milestoneArray[i].children[3].innerHTML;
console.log("6th column(violation): ",$(milestoneArray[i].children[5].children[0]).attr('title'));
console.log("7th column(completed): ",$(milestoneArray[i].children[6].children[0]).attr('title'));
if(timeRemain[i] !== undefined){
if(timeRemain[i] === "00:00" && $(milestoneArray[i].children[5].children[0]).attr('title') !== ""){
timeStatus[i] = "OUT";
} else if(timeRemain[i] === "00:00" && $(milestoneArray[i].children[5].children[0]).attr('title') === ""){
timeStatus[i] = "COMPLETED";
} else if(timeRemain[i].substr(0,timeRemain[i].length -3) < 17){
timeStatus[i] = "ALMOST";
} else {
timeStatus[i] = "IN";
}
}
}
}
//add data to infobar
$('#infoBar').append("<div class='infoBarCenter'>"+clientName+"<br>"+cluster+" - "+caseTitle+"</div>");
var timeInfo = "<div class='infoBarLeft'>";
for (var j = 1, leng = timeTitle.length;j<leng;j++){
timeInfo+="<span>"+timeTitle[j]+": "+timeRemain[j]+" Status: </span><span class='"+timeStatus[j]+"'>"+timeStatus[j]+"</span></br>";
}
timeInfo+="</div>";
$('#infoBar').append(timeInfo);
$('#infoBar').append("<div class='infoBarRight'><select id='selectFontSize' style='margin-right: 25px;'><option value='large'>Large</option><option value='medium'>Medium</option><option value='small'>Small</option><option value='x-small'>X-Small</option><option value='xx-small'>XX-Small</option><option value='15px' selected>15px</option><option value='14px'>14px</option></select>"+"Contact Name: "+contactName+"<br><img width='16' height='10' src='/img/btn_nodial_inline.gif'> "+contactPhone+"<br>CSD: "+csdName+" - TAM: "+tamName+"</div>");
$(".ALMOST").css("color","#CD5C5C");
$(".COMPLETED").css("color","#00FF00");
$(".OUT").css("color","#CD5C5C");
$(".OUT").css("font-weight","900");
} //end createInfoBar
checkImportantFields();
//try to populate infoBar until successful
var infoBarInterval = setInterval(function(){
try{
createInfoBar();
clearInterval(infoBarInterval);
} catch(e){}},500);
//try to update comments until successful
//window.onload = setTimeout(updateComments,1200);
var intCount = 0;
var updateCommentsInterval = setInterval(function(){
updateComments();
descriptionImage();
intCount++;
if(document.getElementsByClassName('beautified_comment').length > 3 || intCount === 12){
clearInterval(updateCommentsInterval);
}
},100);
}//end block
//Hide infoBar when at top of page
$(window).scroll(function() {
if(window.scrollY < 120){
$('#infoBar').fadeOut();
} else{
$('#infoBar').slideDown();
}
});