Subversion Repositories SmartDukaan

Rev

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