Subversion Repositories SmartDukaan

Rev

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