Subversion Repositories SmartDukaan

Rev

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