Subversion Repositories SmartDukaan

Rev

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

Rev Author Line No. Line
2749 vikas 1
var orderTable;
2
var cartTable;
3096 mandeep.dh 3
 
3090 mandeep.dh 4
function loadUserPane(domId, userId) {
3228 mandeep.dh 5
    $.ajax({
6
        type : "GET",
7
        url : "/crm/user-info?userId=" + userId,
8
        success : function(response) {
9
            $('#' + domId).html(response);
10
        }
11
    });
2674 vikas 12
}
13
 
3228 mandeep.dh 14
function loadOrderPane(domId, userId, orderId) {
15
    $.ajax({
16
        type : "GET",
17
        url : "/crm/user-orders?userId=" + userId,
18
        success : function(response) {
19
            $('#' + domId).html(response);
3499 mandeep.dh 20
            loadOrderInfo("bottom-infopane", orderId);
3228 mandeep.dh 21
            orderTable = $('#user-orders').dataTable({
22
                "aaSorting" : [ [ 1, 'desc' ] ],
4241 anupam.sin 23
              "bAutoWidth": false,
24
              "aoColumns" : [{ "sWidth": "16%" },//order id
25
                             { "sWidth": "30%" },//item desc
26
                             { "sWidth": "16%" },//created
27
                             { "sWidth": "8%" },//amount
28
                             { "sWidth": "17%" },//status
29
                             { "sWidth": "9%" }],//mobile no.
3996 mandeep.dh 30
                "fnDrawCallback": function() { truncateText(125); },
4605 anupam.sin 31
                "iDisplayLength" : 10,
3339 mandeep.dh 32
                "sDom" : 'T<"clear">lfrtip',
33
                "oTableTools" : {
34
                    "sSwfPath" : "swf/copy_cvs_xls_pdf.swf"
35
                },
3228 mandeep.dh 36
                "aLengthMenu" : [ [ 5, 10, 20, -1 ], [ 5, 10, 20, "All" ] ]
37
            });
38
        }
39
    });
2674 vikas 40
}
41
 
6111 anupam.sin 42
function loadRechargeOrderPane(domId, userId, rechargeOrderId) {
43
    $.ajax({
44
        type : "GET",
45
        url : "/crm/recharge-orders?userId=" + userId,
46
        success : function(response) {
47
            $('#' + domId).html(response);
48
            loadRechargeOrderInfo("bottom-infopane", rechargeOrderId);
49
            orderTable = $('#recharge-orders').dataTable({
50
                "aaSorting" : [ [ 1, 'desc' ] ],
51
              "bAutoWidth": false,
52
              "aoColumns" : [{ "sWidth": "16%" },//recharge order id
53
                             { "sWidth": "30%" },//desc
54
                             { "sWidth": "16%" },//created
55
                             { "sWidth": "8%" },//amount
56
                             { "sWidth": "17%" },//status
57
                             { "sWidth": "9%" }],//mobile no.
58
                "fnDrawCallback": function() { truncateText(125); },
59
                "iDisplayLength" : 10,
60
                "sDom" : 'T<"clear">lfrtip',
61
                "oTableTools" : {
62
                    "sSwfPath" : "swf/copy_cvs_xls_pdf.swf"
63
                },
64
                "aLengthMenu" : [ [ 5, 10, 20, -1 ], [ 5, 10, 20, "All" ] ]
65
            });
66
        }
67
    });
68
}
69
 
70
function loadRechargeOrderInfo(domId, rechargeOrderId) {
71
    $.ajax({
72
        type : "GET",
73
        url : "/crm/recharge-order-info?rechargeOrderId=" + rechargeOrderId,
74
        success : function(response) {
75
            $('#' + domId).html(response);
76
 
77
            var trId = 'order-row-' + rechargeOrderId;
78
            if (orderTable != null) {
79
                for ( var index in orderTable.fnGetNodes()) {
80
                    var item = orderTable.fnGetNodes()[index];
81
                    if ($(item).attr('id') == trId) {
82
                        orderTable.fnDisplayRow(item);
83
                        break;
84
                    }
85
                }
86
            }
87
 
88
            $('#recharge-orders tr').removeClass('selected');
6153 anupam.sin 89
            $('#order-row-' + rechargeOrderId).addClass('selected');
6111 anupam.sin 90
        }
91
    });
92
}
93
 
3228 mandeep.dh 94
function loadCartPane(domId, userId, cartId) {
95
    $.ajax({
96
        type : "GET",
97
        url : "/crm/user-cart?userId=" + userId + "&cartId=" + cartId,
98
        success : function(response) {
99
            $('#' + domId).html(response);
100
            cartTable = $('#user-cart').dataTable({
101
                "aaSorting" : [ [ 1, 'desc' ] ],
4241 anupam.sin 102
              "bAutoWidth": false,
103
              "aoColumns" : [{ "sWidth": "32%" },//name
104
                             { "sWidth": "9%" },//quantity
105
                             { "sWidth": "16%" },//actual price
106
                             { "sWidth": "16%" },//discounted price
107
                             { "sWidth": "9%" },//estimate
108
                             { "sWidth": "18%" }],//created on
3228 mandeep.dh 109
                "iDisplayLength" : 10,
3339 mandeep.dh 110
                "sDom" : 'T<"clear">lfrtip',
111
                "oTableTools" : {
112
                    "sSwfPath" : "swf/copy_cvs_xls_pdf.swf"
113
                },
3228 mandeep.dh 114
                "aLengthMenu" : [ [ 5, 10, 20, -1 ], [ 5, 10, 20, "All" ] ]
115
            });
116
        }
117
    });
2714 vikas 118
}
119
 
3499 mandeep.dh 120
function loadOrderInfo(domId, orderId) {
3228 mandeep.dh 121
    $.ajax({
122
        type : "GET",
3499 mandeep.dh 123
        url : "/crm/user-order-info?orderId=" + orderId,
3228 mandeep.dh 124
        success : function(response) {
125
            $('#' + domId).html(response);
3220 mandeep.dh 126
 
3228 mandeep.dh 127
            var trId = 'order-row-' + orderId;
128
            if (orderTable != null) {
129
                for ( var index in orderTable.fnGetNodes()) {
130
                    var item = orderTable.fnGetNodes()[index];
131
                    if ($(item).attr('id') == trId) {
132
                        orderTable.fnDisplayRow(item);
133
                        break;
134
                    }
135
                }
136
            }
3220 mandeep.dh 137
 
3228 mandeep.dh 138
            $('#user-orders tr').removeClass('selected');
139
            $('#order-row-' + orderId).addClass('selected');
140
        }
141
    });
2714 vikas 142
}
143
 
3228 mandeep.dh 144
function loadLineInfo(domId, userId, itemId) {
145
    $.ajax({
146
        type : "GET",
147
        url : "/crm/user-line-info?userId=" + userId + "&itemId=" + itemId,
148
        success : function(response) {
149
            $('#' + domId).html(response);
150
            $('#user-cart tr').removeClass('selected');
151
            $('#cart-row-' + itemId).addClass('selected');
152
        }
153
    });
2830 vikas 154
}
155
 
3228 mandeep.dh 156
function loadTicketInfo(domId, ticketId, ticketTable, activityId) {
157
    $.ajax({
158
        type : "GET",
3405 mandeep.dh 159
        url : "/crm/tickets/" + ticketId + "/edit",
3228 mandeep.dh 160
        success : function(response) {
161
            $('#' + domId).html(response);
3206 mandeep.dh 162
 
3228 mandeep.dh 163
            var trId = 'ticket-row-' + ticketId;
164
            if (ticketTable != null) {
165
                for ( var index in ticketTable.fnGetNodes()) {
166
                    var item = ticketTable.fnGetNodes()[index];
167
                    if ($(item).attr('id') == trId) {
168
                        ticketTable.fnDisplayRow(item);
169
                        break;
170
                    }
171
                }
172
            }
3206 mandeep.dh 173
 
3228 mandeep.dh 174
            $('#tickets tr').removeClass('selected');
175
            $('#' + trId).addClass('selected');
176
 
177
            // For tickets accessed from activity page
178
            if (activityId != null) {
3339 mandeep.dh 179
                $('#activity tr').removeClass('selected');
3228 mandeep.dh 180
                $('#activity-row-' + activityId).addClass('selected');
181
            }
3546 mandeep.dh 182
 
183
            $('#order-table').dataTable({
184
                "aaSorting" : [ [ 2, 'desc' ] ],
4241 anupam.sin 185
//            "bAutoWidth": false,
186
//            "aoColumns" : [{ "sWidth": "5%" },
187
//                           { "sWidth": "20%" },
188
//                           { "sWidth": "20%" },
189
//                           { "sWidth": "12.5%" },
190
//                           { "sWidth": "12.5%" },
191
//                           { "sWidth": "10%" },
192
//                           { "sWidth": "10%" },
193
//                           { "sWidth": "10%" }],
4605 anupam.sin 194
                "iDisplayLength" : 10,
3546 mandeep.dh 195
                "fnDrawCallback": function() {truncateText(100);},
196
                "aLengthMenu" : [ [ 5, 10, 20, -1 ], [ 5, 10, 20, "All" ] ]
197
            });
3228 mandeep.dh 198
        }
199
    });
3090 mandeep.dh 200
}
201
 
3405 mandeep.dh 202
function createTicketDataTable(domId) {
3499 mandeep.dh 203
    var ticketsTable = $('#' + domId).dataTable({
4142 mandeep.dh 204
         "aaSorting" : [ [ 3, 'asc' ] ],
4241 anupam.sin 205
         "bAutoWidth": false,
206
         "aoColumns" : [{ "sWidth": "9%" },//ticket id
207
                        { "sWidth": "16%" },//customer id or Description when orderId is set
208
                        { "sWidth": "21%" },//category id
209
                        { "sWidth": "13%" },//date created
210
                        { "sWidth": "13%" },//date closed
211
                        { "sWidth": "12%" },//assignee
212
                        { "sWidth": "8%" },//status
213
                        { "sWidth": "8%" }],//priority
3546 mandeep.dh 214
        "fnDrawCallback": function() {truncateText(85);},
4605 anupam.sin 215
        "iDisplayLength" : 10,
3339 mandeep.dh 216
        "sDom" : 'T<"clear">lfrtip',
217
        "oTableTools" : {
5203 amar.kumar 218
            "sSwfPath" : "swf/copy_cvs_xls_pdf.swf",
219
            "sExtends": "csv",
220
            "sFieldSeperator": "`"
3339 mandeep.dh 221
        },
222
        "aLengthMenu" : [ [ 5, 10, 20, -1 ], [ 5, 10, 20, "All" ] ]
223
    });
3499 mandeep.dh 224
 
225
    return ticketsTable;
3339 mandeep.dh 226
}
227
 
4241 anupam.sin 228
function loadActivityDescription(domId, aActivityId) {
5521 amar.kumar 229
	if($(aActivityId).attr('isRead')=="true") {
230
		$('#' + domId).html("<h4>Activity Description :</h4><pre>" + $(aActivityId).parent().siblings('td[id="activity-description"]').attr('title') + '</pre>');
231
	} else {
232
		$('#' + domId).html("<h4>Activity Description :</h4><pre>" + $(aActivityId).parent().siblings('td[id="activity-description"]').attr('title') + 
233
				'</pre><br/><input type="button" value="Mark as read" activityid="'+ $(aActivityId).attr('activityid') +'" id="mark-as-read">');
234
	}
4241 anupam.sin 235
    $('#activity-table tr').removeClass('selected');
236
    $(aActivityId).parent().parent().addClass('selected');
237
}
238
 
3422 mandeep.dh 239
function loadActivityInfo(domId, activityId) {
3228 mandeep.dh 240
    $.ajax({
241
        type : "GET",
3422 mandeep.dh 242
        url : "/crm/activity-info?activityId=" + activityId,
3228 mandeep.dh 243
        success : function(response) {
244
            $('#' + domId).html(response);
3339 mandeep.dh 245
            $('#activity tr').removeClass('selected');
3228 mandeep.dh 246
            $('#activity-row-' + activityId).addClass('selected');
3390 mandeep.dh 247
            $('#activity').css('table-layout', 'fixed');
3228 mandeep.dh 248
        }
249
    });
3090 mandeep.dh 250
}
251
 
3405 mandeep.dh 252
function createActivityDataTable(domId) {
3499 mandeep.dh 253
    var activityTable = $('#' + domId).dataTable({
3339 mandeep.dh 254
        "aaSorting" : [ [ 4, 'desc' ] ],
4241 anupam.sin 255
     "bAutoWidth": false,
5203 amar.kumar 256
      "aoColumns" : [{ "sWidth": "7%" },//id
257
                     { "sWidth": "18%" },//activity type
258
                     { "sWidth": "11%" },//description
259
                     { "sWidth": "11%" },//timestamp
4241 anupam.sin 260
                     { "sWidth": "12%" },//creator
5203 amar.kumar 261
                     { "sWidth": "6%" },//customer id
262
                     { "sWidth": "7%" },//ticket id
263
                     { "sWidth": "7%" },//ticket status
264
                     { "sWidth": "12%" },//category
265
                     { "sWidth": "9%" }],//contact number
4605 anupam.sin 266
        "iDisplayLength" : 10,
3339 mandeep.dh 267
        "sDom" : 'T<"clear">lfrtip',
3546 mandeep.dh 268
        "fnDrawCallback": function() {truncateText(95);},
3339 mandeep.dh 269
        "oTableTools" : {
5203 amar.kumar 270
            "sSwfPath" : "swf/copy_cvs_xls_pdf.swf",
271
            "sExtends": "csv",
272
            "sFieldSeperator": "`"
3339 mandeep.dh 273
        },
274
        "aLengthMenu" : [ [ 5, 10, 20, -1 ], [ 5, 10, 20, "All" ] ]
275
    });
3499 mandeep.dh 276
 
277
    return activityTable;
3339 mandeep.dh 278
}
279
 
4793 amar.kumar 280
function loadAgentsInfo(domId) {
281
	$.ajax({
282
		type    : "GET",
283
		url	    : "/crm/agent",
284
		success : function(response) {
285
			$('#' + domId).html(response);
286
 
287
			var agentTable = $('#agents').dataTable({
288
                "aaSorting" : [ [ 1, 'asc' ] ],
289
                "bAutoWidth": false,
290
                "aoColumns" : [{ "sWidth": "12%", "sSortDataType": "dom-text", "sType": "numeric" },//AgentID
291
                               { "sWidth": "35%" },//Agent Name
292
                               { "sWidth": "40%" },//Email ID
293
                               { "sWidth": "13%", "sSortDataType": "dom-text", "sType": "numeric"}],//Manager ID
294
                "iDisplayLength" : 10,
295
                "sDom" : 'T<"clear">lfrtip',
296
                "oTableTools" : {
297
                    "sSwfPath" : "swf/copy_cvs_xls_pdf.swf"
298
                },
299
            });
300
		}
301
	});
302
}
303
 
5909 amar.kumar 304
function loadAllOpenTickets(domId) {
305
	$.ajax({
306
		type    : "GET",
307
		url	    : "/crm/tickets!getAllOpenTickets",
308
		success : function(response) {
309
			$('#' + domId).html(response);
310
 
311
			var agentTable = $('#open-tickets').dataTable({
312
                "aaSorting" : [ [ 1, 'asc' ] ],
313
                "bAutoWidth": true,
314
                "iDisplayLength" : 25,
315
                "sDom" : 'T<"clear">lfrtip',
316
                "oTableTools" : {
317
                    "sSwfPath" : "swf/copy_cvs_xls_pdf.swf"
318
                },
319
            });
320
		}
321
	});
322
}
323
 
3405 mandeep.dh 324
function loadTicketCreationForm(domId, params) {
3228 mandeep.dh 325
    $.ajax({
326
        type : "GET",
3339 mandeep.dh 327
        url : "/crm/tickets/new",
3405 mandeep.dh 328
        data : params,
3339 mandeep.dh 329
        success : function(response) {
330
            $('#' + domId).html(response);
331
        }
332
    });
333
}
334
 
3405 mandeep.dh 335
function loadActivityCreationForm(domId, params) {
3339 mandeep.dh 336
    $.ajax({
337
        type : "GET",
338
        url : "/crm/activity/new",
3405 mandeep.dh 339
        data : params,
3339 mandeep.dh 340
        success : function(response) {
341
            $('#' + domId).html(response);
342
        }
343
    });
344
}
345
 
3090 mandeep.dh 346
function updateTicket(domId, ticketId, params) {
3228 mandeep.dh 347
    $.ajax({
4782 mandeep.dh 348
        type : "POST",
349
        url : "/crm/tickets!update?id=" + ticketId,
350
        data : params,
3228 mandeep.dh 351
        success : function(response) {
3339 mandeep.dh 352
            var ticketTable = $('table[id$="tickets"]');
353
            if (ticketTable.length == 1) {
354
                var rowIndex = ticketTable.dataTable().fnGetPosition($('tr#ticket-row-' + ticketId)[0]);
355
                var responseObj = jQuery(response);
3546 mandeep.dh 356
                var actionMessages = responseObj.find('#action-messages').html();
3339 mandeep.dh 357
                responseObj.find('#ticket-row-' + ticketId).children().each(
358
                        function(i, item) {
359
                            var th = responseObj.find('th').eq(i);
360
                            if (th.text() == "Ticket Id") {
361
                                return;
362
                            }
363
 
364
                            var thOld = ticketTable.find('th').filter(
365
                                    function(index) {
366
                                        if ($(this).text() == th.text()) {
367
                                            return true;
368
                                        }
369
 
370
                                        return false;
371
                                    });
372
 
4249 anupam.sin 373
                            if ($(thOld).length != 0) {
3339 mandeep.dh 374
                                ticketTable.dataTable().fnUpdate($(item).text(), rowIndex, $(thOld).index(), true, false);
375
                            }
376
                        });
377
 
3546 mandeep.dh 378
                loadTicketInfo("bottom-infopane", ticketId, ticketTable.dataTable(), null);
3339 mandeep.dh 379
                ticketTable.css('table-layout', 'fixed');
3546 mandeep.dh 380
 
381
                var alertString = jQuery.trim(actionMessages);
382
                if (alertString != '') {
383
                    alert(alertString);
384
                }
3339 mandeep.dh 385
            }
386
            else {
387
                loadTicketInfo("bottom-infopane", ticketId, null, null);
388
            }
389
 
3499 mandeep.dh 390
            truncateText(85);
3339 mandeep.dh 391
        }
392
    });
393
}
394
 
3090 mandeep.dh 395
function createTicket(domId, params) {
3228 mandeep.dh 396
    $.ajax({
397
        type : "POST",
3339 mandeep.dh 398
        url : "/crm/tickets",
3228 mandeep.dh 399
        data : params,
400
        success : function(response) {
401
            $('#' + domId).html(response);
3405 mandeep.dh 402
            var ticketTable = createTicketDataTable('tickets');
3228 mandeep.dh 403
        }
404
    });
3090 mandeep.dh 405
}
406
 
4793 amar.kumar 407
function createAgent(params, managerId){
408
	$.ajax({
409
		type : "POST",
410
		url : "/crm/agent!createAgent?managerId="+managerId,
411
		data : params,
412
		success : function(response) {
413
			alert("Agent created with the specified information");
414
			$.colorbox.close();
415
			$('#infopane').html(response);
416
			var agentTable = $('#agents').dataTable({
417
                "aaSorting" : [ [ 1, 'asc' ] ],
418
                "bAutoWidth": false,
419
                "aoColumns" : [{ "sWidth": "12%", "sSortDataType": "dom-text", "sType": "numeric" },//AgentID
420
                               { "sWidth": "35%" },//Agent Name
421
                               { "sWidth": "40%" },//Email ID
422
                               { "sWidth": "13%", "sSortDataType": "dom-text", "sType": "numeric"}],//Manager ID
423
                "iDisplayLength" : 10,
424
                "sDom" : 'T<"clear">lfrtip',
425
                "oTableTools" : {
426
                    "sSwfPath" : "swf/copy_cvs_xls_pdf.swf"
427
                },
428
            });
429
		}
430
	});
431
}
432
 
5168 amar.kumar 433
function changeAgentRole(params){
434
	$.ajax({
435
		type : "POST",
436
		url : "/crm/agent!changeAgentRole",
437
		data : params,
438
		success : function(response) {
439
			alert("Agent role changed");
440
			$.colorbox.close();
441
			$('#infopane').html(response);
442
			var agentTable = $('#agents').dataTable({
443
                "aaSorting" : [ [ 1, 'asc' ] ],
444
                "bAutoWidth": false,
445
                "aoColumns" : [{ "sWidth": "12%", "sSortDataType": "dom-text", "sType": "numeric" },//AgentID
446
                               { "sWidth": "35%" },//Agent Name
447
                               { "sWidth": "40%" },//Email ID
448
                               { "sWidth": "13%", "sSortDataType": "dom-text", "sType": "numeric"}],//Manager ID
449
                "iDisplayLength" : 10,
450
                "sDom" : 'T<"clear">lfrtip',
451
                "oTableTools" : {
452
                    "sSwfPath" : "swf/copy_cvs_xls_pdf.swf"
453
                },
454
            });
455
		}
456
	});
457
}
458
 
3090 mandeep.dh 459
function createActivity(domId, params) {
3228 mandeep.dh 460
    $.ajax({
461
        type : "POST",
3339 mandeep.dh 462
        url : "/crm/activity",
3228 mandeep.dh 463
        data : params,
464
        success : function(response) {
465
            $('#' + domId).html(response);
3405 mandeep.dh 466
            var activityTable = createActivityDataTable('activity');
3228 mandeep.dh 467
        }
468
    });
3106 mandeep.dh 469
}
470
 
471
function goToHomePage() {
3228 mandeep.dh 472
    document.location.href = "/crm";
3106 mandeep.dh 473
}
474
 
3422 mandeep.dh 475
function loadTickets(domId, getURL, ticketId) {
3228 mandeep.dh 476
    $.ajax({
477
        type : "GET",
3234 mandeep.dh 478
        url : getURL,
3228 mandeep.dh 479
        success : function(response) {
480
            $('#' + domId).html(response);
3405 mandeep.dh 481
            var ticketTable = createTicketDataTable('tickets');
3422 mandeep.dh 482
            if (ticketId != null) {
483
                loadTicketInfo("bottom-infopane", ticketId, ticketTable.dataTable(), null);
484
                ticketTable.css('table-layout', 'fixed');
485
            }
3228 mandeep.dh 486
        }
487
    });
3106 mandeep.dh 488
}
5225 amar.kumar 489
function changeActivityFormValidCriteria(commonDescription) {
490
	if(commonDescription == "") {
491
		$('#description').addClass('required');
492
	} else {
493
		$('#description').removeClass('required');
494
	}
495
}
3137 mandeep.dh 496
 
3422 mandeep.dh 497
function processActivityTypeChange(activityType) {
5203 amar.kumar 498
	if(activityType != "RECEIVED_CALL_FROM_CUSTOMER") {
499
		$('select#common-activity-desc').hide();
5224 amar.kumar 500
		$('#description').addClass('required');
5203 amar.kumar 501
	} else {
502
		$('select#common-activity-desc').show();
503
	}
3269 mandeep.dh 504
    if (activityType == "SEND_EMAIL_TO_CUSTOMER") {
3228 mandeep.dh 505
        $.colorbox({
506
            inline : true,
3519 mandeep.dh 507
            width : "775px",
508
            height : "445px",
3228 mandeep.dh 509
            href : "div#mail-div",
510
            onClosed : function() {
3519 mandeep.dh 511
				CKEDITOR.instances['mail-body'].destroy(false);
3228 mandeep.dh 512
                $("div#mail-div").hide();
513
                $('select#activity-type').val('OTHER');
514
            }
515
        });
3206 mandeep.dh 516
 
3228 mandeep.dh 517
        $("div#mail-div").show();
3701 mandeep.dh 518
        $('#mail-body').ckeditor({toolbar : 'Basic', scayt_autoStartup : true});
3228 mandeep.dh 519
    }
4020 mandeep.dh 520
    else if (activityType == "ESCALATE_TICKET") {
521
        $.colorbox({
522
            inline : true,
523
            width : "675px",
4027 mandeep.dh 524
            height : "560px",
4020 mandeep.dh 525
            href : "div#escalation-div",
526
            onClosed : function() {
527
                CKEDITOR.instances['escalation-mail-body'].destroy(false);
528
                $("div#escalation-div").hide();
529
                $('select#activity-type').val('OTHER');
530
            }
531
        });
532
 
533
        $("div#escalation-div").show();
534
        $('#escalation-mail-body').ckeditor({toolbar : 'Basic', scayt_autoStartup : true});
535
    }
3206 mandeep.dh 536
}
537
 
538
function processInputFormSubmit() {
3228 mandeep.dh 539
    $.ajax({
540
        type : "POST",
541
        url : "/crm/",
542
        success : function(response) {
543
            $.html(response);
3405 mandeep.dh 544
            var ticketTable = createTicketDataTable('tickets');
3228 mandeep.dh 545
        }
546
    });
3339 mandeep.dh 547
}
548
 
549
function listActivities(domId, params) {
550
    $.ajax({
551
        type : "GET",
552
        url : "/crm/activity",
553
        data : params,
554
        success : function(response) {
555
            $('#' + domId).html(response);
3405 mandeep.dh 556
            var activityTable = createActivityDataTable('activity');
3339 mandeep.dh 557
        }
558
    });
559
}
560
 
561
function truncateText(widthSize) {
4241 anupam.sin 562
    $(".truncated-text").each(function() {
563
    	$(this).truncate({
564
            width : $(this).attr('truncatedTextWidth'),
565
            addtitle : true
566
        });
567
	})
3339 mandeep.dh 568
}
3390 mandeep.dh 569
 
570
function markAsRead(activityId) {
571
    $.ajax({
572
        type : "POST",
573
        url : "/crm/activity!markAsRead?activityId=" + activityId,
574
        success: function(response) {
575
            listActivities('infopane', "creatorId=1");
576
        }
577
    });
578
}
3397 mandeep.dh 579
 
580
function loadAdvancedSearchBox() {
581
    $.colorbox({
582
        inline : true,
583
        width : "535px",
584
        height : "465px",
585
        href : "form#search",
586
        onClosed : function() {
587
            $("form#search").hide();
588
        }
589
    });
590
 
591
    $("form#search").show();
592
}
593
 
594
function processSearchEntityChange(searchEntity) {
595
    if (searchEntity == "Tickets") {
596
        $("#assignee").show();
597
        $("#creator").hide();
4142 mandeep.dh 598
        $("tr#activityTypes").hide();
3397 mandeep.dh 599
    }
600
    else if (searchEntity == "Activities") {
601
        $("#assignee").hide();
602
        $("#creator").show();
4142 mandeep.dh 603
        $("tr#activityTypes").show();
3397 mandeep.dh 604
    }
605
}
3499 mandeep.dh 606
 
607
function increaseTrustLevel(domId, userId, trustLevelDelta) {
608
    $.ajax({
609
        type : "PUT",
610
        url : "/crm/user-info/" + userId + "?trustLevelDelta=" + trustLevelDelta,
611
        success : function(response) {
612
            $('#' + domId).html(response);
613
        }
614
    });
615
}
616
 
4241 anupam.sin 617
function displayCancelOrderPopUp() {
618
    	$.colorbox({
619
            inline : true,
620
            width : "650px",
4314 anupam.sin 621
            height : "550px",
4689 anupam.sin 622
            href : "div#cancel-div",
4241 anupam.sin 623
            onClosed : function() {
4689 anupam.sin 624
                CKEDITOR.instances['cancel-body'].destroy(false);
625
                $("div#cancel-div").hide();
4241 anupam.sin 626
            }
627
        });
628
 
4689 anupam.sin 629
        $("div#cancel-div").show();
630
        $('#cancel-body').ckeditor({toolbar : 'Basic', scayt_autoStartup : true});
4241 anupam.sin 631
}
632
 
633
function cancelOrder(domId, ticketId, orderId, orderStatus, formData) {
4704 anupam.sin 634
	if ($('#cancellationInitiator').val()) {
4689 anupam.sin 635
		var cancellationInitiator = $('#cancellationInitiator').val();
636
		var uri = "/crm/user-order-info!markOrderForCancellation?orderId=" + orderId
637
						+ "&cancellationInitiator=" + cancellationInitiator + "&" + formData;
638
		var cancellationResult = function() {
639
			document.location.href = "/crm?email=&orderId=" + orderId;
640
		}
641
	} else {
642
		var uri = "/crm/tickets!updateOrderStatus?id=" + ticketId + "&orderId=" + orderId
643
						+ "&orderStatus=" + orderStatus + "&" + formData;
644
		var cancellationResult = function(response) {
645
            $('#' + domId).html(response);
646
        }
647
	}
4241 anupam.sin 648
    $.ajax({
649
        type : "POST",
4689 anupam.sin 650
        url : uri,
651
        success : cancellationResult
4241 anupam.sin 652
    });
4681 amar.kumar 653
 
654
    if(formData.indexOf("LOWER_PRICE_AVAILABLE_ELSEWHERE")!=-1){
655
    	var desc = formData.split("&");
656
    	var description = "Order cancelled because of Lower Price Available elsewhere";
657
    	$.ajax({
658
    		type : "POST",
659
    		url : "/crm/tickets?orderId="+orderId+"&priority=MEDIUM&category=PRODUCT_PROCUREMENT"
660
    				+ "&assigneeEmailId=chaitnaya.vats@shop2020.in&description="+description+"&"+desc[1],
661
    		success : function(response){
662
    			alert("Ticket created for Lower Price Available elsewhere");
663
    		}
664
    	});
665
 
666
    }
4241 anupam.sin 667
}
4065 mandeep.dh 668
 
4241 anupam.sin 669
function updateOrderStatus(domId, ticketId, orderId, orderStatus) {
3499 mandeep.dh 670
    $.ajax({
3546 mandeep.dh 671
        type : "POST",
4241 anupam.sin 672
        url : "/crm/tickets!updateOrderStatus?id=" + ticketId + "&orderId=" + orderId
673
        					+ "&orderStatus=" + orderStatus,
3499 mandeep.dh 674
        success : function(response) {
3546 mandeep.dh 675
            $('#' + domId).html(response);
3499 mandeep.dh 676
        }
677
    });
3711 mandeep.dh 678
}
679
 
680
function loadUnreadActivities(domId) {
681
    $.ajax({
682
        type : "GET",
683
        url : "/crm/activity!getUnreadActivities",
684
        success : function(response) {
685
            $('#' + domId).html(response);
686
            var activityTable = createActivityDataTable('activity');
687
        }
688
    });
689
}
4065 mandeep.dh 690
 
691
function refreshSidebar() {
692
    $.ajax({
4142 mandeep.dh 693
        type : "PUT",
694
        url : "/crm",
695
        success : function(response) {
696
            $('#sidebar').html($(response).find('#sidebar').html());
697
        }
698
    });
699
}
700
 
701
function changeAddress(urlParams) {
702
    $.ajax({
4065 mandeep.dh 703
        type : "GET",
704
        url : "/crm",
705
        success : function(response) {
706
            $('#sidebar').html($(response).find('#sidebar').html());
707
        }
708
    });
4267 anupam.sin 709
}
710
 
4681 amar.kumar 711
function showHidecancelReasonDiv(cancelReason){
4793 amar.kumar 712
	var reasonsToShowDiv = ['LOWER_PRICE_AVAILABLE_ELSEWHERE','OTHER','OUT_OF_STOCK','COLOR_OUT_OF_STOCK'];
713
	if(($.inArray(cancelReason, reasonsToShowDiv))!=-1){
4681 amar.kumar 714
		$('#cancelReasonBox').show();
715
	} else {
716
		$('#cancelReasonBox').hide();
717
	}
718
}
719
 
4438 anupam.sin 720
function blockPayment(transactionId, ticketId, paymentId) {
4267 anupam.sin 721
	$.ajax({
722
		type : "GET",
4451 anupam.sin 723
		url : "/crm/tickets!blockPayment?transactionId=" + transactionId + "&id=" + ticketId + "&paymentId=" + paymentId,
4267 anupam.sin 724
		success : function(response) {
725
            $('#bottom-infopane').html(response);
726
        }
727
	});
728
}
729
 
4438 anupam.sin 730
function allowPayment(transactionId, ticketId, paymentId) {
4267 anupam.sin 731
	$.ajax({
732
		type : "GET",
4451 anupam.sin 733
		url : "/crm/tickets!allowPayment?transactionId=" + transactionId + "&id=" + ticketId + "&paymentId=" + paymentId,
4267 anupam.sin 734
		success : function(response) {
735
            $('#bottom-infopane').html(response);
736
        }
737
	});
4490 anupam.sin 738
}
739
 
740
function denyDOA(orderId, ticketId) {
741
	$.ajax({
742
		type : "GET",
743
		url : "/crm/tickets!denyDOA?orderId=" + orderId + "&id=" + ticketId,
744
		success : function(response) {
745
            $('#bottom-infopane').html(response);
746
        }
747
	});
748
}
749
 
750
 
751
function authorizeDOA(orderId, ticketId) {
752
	$.ajax({
753
		type : "GET",
754
		url : "/crm/tickets!authorizeDOA?orderId=" + orderId + "&id=" + ticketId,
755
		success : function(response) {
756
            $('#bottom-infopane').html(response);
757
        }
758
	});
759
}
760
 
761
function denyReturn(orderId, ticketId) {
762
	$.ajax({
763
		type : "GET",
764
		url : "/crm/tickets!denyReturn?orderId=" + orderId + "&id=" + ticketId,
765
		success : function(response) {
766
            $('#bottom-infopane').html(response);
767
        }
768
	});
769
}
770
 
771
 
772
function authorizeReturn(orderId, ticketId) {
773
	$.ajax({
774
		type : "GET",
775
		url : "/crm/tickets!authorizeReturn?orderId=" + orderId + "&id=" + ticketId,
776
		success : function(response) {
777
            $('#bottom-infopane').html(response);
778
        }
779
	});
4689 anupam.sin 780
}
781
 
782
function markOrderForCancellation(orderId, formData) {
783
	console.log(typeof(orderId), typeof(formData), orderId, formData);
784
 
785
	$.ajax({
786
		type : "GET",
787
		url : "/crm/user-order-info!markOrderForCancellation?orderId=" + orderId + "&cancellationInitiator=" + formData,
788
		success : function(response) {
789
			document.location.href = "/crm?email=&orderId=" + orderId;
790
        }
791
	});
4793 amar.kumar 792
}
793
 
794
function loadAgentCreationForm() {
795
	$.colorbox({
796
        inline : true,
797
        width : "550px",
798
        height : "400px",
799
        href : "div#create-agent-div",
800
        onClosed : function() {
801
            $("div#create-agent-div").hide();
802
        }
803
    });
804
 
805
    $("div#create-agent-div").show();
806
 
807
}
808
 
809
function deactivateAgentPopup() {
810
	$.colorbox({
811
        inline : true,
812
        width : "400px",
813
        height : "150px",
814
        href : "div#deactivate-agent-div",
815
        onClosed : function() {
816
            $("div#deactivate-agent-div").hide();
817
        }
818
    });
819
 
820
    $("div#deactivate-agent-div").show();
821
 
822
}
823
 
824
function changeAgentPasswordPopup(){
825
	$.colorbox({
826
        inline : true,
827
        width  : "350px",
828
        height : "350px",
829
        href   : "div#change-password-div",
830
        onClosed : function() {
831
            $("div#change-password-div").hide();
832
        }
833
    });
834
 
835
    $("div#change-password-div").show();
836
}
837
 
5168 amar.kumar 838
function changeAgentRolePopup(){
839
	$.colorbox({
840
        inline : true,
841
        width  : "375px",
842
        height : "350px",
843
        href   : "div#change-agent-role-div",
844
        onClosed : function() {
845
            $("div#change-agent-role-div").hide();
846
        }
847
    });
4793 amar.kumar 848
 
5168 amar.kumar 849
    $("div#change-agent-role-div").show();
850
}
851
 
4793 amar.kumar 852
function updateAgentPassword(){
853
	if(($('#change-password1').val().trim())==($('#change-password2').val().trim())){
854
		$.ajax({
855
			type : "POST",
856
			url : "/crm/agent!changePassword?emailId=" + $('#agentEmail').val() + "&newPassword=" + $('#change-password1').val().trim(),
857
			success : function(response) {
858
				alert("Password updated successfully");
859
				$.colorbox.close();
860
			}
861
		});
862
	}
863
	else { 
864
		alert("Passwords not matching");
865
		return false;
866
	}
867
}
868
 
869
function validateAgentCreationForm(){
870
	var formError = false;
871
	if($('#new-agent-name').val().length == 0) {
872
		$('#agent-name-error').html("Please enter the name");
873
		$('#new-agent-name').addClass('agent-form-error');
874
		formError = true;
875
	}
876
	if(($('#new-agent-id').val().length == 0)) {
877
		$('#agent-email-error').html("Please enter the Email-ID");
878
		$('#new-agent-id').addClass('agent-form-error');
879
		formError = true;
880
	}
881
	if($('#create-password1').val().length == 0) {
882
		$('#agent-password1-error').html("Please enter password");
883
		$('#create-password1').addClass('agent-form-error');
884
		formError = true;
885
	} else if($('#create-password2').val().length == 0){
886
		$('#agent-password2-error').html("Please re enter password");
887
		$('#create-password2').addClass('agent-form-error');
888
		formError = true;
889
	} else if($('#create-password1').val()!=$('#create-password2').val()) {
890
		$('#agent-password1-error').html("Please make sure you entered same passwords");
891
		$('#create-password1').addClass('agent-form-error');
892
		$('#create-password2').addClass('agent-form-error');
893
		formError = true;
894
	}
895
 
896
	if(formError){
897
		return false;
898
	}
899
	return true;
900
}
901
 
902
function clearAgentCreationForm() {
903
		$('#agent-name-error').html("");
904
		$('#new-agent-name').removeClass('agent-form-error');
905
		$('#agent-email-error').html("");
906
		$('#new-agent-id').removeClass('agent-form-error');
907
		$('#agent-password1-error').html("");
908
		$('#create-password1').removeClass('agent-form-error');
909
		$('#agent-password2-error').html("");
910
		$('#create-password2').removeClass('agent-form-error');
911
		$('#agent-password1-error').html("");
912
		$('#create-password1').removeClass('agent-form-error');
913
		$('#create-password2').removeClass('agent-form-error');
914
}
915
 
916
function deactivateAgent(emailId, id) {
917
	$.ajax({
918
		type : "POST",
919
		url : "/crm/agent!deActivateAgent?emailId=" + emailId+ "&id=" + id,
920
		success : function(response) {   
921
			alert("Agent : " + "deactivated successfully");
922
			$.colorbox.close();
923
			$('#infopane').html(response);
924
 
925
			var agentTable = $('#agents').dataTable({
926
                "aaSorting" : [ [ 1, 'asc' ] ],
927
                "bAutoWidth": false,
928
                "aoColumns" : [{ "sWidth": "12%", "sSortDataType": "dom-text", "sType": "numeric" },//AgentID
929
                               { "sWidth": "35%" },//Agent Name
930
                               { "sWidth": "40%" },//Email ID
931
                               { "sWidth": "13%", "sSortDataType": "dom-text", "sType": "numeric"}],//Manager ID
932
                "iDisplayLength" : 10,
933
                "sDom" : 'T<"clear">lfrtip',
934
                "oTableTools" : {
935
                    "sSwfPath" : "swf/copy_cvs_xls_pdf.swf"
936
                },
937
            });
938
		}
939
	});
5791 anupam.sin 940
}
941
 
5917 anupam.sin 942
function extendExpiryDate(domId, ticketId, orderId, pickupExtension) {
5791 anupam.sin 943
    $.ajax({
944
        type : "POST",
5917 anupam.sin 945
        url : "/crm/tickets!extendExpiry?id=" + ticketId + "&orderId=" + orderId + "&pickupExtension=" + pickupExtension,
5791 anupam.sin 946
        success : function(response) {
947
            $('#' + domId).html(response);
948
        }
949
    });
6507 anupam.sin 950
}
951
 
952
function refundRechargeOrder(rechargeOrderId, domId) {
953
	$.ajax({
954
        type : "POST",
955
        url : "/crm/recharge-order-info!refundRechargeOrder?rechargeOrderId=" + rechargeOrderId,
956
        success : function(response) {
957
        	$('#' + domId).html(response);
958
            var trId = 'order-row-' + rechargeOrderId;
959
            if (orderTable != null) {
960
                for ( var index in orderTable.fnGetNodes()) {
961
                    var item = orderTable.fnGetNodes()[index];
962
                    if ($(item).attr('id') == trId) {
963
                        orderTable.fnDisplayRow(item);
964
                        break;
965
                    }
966
                }
967
            }
968
            $('#recharge-orders tr').removeClass('selected');
969
            $('#order-row-' + rechargeOrderId).addClass('selected');
970
        },
971
        error : function() {
972
        	$('#' + domId).html("<div style='padding:15px 5px 15px 5px;color:red;'><b>Error in refunding. " +
973
        			"<a href='/crm/?email=&mobileNumber=&orderId=&ticketId=&rechargeOrderId=" + rechargeOrderId + "&deviceNumber=&submit=Search'>Try again</a> or contact Engineering team.</b></div>");
974
        }
975
    });
976
 
4241 anupam.sin 977
}