Subversion Repositories SmartDukaan

Rev

Rev 7372 | Rev 7399 | 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
6985 anupam.sin 29
                             { "sWidth": "13%" }],//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
6982 anupam.sin 57
                             { "sWidth": "13%" }],//mobile no.
58
                "fnDrawCallback": function() { truncateText(180); },
6111 anupam.sin 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
7162 kshitij.so 291
                               { "sWidth": "25%" },//Agent Name
292
                               { "sWidth": "30%" },//Email ID
293
                               { "sWidth": "20%" },//Role
4793 amar.kumar 294
                               { "sWidth": "13%", "sSortDataType": "dom-text", "sType": "numeric"}],//Manager ID
295
                "iDisplayLength" : 10,
296
                "sDom" : 'T<"clear">lfrtip',
297
                "oTableTools" : {
298
                    "sSwfPath" : "swf/copy_cvs_xls_pdf.swf"
299
                },
300
            });
301
		}
302
	});
303
}
304
 
5909 amar.kumar 305
function loadAllOpenTickets(domId) {
306
	$.ajax({
307
		type    : "GET",
308
		url	    : "/crm/tickets!getAllOpenTickets",
309
		success : function(response) {
310
			$('#' + domId).html(response);
311
 
312
			var agentTable = $('#open-tickets').dataTable({
313
                "aaSorting" : [ [ 1, 'asc' ] ],
314
                "bAutoWidth": true,
315
                "iDisplayLength" : 25,
316
                "sDom" : 'T<"clear">lfrtip',
317
                "oTableTools" : {
318
                    "sSwfPath" : "swf/copy_cvs_xls_pdf.swf"
319
                },
320
            });
321
		}
322
	});
323
}
324
 
3405 mandeep.dh 325
function loadTicketCreationForm(domId, params) {
3228 mandeep.dh 326
    $.ajax({
327
        type : "GET",
3339 mandeep.dh 328
        url : "/crm/tickets/new",
3405 mandeep.dh 329
        data : params,
3339 mandeep.dh 330
        success : function(response) {
331
            $('#' + domId).html(response);
332
        }
333
    });
334
}
335
 
3405 mandeep.dh 336
function loadActivityCreationForm(domId, params) {
3339 mandeep.dh 337
    $.ajax({
338
        type : "GET",
339
        url : "/crm/activity/new",
3405 mandeep.dh 340
        data : params,
3339 mandeep.dh 341
        success : function(response) {
342
            $('#' + domId).html(response);
343
        }
344
    });
345
}
346
 
3090 mandeep.dh 347
function updateTicket(domId, ticketId, params) {
3228 mandeep.dh 348
    $.ajax({
4782 mandeep.dh 349
        type : "POST",
350
        url : "/crm/tickets!update?id=" + ticketId,
351
        data : params,
3228 mandeep.dh 352
        success : function(response) {
3339 mandeep.dh 353
            var ticketTable = $('table[id$="tickets"]');
354
            if (ticketTable.length == 1) {
355
                var rowIndex = ticketTable.dataTable().fnGetPosition($('tr#ticket-row-' + ticketId)[0]);
356
                var responseObj = jQuery(response);
3546 mandeep.dh 357
                var actionMessages = responseObj.find('#action-messages').html();
3339 mandeep.dh 358
                responseObj.find('#ticket-row-' + ticketId).children().each(
359
                        function(i, item) {
360
                            var th = responseObj.find('th').eq(i);
361
                            if (th.text() == "Ticket Id") {
362
                                return;
363
                            }
364
 
365
                            var thOld = ticketTable.find('th').filter(
366
                                    function(index) {
367
                                        if ($(this).text() == th.text()) {
368
                                            return true;
369
                                        }
370
 
371
                                        return false;
372
                                    });
373
 
4249 anupam.sin 374
                            if ($(thOld).length != 0) {
3339 mandeep.dh 375
                                ticketTable.dataTable().fnUpdate($(item).text(), rowIndex, $(thOld).index(), true, false);
376
                            }
377
                        });
378
 
3546 mandeep.dh 379
                loadTicketInfo("bottom-infopane", ticketId, ticketTable.dataTable(), null);
3339 mandeep.dh 380
                ticketTable.css('table-layout', 'fixed');
3546 mandeep.dh 381
 
382
                var alertString = jQuery.trim(actionMessages);
383
                if (alertString != '') {
384
                    alert(alertString);
385
                }
3339 mandeep.dh 386
            }
387
            else {
388
                loadTicketInfo("bottom-infopane", ticketId, null, null);
389
            }
390
 
3499 mandeep.dh 391
            truncateText(85);
3339 mandeep.dh 392
        }
393
    });
394
}
395
 
3090 mandeep.dh 396
function createTicket(domId, params) {
3228 mandeep.dh 397
    $.ajax({
398
        type : "POST",
3339 mandeep.dh 399
        url : "/crm/tickets",
3228 mandeep.dh 400
        data : params,
401
        success : function(response) {
402
            $('#' + domId).html(response);
3405 mandeep.dh 403
            var ticketTable = createTicketDataTable('tickets');
3228 mandeep.dh 404
        }
405
    });
3090 mandeep.dh 406
}
407
 
4793 amar.kumar 408
function createAgent(params, managerId){
409
	$.ajax({
410
		type : "POST",
411
		url : "/crm/agent!createAgent?managerId="+managerId,
412
		data : params,
413
		success : function(response) {
414
			alert("Agent created with the specified information");
415
			$.colorbox.close();
416
			$('#infopane').html(response);
417
			var agentTable = $('#agents').dataTable({
418
                "aaSorting" : [ [ 1, 'asc' ] ],
419
                "bAutoWidth": false,
420
                "aoColumns" : [{ "sWidth": "12%", "sSortDataType": "dom-text", "sType": "numeric" },//AgentID
7162 kshitij.so 421
                               { "sWidth": "25%" },//Agent Name
422
                               { "sWidth": "30%" },//Email ID
423
                               { "sWidth": "20%" },//Role
4793 amar.kumar 424
                               { "sWidth": "13%", "sSortDataType": "dom-text", "sType": "numeric"}],//Manager ID
425
                "iDisplayLength" : 10,
426
                "sDom" : 'T<"clear">lfrtip',
427
                "oTableTools" : {
428
                    "sSwfPath" : "swf/copy_cvs_xls_pdf.swf"
429
                },
430
            });
431
		}
432
	});
433
}
434
 
5168 amar.kumar 435
function changeAgentRole(params){
436
	$.ajax({
437
		type : "POST",
438
		url : "/crm/agent!changeAgentRole",
439
		data : params,
440
		success : function(response) {
441
			alert("Agent role changed");
442
			$.colorbox.close();
443
			$('#infopane').html(response);
444
			var agentTable = $('#agents').dataTable({
445
                "aaSorting" : [ [ 1, 'asc' ] ],
446
                "bAutoWidth": false,
447
                "aoColumns" : [{ "sWidth": "12%", "sSortDataType": "dom-text", "sType": "numeric" },//AgentID
7162 kshitij.so 448
                               { "sWidth": "25%" },//Agent Name
449
                               { "sWidth": "30%" },//Email ID
450
                               { "sWidth": "20%" },//Role
5168 amar.kumar 451
                               { "sWidth": "13%", "sSortDataType": "dom-text", "sType": "numeric"}],//Manager ID
452
                "iDisplayLength" : 10,
453
                "sDom" : 'T<"clear">lfrtip',
454
                "oTableTools" : {
455
                    "sSwfPath" : "swf/copy_cvs_xls_pdf.swf"
456
                },
457
            });
458
		}
459
	});
460
}
461
 
3090 mandeep.dh 462
function createActivity(domId, params) {
3228 mandeep.dh 463
    $.ajax({
464
        type : "POST",
3339 mandeep.dh 465
        url : "/crm/activity",
3228 mandeep.dh 466
        data : params,
467
        success : function(response) {
468
            $('#' + domId).html(response);
3405 mandeep.dh 469
            var activityTable = createActivityDataTable('activity');
3228 mandeep.dh 470
        }
471
    });
3106 mandeep.dh 472
}
473
 
474
function goToHomePage() {
3228 mandeep.dh 475
    document.location.href = "/crm";
3106 mandeep.dh 476
}
477
 
3422 mandeep.dh 478
function loadTickets(domId, getURL, ticketId) {
3228 mandeep.dh 479
    $.ajax({
480
        type : "GET",
3234 mandeep.dh 481
        url : getURL,
3228 mandeep.dh 482
        success : function(response) {
483
            $('#' + domId).html(response);
3405 mandeep.dh 484
            var ticketTable = createTicketDataTable('tickets');
3422 mandeep.dh 485
            if (ticketId != null) {
486
                loadTicketInfo("bottom-infopane", ticketId, ticketTable.dataTable(), null);
487
                ticketTable.css('table-layout', 'fixed');
488
            }
3228 mandeep.dh 489
        }
490
    });
3106 mandeep.dh 491
}
5225 amar.kumar 492
function changeActivityFormValidCriteria(commonDescription) {
493
	if(commonDescription == "") {
494
		$('#description').addClass('required');
495
	} else {
496
		$('#description').removeClass('required');
497
	}
498
}
3137 mandeep.dh 499
 
3422 mandeep.dh 500
function processActivityTypeChange(activityType) {
5203 amar.kumar 501
	if(activityType != "RECEIVED_CALL_FROM_CUSTOMER") {
502
		$('select#common-activity-desc').hide();
5224 amar.kumar 503
		$('#description').addClass('required');
5203 amar.kumar 504
	} else {
505
		$('select#common-activity-desc').show();
506
	}
3269 mandeep.dh 507
    if (activityType == "SEND_EMAIL_TO_CUSTOMER") {
3228 mandeep.dh 508
        $.colorbox({
509
            inline : true,
3519 mandeep.dh 510
            width : "775px",
511
            height : "445px",
3228 mandeep.dh 512
            href : "div#mail-div",
513
            onClosed : function() {
3519 mandeep.dh 514
				CKEDITOR.instances['mail-body'].destroy(false);
3228 mandeep.dh 515
                $("div#mail-div").hide();
516
                $('select#activity-type').val('OTHER');
517
            }
518
        });
3206 mandeep.dh 519
 
3228 mandeep.dh 520
        $("div#mail-div").show();
3701 mandeep.dh 521
        $('#mail-body').ckeditor({toolbar : 'Basic', scayt_autoStartup : true});
3228 mandeep.dh 522
    }
4020 mandeep.dh 523
    else if (activityType == "ESCALATE_TICKET") {
524
        $.colorbox({
525
            inline : true,
526
            width : "675px",
4027 mandeep.dh 527
            height : "560px",
4020 mandeep.dh 528
            href : "div#escalation-div",
529
            onClosed : function() {
530
                CKEDITOR.instances['escalation-mail-body'].destroy(false);
531
                $("div#escalation-div").hide();
532
                $('select#activity-type').val('OTHER');
533
            }
534
        });
535
 
536
        $("div#escalation-div").show();
537
        $('#escalation-mail-body').ckeditor({toolbar : 'Basic', scayt_autoStartup : true});
538
    }
3206 mandeep.dh 539
}
540
 
541
function processInputFormSubmit() {
3228 mandeep.dh 542
    $.ajax({
543
        type : "POST",
544
        url : "/crm/",
545
        success : function(response) {
546
            $.html(response);
3405 mandeep.dh 547
            var ticketTable = createTicketDataTable('tickets');
3228 mandeep.dh 548
        }
549
    });
3339 mandeep.dh 550
}
551
 
552
function listActivities(domId, params) {
553
    $.ajax({
554
        type : "GET",
555
        url : "/crm/activity",
556
        data : params,
557
        success : function(response) {
558
            $('#' + domId).html(response);
3405 mandeep.dh 559
            var activityTable = createActivityDataTable('activity');
3339 mandeep.dh 560
        }
561
    });
562
}
563
 
564
function truncateText(widthSize) {
4241 anupam.sin 565
    $(".truncated-text").each(function() {
566
    	$(this).truncate({
567
            width : $(this).attr('truncatedTextWidth'),
568
            addtitle : true
569
        });
570
	})
3339 mandeep.dh 571
}
3390 mandeep.dh 572
 
573
function markAsRead(activityId) {
574
    $.ajax({
575
        type : "POST",
576
        url : "/crm/activity!markAsRead?activityId=" + activityId,
577
        success: function(response) {
578
            listActivities('infopane', "creatorId=1");
579
        }
580
    });
581
}
3397 mandeep.dh 582
 
583
function loadAdvancedSearchBox() {
584
    $.colorbox({
585
        inline : true,
586
        width : "535px",
587
        height : "465px",
588
        href : "form#search",
589
        onClosed : function() {
590
            $("form#search").hide();
591
        }
592
    });
593
 
594
    $("form#search").show();
595
}
596
 
597
function processSearchEntityChange(searchEntity) {
598
    if (searchEntity == "Tickets") {
599
        $("#assignee").show();
600
        $("#creator").hide();
4142 mandeep.dh 601
        $("tr#activityTypes").hide();
3397 mandeep.dh 602
    }
603
    else if (searchEntity == "Activities") {
604
        $("#assignee").hide();
605
        $("#creator").show();
4142 mandeep.dh 606
        $("tr#activityTypes").show();
3397 mandeep.dh 607
    }
608
}
3499 mandeep.dh 609
 
610
function increaseTrustLevel(domId, userId, trustLevelDelta) {
611
    $.ajax({
612
        type : "PUT",
613
        url : "/crm/user-info/" + userId + "?trustLevelDelta=" + trustLevelDelta,
614
        success : function(response) {
615
            $('#' + domId).html(response);
616
        }
617
    });
618
}
619
 
4241 anupam.sin 620
function displayCancelOrderPopUp() {
621
    	$.colorbox({
622
            inline : true,
623
            width : "650px",
4314 anupam.sin 624
            height : "550px",
4689 anupam.sin 625
            href : "div#cancel-div",
4241 anupam.sin 626
            onClosed : function() {
4689 anupam.sin 627
                CKEDITOR.instances['cancel-body'].destroy(false);
628
                $("div#cancel-div").hide();
4241 anupam.sin 629
            }
630
        });
631
 
4689 anupam.sin 632
        $("div#cancel-div").show();
633
        $('#cancel-body').ckeditor({toolbar : 'Basic', scayt_autoStartup : true});
4241 anupam.sin 634
}
635
 
7393 anupam.sin 636
function displayCancelStoreOrderPopUp() {
637
	$.colorbox({
638
        inline : true,
639
        width : "650px",
640
        height : "550px",
641
        href : "#cancel-store-order-div",
642
        onClosed : function() {
643
            CKEDITOR.instances['cancel-store-order-body'].destroy(false);
644
            $("#cancel-store-order-div").hide();
645
        }
646
    });
647
 
648
    $("#cancel-store-order-div").show();
649
    $('#cancel-store-order-body').ckeditor({toolbar : 'Basic', scayt_autoStartup : true});
650
}
651
 
7372 kshitij.so 652
function displayLimitedCancelOrderPopUp() {
653
	$.colorbox({
654
        inline : true,
655
        width : "650px",
656
        height : "550px",
657
        href : "div#cancel-div-limited",
658
        onClosed : function() {
659
            CKEDITOR.instances['cancel-body'].destroy(false);
660
            $("div#cancel-div-limited").hide();
661
        }
662
    });
663
 
664
    $("div#cancel-div-limited").show();
665
    $('#cancel-body').ckeditor({toolbar : 'Basic', scayt_autoStartup : true});
666
}
667
 
4241 anupam.sin 668
function cancelOrder(domId, ticketId, orderId, orderStatus, formData) {
4704 anupam.sin 669
	if ($('#cancellationInitiator').val()) {
4689 anupam.sin 670
		var cancellationInitiator = $('#cancellationInitiator').val();
671
		var uri = "/crm/user-order-info!markOrderForCancellation?orderId=" + orderId
672
						+ "&cancellationInitiator=" + cancellationInitiator + "&" + formData;
673
		var cancellationResult = function() {
674
			document.location.href = "/crm?email=&orderId=" + orderId;
675
		}
676
	} else {
677
		var uri = "/crm/tickets!updateOrderStatus?id=" + ticketId + "&orderId=" + orderId
678
						+ "&orderStatus=" + orderStatus + "&" + formData;
679
		var cancellationResult = function(response) {
680
            $('#' + domId).html(response);
681
        }
682
	}
4241 anupam.sin 683
    $.ajax({
684
        type : "POST",
4689 anupam.sin 685
        url : uri,
686
        success : cancellationResult
4241 anupam.sin 687
    });
4681 amar.kumar 688
 
689
    if(formData.indexOf("LOWER_PRICE_AVAILABLE_ELSEWHERE")!=-1){
690
    	var desc = formData.split("&");
691
    	var description = "Order cancelled because of Lower Price Available elsewhere";
692
    	$.ajax({
693
    		type : "POST",
694
    		url : "/crm/tickets?orderId="+orderId+"&priority=MEDIUM&category=PRODUCT_PROCUREMENT"
695
    				+ "&assigneeEmailId=chaitnaya.vats@shop2020.in&description="+description+"&"+desc[1],
696
    		success : function(response){
697
    			alert("Ticket created for Lower Price Available elsewhere");
698
    		}
699
    	});
700
 
701
    }
4241 anupam.sin 702
}
4065 mandeep.dh 703
 
7393 anupam.sin 704
function cancelStoreOrder(domId, ticketId, orderId, orderStatus, formData) {
705
	if ($('#cancellationInitiator').val() != "CUSTOMER" && $('#cancellationInitiator').val() != "INTERNAL") {
706
		alert("Cannot refund");
707
		return false;
708
	} 
709
	var cancellationInitiator = $('#cancellationInitiator').val();
710
	var uri = "/crm/user-order-info!markOrderForCancellation?orderId=" + orderId
711
					+ "&cancellationInitiator=" + cancellationInitiator + "&" + formData;
712
	var cancellationResult = function() {
713
		document.location.href = "/crm?email=&orderId=" + orderId;
714
	}
715
 
716
    $.ajax({
717
        type : "POST",
718
        url : uri,
719
        success : cancellationResult
720
    });
721
}
722
 
4241 anupam.sin 723
function updateOrderStatus(domId, ticketId, orderId, orderStatus) {
3499 mandeep.dh 724
    $.ajax({
3546 mandeep.dh 725
        type : "POST",
4241 anupam.sin 726
        url : "/crm/tickets!updateOrderStatus?id=" + ticketId + "&orderId=" + orderId
727
        					+ "&orderStatus=" + orderStatus,
3499 mandeep.dh 728
        success : function(response) {
3546 mandeep.dh 729
            $('#' + domId).html(response);
3499 mandeep.dh 730
        }
731
    });
3711 mandeep.dh 732
}
733
 
734
function loadUnreadActivities(domId) {
735
    $.ajax({
736
        type : "GET",
737
        url : "/crm/activity!getUnreadActivities",
738
        success : function(response) {
739
            $('#' + domId).html(response);
740
            var activityTable = createActivityDataTable('activity');
741
        }
742
    });
743
}
4065 mandeep.dh 744
 
745
function refreshSidebar() {
746
    $.ajax({
4142 mandeep.dh 747
        type : "PUT",
748
        url : "/crm",
749
        success : function(response) {
750
            $('#sidebar').html($(response).find('#sidebar').html());
751
        }
752
    });
753
}
754
 
755
function changeAddress(urlParams) {
756
    $.ajax({
4065 mandeep.dh 757
        type : "GET",
758
        url : "/crm",
759
        success : function(response) {
760
            $('#sidebar').html($(response).find('#sidebar').html());
761
        }
762
    });
4267 anupam.sin 763
}
764
 
4681 amar.kumar 765
function showHidecancelReasonDiv(cancelReason){
4793 amar.kumar 766
	var reasonsToShowDiv = ['LOWER_PRICE_AVAILABLE_ELSEWHERE','OTHER','OUT_OF_STOCK','COLOR_OUT_OF_STOCK'];
767
	if(($.inArray(cancelReason, reasonsToShowDiv))!=-1){
4681 amar.kumar 768
		$('#cancelReasonBox').show();
769
	} else {
770
		$('#cancelReasonBox').hide();
771
	}
772
}
773
 
4438 anupam.sin 774
function blockPayment(transactionId, ticketId, paymentId) {
4267 anupam.sin 775
	$.ajax({
776
		type : "GET",
4451 anupam.sin 777
		url : "/crm/tickets!blockPayment?transactionId=" + transactionId + "&id=" + ticketId + "&paymentId=" + paymentId,
4267 anupam.sin 778
		success : function(response) {
779
            $('#bottom-infopane').html(response);
780
        }
781
	});
782
}
783
 
4438 anupam.sin 784
function allowPayment(transactionId, ticketId, paymentId) {
4267 anupam.sin 785
	$.ajax({
786
		type : "GET",
4451 anupam.sin 787
		url : "/crm/tickets!allowPayment?transactionId=" + transactionId + "&id=" + ticketId + "&paymentId=" + paymentId,
4267 anupam.sin 788
		success : function(response) {
789
            $('#bottom-infopane').html(response);
790
        }
791
	});
4490 anupam.sin 792
}
793
 
794
function denyDOA(orderId, ticketId) {
795
	$.ajax({
796
		type : "GET",
797
		url : "/crm/tickets!denyDOA?orderId=" + orderId + "&id=" + ticketId,
798
		success : function(response) {
799
            $('#bottom-infopane').html(response);
800
        }
801
	});
802
}
803
 
804
 
805
function authorizeDOA(orderId, ticketId) {
806
	$.ajax({
807
		type : "GET",
808
		url : "/crm/tickets!authorizeDOA?orderId=" + orderId + "&id=" + ticketId,
809
		success : function(response) {
810
            $('#bottom-infopane').html(response);
811
        }
812
	});
813
}
814
 
815
function denyReturn(orderId, ticketId) {
816
	$.ajax({
817
		type : "GET",
818
		url : "/crm/tickets!denyReturn?orderId=" + orderId + "&id=" + ticketId,
819
		success : function(response) {
820
            $('#bottom-infopane').html(response);
821
        }
822
	});
823
}
824
 
825
 
826
function authorizeReturn(orderId, ticketId) {
827
	$.ajax({
828
		type : "GET",
829
		url : "/crm/tickets!authorizeReturn?orderId=" + orderId + "&id=" + ticketId,
830
		success : function(response) {
831
            $('#bottom-infopane').html(response);
832
        }
833
	});
4689 anupam.sin 834
}
835
 
836
function markOrderForCancellation(orderId, formData) {
837
	console.log(typeof(orderId), typeof(formData), orderId, formData);
838
 
839
	$.ajax({
840
		type : "GET",
841
		url : "/crm/user-order-info!markOrderForCancellation?orderId=" + orderId + "&cancellationInitiator=" + formData,
842
		success : function(response) {
843
			document.location.href = "/crm?email=&orderId=" + orderId;
844
        }
845
	});
4793 amar.kumar 846
}
847
 
848
function loadAgentCreationForm() {
849
	$.colorbox({
850
        inline : true,
851
        width : "550px",
852
        height : "400px",
853
        href : "div#create-agent-div",
854
        onClosed : function() {
855
            $("div#create-agent-div").hide();
856
        }
857
    });
858
 
859
    $("div#create-agent-div").show();
860
 
861
}
862
 
863
function deactivateAgentPopup() {
864
	$.colorbox({
865
        inline : true,
866
        width : "400px",
867
        height : "150px",
868
        href : "div#deactivate-agent-div",
869
        onClosed : function() {
870
            $("div#deactivate-agent-div").hide();
871
        }
872
    });
873
 
874
    $("div#deactivate-agent-div").show();
875
 
876
}
877
 
878
function changeAgentPasswordPopup(){
879
	$.colorbox({
880
        inline : true,
881
        width  : "350px",
882
        height : "350px",
883
        href   : "div#change-password-div",
884
        onClosed : function() {
885
            $("div#change-password-div").hide();
886
        }
887
    });
888
 
889
    $("div#change-password-div").show();
890
}
891
 
5168 amar.kumar 892
function changeAgentRolePopup(){
893
	$.colorbox({
894
        inline : true,
895
        width  : "375px",
896
        height : "350px",
897
        href   : "div#change-agent-role-div",
898
        onClosed : function() {
899
            $("div#change-agent-role-div").hide();
900
        }
901
    });
4793 amar.kumar 902
 
5168 amar.kumar 903
    $("div#change-agent-role-div").show();
904
}
905
 
4793 amar.kumar 906
function updateAgentPassword(){
907
	if(($('#change-password1').val().trim())==($('#change-password2').val().trim())){
908
		$.ajax({
909
			type : "POST",
910
			url : "/crm/agent!changePassword?emailId=" + $('#agentEmail').val() + "&newPassword=" + $('#change-password1').val().trim(),
911
			success : function(response) {
912
				alert("Password updated successfully");
913
				$.colorbox.close();
914
			}
915
		});
916
	}
917
	else { 
918
		alert("Passwords not matching");
919
		return false;
920
	}
921
}
922
 
923
function validateAgentCreationForm(){
924
	var formError = false;
925
	if($('#new-agent-name').val().length == 0) {
926
		$('#agent-name-error').html("Please enter the name");
927
		$('#new-agent-name').addClass('agent-form-error');
928
		formError = true;
929
	}
930
	if(($('#new-agent-id').val().length == 0)) {
931
		$('#agent-email-error').html("Please enter the Email-ID");
932
		$('#new-agent-id').addClass('agent-form-error');
933
		formError = true;
934
	}
935
	if($('#create-password1').val().length == 0) {
936
		$('#agent-password1-error').html("Please enter password");
937
		$('#create-password1').addClass('agent-form-error');
938
		formError = true;
939
	} else if($('#create-password2').val().length == 0){
940
		$('#agent-password2-error').html("Please re enter password");
941
		$('#create-password2').addClass('agent-form-error');
942
		formError = true;
943
	} else if($('#create-password1').val()!=$('#create-password2').val()) {
944
		$('#agent-password1-error').html("Please make sure you entered same passwords");
945
		$('#create-password1').addClass('agent-form-error');
946
		$('#create-password2').addClass('agent-form-error');
947
		formError = true;
948
	}
949
 
950
	if(formError){
951
		return false;
952
	}
953
	return true;
954
}
955
 
956
function clearAgentCreationForm() {
957
		$('#agent-name-error').html("");
958
		$('#new-agent-name').removeClass('agent-form-error');
959
		$('#agent-email-error').html("");
960
		$('#new-agent-id').removeClass('agent-form-error');
961
		$('#agent-password1-error').html("");
962
		$('#create-password1').removeClass('agent-form-error');
963
		$('#agent-password2-error').html("");
964
		$('#create-password2').removeClass('agent-form-error');
965
		$('#agent-password1-error').html("");
966
		$('#create-password1').removeClass('agent-form-error');
967
		$('#create-password2').removeClass('agent-form-error');
968
}
969
 
970
function deactivateAgent(emailId, id) {
971
	$.ajax({
972
		type : "POST",
973
		url : "/crm/agent!deActivateAgent?emailId=" + emailId+ "&id=" + id,
7162 kshitij.so 974
		success : function(response) { 
975
			alert("Agent deactivated successfully");
4793 amar.kumar 976
			$.colorbox.close();
977
			$('#infopane').html(response);
978
			var agentTable = $('#agents').dataTable({
979
                "aaSorting" : [ [ 1, 'asc' ] ],
980
                "bAutoWidth": false,
981
                "aoColumns" : [{ "sWidth": "12%", "sSortDataType": "dom-text", "sType": "numeric" },//AgentID
7162 kshitij.so 982
                               { "sWidth": "25%" },//Agent Name
983
                               { "sWidth": "30%" },//Email ID
984
                               { "sWidth": "20%" },//Role
4793 amar.kumar 985
                               { "sWidth": "13%", "sSortDataType": "dom-text", "sType": "numeric"}],//Manager ID
986
                "iDisplayLength" : 10,
987
                "sDom" : 'T<"clear">lfrtip',
988
                "oTableTools" : {
989
                    "sSwfPath" : "swf/copy_cvs_xls_pdf.swf"
990
                },
991
            });
992
		}
993
	});
5791 anupam.sin 994
}
995
 
5917 anupam.sin 996
function extendExpiryDate(domId, ticketId, orderId, pickupExtension) {
5791 anupam.sin 997
    $.ajax({
998
        type : "POST",
5917 anupam.sin 999
        url : "/crm/tickets!extendExpiry?id=" + ticketId + "&orderId=" + orderId + "&pickupExtension=" + pickupExtension,
5791 anupam.sin 1000
        success : function(response) {
1001
            $('#' + domId).html(response);
1002
        }
1003
    });
6507 anupam.sin 1004
}
1005
 
1006
function refundRechargeOrder(rechargeOrderId, domId) {
1007
	$.ajax({
1008
        type : "POST",
1009
        url : "/crm/recharge-order-info!refundRechargeOrder?rechargeOrderId=" + rechargeOrderId,
1010
        success : function(response) {
6516 anupam.sin 1011
        	location.reload();
6507 anupam.sin 1012
        },
1013
        error : function() {
1014
        	$('#' + domId).html("<div style='padding:15px 5px 15px 5px;color:red;'><b>Error in refunding. " +
1015
        			"<a href='/crm/?email=&mobileNumber=&orderId=&ticketId=&rechargeOrderId=" + rechargeOrderId + "&deviceNumber=&submit=Search'>Try again</a> or contact Engineering team.</b></div>");
1016
        }
1017
    });
1018
 
6985 anupam.sin 1019
}
1020
 
1021
function changeShippingAddress(orderId) {
1022
	$.ajax({
1023
        type : "POST",
1024
        url : "/crm/user-order-info!changeShippingAddress?orderId=" + orderId,
1025
        data : $('#shippingAddressFrm').serialize(),
1026
        success : function(response) {
1027
        	location.reload();
1028
        },
1029
        error : function() {
1030
        	location.reload();
1031
        }
1032
    });
1033
 
7372 kshitij.so 1034
}