Subversion Repositories SmartDukaan

Rev

Rev 7162 | Rev 7393 | 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
 
7372 kshitij.so 636
function displayLimitedCancelOrderPopUp() {
637
	$.colorbox({
638
        inline : true,
639
        width : "650px",
640
        height : "550px",
641
        href : "div#cancel-div-limited",
642
        onClosed : function() {
643
            CKEDITOR.instances['cancel-body'].destroy(false);
644
            $("div#cancel-div-limited").hide();
645
        }
646
    });
647
 
648
    $("div#cancel-div-limited").show();
649
    $('#cancel-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
 
4241 anupam.sin 688
function updateOrderStatus(domId, ticketId, orderId, orderStatus) {
3499 mandeep.dh 689
    $.ajax({
3546 mandeep.dh 690
        type : "POST",
4241 anupam.sin 691
        url : "/crm/tickets!updateOrderStatus?id=" + ticketId + "&orderId=" + orderId
692
        					+ "&orderStatus=" + orderStatus,
3499 mandeep.dh 693
        success : function(response) {
3546 mandeep.dh 694
            $('#' + domId).html(response);
3499 mandeep.dh 695
        }
696
    });
3711 mandeep.dh 697
}
698
 
699
function loadUnreadActivities(domId) {
700
    $.ajax({
701
        type : "GET",
702
        url : "/crm/activity!getUnreadActivities",
703
        success : function(response) {
704
            $('#' + domId).html(response);
705
            var activityTable = createActivityDataTable('activity');
706
        }
707
    });
708
}
4065 mandeep.dh 709
 
710
function refreshSidebar() {
711
    $.ajax({
4142 mandeep.dh 712
        type : "PUT",
713
        url : "/crm",
714
        success : function(response) {
715
            $('#sidebar').html($(response).find('#sidebar').html());
716
        }
717
    });
718
}
719
 
720
function changeAddress(urlParams) {
721
    $.ajax({
4065 mandeep.dh 722
        type : "GET",
723
        url : "/crm",
724
        success : function(response) {
725
            $('#sidebar').html($(response).find('#sidebar').html());
726
        }
727
    });
4267 anupam.sin 728
}
729
 
4681 amar.kumar 730
function showHidecancelReasonDiv(cancelReason){
4793 amar.kumar 731
	var reasonsToShowDiv = ['LOWER_PRICE_AVAILABLE_ELSEWHERE','OTHER','OUT_OF_STOCK','COLOR_OUT_OF_STOCK'];
732
	if(($.inArray(cancelReason, reasonsToShowDiv))!=-1){
4681 amar.kumar 733
		$('#cancelReasonBox').show();
734
	} else {
735
		$('#cancelReasonBox').hide();
736
	}
737
}
738
 
4438 anupam.sin 739
function blockPayment(transactionId, ticketId, paymentId) {
4267 anupam.sin 740
	$.ajax({
741
		type : "GET",
4451 anupam.sin 742
		url : "/crm/tickets!blockPayment?transactionId=" + transactionId + "&id=" + ticketId + "&paymentId=" + paymentId,
4267 anupam.sin 743
		success : function(response) {
744
            $('#bottom-infopane').html(response);
745
        }
746
	});
747
}
748
 
4438 anupam.sin 749
function allowPayment(transactionId, ticketId, paymentId) {
4267 anupam.sin 750
	$.ajax({
751
		type : "GET",
4451 anupam.sin 752
		url : "/crm/tickets!allowPayment?transactionId=" + transactionId + "&id=" + ticketId + "&paymentId=" + paymentId,
4267 anupam.sin 753
		success : function(response) {
754
            $('#bottom-infopane').html(response);
755
        }
756
	});
4490 anupam.sin 757
}
758
 
759
function denyDOA(orderId, ticketId) {
760
	$.ajax({
761
		type : "GET",
762
		url : "/crm/tickets!denyDOA?orderId=" + orderId + "&id=" + ticketId,
763
		success : function(response) {
764
            $('#bottom-infopane').html(response);
765
        }
766
	});
767
}
768
 
769
 
770
function authorizeDOA(orderId, ticketId) {
771
	$.ajax({
772
		type : "GET",
773
		url : "/crm/tickets!authorizeDOA?orderId=" + orderId + "&id=" + ticketId,
774
		success : function(response) {
775
            $('#bottom-infopane').html(response);
776
        }
777
	});
778
}
779
 
780
function denyReturn(orderId, ticketId) {
781
	$.ajax({
782
		type : "GET",
783
		url : "/crm/tickets!denyReturn?orderId=" + orderId + "&id=" + ticketId,
784
		success : function(response) {
785
            $('#bottom-infopane').html(response);
786
        }
787
	});
788
}
789
 
790
 
791
function authorizeReturn(orderId, ticketId) {
792
	$.ajax({
793
		type : "GET",
794
		url : "/crm/tickets!authorizeReturn?orderId=" + orderId + "&id=" + ticketId,
795
		success : function(response) {
796
            $('#bottom-infopane').html(response);
797
        }
798
	});
4689 anupam.sin 799
}
800
 
801
function markOrderForCancellation(orderId, formData) {
802
	console.log(typeof(orderId), typeof(formData), orderId, formData);
803
 
804
	$.ajax({
805
		type : "GET",
806
		url : "/crm/user-order-info!markOrderForCancellation?orderId=" + orderId + "&cancellationInitiator=" + formData,
807
		success : function(response) {
808
			document.location.href = "/crm?email=&orderId=" + orderId;
809
        }
810
	});
4793 amar.kumar 811
}
812
 
813
function loadAgentCreationForm() {
814
	$.colorbox({
815
        inline : true,
816
        width : "550px",
817
        height : "400px",
818
        href : "div#create-agent-div",
819
        onClosed : function() {
820
            $("div#create-agent-div").hide();
821
        }
822
    });
823
 
824
    $("div#create-agent-div").show();
825
 
826
}
827
 
828
function deactivateAgentPopup() {
829
	$.colorbox({
830
        inline : true,
831
        width : "400px",
832
        height : "150px",
833
        href : "div#deactivate-agent-div",
834
        onClosed : function() {
835
            $("div#deactivate-agent-div").hide();
836
        }
837
    });
838
 
839
    $("div#deactivate-agent-div").show();
840
 
841
}
842
 
843
function changeAgentPasswordPopup(){
844
	$.colorbox({
845
        inline : true,
846
        width  : "350px",
847
        height : "350px",
848
        href   : "div#change-password-div",
849
        onClosed : function() {
850
            $("div#change-password-div").hide();
851
        }
852
    });
853
 
854
    $("div#change-password-div").show();
855
}
856
 
5168 amar.kumar 857
function changeAgentRolePopup(){
858
	$.colorbox({
859
        inline : true,
860
        width  : "375px",
861
        height : "350px",
862
        href   : "div#change-agent-role-div",
863
        onClosed : function() {
864
            $("div#change-agent-role-div").hide();
865
        }
866
    });
4793 amar.kumar 867
 
5168 amar.kumar 868
    $("div#change-agent-role-div").show();
869
}
870
 
4793 amar.kumar 871
function updateAgentPassword(){
872
	if(($('#change-password1').val().trim())==($('#change-password2').val().trim())){
873
		$.ajax({
874
			type : "POST",
875
			url : "/crm/agent!changePassword?emailId=" + $('#agentEmail').val() + "&newPassword=" + $('#change-password1').val().trim(),
876
			success : function(response) {
877
				alert("Password updated successfully");
878
				$.colorbox.close();
879
			}
880
		});
881
	}
882
	else { 
883
		alert("Passwords not matching");
884
		return false;
885
	}
886
}
887
 
888
function validateAgentCreationForm(){
889
	var formError = false;
890
	if($('#new-agent-name').val().length == 0) {
891
		$('#agent-name-error').html("Please enter the name");
892
		$('#new-agent-name').addClass('agent-form-error');
893
		formError = true;
894
	}
895
	if(($('#new-agent-id').val().length == 0)) {
896
		$('#agent-email-error').html("Please enter the Email-ID");
897
		$('#new-agent-id').addClass('agent-form-error');
898
		formError = true;
899
	}
900
	if($('#create-password1').val().length == 0) {
901
		$('#agent-password1-error').html("Please enter password");
902
		$('#create-password1').addClass('agent-form-error');
903
		formError = true;
904
	} else if($('#create-password2').val().length == 0){
905
		$('#agent-password2-error').html("Please re enter password");
906
		$('#create-password2').addClass('agent-form-error');
907
		formError = true;
908
	} else if($('#create-password1').val()!=$('#create-password2').val()) {
909
		$('#agent-password1-error').html("Please make sure you entered same passwords");
910
		$('#create-password1').addClass('agent-form-error');
911
		$('#create-password2').addClass('agent-form-error');
912
		formError = true;
913
	}
914
 
915
	if(formError){
916
		return false;
917
	}
918
	return true;
919
}
920
 
921
function clearAgentCreationForm() {
922
		$('#agent-name-error').html("");
923
		$('#new-agent-name').removeClass('agent-form-error');
924
		$('#agent-email-error').html("");
925
		$('#new-agent-id').removeClass('agent-form-error');
926
		$('#agent-password1-error').html("");
927
		$('#create-password1').removeClass('agent-form-error');
928
		$('#agent-password2-error').html("");
929
		$('#create-password2').removeClass('agent-form-error');
930
		$('#agent-password1-error').html("");
931
		$('#create-password1').removeClass('agent-form-error');
932
		$('#create-password2').removeClass('agent-form-error');
933
}
934
 
935
function deactivateAgent(emailId, id) {
936
	$.ajax({
937
		type : "POST",
938
		url : "/crm/agent!deActivateAgent?emailId=" + emailId+ "&id=" + id,
7162 kshitij.so 939
		success : function(response) { 
940
			alert("Agent deactivated successfully");
4793 amar.kumar 941
			$.colorbox.close();
942
			$('#infopane').html(response);
943
			var agentTable = $('#agents').dataTable({
944
                "aaSorting" : [ [ 1, 'asc' ] ],
945
                "bAutoWidth": false,
946
                "aoColumns" : [{ "sWidth": "12%", "sSortDataType": "dom-text", "sType": "numeric" },//AgentID
7162 kshitij.so 947
                               { "sWidth": "25%" },//Agent Name
948
                               { "sWidth": "30%" },//Email ID
949
                               { "sWidth": "20%" },//Role
4793 amar.kumar 950
                               { "sWidth": "13%", "sSortDataType": "dom-text", "sType": "numeric"}],//Manager ID
951
                "iDisplayLength" : 10,
952
                "sDom" : 'T<"clear">lfrtip',
953
                "oTableTools" : {
954
                    "sSwfPath" : "swf/copy_cvs_xls_pdf.swf"
955
                },
956
            });
957
		}
958
	});
5791 anupam.sin 959
}
960
 
5917 anupam.sin 961
function extendExpiryDate(domId, ticketId, orderId, pickupExtension) {
5791 anupam.sin 962
    $.ajax({
963
        type : "POST",
5917 anupam.sin 964
        url : "/crm/tickets!extendExpiry?id=" + ticketId + "&orderId=" + orderId + "&pickupExtension=" + pickupExtension,
5791 anupam.sin 965
        success : function(response) {
966
            $('#' + domId).html(response);
967
        }
968
    });
6507 anupam.sin 969
}
970
 
971
function refundRechargeOrder(rechargeOrderId, domId) {
972
	$.ajax({
973
        type : "POST",
974
        url : "/crm/recharge-order-info!refundRechargeOrder?rechargeOrderId=" + rechargeOrderId,
975
        success : function(response) {
6516 anupam.sin 976
        	location.reload();
6507 anupam.sin 977
        },
978
        error : function() {
979
        	$('#' + domId).html("<div style='padding:15px 5px 15px 5px;color:red;'><b>Error in refunding. " +
980
        			"<a href='/crm/?email=&mobileNumber=&orderId=&ticketId=&rechargeOrderId=" + rechargeOrderId + "&deviceNumber=&submit=Search'>Try again</a> or contact Engineering team.</b></div>");
981
        }
982
    });
983
 
6985 anupam.sin 984
}
985
 
986
function changeShippingAddress(orderId) {
987
	$.ajax({
988
        type : "POST",
989
        url : "/crm/user-order-info!changeShippingAddress?orderId=" + orderId,
990
        data : $('#shippingAddressFrm').serialize(),
991
        success : function(response) {
992
        	location.reload();
993
        },
994
        error : function() {
995
        	location.reload();
996
        }
997
    });
998
 
7372 kshitij.so 999
}