Subversion Repositories SmartDukaan

Rev

Rev 18348 | Rev 18354 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

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