Subversion Repositories SmartDukaan

Rev

Rev 35626 | Rev 36040 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
27410 tejbeer 1
var TEAM_ACTIVITY = ["COMMUNICATION_OUT", "COMMUNICATION_INTERNAL",
2
	"ESCALATED", "ASSIGNED", "CATEGORY_CHANGED"];
35569 amit 3
 
4
// Activity type constants for consistent usage
5
var ActivityType = {
6
	OPENED: "OPENED",
7
	COMMUNICATION_IN: "COMMUNICATION_IN",
8
	COMMUNICATION_OUT: "COMMUNICATION_OUT",
9
	COMMUNICATION_INTERNAL: "COMMUNICATION_INTERNAL",
10
	RESOLVED: "RESOLVED",
11
	RESOLVED_ACCEPTED: "RESOLVED_ACCEPTED",
12
	RESOLVED_REJECTED: "RESOLVED_REJECTED",
13
	ESCALATED: "ESCALATED",
14
	ASSIGNED: "ASSIGNED",
15
	CATEGORY_CHANGED: "CATEGORY_CHANGED"
16
};
17
 
18
// Helper function to normalize boolean values from various sources
19
function toBool(val) {
20
	return val === true || val === "true";
21
}
22
 
23
// Helper function to escape HTML and prevent XSS
24
function escapeHtml(text) {
25
	if (text == null) return '';
26
	var div = document.createElement('div');
27
	div.textContent = text;
28
	return div.innerHTML;
29
}
30
 
24417 govind 31
$(function() {
32
 
27754 amit.gupta 33
	$(document).on('click', ".create-ticket-category", function() {
24417 govind 34
		console.log("create ticket category clicked......");
35
		loadCreateCategory("main-content");
36
	});
27754 amit.gupta 37
	$(document).on('click', ".create-region", function() {
24417 govind 38
		loadCreateRegion("main-content");
39
	});
27755 amit.gupta 40
	$(document).on('click', "#manager-ticket-search-by-partner-name",
27410 tejbeer 41
		function() {
35626 amit 42
			if ($("#manager-ticket-content-area").length) {
43
				refreshManagerTicketTable(0);
44
			} else if ($("#partner-ticket-content-area").length) {
45
				refreshPartnerTicketTable();
27410 tejbeer 46
			}
47
		});
27755 amit.gupta 48
	$(document).on('click', "#retailer-details-search-button-by-ticketId",
27410 tejbeer 49
		function() {
50
			var searchContent = $("#search-by-ticketId").val();
51
			if (searchContent == "" || searchContent == undefined
52
				|| searchContent == null) {
53
				alert("Input field can't be empty");
54
				return false;
55
			}
35626 amit 56
			if ($("#manager-ticket-content-area").length) {
57
				refreshManagerTicketTable(0);
58
			} else if ($("#partner-ticket-content-area").length) {
59
				refreshPartnerTicketTable();
60
			}
27410 tejbeer 61
		});
27755 amit.gupta 62
	$(document).on('click', "#assignee-ticket-search-by-partner-name",
27410 tejbeer 63
		function() {
35626 amit 64
			refreshMyTicketTable(0);
27410 tejbeer 65
		});
27755 amit.gupta 66
	$(document).on('click', "#assignee-retailer-details-search-button-by-ticketId",
27410 tejbeer 67
		function() {
68
			var searchContent = $("#assignee-search-by-ticketId").val();
69
			if (searchContent == "" || searchContent == undefined
70
				|| searchContent == null) {
71
				alert("Input field can't be empty");
72
				return false;
73
			}
35626 amit 74
			refreshMyTicketTable(0);
27410 tejbeer 75
		});
24787 govind 76
 
35592 amit 77
	$(document).on('click', ".ticket-last-activity", function() {
24620 govind 78
		var ticketId = $(this).data('ticketid');
79
		var activity = $(this).data('activity');
35594 amit 80
		var partnerName = $(this).data('partnername') || '';
24620 govind 81
		console.log(ticketId);
82
		console.log(activity);
35594 amit 83
		var message = partnerName ? "Mark Ticket #" + ticketId + " - " + partnerName + " as resolved?" : "Are you sure!";
84
		if (confirm(message) == true) {
24620 govind 85
			createLastActivity(ticketId, activity);
86
		}
87
	});
24471 govind 88
 
27754 amit.gupta 89
	$(document).on('change', "#region", function() {
24620 govind 90
		var regionId = $("#region").val();
24557 govind 91
		console.log(regionId);
92
		loadPartnerForRegion(regionId);
93
	});
25570 tejbeer 94
 
27754 amit.gupta 95
	$(document).on('change', "#regionPosition", function() {
25570 tejbeer 96
		var regionId = $("#regionPosition").val();
97
		console.log(regionId);
98
		loadPartnerForRegionId(regionId);
99
	});
100
 
27754 amit.gupta 101
	$(document).on('change', "#managersearchType", function() {
24747 govind 102
		var searchType = $("#managersearchType").val();
103
		console.log(searchType);
104
		var html;
105
		if (searchType == "PARTNER_NAME") {
106
			$('.byPartnerName').css('display', 'inline-block');
107
			$('.byTicketId').css('display', 'none');
108
			$("#search-by-ticketId").val("");
109
		} else {
110
			$('.byPartnerName').css('display', 'none');
111
			$('.byTicketId').css('display', 'inline-block');
24824 govind 112
			$('#manager-ticket-search-by-partner-name').data('id', "");
24747 govind 113
		}
24557 govind 114
 
24747 govind 115
	});
27754 amit.gupta 116
	$(document).on('change', "#assigneesearchType", function() {
24787 govind 117
		var searchType = $("#assigneesearchType").val();
118
		console.log(searchType);
119
		var html;
120
		if (searchType == "PARTNER_NAME") {
121
			$('.assigneebyPartnerName').css('display', 'inline-block');
122
			$('.assigneebyTicketId').css('display', 'none');
123
			$("#assignee-search-by-ticketId").val("");
124
		} else {
125
			$('.assigneebyPartnerName').css('display', 'none');
126
			$('.assigneebyTicketId').css('display', 'inline-block');
24824 govind 127
			$("#assignee-ticket-search-by-partner-name").data('id', '');
24787 govind 128
		}
24747 govind 129
 
24787 govind 130
	});
131
 
31762 tejbeer 132
	$(document).on('click', ".change-ticket-auth-button",
133
		function() {
134
			var ticketId = $("#ticketId").val();
135
			var subCategory = $("#subCategory").val();
136
			var authUserId = $("#authUserCategory").val();
137
			var categoryId = $("#categoryAuth").val();
138
 
139
			var escalationType = $("#escalationType").val();
140
			console.log(ticketId);
141
			if (subCategory == null || subCategory == ""
142
				|| subCategory == undefined) {
143
				alert("Choose appropriate subCategory");
144
				return false;
145
			}
146
			console.log(subCategory);
147
			console.log(authUserId);
148
 
149
			console.log(categoryId);
150
 
151
			if (confirm("Are you sure you want to change ticket!") == true) {
152
				changeTicket(ticketId, subCategory, authUserId,
153
					categoryId, escalationType);
154
			}
155
		});
156
 
27755 amit.gupta 157
	$(document).on('click', ".change-ticket-button",
31762 tejbeer 158
		function() {
159
			var ticketId = $("#ticketId").val();
160
			var subCategory = $("#subCategory").val();
161
			var authUserId;
162
			var categoryId = $("#category").val();
163
 
164
			var escalationType = $("#escalationType").val();
165
			console.log(ticketId);
166
			if (subCategory == null || subCategory == ""
167
				|| subCategory == undefined) {
168
				alert("Choose appropriate subCategory");
169
				return false;
170
			}
171
 
172
			console.log(subCategory);
173
 
174
			console.log(categoryId);
175
			console.log(authUserId);
176
			if (confirm("Are you sure you want to change ticket!") == true) {
177
				changeTicket(ticketId, subCategory, authUserId,
178
					categoryId, escalationType);
179
			}
180
		});
34913 ranu 181
 
182
	$(document).on('click', ".change-partner-ticket-button",
183
		function () {
184
			var ticketId = $("#ticketId").val();
185
			var subCategory = $("#subCategory").val();
186
			var authUserId;
187
			var categoryId = $("#category").val();
188
 
189
			var escalationType = $("#escalationType").val();
190
			console.log(ticketId);
191
			if (subCategory == null || subCategory == ""
192
				|| subCategory == undefined) {
193
				alert("Choose appropriate subCategory");
194
				return false;
195
			}
196
 
197
			console.log(subCategory);
198
 
199
			console.log(categoryId);
200
			console.log(authUserId);
201
			if (confirm("Are you sure you want to change ticket!") == true) {
202
				changeMyPartnerTicket(ticketId, subCategory, authUserId,
203
					categoryId, escalationType);
204
			}
205
		});
35592 amit 206
	$(document).on('click', ".edit-ticket", function() {
24471 govind 207
		var ticketId = $(this).data('ticketid1');
24467 govind 208
		loadEditTicket(ticketId);
24439 govind 209
	});
34913 ranu 210
 
35592 amit 211
	$(document).on('click', ".edit-ticket-partner", function () {
34913 ranu 212
		var ticketId = $(this).data('ticketid1');
213
		loadMyPartnerEditTicket(ticketId);
214
	});
215
 
27754 amit.gupta 216
	$(document).on('click', ".manager-ticket", function() {
24747 govind 217
		loadManagerTicket("main-content", null, null);
24439 govind 218
	});
27754 amit.gupta 219
	$(document).on('click', ".access-management", function() {
26014 amit.gupta 220
		loadAccessManagement("main-content", null, null);
221
	});
27754 amit.gupta 222
	$(document).on('click', ".ticketType", function() {
24534 govind 223
		console.log("create Region");
24417 govind 224
		loadCreateRegion("main-content");
225
	});
35592 amit 226
	$(document).on('click', ".activities-link", function() {
24417 govind 227
		var ticketId = $(this).data('ticketid');
228
		var assignee = $(this).data('assignee');
24824 govind 229
		var internal = $(this).data('internal');
230
		var roleType = $(this).data('role');
35569 amit 231
		var isCrmUser = $(this).data('crm');
24417 govind 232
		console.log(assignee);
35569 amit 233
		loadActivities(ticketId, assignee, internal, roleType, isCrmUser);
24417 govind 234
	});
27754 amit.gupta 235
	$(document).on('click', ".my-ticket", function() {
24824 govind 236
		loadMyTicket("main-content", null, null, null, null, null);
24417 govind 237
	});
27754 amit.gupta 238
	$(document).on('click', "#close-ticket", function() {
24417 govind 239
		var ticketId = $(this).data('ticketid');
24439 govind 240
		closeTicket(ticketId);
24417 govind 241
	});
27410 tejbeer 242
 
27754 amit.gupta 243
	$(document).on('change', '.partners', function() {
27410 tejbeer 244
		console.log("Hello");
245
	});
27270 tejbeer 246
	var documentIds = [];
247
	var count = 0;
248
 
27755 amit.gupta 249
	$(document).on('click', ".submit-message-button",
27410 tejbeer 250
		function() {
251
			var message = $("#activityMessage").val();
252
			var internal = $("#internalCommunication").prop("checked");
253
			if (message == "" || message == null || message == undefined) {
254
				alert("message field can't be empty");
255
				return false;
256
			}
257
			var ticketId = $("#ticketIdforactivity").val();
258
			var assignee = $("#assigneeUser").val();
259
			var roleType = $("#role").val();
35569 amit 260
			var isCrmUser = $("#crmUser").val();
27410 tejbeer 261
			count = 0;
262
			console.log(message, ticketId, assignee);
27285 tejbeer 263
 
35569 amit 264
			createActivity(message, ticketId, assignee, internal, roleType, isCrmUser,
27410 tejbeer 265
				documentIds);
266
		});
27270 tejbeer 267
 
27754 amit.gupta 268
	$(document).on('click', ".uploadFile", function() {
27270 tejbeer 269
		$("#file1").trigger('click');
24417 govind 270
	});
271
 
27755 amit.gupta 272
	$(document).on('change', "input[name=file1]",
31762 tejbeer 273
		function(evt) {
274
			var output = [];
275
			var fileBundle = [];
276
			for (var i = 0, f; f = evt.target.files[i]; i++) {
277
				count++;
278
				console.log(count);
279
				if (evt.target.files[i].size > 5000000) {
280
					alert("Size should be less than 5MB");
281
					return false;
282
				}
27270 tejbeer 283
 
31762 tejbeer 284
				if (count > "5") {
285
					alert("five files send at a time");
286
					var lilength = $('.fileList li').size();
287
					console.log(lilength);
288
					count = lilength;
289
					console.log(lilength)
290
					return false;
291
				}
27270 tejbeer 292
 
31762 tejbeer 293
				var file = evt.target.files[i];
294
				fileBundle.push(file);
295
				console.log(fileBundle);
27270 tejbeer 296
 
31762 tejbeer 297
				var removeLink = "<a class=\"removeFile\" href=\"#\" data-fileid=\""
298
					+ i + "\">Remove</a>";
27270 tejbeer 299
 
31762 tejbeer 300
				output.push("<li><strong>", file.name,
301
					"</strong> - ", "&nbsp; &nbsp; ",
302
					removeLink, "</li> ");
27270 tejbeer 303
 
31762 tejbeer 304
			}
27270 tejbeer 305
 
31762 tejbeer 306
			for (var j = 0; j < fileBundle.length; j++) {
307
				console.log(fileBundle[j])
308
				var url = context + '/document-upload';
309
				doAjaxUploadRequestHandler(
310
					url,
311
					'POST',
312
					fileBundle[j],
313
					function(response) {
314
						console.log(response);
315
						var documentId = response.response.document_id;
316
						console.log("documentId : "
317
							+ documentId);
318
						documentIds.push(documentId);
27270 tejbeer 319
 
31762 tejbeer 320
					});
27270 tejbeer 321
 
31762 tejbeer 322
			}
323
			console.log(documentIds);
324
			$(".fileList").append(output.join(""));
27270 tejbeer 325
 
31762 tejbeer 326
		});
27270 tejbeer 327
 
27754 amit.gupta 328
	$(document).on('click', ".removeFile", function(e) {
27270 tejbeer 329
		e.preventDefault();
27285 tejbeer 330
		console.log("Hello")
27270 tejbeer 331
		var fileId = $(this).parent().children("a").data("fileid");
27285 tejbeer 332
		for (var i = 0; i < documentIds.length; ++i) {
333
			if (documentIds[i].id === fileId)
334
				documentIds.splice(i, 1);
335
		}
336
		console.log(documentIds)
337
		$(this).parent().remove();
338
		var lilen = $('.fileList li').size();
27270 tejbeer 339
 
27285 tejbeer 340
		count = lilen;
341
		console.log(count)
342
		/*
343
		 * var lilength = $('.fileList li').size(); if (lilength == 1) {
344
		 * console.log(lilength) $(".fileList li").remove(); } else {
345
		 * console.log(lilength) $(".fileList li").eq(fileId).remove(); } var
346
		 * lilen = $('.fileList li').size();
347
		 * 
348
		 * count = lilen; console.log(count)
349
		 * 
350
		 * console.log(documentIds);
351
		 */
27270 tejbeer 352
 
353
	});
354
 
35626 amit 355
	// AJAX pagination for My Ticket
356
	$(document).on('click', "#ticket-content-area .ticket-page-link", function(e) {
357
		e.preventDefault();
358
		refreshMyTicketTable($(this).data('page'));
359
	});
360
	$(document).on('change', "#ticket-content-area .ticket-page-size", function() {
361
		refreshMyTicketTable(0);
362
	});
24417 govind 363
 
35626 amit 364
	// AJAX pagination for Manager Ticket
365
	$(document).on('click', "#manager-ticket-content-area .manager-ticket-page-link", function(e) {
366
		e.preventDefault();
367
		refreshManagerTicketTable($(this).data('page'));
368
	});
369
	$(document).on('change', "#manager-ticket-content-area .manager-ticket-page-size", function() {
370
		refreshManagerTicketTable(0);
371
	});
24747 govind 372
 
35626 amit 373
	// AJAX pagination for Partner Ticket
374
	$(document).on('click', "#partner-ticket-content-area .partner-ticket-page-link", function(e) {
375
		e.preventDefault();
376
		refreshPartnerTicketTable();
377
	});
24699 govind 378
 
35626 amit 379
	// Search form handlers
380
	$(document).on('submit', "#ticket-search-form", function(e) {
381
		e.preventDefault();
382
		refreshMyTicketTable(0);
383
	});
384
	$(document).on('click', "#ticket-search-btn", function() {
385
		refreshMyTicketTable(0);
386
	});
387
	$(document).on('click', "#ticket-search-clear", function() {
388
		$("#ticket-search-input").val('');
389
		$(this).hide();
390
		refreshMyTicketTable(0);
391
	});
24467 govind 392
 
35626 amit 393
	$(document).on('submit', "#manager-ticket-search-form", function(e) {
394
		e.preventDefault();
395
		refreshManagerTicketTable(0);
396
	});
397
	$(document).on('click', "#manager-ticket-search-btn", function() {
398
		refreshManagerTicketTable(0);
399
	});
400
	$(document).on('click', "#manager-ticket-search-clear", function() {
401
		$("#manager-ticket-search-input").val('');
402
		$(this).hide();
403
		refreshManagerTicketTable(0);
404
	});
27755 amit.gupta 405
	$(document).on('click', "#positions-paginated .next",
27410 tejbeer 406
		function() {
407
			loadPaginatedNextItems('/cs/position-paginated', null,
408
				'positions-paginated', 'position-table',
409
				'position-details-container');
410
			$(this).blur();
411
		});
24417 govind 412
 
27755 amit.gupta 413
	$(document).on('click', "#positions-paginated .previous",
27410 tejbeer 414
		function() {
415
			loadPaginatedPreviousItems('/cs/position-paginated', null,
416
				'positions-paginated', 'position-table',
417
				'position-details-container');
418
			$(this).blur();
419
		});
24471 govind 420
 
27754 amit.gupta 421
	$(document).on('click', ".create-partner-region", function() {
24417 govind 422
		loadCreatePartnerRegion("main-content");
423
	});
27754 amit.gupta 424
	$(document).on('click', ".create-ticket", function() {
24417 govind 425
		loadCreateTicket("main-content");
426
	});
34913 ranu 427
 
428
	$(document).on('click', ".my-partner-ticket", function () {
429
		loadMyPartnerTicket("main-content");
430
	});
27755 amit.gupta 431
	$(document).on('click', ".create-ticket-button",
31762 tejbeer 432
		function() {
433
			var categoryId = $('#category').val();
434
			var subCategoryId = $('#subCategory').val();
35592 amit 435
			var message = $('#message').val();
436
 
437
			if (categoryId == "" || categoryId == null || categoryId == undefined) {
438
				alert("Please select a category");
31762 tejbeer 439
				return false;
440
			}
35592 amit 441
			if (subCategoryId == "" || subCategoryId == null || subCategoryId == undefined) {
442
				alert("Please select a subcategory");
31762 tejbeer 443
				return false;
444
			}
35592 amit 445
			if (message == "" || message == null || message == undefined || message.trim() == "") {
446
				alert("Please describe your issue");
447
				$('#message').focus();
448
				return false;
449
			}
24417 govind 450
 
35592 amit 451
			if (confirm("Are you sure you want to create this ticket?")) {
452
				var params = {
453
					"categoryId": categoryId,
454
					"subCategoryId": subCategoryId,
455
					"message": message
456
				};
457
				doPostAjaxRequestWithParamsHandler(
458
					context + "/cs/createTicket",
459
					params,
460
					function(response) {
461
						if (response == "true") {
462
							alert("Ticket created successfully");
463
							loadCreateTicket("main-content");
464
						} else {
465
							alert("You have reached maximum number of unresolved tickets. Please accept resolution for resolved tickets to create new ones.");
27410 tejbeer 466
						}
35592 amit 467
					});
468
			}
31762 tejbeer 469
		});
27754 amit.gupta 470
	$(document).on('click', ".create-position", function() {
24417 govind 471
		loadCreatePosition("main-content");
472
	});
473
 
27754 amit.gupta 474
	$(document).on('click', ".positionPartnerView", function() {
27410 tejbeer 475
		$clickedElement = $(this);
476
		var positionId = $clickedElement.data("positionid");
477
		$tdElement = $(this).closest('td');
478
		doGetAjaxRequestHandler(context + "/cs/getPosition?positionId=" + positionId, function(response) {
31762 tejbeer 479
 
27410 tejbeer 480
			$tdElement.html(response);
481
			$tdElement.find('.partners').multiselect({
482
				includeSelectAllOption: true,
483
				multiple: true,
484
				maxHeight: 200,
485
				buttonWidth: '180px',
486
				numberDisplayed: 1,
487
				nonSelectedText: 'Partners',
488
				nSelectedText: ' - Users Selected',
489
				allSelectedText: 'All Users Selected',
490
				enableFiltering: true,
491
				enableCaseInsensitiveFiltering: true
492
			});
493
		});
494
	});
495
 
496
 
35626 amit 497
	$(document).on('change', "#ticketStatus", function() {
498
		refreshMyTicketTable(0);
499
	});
500
	$(document).on('change', "#orderBy", function() {
501
		refreshMyTicketTable(0);
502
	});
503
	$(document).on('change', "#managerTicketStatus", function() {
504
		// Check if we're on manager ticket page or partner ticket page
505
		if ($("#manager-ticket-content-area").length) {
506
			refreshManagerTicketTable(0);
507
		} else if ($("#partner-ticket-content-area").length) {
508
			refreshPartnerTicketTable();
509
		}
510
	});
511
	$(document).on('change', "#managerTicketorderBy", function() {
512
		if ($("#manager-ticket-content-area").length) {
513
			refreshManagerTicketTable(0);
514
		} else if ($("#partner-ticket-content-area").length) {
515
			refreshPartnerTicketTable();
516
		}
517
	});
27754 amit.gupta 518
	$(document).on('change', "#category", function() {
24417 govind 519
		var categoryId = $("#category").val();
31762 tejbeer 520
		//	$("#auth-user-for-category").hide();
24417 govind 521
		loadSubCategories(categoryId);
522
	});
31762 tejbeer 523
 
524
	$(document).on('change', "#authUserCategory", function() {
525
		var authId = $("#authUserCategory").val();
526
		console.log(authId)
527
		loadCategories(authId);
528
	});
529
 
530
	$(document).on('change', "#categoryAuth", function() {
531
		var categoryId = $("#categoryAuth").val();
532
		var authId = $("#authUserCategory").val();
533
 
534
		console.log(categoryId)
535
		loadAuthSubCategories(categoryId, authId);
536
	});
537
 
538
 
33081 ranu 539
	$(document).on('click', ".create-ticket-category-button", function () {
540
		console.log("create-ticket-category-button clicked......");
541
 
542
		var name = $("#categoryName").val();
543
		var description = $("#categorydescription").val();
544
		var categoryType = $("#categoryType").is(":checked") ? 1 : 0;
545
 
546
		console.log('cccccccccccccc', name, description, categoryType);
547
 
548
		if (name === "" || name === null || name === undefined) {
549
			alert("Name field can't be empty");
550
			return false;
551
		}
552
 
553
		if (description === "" || description === null || description === undefined) {
554
			alert("Description field can't be empty");
555
			return false;
556
		}
557
 
558
		if (confirm("Are you sure you want to create a ticket category?")) {
559
			createCategory("main-content", name, description, categoryType);
560
		}
561
	});
562
 
27755 amit.gupta 563
	$(document).on('click', ".create-region-button",
31762 tejbeer 564
		function() {
565
			var name = $("#regionName").val();
566
			var description = $("#regiondescription").val();
567
			if (name == "" || name == null || name == undefined) {
568
				alert("Name field can't be empty");
569
				return false;
570
			}
571
			if (description == "" || description == null
572
				|| description == undefined) {
573
				alert("Description field can't be empty");
574
				return false;
575
			}
576
			if (confirm("Are you sure you want to create region!") == true) {
577
				createRegion("main-content", name, description);
578
			}
579
		});
24417 govind 580
 
27755 amit.gupta 581
	$(document).on('click', ".create-partner-region-button",
31762 tejbeer 582
		function() {
24417 govind 583
 
31762 tejbeer 584
			var regionId = $("#region").val();
585
			var fofoIds = $("#partner").val();
586
			console.log(regionId, fofoIds);
587
			if (regionId == "" || regionId == null
588
				|| regionId == undefined) {
589
				alert("regionId field can't be empty");
590
				return false;
591
			}
592
			if (fofoIds == "" || fofoIds == null
593
				|| fofoIds == undefined) {
594
				alert("select appropriate partner");
595
				return false;
596
			}
597
			if (confirm("Are you sure you want to create partner region!") == true) {
598
				createPartnerRegion("main-content", regionId,
599
					fofoIds);
600
			}
601
		});
27755 amit.gupta 602
	$(document).on('click', ".create-position-button",
31762 tejbeer 603
		function() {
24417 govind 604
 
31762 tejbeer 605
			var authUser = $("#authUser").val();
606
			var ticketCategoryPosition = $(
607
				"#ticketCategoryPosition").val();
608
			var escalationType = $("#escalationType").val();
609
			var regionPosition = $("#regionPosition").val();
25570 tejbeer 610
 
611
 
31771 tejbeer 612
			let ticketAssignee = $('#ticketAssignee').is(':checked');
613
 
614
 
615
			console.log(ticketAssignee);
31762 tejbeer 616
			var fofoIds = $("#partner").val();
617
			if (fofoIds.includes("0")) {
618
				fofoIds = [0];
619
				console.log(fofoIds);
620
			} else {
621
				console.log(fofoIds);
622
			}
623
			console.log(authUser, ticketCategoryPosition,
624
				escalationType, regionPosition);
625
			if (authUser == "" || authUser == null
626
				|| authUser == undefined) {
627
				alert("select appropriate authUser");
628
				return false;
629
			}
630
			if (ticketCategoryPosition == ""
631
				|| ticketCategoryPosition == null
632
				|| ticketCategoryPosition == undefined) {
633
				alert("select appropriate category");
634
				return false;
635
			}
636
			if (escalationType == "" || escalationType == null
637
				|| escalationType == undefined) {
638
				alert("select appropriate escalationType");
639
				return false;
640
			}
641
			if (regionPosition == "" || regionPosition == null
642
				|| regionPosition == undefined) {
643
				alert("select appropriate Region");
644
				return false;
645
			}
24417 govind 646
 
31762 tejbeer 647
			if (confirm("Are you sure you want to create Position!") == true) {
648
				createPosition("main-content", authUser,
649
					ticketCategoryPosition, escalationType,
31771 tejbeer 650
					regionPosition, fofoIds,
651
					ticketAssignee
652
				);
31762 tejbeer 653
			}
654
 
655
		});
656
 
27754 amit.gupta 657
	$(document).on('change', "#ticketCategory", function() {
24417 govind 658
		console.log("change ticket category clicked......");
659
		var ticketCategoryId = $(this).val();
660
		console.log(ticketCategoryId);
661
		loadticketSubCategoryById(ticketCategoryId);
662
	});
27754 amit.gupta 663
	$(document).on('click', ".create-ticket-sub-category", function() {
24417 govind 664
		console.log("create ticket category clicked......");
665
		loadCreateSubCategory("main-content");
666
	});
667
 
27755 amit.gupta 668
	$(document).on('click', ".create-ticket-sub-category-button",
31762 tejbeer 669
		function() {
670
			console
671
				.log("create-ticket-category-button clicked......");
672
			var name = $("#subcategoryName").val();
673
			var description = $("#subcategorydescription").val();
674
			var ticketCategoryId = $("#ticketCategory").val();
675
			console.log(name, description);
676
			if (name == "" || name == null || name == undefined) {
677
				alert("Name field can't be empty");
678
				return false;
679
			}
680
			if (description == "" || description == null
681
				|| description == undefined) {
682
				alert("Description field can't be empty");
683
				return false;
684
			}
685
			if (ticketCategoryId == "" || ticketCategoryId == null
686
				|| ticketCategoryId == undefined) {
687
				alert("select appropriate category name");
688
				return false;
689
			}
690
			if (confirm("Are you sure you want to create ticket category!") == true) {
691
				createSubCategory("main-content", name,
692
					description, ticketCategoryId);
693
			}
694
		});
27754 amit.gupta 695
	$(document).on('click', ".remove-position", function() {
24471 govind 696
		var positionId = $(this).data('positionid');
697
		if (confirm("Are you sure you want to remove position!") == true) {
24534 govind 698
			removePosition(positionId);
24471 govind 699
		}
700
	});
24417 govind 701
 
31762 tejbeer 702
 
703
	$(document).on('change', "#ticketAssign", function() {
704
		var positionId = $(this).data('positionid');
705
		if (confirm("Are you sure you want to change ticket Assignee !") == true) {
706
			doPostAjaxRequestHandler(context + "/cs/changeTicketAssignee?positionId="
707
				+ positionId, function(response) {
708
					if (response == "true") {
709
						alert("change successfully");
710
						loadCreatePosition("main-content");
711
					}
712
				});
713
		}
714
	});
715
 
716
 
717
 
718
 
27755 amit.gupta 719
	$(document).on('click', ".update-position",
31762 tejbeer 720
		function() {
721
			var positionId = $(this).data('positionid');
722
			var regionId = $(this).data('regionid');
723
			var row = $(this);
724
			var selectedFofoIds = $(this).closest("tr").find(
725
				'#partners').val();
726
			if (selectedFofoIds.includes("0")) {
727
				selectedFofoIds = [0];
728
				console.log(selectedFofoIds);
729
			} else {
730
				console.log(selectedFofoIds);
731
			}
732
			if (confirm("Are you sure you want to update the partners!") == true) {
733
				doPostAjaxRequestWithJsonHandler(context
734
					+ "/cs/updatePartnerPosition?regionId="
735
					+ regionId + "&positionId=" + positionId,
736
					JSON.stringify(selectedFofoIds), function(
737
						response) {
738
					if (response == "true") {
739
						alert("Update successfully");
32885 shampa 740
						//loadCreatePosition("main-content");
31762 tejbeer 741
					}
742
				});
743
			}
25570 tejbeer 744
 
31762 tejbeer 745
		});
27410 tejbeer 746
 
24417 govind 747
});
748
 
749
function loadCreateCategory(domId) {
750
	doGetAjaxRequestHandler(context + "/cs/createCategory", function(response) {
751
		$('#' + domId).html(response);
752
	});
753
}
24534 govind 754
function removePosition(positionId) {
755
	doDeleteAjaxRequestHandler(context + "/cs/removePosition?positionId="
27410 tejbeer 756
		+ positionId, function(response) {
757
			if (response == "true") {
758
				alert("Position removed successfully");
759
				loadCreatePosition("main-content");
760
			}
761
		});
24471 govind 762
}
24417 govind 763
 
764
function loadCreateRegion(domId) {
765
	doGetAjaxRequestHandler(context + "/cs/createRegion", function(response) {
766
		$('#' + domId).html(response);
767
	});
768
}
24824 govind 769
function loadMyTicket(domId, ticketStatus, sortOrder, ticketSearchType,
27410 tejbeer 770
	searchTerm, searchValue) {
24620 govind 771
 
24699 govind 772
	if (ticketStatus == null && sortOrder == null) {
773
		doGetAjaxRequestHandler(context + "/cs/myticket", function(response) {
774
			$('#' + domId).html(response);
775
		});
24824 govind 776
	} else if (ticketSearchType == null) {
24699 govind 777
		doGetAjaxRequestHandler(context + "/cs/myticket?ticketStatus="
27410 tejbeer 778
			+ ticketStatus + "&orderby=" + sortOrder, function(response) {
779
				$('#' + domId).html(response);
780
			});
24824 govind 781
	} else {
782
		doGetAjaxRequestHandler(context + "/cs/myticket?ticketStatus="
27410 tejbeer 783
			+ ticketStatus + "&orderby=" + sortOrder + "&ticketSearchType="
784
			+ ticketSearchType + "&searchTerm=" + searchTerm, function(
24824 govind 785
				response) {
786
			$('#' + domId).html(response);
787
			if (ticketSearchType == "PARTNER_NAME") {
788
				$('.assigneebyPartnerName').css('display', 'inline-block');
789
				$('.assingeebyTicketId').css('display', 'none');
790
				$("#typeaheadpartnernameforassignee").val(searchValue);
791
				$("#assignee-partner-name-input").val(searchTerm);
792
			} else {
793
				$('.assigneebyPartnerName').css('display', 'none');
794
				$('.assigneebyTicketId').css('display', 'inline-block');
795
				$("#assignee-search-by-ticketId").val(searchTerm);
796
			}
24699 govind 797
		});
798
	}
24417 govind 799
}
800
 
801
function loadCreatePartnerRegion(domId) {
802
	doGetAjaxRequestHandler(context + "/cs/createPartnerRegion", function(
27410 tejbeer 803
		response) {
24417 govind 804
		$('#' + domId).html(response);
805
	});
806
}
807
function loadCreatePosition(domId) {
808
	doGetAjaxRequestHandler(context + "/cs/createPosition", function(response) {
809
		$('#' + domId).html(response);
810
	});
811
}
812
function loadSubCategories(categoryId) {
813
	doGetAjaxRequestHandler(context
27410 tejbeer 814
		+ "/cs/getSubCategoriesByCategoryId?categoryId=" + categoryId,
815
		function(response) {
816
			$('#' + "create-ticket-sub-categories").html(response);
817
		});
24417 govind 818
}
31762 tejbeer 819
 
820
function loadCategories(authId) {
821
	doGetAjaxRequestHandler(context
822
		+ "/cs/getCategoriesByAuthId?authId=" + authId,
823
		function(response) {
824
			$('#' + "create-tickets-categories-for-auth").html(response);
825
		});
826
}
827
 
828
function loadAuthSubCategories(categoryId, authId) {
829
	doGetAjaxRequestHandler(context
830
		+ "/cs/getSubCategoriesByCategoryId?categoryId=" + categoryId,
831
		function(response) {
832
			$('#' + "create-ticket-sub-categories-for-auth").html(response);
833
		});
834
 
835
 
836
	doGetAjaxRequestHandler(context
837
		+ "/cs/getEscalationTypeByCategoryId?categoryId=" + categoryId + "&authId=" + authId,
838
		function(response) {
839
			$('#' + "create-ticket-escalationType-for-auth").html(response);
840
		});
841
 
842
 
843
}
844
 
33081 ranu 845
function createCategory(domId, name, description, categoryType) {
24417 govind 846
	var params = {
27410 tejbeer 847
		"name": name,
33081 ranu 848
		"description": description,
849
		"categoryType": categoryType,
850
	};
851
 
852
	doPostAjaxRequestWithParamsHandler(context + "/cs/createCategory", params, function (response) {
853
		alert("Category created successfully");
854
		loadCreateCategory(domId);
855
	});
24417 govind 856
}
33081 ranu 857
 
31762 tejbeer 858
function changeTicket(ticketId, subCategoryId, authUserId, categoryId, escalationType) {
24467 govind 859
	var params = {
27410 tejbeer 860
		"ticketId": ticketId,
861
		"subCategoryId": subCategoryId,
862
		"authUserId": authUserId,
31762 tejbeer 863
		"categoryId": categoryId,
864
		"escalationType": escalationType
24471 govind 865
	}
866
	doPostAjaxRequestWithParamsHandler(context + "/cs/edit-ticket", params,
27410 tejbeer 867
		function(response) {
868
			if (response == "true") {
35604 amit 869
				$('#theModal').modal('hide');
870
				$('body').removeClass('modal-open');
871
				$('.modal-backdrop').remove();
27410 tejbeer 872
				alert("Ticket changed successfully");
35626 amit 873
				if ($("#manager-ticket-content-area").length) {
874
					refreshManagerTicketTable(0);
875
				} else if ($("#ticket-content-area").length) {
876
					refreshMyTicketTable(0);
877
				} else {
878
					loadManagerTicket("main-content", null, null, null, null, null);
879
				}
27410 tejbeer 880
			}
881
		});
24467 govind 882
}
34913 ranu 883
 
884
function changeMyPartnerTicket(ticketId, subCategoryId, authUserId, categoryId, escalationType) {
885
	var params = {
886
		"ticketId": ticketId,
887
		"subCategoryId": subCategoryId,
888
		"authUserId": authUserId,
889
		"categoryId": categoryId,
890
		"escalationType": escalationType
891
	}
892
	doPostAjaxRequestWithParamsHandler(context + "/cs/edit-partner-ticket", params,
893
		function (response) {
894
			if (response == "true") {
35604 amit 895
				$('#theModal2').modal('hide');
896
				$('body').removeClass('modal-open');
897
				$('.modal-backdrop').remove();
34913 ranu 898
				alert("Ticket changed successfully");
35626 amit 899
				if ($("#partner-ticket-content-area").length) {
900
					refreshPartnerTicketTable();
901
				} else {
902
					loadMyPartnerTicket("main-content");
903
				}
34913 ranu 904
			}
905
		});
906
}
907
 
908
 
24417 govind 909
function createRegion(domId, name, description) {
910
	var params = {
27410 tejbeer 911
		"name": name,
912
		"description": description
24417 govind 913
	}
914
	doPostAjaxRequestWithParamsHandler(context + "/cs/createRegion", params,
27410 tejbeer 915
		function(response) {
916
			if (response == "true") {
917
				alert("Region created successfully");
918
				loadCreateRegion(domId);
919
			}
920
		});
24417 govind 921
}
922
function loadCreateSubCategory(domId) {
923
	doGetAjaxRequestHandler(context + "/cs/createSubCategory", function(
27410 tejbeer 924
		response) {
24417 govind 925
		$('#' + domId).html(response);
926
	});
927
}
24747 govind 928
function loadManagerTicket(domId, ticketStatus, sortOrder, ticketSearchType,
27410 tejbeer 929
	searchTerm, searchValue) {
24751 govind 930
	if (ticketStatus == null && sortOrder == null) {
24747 govind 931
		doGetAjaxRequestHandler(context + "/cs/managerTicket", function(
27410 tejbeer 932
			response) {
24699 govind 933
			$('#' + domId).html(response);
934
		});
24824 govind 935
	} else if (ticketSearchType == null) {
24747 govind 936
		doGetAjaxRequestHandler(context + "/cs/managerTicket?ticketStatus="
27410 tejbeer 937
			+ ticketStatus + "&orderby=" + sortOrder, function(response) {
938
				$('#' + domId).html(response);
939
			});
24824 govind 940
	} else {
24751 govind 941
		doGetAjaxRequestHandler(context + "/cs/managerTicket?ticketStatus="
27410 tejbeer 942
			+ ticketStatus + "&orderby=" + sortOrder + "&ticketSearchType="
943
			+ ticketSearchType + "&searchTerm=" + searchTerm, function(
24747 govind 944
				response) {
945
			$('#' + domId).html(response);
946
			if (ticketSearchType == "PARTNER_NAME") {
947
				$('.byPartnerName').css('display', 'inline-block');
948
				$('.byTicketId').css('display', 'none');
24748 govind 949
				$("#typeaheadpartnername").val(searchValue);
24747 govind 950
				$("#partner-name-input").val(searchTerm);
951
			} else {
952
				$('.byPartnerName').css('display', 'none');
953
				$('.byTicketId').css('display', 'inline-block');
954
				$("#search-by-ticketId").val(searchTerm);
955
			}
956
		});
957
	}
24439 govind 958
}
24417 govind 959
function loadCreateTicket(domId) {
960
	doGetAjaxRequestHandler(context + "/cs/createTicket", function(response) {
961
		$('#' + domId).html(response);
962
	});
963
}
34913 ranu 964
 
965
function loadMyPartnerTicket(domId) {
966
	doGetAjaxRequestHandler(context + "/cs/myPartyTicketTicket", function (response) {
967
		$('#' + domId).html(response);
968
	});
969
}
24417 govind 970
function loadticketSubCategoryById(ticketCategoryId) {
971
	doGetAjaxRequestHandler(context
27410 tejbeer 972
		+ "/cs/getSubCategoryByCategoryId?ticketCategoryId="
973
		+ ticketCategoryId, function(response) {
33081 ranu 974
		console.log('response', response);
27410 tejbeer 975
			$(".ticket-sub-category-container").html(response);
976
		});
24417 govind 977
}
978
function createPartnerRegion(domId, regionId, fofoIds) {
979
	doPostAjaxRequestWithJsonHandler(context
27410 tejbeer 980
		+ "/cs/createPartnerRegion?regionId=" + regionId, JSON
24417 govind 981
			.stringify(fofoIds), function(response) {
27410 tejbeer 982
				if (response == "true") {
983
					alert("added region to partner successfully");
984
					loadCreatePartnerRegion(domId);
985
				}
986
			});
24417 govind 987
}
988
function createSubCategory(domId, name, description, categoryId) {
989
	var params = {
27410 tejbeer 990
		"categoryId": categoryId,
991
		"name": name,
992
		"description": description
24417 govind 993
	}
994
	doPostAjaxRequestWithParamsHandler(context + "/cs/createSubCategory",
27410 tejbeer 995
		params, function(response) {
996
			alert("Sub Category created successfully");
997
			loadCreateSubCategory(domId);
998
		});
24417 govind 999
}
24620 govind 1000
function createLastActivity(ticketId, activity) {
1001
	var params = {
27410 tejbeer 1002
		"ticketId": ticketId,
1003
		"lastactivity": activity
24620 govind 1004
	}
1005
	doPostAjaxRequestWithParamsHandler(context + "/cs/create-last-activity",
27410 tejbeer 1006
		params, function(response) {
1007
			if (response == "true") {
1008
				alert("successfully mark last activity");
35626 amit 1009
				if ($("#ticket-content-area").length) {
1010
					refreshMyTicketTable(0);
1011
				} else if ($("#manager-ticket-content-area").length) {
1012
					refreshManagerTicketTable(0);
1013
				} else if ($("#partner-ticket-content-area").length) {
1014
					refreshPartnerTicketTable();
1015
				} else {
1016
					loadMyTicket("main-content", null, null);
1017
				}
27410 tejbeer 1018
			}
1019
		});
24620 govind 1020
}
24439 govind 1021
 
25570 tejbeer 1022
function createPosition(domId, authUserId, categoryId, escalationType,
31762 tejbeer 1023
	regionId, fofoIds, ticketAssignee) {
25570 tejbeer 1024
 
1025
	var createPositionModel = {};
1026
	createPositionModel['authUserId'] = authUserId;
1027
	createPositionModel['categoryId'] = categoryId
1028
	createPositionModel['escalationType'] = escalationType;
1029
	createPositionModel['regionId'] = regionId,
31762 tejbeer 1030
 
1031
		createPositionModel['ticketAssigned'] = ticketAssignee,
27410 tejbeer 1032
		createPositionModel['fofoIds'] = fofoIds
25570 tejbeer 1033
 
1034
	console.log(createPositionModel);
1035
	doPostAjaxRequestWithJsonHandler(context + "/cs/createPosition", JSON
27410 tejbeer 1036
		.stringify(createPositionModel), function(response) {
1037
			if (response == "true") {
1038
				alert("Position created successfully");
1039
				loadCreatePosition(domId);
1040
			}
1041
		});
24417 govind 1042
}
35569 amit 1043
function createActivity(message, ticketId, assigneeId, internal, roleType, isCrmUser,
27410 tejbeer 1044
	documentIds) {
27270 tejbeer 1045
 
24417 govind 1046
	var params = {
27410 tejbeer 1047
		"message": message,
1048
		"ticketId": ticketId,
1049
		"assigneeId": assigneeId,
1050
		"internal": internal,
1051
		"documentIds": documentIds,
24417 govind 1052
	}
27270 tejbeer 1053
	if (documentIds.includes("0")) {
27410 tejbeer 1054
		documentIds = [0];
27270 tejbeer 1055
		console.log(documentIds);
1056
	} else {
1057
		console.log(documentIds);
1058
	}
1059
	console.log(JSON.stringify(documentIds))
1060
	doPostAjaxRequestWithJsonHandler(context + "/cs/createActivity?message="
27410 tejbeer 1061
		+ message + "&ticketId=" + ticketId + "&assigneeId=" + assigneeId
1062
		+ "&internal=" + internal, JSON.stringify(documentIds), function(
27270 tejbeer 1063
			response) {
1064
		response = JSON.parse(response);
1065
 
1066
		documentIds.splice(0, documentIds.length);
27285 tejbeer 1067
 
27270 tejbeer 1068
		console.log(documentIds)
27285 tejbeer 1069
		$(".fileList li").remove();
27270 tejbeer 1070
		var assigneeName = response.firstName;
35569 amit 1071
		loadActivities(ticketId, assigneeName, internal, roleType, isCrmUser)
27270 tejbeer 1072
	});
24417 govind 1073
}
24471 govind 1074
function loadEditTicket(ticketId) {
1075
	doGetAjaxRequestHandler(context + "/cs/edit-ticket?ticketId=" + ticketId,
27410 tejbeer 1076
		function(response) {
1077
			$("#theModal .modal-content").html(response);
35594 amit 1078
			$("#theModal").modal('show');
27410 tejbeer 1079
		});
24467 govind 1080
}
34913 ranu 1081
 
1082
function loadMyPartnerEditTicket(ticketId) {
1083
	doGetAjaxRequestHandler(context + "/cs/edit-partner-ticket?ticketId=" + ticketId,
1084
		function (response) {
1085
			$("#theModal2 .modal-content").html(response);
35594 amit 1086
			$("#theModal2").modal('show');
34913 ranu 1087
		});
1088
}
24557 govind 1089
function loadPartnerForRegion(regionId) {
1090
	doGetAjaxRequestHandler(context + "/cs/getPartners?regionId=" + regionId,
27410 tejbeer 1091
		function(response) {
1092
			$("#partner-region-container").html(response);
1093
		});
24557 govind 1094
}
25570 tejbeer 1095
 
1096
function loadPartnerForRegionId(regionId) {
1097
	doGetAjaxRequestHandler(context + "/cs/getPartnersByRegion?regionId="
27410 tejbeer 1098
		+ regionId, function(response) {
1099
			$("#partner-subregion-container").html(response);
1100
		});
25570 tejbeer 1101
}
1102
 
26014 amit.gupta 1103
function loadAccessManagement(domId) {
27141 amit.gupta 1104
	doGetAjaxRequestHandler(context + "/admin/access-management", function(
27410 tejbeer 1105
		response) {
26014 amit.gupta 1106
		$('#' + domId).html(response);
1107
	});
1108
}
1109
 
35569 amit 1110
function loadActivities(ticketId, assignee, internal, roleType, isCrmUser) {
24417 govind 1111
 
35626 amit 1112
	// Set current ticket ID for read tracking
1113
	if (typeof TicketManager !== 'undefined') {
1114
		TicketManager.setCurrentTicketId(ticketId);
1115
	}
1116
 
35569 amit 1117
	// Show loading spinner
1118
	$(".activity-container .modal-body").html('<div class="text-center" style="padding:20px;"><i class="fa fa-spinner fa-spin fa-2x"></i><br>Loading...</div>');
24417 govind 1119
	$("#activityMessage").val("");
1120
	$("#ticketIdforactivity").val(ticketId);
24824 govind 1121
	$("#role").val(roleType);
35569 amit 1122
	$("#crmUser").val(isCrmUser);
27270 tejbeer 1123
	$(".activity-container .modal-title").html(
27410 tejbeer 1124
		"Activity history for Ticket Id " + ticketId)
24417 govind 1125
	console.log(ticketId);
1126
	doGetAjaxRequestHandler(
27410 tejbeer 1127
		context + "/cs/getActivities?ticketId=" + ticketId,
1128
		function(response) {
35569 amit 1129
			$(".activity-container .modal-body").empty(); // Clear loading spinner
27410 tejbeer 1130
			response = JSON.parse(response);
1131
			console.log(response);
27270 tejbeer 1132
 
27410 tejbeer 1133
			for (var i = 0; i < response.length; i++) {
1134
				console.log(response[i].activityAttachment.length);
1135
				var activityAttachment = []
1136
				var attachments = "";
1137
				if (response[i].activityAttachment.length > 0) {
1138
					for (var j = 0; j < response[i].activityAttachment.length; j++) {
35569 amit 1139
						var docName = escapeHtml(response[i].activityAttachment[j].documentName);
27410 tejbeer 1140
						var assigneeAttachment = "<a href=\"javascript:void(0)\" style=\"color:#337ab7;float:right;\"onclick=\"downloadDocument("
1141
							+ response[i].activityAttachment[j].documentId
1142
							+ ",\`"
35569 amit 1143
							+ docName
27410 tejbeer 1144
							+ "\`)\">"
35569 amit 1145
							+ docName
27410 tejbeer 1146
							+ "&nbsp;<i class=\"fa fa-download\"></i>"
1147
							+ "</a>"
1148
						activityAttachment.push(assigneeAttachment);
27270 tejbeer 1149
					}
27410 tejbeer 1150
					attachments = activityAttachment.join("");
1151
					console.log(attachments);
1152
				}
24417 govind 1153
 
35569 amit 1154
				var activityType = response[i].type;
1155
				var escapedMessage = escapeHtml(response[i].message);
1156
				var formattedTime = moment(response[i].createTimestamp).format('DD/MM/YYYY, h:mm:ss a');
1157
 
1158
				if (activityType == ActivityType.OPENED || activityType == ActivityType.COMMUNICATION_IN) {
1159
 
27410 tejbeer 1160
					var partnerMessage = "<div class=\"incoming_msg\">"
1161
						+ "<div class=\"received_msg\">"
1162
						+ "<div class=\"received_withd_msg\">" + "<p>"
35569 amit 1163
						+ escapedMessage + "</p><div>"
27410 tejbeer 1164
						+ `${attachments}`
1165
						+ "</div> <span class=\"time_date\"> "
35569 amit 1166
						+ formattedTime
27410 tejbeer 1167
						+ "</span></div>" + "</div>" + "</div>";
1168
					$(".activity-container .modal-body").append(
1169
						partnerMessage);
27270 tejbeer 1170
 
35569 amit 1171
				} else if (activityType == ActivityType.COMMUNICATION_OUT) {
1172
					var senderName = escapeHtml(response[i].name ? response[i].name : "Support");
27410 tejbeer 1173
					var assigneeMessage = "<div class=\"outgoing_msg\">"
1174
						+ "<div class=\"sent_msg\">"
1175
						+ "<span style=color:green>"
1176
						+ "~"
35569 amit 1177
						+ senderName + "<p>"
1178
						+ escapedMessage + "</span> </p><div>"
27410 tejbeer 1179
						+ `${attachments}`
1180
						+ "</div> <span class=\"time_date\">"
35569 amit 1181
						+ formattedTime
27410 tejbeer 1182
						+ "</span> </div>" + "</div>";
1183
					$(".activity-container .modal-body").append(
1184
						assigneeMessage);
27270 tejbeer 1185
 
35569 amit 1186
				} else if (response[i].name && activityType == ActivityType.COMMUNICATION_INTERNAL) {
1187
					var senderName = escapeHtml(response[i].name);
27410 tejbeer 1188
					var assigneeMessage = "<div class=\"outgoing_msg\">"
1189
						+ "<div class=\"sent_msg\">"
1190
						+ "<span style=color:green>"
1191
						+ "~"
35569 amit 1192
						+ senderName
27410 tejbeer 1193
						+ "<p style=\"color: white;background: #b75454;\">"
35569 amit 1194
						+ escapedMessage + "</span> </p> <div>"
27410 tejbeer 1195
						+ `${attachments}`
1196
						+ "</div> <span class=\"time_date\">"
35569 amit 1197
						+ formattedTime
27410 tejbeer 1198
						+ "</span> </div>" + "</div>";
1199
					$(".activity-container .modal-body").append(
1200
						assigneeMessage);
27270 tejbeer 1201
 
27410 tejbeer 1202
				} else {
35640 amit 1203
					var typeLabel = activityType == "ESCALATED" ? "Escalated"
1204
						: activityType == "ESCALATED_FINAL" ? "Final Escalation"
1205
						: activityType == "ASSIGNED" ? "Assigned"
1206
						: activityType == "CATEGORY_CHANGED" ? "Category Changed"
1207
						: activityType;
1208
					var systemMessage = "<div class=\"system-activity\">"
1209
						+ "<span>" + escapeHtml(typeLabel) + " &middot; " + formattedTime + "</span>"
1210
						+ "</div>";
27410 tejbeer 1211
					$(".activity-container .modal-body").append(
35640 amit 1212
						systemMessage);
27270 tejbeer 1213
 
24417 govind 1214
				}
24824 govind 1215
 
27410 tejbeer 1216
			}
35569 amit 1217
			// Only show internal checkbox to CRM users (they can choose internal/external)
1218
			// Non-CRM users always send internal, so hide the checkbox
1219
			if (toBool(roleType) && toBool(isCrmUser)) {
27410 tejbeer 1220
				$('.internalCheckBox').css('display', 'block');
35569 amit 1221
				$('#internalCommunication').prop('checked', toBool(internal));
27410 tejbeer 1222
			} else {
1223
				$('.internalCheckBox').css('display', 'none');
35569 amit 1224
				// Non-CRM users always send internal
1225
				$('#internalCommunication').prop('checked', true);
27410 tejbeer 1226
			}
1227
		});
24417 govind 1228
}
27270 tejbeer 1229
 
1230
function downloadDocument(documentId, documentName) {
1231
	console.log(documentName)
1232
	doAjaxGetDownload(context + "/download?documentId=" + documentId,
27410 tejbeer 1233
		documentName);
27270 tejbeer 1234
}
35626 amit 1235
 
1236
// AJAX refresh functions for ticket tables (SPA-style, no full page reload)
1237
 
1238
function refreshMyTicketTable(page) {
1239
	var ticketStatus = $("#ticketStatus").val() || "OPENED";
1240
	var orderBy = $("#orderBy").val() || "DESCENDING";
1241
	var search = $("#ticket-search-input").val() || "";
1242
	var pageSize = $("#ticket-content-area .ticket-page-size").val() || "25";
1243
 
1244
	var searchType = $("#assigneesearchType").val();
1245
	var searchTerm = "";
1246
	if (searchType == "PARTNER_NAME") {
1247
		searchTerm = $("#assignee-partner-name-input").val() || "";
1248
	} else if (searchType == "TICKET_ID") {
1249
		searchTerm = $("#assignee-search-by-ticketId").val() || "";
1250
	}
1251
 
1252
	var url = context + "/cs/myticket-content?ticketStatus=" + encodeURIComponent(ticketStatus)
1253
		+ "&orderby=" + encodeURIComponent(orderBy)
1254
		+ "&page=" + (page || 0)
1255
		+ "&pageSize=" + pageSize
1256
		+ "&search=" + encodeURIComponent(search);
1257
 
1258
	if (searchType && searchType != "") {
1259
		url += "&ticketSearchType=" + encodeURIComponent(searchType) + "&searchTerm=" + encodeURIComponent(searchTerm);
1260
	}
1261
 
1262
	// Show/hide clear button
1263
	if (search && search != "") {
1264
		$("#ticket-search-clear").show();
1265
	} else {
1266
		$("#ticket-search-clear").hide();
1267
	}
1268
 
1269
	doGetAjaxRequestHandler(url, function(response) {
1270
		$('#ticket-content-area').html(response);
1271
	});
1272
}
1273
 
1274
function refreshManagerTicketTable(page) {
1275
	var ticketStatus = $("#managerTicketStatus").val() || "OPENED";
1276
	var orderBy = $("#managerTicketorderBy").val() || "DESCENDING";
1277
	var search = $("#manager-ticket-search-input").val() || "";
1278
	var pageSize = $("#manager-ticket-content-area .manager-ticket-page-size").val() || "25";
1279
 
1280
	var searchType = $("#managersearchType").val();
1281
	var searchTerm = "";
1282
	if (searchType == "PARTNER_NAME") {
1283
		searchTerm = $("#partner-name-input").val() || "";
1284
	} else if (searchType == "TICKET_ID") {
1285
		searchTerm = $("#search-by-ticketId").val() || "";
1286
	}
1287
 
1288
	var url = context + "/cs/managerTicket-content?ticketStatus=" + encodeURIComponent(ticketStatus)
1289
		+ "&orderby=" + encodeURIComponent(orderBy)
1290
		+ "&page=" + (page || 0)
1291
		+ "&pageSize=" + pageSize
1292
		+ "&search=" + encodeURIComponent(search);
1293
 
1294
	if (searchType && searchType != "") {
1295
		url += "&ticketSearchType=" + encodeURIComponent(searchType) + "&searchTerm=" + encodeURIComponent(searchTerm);
1296
	}
1297
 
1298
	// Show/hide clear button
1299
	if (search && search != "") {
1300
		$("#manager-ticket-search-clear").show();
1301
	} else {
1302
		$("#manager-ticket-search-clear").hide();
1303
	}
1304
 
1305
	doGetAjaxRequestHandler(url, function(response) {
1306
		$('#manager-ticket-content-area').html(response);
1307
	});
1308
}
1309
 
1310
function refreshPartnerTicketTable() {
1311
	var ticketStatus = $("#managerTicketStatus").val() || "OPENED";
1312
	var orderBy = $("#managerTicketorderBy").val() || "DESCENDING";
1313
 
1314
	var searchType = $("#managersearchType").val();
1315
	var searchTerm = "";
1316
	if (searchType == "PARTNER_NAME") {
1317
		searchTerm = $("#partner-name-input").val() || "";
1318
	} else if (searchType == "TICKET_ID") {
1319
		searchTerm = $("#search-by-ticketId").val() || "";
1320
	}
1321
 
1322
	var url = context + "/cs/myPartyTicket-content?ticketStatus=" + encodeURIComponent(ticketStatus)
1323
		+ "&orderby=" + encodeURIComponent(orderBy);
1324
 
1325
	if (searchType && searchType != "") {
1326
		url += "&ticketSearchType=" + encodeURIComponent(searchType) + "&searchTerm=" + encodeURIComponent(searchTerm);
1327
	}
1328
 
1329
	doGetAjaxRequestHandler(url, function(response) {
1330
		$('#partner-ticket-content-area').html(response);
1331
	});
1332
}