Subversion Repositories SmartDukaan

Rev

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