Subversion Repositories SmartDukaan

Rev

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