Subversion Repositories SmartDukaan

Rev

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