Subversion Repositories SmartDukaan

Rev

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