Subversion Repositories SmartDukaan

Rev

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