Subversion Repositories SmartDukaan

Rev

Rev 8821 | Rev 9174 | 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
 
7572 anupam.sin 138
            $('#user-orders tr, #orders-without-user tr').removeClass('selected');
3228 mandeep.dh 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
 
4241 anupam.sin 652
function cancelOrder(domId, ticketId, orderId, orderStatus, formData) {
4704 anupam.sin 653
	if ($('#cancellationInitiator').val()) {
4689 anupam.sin 654
		var cancellationInitiator = $('#cancellationInitiator').val();
655
		var uri = "/crm/user-order-info!markOrderForCancellation?orderId=" + orderId
656
						+ "&cancellationInitiator=" + cancellationInitiator + "&" + formData;
657
		var cancellationResult = function() {
658
			document.location.href = "/crm?email=&orderId=" + orderId;
659
		}
660
	} else {
661
		var uri = "/crm/tickets!updateOrderStatus?id=" + ticketId + "&orderId=" + orderId
662
						+ "&orderStatus=" + orderStatus + "&" + formData;
663
		var cancellationResult = function(response) {
664
            $('#' + domId).html(response);
665
        }
666
	}
4241 anupam.sin 667
    $.ajax({
668
        type : "POST",
4689 anupam.sin 669
        url : uri,
670
        success : cancellationResult
4241 anupam.sin 671
    });
4681 amar.kumar 672
 
673
    if(formData.indexOf("LOWER_PRICE_AVAILABLE_ELSEWHERE")!=-1){
674
    	var desc = formData.split("&");
675
    	var description = "Order cancelled because of Lower Price Available elsewhere";
676
    	$.ajax({
677
    		type : "POST",
678
    		url : "/crm/tickets?orderId="+orderId+"&priority=MEDIUM&category=PRODUCT_PROCUREMENT"
679
    				+ "&assigneeEmailId=chaitnaya.vats@shop2020.in&description="+description+"&"+desc[1],
680
    		success : function(response){
681
    			alert("Ticket created for Lower Price Available elsewhere");
682
    		}
683
    	});
684
 
685
    }
4241 anupam.sin 686
}
4065 mandeep.dh 687
 
7393 anupam.sin 688
function cancelStoreOrder(domId, ticketId, orderId, orderStatus, formData) {
689
	if ($('#cancellationInitiator').val() != "CUSTOMER" && $('#cancellationInitiator').val() != "INTERNAL") {
690
		alert("Cannot refund");
691
		return false;
692
	} 
693
	var cancellationInitiator = $('#cancellationInitiator').val();
694
	var uri = "/crm/user-order-info!markOrderForCancellation?orderId=" + orderId
695
					+ "&cancellationInitiator=" + cancellationInitiator + "&" + formData;
696
	var cancellationResult = function() {
697
		document.location.href = "/crm?email=&orderId=" + orderId;
698
	}
699
 
700
    $.ajax({
701
        type : "POST",
702
        url : uri,
703
        success : cancellationResult
704
    });
705
}
706
 
4241 anupam.sin 707
function updateOrderStatus(domId, ticketId, orderId, orderStatus) {
3499 mandeep.dh 708
    $.ajax({
3546 mandeep.dh 709
        type : "POST",
4241 anupam.sin 710
        url : "/crm/tickets!updateOrderStatus?id=" + ticketId + "&orderId=" + orderId
711
        					+ "&orderStatus=" + orderStatus,
3499 mandeep.dh 712
        success : function(response) {
3546 mandeep.dh 713
            $('#' + domId).html(response);
3499 mandeep.dh 714
        }
715
    });
3711 mandeep.dh 716
}
717
 
718
function loadUnreadActivities(domId) {
719
    $.ajax({
720
        type : "GET",
721
        url : "/crm/activity!getUnreadActivities",
722
        success : function(response) {
723
            $('#' + domId).html(response);
724
            var activityTable = createActivityDataTable('activity');
725
        }
726
    });
727
}
4065 mandeep.dh 728
 
729
function refreshSidebar() {
730
    $.ajax({
4142 mandeep.dh 731
        type : "PUT",
732
        url : "/crm",
733
        success : function(response) {
734
            $('#sidebar').html($(response).find('#sidebar').html());
735
        }
736
    });
737
}
738
 
739
function changeAddress(urlParams) {
740
    $.ajax({
4065 mandeep.dh 741
        type : "GET",
742
        url : "/crm",
743
        success : function(response) {
744
            $('#sidebar').html($(response).find('#sidebar').html());
745
        }
746
    });
4267 anupam.sin 747
}
748
 
4681 amar.kumar 749
function showHidecancelReasonDiv(cancelReason){
4793 amar.kumar 750
	var reasonsToShowDiv = ['LOWER_PRICE_AVAILABLE_ELSEWHERE','OTHER','OUT_OF_STOCK','COLOR_OUT_OF_STOCK'];
751
	if(($.inArray(cancelReason, reasonsToShowDiv))!=-1){
4681 amar.kumar 752
		$('#cancelReasonBox').show();
753
	} else {
754
		$('#cancelReasonBox').hide();
755
	}
756
}
757
 
4438 anupam.sin 758
function blockPayment(transactionId, ticketId, paymentId) {
4267 anupam.sin 759
	$.ajax({
760
		type : "GET",
4451 anupam.sin 761
		url : "/crm/tickets!blockPayment?transactionId=" + transactionId + "&id=" + ticketId + "&paymentId=" + paymentId,
4267 anupam.sin 762
		success : function(response) {
763
            $('#bottom-infopane').html(response);
764
        }
765
	});
766
}
767
 
4438 anupam.sin 768
function allowPayment(transactionId, ticketId, paymentId) {
4267 anupam.sin 769
	$.ajax({
770
		type : "GET",
4451 anupam.sin 771
		url : "/crm/tickets!allowPayment?transactionId=" + transactionId + "&id=" + ticketId + "&paymentId=" + paymentId,
4267 anupam.sin 772
		success : function(response) {
773
            $('#bottom-infopane').html(response);
774
        }
775
	});
4490 anupam.sin 776
}
777
 
778
function denyDOA(orderId, ticketId) {
779
	$.ajax({
780
		type : "GET",
781
		url : "/crm/tickets!denyDOA?orderId=" + orderId + "&id=" + ticketId,
782
		success : function(response) {
783
            $('#bottom-infopane').html(response);
784
        }
785
	});
786
}
787
 
788
 
789
function authorizeDOA(orderId, ticketId) {
790
	$.ajax({
791
		type : "GET",
792
		url : "/crm/tickets!authorizeDOA?orderId=" + orderId + "&id=" + ticketId,
793
		success : function(response) {
794
            $('#bottom-infopane').html(response);
795
        }
796
	});
797
}
798
 
799
function denyReturn(orderId, ticketId) {
800
	$.ajax({
801
		type : "GET",
802
		url : "/crm/tickets!denyReturn?orderId=" + orderId + "&id=" + ticketId,
803
		success : function(response) {
804
            $('#bottom-infopane').html(response);
805
        }
806
	});
807
}
808
 
809
 
810
function authorizeReturn(orderId, ticketId) {
811
	$.ajax({
812
		type : "GET",
813
		url : "/crm/tickets!authorizeReturn?orderId=" + orderId + "&id=" + ticketId,
814
		success : function(response) {
815
            $('#bottom-infopane').html(response);
816
        }
817
	});
4689 anupam.sin 818
}
819
 
820
function markOrderForCancellation(orderId, formData) {
821
	console.log(typeof(orderId), typeof(formData), orderId, formData);
822
 
823
	$.ajax({
824
		type : "GET",
825
		url : "/crm/user-order-info!markOrderForCancellation?orderId=" + orderId + "&cancellationInitiator=" + formData,
826
		success : function(response) {
827
			document.location.href = "/crm?email=&orderId=" + orderId;
828
        }
829
	});
4793 amar.kumar 830
}
831
 
832
function loadAgentCreationForm() {
833
	$.colorbox({
834
        inline : true,
835
        width : "550px",
836
        height : "400px",
837
        href : "div#create-agent-div",
838
        onClosed : function() {
839
            $("div#create-agent-div").hide();
840
        }
841
    });
842
 
843
    $("div#create-agent-div").show();
844
 
845
}
846
 
847
function deactivateAgentPopup() {
848
	$.colorbox({
849
        inline : true,
850
        width : "400px",
851
        height : "150px",
852
        href : "div#deactivate-agent-div",
853
        onClosed : function() {
854
            $("div#deactivate-agent-div").hide();
855
        }
856
    });
857
 
858
    $("div#deactivate-agent-div").show();
859
 
860
}
861
 
862
function changeAgentPasswordPopup(){
863
	$.colorbox({
864
        inline : true,
865
        width  : "350px",
866
        height : "350px",
867
        href   : "div#change-password-div",
868
        onClosed : function() {
869
            $("div#change-password-div").hide();
870
        }
871
    });
872
 
873
    $("div#change-password-div").show();
874
}
875
 
5168 amar.kumar 876
function changeAgentRolePopup(){
877
	$.colorbox({
878
        inline : true,
879
        width  : "375px",
880
        height : "350px",
881
        href   : "div#change-agent-role-div",
882
        onClosed : function() {
883
            $("div#change-agent-role-div").hide();
884
        }
885
    });
4793 amar.kumar 886
 
5168 amar.kumar 887
    $("div#change-agent-role-div").show();
888
}
889
 
4793 amar.kumar 890
function updateAgentPassword(){
891
	if(($('#change-password1').val().trim())==($('#change-password2').val().trim())){
892
		$.ajax({
893
			type : "POST",
894
			url : "/crm/agent!changePassword?emailId=" + $('#agentEmail').val() + "&newPassword=" + $('#change-password1').val().trim(),
895
			success : function(response) {
896
				alert("Password updated successfully");
897
				$.colorbox.close();
898
			}
899
		});
900
	}
901
	else { 
902
		alert("Passwords not matching");
903
		return false;
904
	}
905
}
906
 
907
function validateAgentCreationForm(){
908
	var formError = false;
909
	if($('#new-agent-name').val().length == 0) {
910
		$('#agent-name-error').html("Please enter the name");
911
		$('#new-agent-name').addClass('agent-form-error');
912
		formError = true;
913
	}
914
	if(($('#new-agent-id').val().length == 0)) {
915
		$('#agent-email-error').html("Please enter the Email-ID");
916
		$('#new-agent-id').addClass('agent-form-error');
917
		formError = true;
918
	}
919
	if($('#create-password1').val().length == 0) {
920
		$('#agent-password1-error').html("Please enter password");
921
		$('#create-password1').addClass('agent-form-error');
922
		formError = true;
923
	} else if($('#create-password2').val().length == 0){
924
		$('#agent-password2-error').html("Please re enter password");
925
		$('#create-password2').addClass('agent-form-error');
926
		formError = true;
927
	} else if($('#create-password1').val()!=$('#create-password2').val()) {
928
		$('#agent-password1-error').html("Please make sure you entered same passwords");
929
		$('#create-password1').addClass('agent-form-error');
930
		$('#create-password2').addClass('agent-form-error');
931
		formError = true;
932
	}
933
 
934
	if(formError){
935
		return false;
936
	}
937
	return true;
938
}
939
 
940
function clearAgentCreationForm() {
941
		$('#agent-name-error').html("");
942
		$('#new-agent-name').removeClass('agent-form-error');
943
		$('#agent-email-error').html("");
944
		$('#new-agent-id').removeClass('agent-form-error');
945
		$('#agent-password1-error').html("");
946
		$('#create-password1').removeClass('agent-form-error');
947
		$('#agent-password2-error').html("");
948
		$('#create-password2').removeClass('agent-form-error');
949
		$('#agent-password1-error').html("");
950
		$('#create-password1').removeClass('agent-form-error');
951
		$('#create-password2').removeClass('agent-form-error');
952
}
953
 
954
function deactivateAgent(emailId, id) {
955
	$.ajax({
956
		type : "POST",
957
		url : "/crm/agent!deActivateAgent?emailId=" + emailId+ "&id=" + id,
7162 kshitij.so 958
		success : function(response) { 
959
			alert("Agent deactivated successfully");
4793 amar.kumar 960
			$.colorbox.close();
961
			$('#infopane').html(response);
962
			var agentTable = $('#agents').dataTable({
963
                "aaSorting" : [ [ 1, 'asc' ] ],
964
                "bAutoWidth": false,
965
                "aoColumns" : [{ "sWidth": "12%", "sSortDataType": "dom-text", "sType": "numeric" },//AgentID
7162 kshitij.so 966
                               { "sWidth": "25%" },//Agent Name
967
                               { "sWidth": "30%" },//Email ID
968
                               { "sWidth": "20%" },//Role
4793 amar.kumar 969
                               { "sWidth": "13%", "sSortDataType": "dom-text", "sType": "numeric"}],//Manager ID
970
                "iDisplayLength" : 10,
971
                "sDom" : 'T<"clear">lfrtip',
972
                "oTableTools" : {
973
                    "sSwfPath" : "swf/copy_cvs_xls_pdf.swf"
974
                },
975
            });
976
		}
977
	});
5791 anupam.sin 978
}
979
 
5917 anupam.sin 980
function extendExpiryDate(domId, ticketId, orderId, pickupExtension) {
5791 anupam.sin 981
    $.ajax({
982
        type : "POST",
5917 anupam.sin 983
        url : "/crm/tickets!extendExpiry?id=" + ticketId + "&orderId=" + orderId + "&pickupExtension=" + pickupExtension,
5791 anupam.sin 984
        success : function(response) {
985
            $('#' + domId).html(response);
986
        }
987
    });
6507 anupam.sin 988
}
989
 
990
function refundRechargeOrder(rechargeOrderId, domId) {
991
	$.ajax({
992
        type : "POST",
993
        url : "/crm/recharge-order-info!refundRechargeOrder?rechargeOrderId=" + rechargeOrderId,
994
        success : function(response) {
6516 anupam.sin 995
        	location.reload();
6507 anupam.sin 996
        },
997
        error : function() {
998
        	$('#' + domId).html("<div style='padding:15px 5px 15px 5px;color:red;'><b>Error in refunding. " +
999
        			"<a href='/crm/?email=&mobileNumber=&orderId=&ticketId=&rechargeOrderId=" + rechargeOrderId + "&deviceNumber=&submit=Search'>Try again</a> or contact Engineering team.</b></div>");
1000
        }
1001
    });
6985 anupam.sin 1002
}
1003
 
7730 anupam.sin 1004
function convertStoreToNormal(orderId) {
1005
	$.ajax({
1006
        type : "POST",
7732 anupam.sin 1007
        url : "/crm/user-order-info!convertStoreToNormal?orderId=" + orderId,
7730 anupam.sin 1008
        success : function() {
1009
        	location.reload();
1010
        },
1011
        error: function() {
1012
        	location.reload();
1013
        }
1014
    });
1015
}
1016
 
6985 anupam.sin 1017
function changeShippingAddress(orderId) {
1018
	$.ajax({
1019
        type : "POST",
1020
        url : "/crm/user-order-info!changeShippingAddress?orderId=" + orderId,
1021
        data : $('#shippingAddressFrm').serialize(),
1022
        success : function(response) {
1023
        	location.reload();
1024
        },
1025
        error : function() {
1026
        	location.reload();
1027
        }
1028
    });
7372 kshitij.so 1029
}
7572 anupam.sin 1030
 
8821 manish.sha 1031
function refundOrderPayment(params) {
1032
	$.ajax({
1033
        type : "POST",
1034
        url : "/crm/user-order-info!refundOrderPayment",
1035
        data : params,
1036
        success : function(response) {
1037
			alert(response);
1038
			location.reload();
1039
        },
1040
        error : function() {
1041
        	alert("Error in refund");
1042
        	location.reload();
1043
        }
1044
    });
1045
}
1046
 
7572 anupam.sin 1047
function loadOrdersByMobile(domId) {
1048
    orderTable = $('#orders-without-user').dataTable({
1049
      "aaSorting" : [ [ 1, 'desc' ] ],
1050
      "bAutoWidth": false,
1051
      "aoColumns" : [{ "sWidth": "13%" },//order id
1052
                     { "sWidth": "13%" },//Source
1053
                     { "sWidth": "26%" },//item desc
1054
                     { "sWidth": "16%" },//created
1055
                     { "sWidth": "7%" },//amount
1056
                     { "sWidth": "15%" },//status
1057
                     { "sWidth": "10%" }],//mobile no.
1058
        "fnDrawCallback": function() { truncateText(125); },
1059
        "iDisplayLength" : 10,
1060
        "sDom" : 'T<"clear">lfrtip',
1061
        "oTableTools" : {
1062
            "sSwfPath" : "swf/copy_cvs_xls_pdf.swf"
1063
        },
1064
        "aLengthMenu" : [ [ 5, 10, 20, -1 ], [ 5, 10, 20, "All" ] ]
1065
    });
9166 manish.sha 1066
}
1067
 
1068
function loadRechargeOrdersByDeviceNo(domId){
1069
	orderTable = $('#recharge-orders').dataTable({
1070
	      "aaSorting" : [ [ 1, 'desc' ] ],
1071
	      "bAutoWidth": false,
1072
	      "aoColumns" : [{ "sWidth": "16%" },//recharge order id
1073
                         { "sWidth": "30%" },//desc
1074
                         { "sWidth": "16%" },//created
1075
                         { "sWidth": "8%" },//amount
1076
                         { "sWidth": "17%" },//status
1077
                         { "sWidth": "13%" }],//mobile no.
1078
	        "fnDrawCallback": function() { truncateText(125); },
1079
	        "iDisplayLength" : 10,
1080
	        "sDom" : 'T<"clear">lfrtip',
1081
	        "oTableTools" : {
1082
	            "sSwfPath" : "swf/copy_cvs_xls_pdf.swf"
1083
	        },
1084
	        "aLengthMenu" : [ [ 5, 10, 20, -1 ], [ 5, 10, 20, "All" ] ]
1085
	    });
7572 anupam.sin 1086
}