Subversion Repositories SmartDukaan

Rev

Rev 5791 | Rev 5917 | 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,
24
              "aoColumns" : [{ "sWidth": "16%" },//order id
25
                             { "sWidth": "30%" },//item desc
26
                             { "sWidth": "16%" },//created
27
                             { "sWidth": "8%" },//amount
28
                             { "sWidth": "17%" },//status
29
                             { "sWidth": "9%" }],//mobile no.
3996 mandeep.dh 30
                "fnDrawCallback": function() { truncateText(125); },
4605 anupam.sin 31
                "iDisplayLength" : 10,
3339 mandeep.dh 32
                "sDom" : 'T<"clear">lfrtip',
33
                "oTableTools" : {
34
                    "sSwfPath" : "swf/copy_cvs_xls_pdf.swf"
35
                },
3228 mandeep.dh 36
                "aLengthMenu" : [ [ 5, 10, 20, -1 ], [ 5, 10, 20, "All" ] ]
37
            });
38
        }
39
    });
2674 vikas 40
}
41
 
3228 mandeep.dh 42
function loadCartPane(domId, userId, cartId) {
43
    $.ajax({
44
        type : "GET",
45
        url : "/crm/user-cart?userId=" + userId + "&cartId=" + cartId,
46
        success : function(response) {
47
            $('#' + domId).html(response);
48
            cartTable = $('#user-cart').dataTable({
49
                "aaSorting" : [ [ 1, 'desc' ] ],
4241 anupam.sin 50
              "bAutoWidth": false,
51
              "aoColumns" : [{ "sWidth": "32%" },//name
52
                             { "sWidth": "9%" },//quantity
53
                             { "sWidth": "16%" },//actual price
54
                             { "sWidth": "16%" },//discounted price
55
                             { "sWidth": "9%" },//estimate
56
                             { "sWidth": "18%" }],//created on
3228 mandeep.dh 57
                "iDisplayLength" : 10,
3339 mandeep.dh 58
                "sDom" : 'T<"clear">lfrtip',
59
                "oTableTools" : {
60
                    "sSwfPath" : "swf/copy_cvs_xls_pdf.swf"
61
                },
3228 mandeep.dh 62
                "aLengthMenu" : [ [ 5, 10, 20, -1 ], [ 5, 10, 20, "All" ] ]
63
            });
64
        }
65
    });
2714 vikas 66
}
67
 
3499 mandeep.dh 68
function loadOrderInfo(domId, orderId) {
3228 mandeep.dh 69
    $.ajax({
70
        type : "GET",
3499 mandeep.dh 71
        url : "/crm/user-order-info?orderId=" + orderId,
3228 mandeep.dh 72
        success : function(response) {
73
            $('#' + domId).html(response);
3220 mandeep.dh 74
 
3228 mandeep.dh 75
            var trId = 'order-row-' + orderId;
76
            if (orderTable != null) {
77
                for ( var index in orderTable.fnGetNodes()) {
78
                    var item = orderTable.fnGetNodes()[index];
79
                    if ($(item).attr('id') == trId) {
80
                        orderTable.fnDisplayRow(item);
81
                        break;
82
                    }
83
                }
84
            }
3220 mandeep.dh 85
 
3228 mandeep.dh 86
            $('#user-orders tr').removeClass('selected');
87
            $('#order-row-' + orderId).addClass('selected');
88
        }
89
    });
2714 vikas 90
}
91
 
3228 mandeep.dh 92
function loadLineInfo(domId, userId, itemId) {
93
    $.ajax({
94
        type : "GET",
95
        url : "/crm/user-line-info?userId=" + userId + "&itemId=" + itemId,
96
        success : function(response) {
97
            $('#' + domId).html(response);
98
            $('#user-cart tr').removeClass('selected');
99
            $('#cart-row-' + itemId).addClass('selected');
100
        }
101
    });
2830 vikas 102
}
103
 
3228 mandeep.dh 104
function loadTicketInfo(domId, ticketId, ticketTable, activityId) {
105
    $.ajax({
106
        type : "GET",
3405 mandeep.dh 107
        url : "/crm/tickets/" + ticketId + "/edit",
3228 mandeep.dh 108
        success : function(response) {
109
            $('#' + domId).html(response);
3206 mandeep.dh 110
 
3228 mandeep.dh 111
            var trId = 'ticket-row-' + ticketId;
112
            if (ticketTable != null) {
113
                for ( var index in ticketTable.fnGetNodes()) {
114
                    var item = ticketTable.fnGetNodes()[index];
115
                    if ($(item).attr('id') == trId) {
116
                        ticketTable.fnDisplayRow(item);
117
                        break;
118
                    }
119
                }
120
            }
3206 mandeep.dh 121
 
3228 mandeep.dh 122
            $('#tickets tr').removeClass('selected');
123
            $('#' + trId).addClass('selected');
124
 
125
            // For tickets accessed from activity page
126
            if (activityId != null) {
3339 mandeep.dh 127
                $('#activity tr').removeClass('selected');
3228 mandeep.dh 128
                $('#activity-row-' + activityId).addClass('selected');
129
            }
3546 mandeep.dh 130
 
131
            $('#order-table').dataTable({
132
                "aaSorting" : [ [ 2, 'desc' ] ],
4241 anupam.sin 133
//            "bAutoWidth": false,
134
//            "aoColumns" : [{ "sWidth": "5%" },
135
//                           { "sWidth": "20%" },
136
//                           { "sWidth": "20%" },
137
//                           { "sWidth": "12.5%" },
138
//                           { "sWidth": "12.5%" },
139
//                           { "sWidth": "10%" },
140
//                           { "sWidth": "10%" },
141
//                           { "sWidth": "10%" }],
4605 anupam.sin 142
                "iDisplayLength" : 10,
3546 mandeep.dh 143
                "fnDrawCallback": function() {truncateText(100);},
144
                "aLengthMenu" : [ [ 5, 10, 20, -1 ], [ 5, 10, 20, "All" ] ]
145
            });
3228 mandeep.dh 146
        }
147
    });
3090 mandeep.dh 148
}
149
 
3405 mandeep.dh 150
function createTicketDataTable(domId) {
3499 mandeep.dh 151
    var ticketsTable = $('#' + domId).dataTable({
4142 mandeep.dh 152
         "aaSorting" : [ [ 3, 'asc' ] ],
4241 anupam.sin 153
         "bAutoWidth": false,
154
         "aoColumns" : [{ "sWidth": "9%" },//ticket id
155
                        { "sWidth": "16%" },//customer id or Description when orderId is set
156
                        { "sWidth": "21%" },//category id
157
                        { "sWidth": "13%" },//date created
158
                        { "sWidth": "13%" },//date closed
159
                        { "sWidth": "12%" },//assignee
160
                        { "sWidth": "8%" },//status
161
                        { "sWidth": "8%" }],//priority
3546 mandeep.dh 162
        "fnDrawCallback": function() {truncateText(85);},
4605 anupam.sin 163
        "iDisplayLength" : 10,
3339 mandeep.dh 164
        "sDom" : 'T<"clear">lfrtip',
165
        "oTableTools" : {
5203 amar.kumar 166
            "sSwfPath" : "swf/copy_cvs_xls_pdf.swf",
167
            "sExtends": "csv",
168
            "sFieldSeperator": "`"
3339 mandeep.dh 169
        },
170
        "aLengthMenu" : [ [ 5, 10, 20, -1 ], [ 5, 10, 20, "All" ] ]
171
    });
3499 mandeep.dh 172
 
173
    return ticketsTable;
3339 mandeep.dh 174
}
175
 
4241 anupam.sin 176
function loadActivityDescription(domId, aActivityId) {
5521 amar.kumar 177
	if($(aActivityId).attr('isRead')=="true") {
178
		$('#' + domId).html("<h4>Activity Description :</h4><pre>" + $(aActivityId).parent().siblings('td[id="activity-description"]').attr('title') + '</pre>');
179
	} else {
180
		$('#' + domId).html("<h4>Activity Description :</h4><pre>" + $(aActivityId).parent().siblings('td[id="activity-description"]').attr('title') + 
181
				'</pre><br/><input type="button" value="Mark as read" activityid="'+ $(aActivityId).attr('activityid') +'" id="mark-as-read">');
182
	}
4241 anupam.sin 183
    $('#activity-table tr').removeClass('selected');
184
    $(aActivityId).parent().parent().addClass('selected');
185
}
186
 
3422 mandeep.dh 187
function loadActivityInfo(domId, activityId) {
3228 mandeep.dh 188
    $.ajax({
189
        type : "GET",
3422 mandeep.dh 190
        url : "/crm/activity-info?activityId=" + activityId,
3228 mandeep.dh 191
        success : function(response) {
192
            $('#' + domId).html(response);
3339 mandeep.dh 193
            $('#activity tr').removeClass('selected');
3228 mandeep.dh 194
            $('#activity-row-' + activityId).addClass('selected');
3390 mandeep.dh 195
            $('#activity').css('table-layout', 'fixed');
3228 mandeep.dh 196
        }
197
    });
3090 mandeep.dh 198
}
199
 
3405 mandeep.dh 200
function createActivityDataTable(domId) {
3499 mandeep.dh 201
    var activityTable = $('#' + domId).dataTable({
3339 mandeep.dh 202
        "aaSorting" : [ [ 4, 'desc' ] ],
4241 anupam.sin 203
     "bAutoWidth": false,
5203 amar.kumar 204
      "aoColumns" : [{ "sWidth": "7%" },//id
205
                     { "sWidth": "18%" },//activity type
206
                     { "sWidth": "11%" },//description
207
                     { "sWidth": "11%" },//timestamp
4241 anupam.sin 208
                     { "sWidth": "12%" },//creator
5203 amar.kumar 209
                     { "sWidth": "6%" },//customer id
210
                     { "sWidth": "7%" },//ticket id
211
                     { "sWidth": "7%" },//ticket status
212
                     { "sWidth": "12%" },//category
213
                     { "sWidth": "9%" }],//contact number
4605 anupam.sin 214
        "iDisplayLength" : 10,
3339 mandeep.dh 215
        "sDom" : 'T<"clear">lfrtip',
3546 mandeep.dh 216
        "fnDrawCallback": function() {truncateText(95);},
3339 mandeep.dh 217
        "oTableTools" : {
5203 amar.kumar 218
            "sSwfPath" : "swf/copy_cvs_xls_pdf.swf",
219
            "sExtends": "csv",
220
            "sFieldSeperator": "`"
3339 mandeep.dh 221
        },
222
        "aLengthMenu" : [ [ 5, 10, 20, -1 ], [ 5, 10, 20, "All" ] ]
223
    });
3499 mandeep.dh 224
 
225
    return activityTable;
3339 mandeep.dh 226
}
227
 
4793 amar.kumar 228
function loadAgentsInfo(domId) {
229
	$.ajax({
230
		type    : "GET",
231
		url	    : "/crm/agent",
232
		success : function(response) {
233
			$('#' + domId).html(response);
234
 
235
			var agentTable = $('#agents').dataTable({
236
                "aaSorting" : [ [ 1, 'asc' ] ],
237
                "bAutoWidth": false,
238
                "aoColumns" : [{ "sWidth": "12%", "sSortDataType": "dom-text", "sType": "numeric" },//AgentID
239
                               { "sWidth": "35%" },//Agent Name
240
                               { "sWidth": "40%" },//Email ID
241
                               { "sWidth": "13%", "sSortDataType": "dom-text", "sType": "numeric"}],//Manager ID
242
                "iDisplayLength" : 10,
243
                "sDom" : 'T<"clear">lfrtip',
244
                "oTableTools" : {
245
                    "sSwfPath" : "swf/copy_cvs_xls_pdf.swf"
246
                },
247
            });
248
		}
249
	});
250
}
251
 
5909 amar.kumar 252
function loadAllOpenTickets(domId) {
253
	$.ajax({
254
		type    : "GET",
255
		url	    : "/crm/tickets!getAllOpenTickets",
256
		success : function(response) {
257
			$('#' + domId).html(response);
258
 
259
			var agentTable = $('#open-tickets').dataTable({
260
                "aaSorting" : [ [ 1, 'asc' ] ],
261
                "bAutoWidth": true,
262
                "iDisplayLength" : 25,
263
                "sDom" : 'T<"clear">lfrtip',
264
                "oTableTools" : {
265
                    "sSwfPath" : "swf/copy_cvs_xls_pdf.swf"
266
                },
267
            });
268
		}
269
	});
270
}
271
 
3405 mandeep.dh 272
function loadTicketCreationForm(domId, params) {
3228 mandeep.dh 273
    $.ajax({
274
        type : "GET",
3339 mandeep.dh 275
        url : "/crm/tickets/new",
3405 mandeep.dh 276
        data : params,
3339 mandeep.dh 277
        success : function(response) {
278
            $('#' + domId).html(response);
279
        }
280
    });
281
}
282
 
3405 mandeep.dh 283
function loadActivityCreationForm(domId, params) {
3339 mandeep.dh 284
    $.ajax({
285
        type : "GET",
286
        url : "/crm/activity/new",
3405 mandeep.dh 287
        data : params,
3339 mandeep.dh 288
        success : function(response) {
289
            $('#' + domId).html(response);
290
        }
291
    });
292
}
293
 
3090 mandeep.dh 294
function updateTicket(domId, ticketId, params) {
3228 mandeep.dh 295
    $.ajax({
4782 mandeep.dh 296
        type : "POST",
297
        url : "/crm/tickets!update?id=" + ticketId,
298
        data : params,
3228 mandeep.dh 299
        success : function(response) {
3339 mandeep.dh 300
            var ticketTable = $('table[id$="tickets"]');
301
            if (ticketTable.length == 1) {
302
                var rowIndex = ticketTable.dataTable().fnGetPosition($('tr#ticket-row-' + ticketId)[0]);
303
                var responseObj = jQuery(response);
3546 mandeep.dh 304
                var actionMessages = responseObj.find('#action-messages').html();
3339 mandeep.dh 305
                responseObj.find('#ticket-row-' + ticketId).children().each(
306
                        function(i, item) {
307
                            var th = responseObj.find('th').eq(i);
308
                            if (th.text() == "Ticket Id") {
309
                                return;
310
                            }
311
 
312
                            var thOld = ticketTable.find('th').filter(
313
                                    function(index) {
314
                                        if ($(this).text() == th.text()) {
315
                                            return true;
316
                                        }
317
 
318
                                        return false;
319
                                    });
320
 
4249 anupam.sin 321
                            if ($(thOld).length != 0) {
3339 mandeep.dh 322
                                ticketTable.dataTable().fnUpdate($(item).text(), rowIndex, $(thOld).index(), true, false);
323
                            }
324
                        });
325
 
3546 mandeep.dh 326
                loadTicketInfo("bottom-infopane", ticketId, ticketTable.dataTable(), null);
3339 mandeep.dh 327
                ticketTable.css('table-layout', 'fixed');
3546 mandeep.dh 328
 
329
                var alertString = jQuery.trim(actionMessages);
330
                if (alertString != '') {
331
                    alert(alertString);
332
                }
3339 mandeep.dh 333
            }
334
            else {
335
                loadTicketInfo("bottom-infopane", ticketId, null, null);
336
            }
337
 
3499 mandeep.dh 338
            truncateText(85);
3339 mandeep.dh 339
        }
340
    });
341
}
342
 
3090 mandeep.dh 343
function createTicket(domId, params) {
3228 mandeep.dh 344
    $.ajax({
345
        type : "POST",
3339 mandeep.dh 346
        url : "/crm/tickets",
3228 mandeep.dh 347
        data : params,
348
        success : function(response) {
349
            $('#' + domId).html(response);
3405 mandeep.dh 350
            var ticketTable = createTicketDataTable('tickets');
3228 mandeep.dh 351
        }
352
    });
3090 mandeep.dh 353
}
354
 
4793 amar.kumar 355
function createAgent(params, managerId){
356
	$.ajax({
357
		type : "POST",
358
		url : "/crm/agent!createAgent?managerId="+managerId,
359
		data : params,
360
		success : function(response) {
361
			alert("Agent created with the specified information");
362
			$.colorbox.close();
363
			$('#infopane').html(response);
364
			var agentTable = $('#agents').dataTable({
365
                "aaSorting" : [ [ 1, 'asc' ] ],
366
                "bAutoWidth": false,
367
                "aoColumns" : [{ "sWidth": "12%", "sSortDataType": "dom-text", "sType": "numeric" },//AgentID
368
                               { "sWidth": "35%" },//Agent Name
369
                               { "sWidth": "40%" },//Email ID
370
                               { "sWidth": "13%", "sSortDataType": "dom-text", "sType": "numeric"}],//Manager ID
371
                "iDisplayLength" : 10,
372
                "sDom" : 'T<"clear">lfrtip',
373
                "oTableTools" : {
374
                    "sSwfPath" : "swf/copy_cvs_xls_pdf.swf"
375
                },
376
            });
377
		}
378
	});
379
}
380
 
5168 amar.kumar 381
function changeAgentRole(params){
382
	$.ajax({
383
		type : "POST",
384
		url : "/crm/agent!changeAgentRole",
385
		data : params,
386
		success : function(response) {
387
			alert("Agent role changed");
388
			$.colorbox.close();
389
			$('#infopane').html(response);
390
			var agentTable = $('#agents').dataTable({
391
                "aaSorting" : [ [ 1, 'asc' ] ],
392
                "bAutoWidth": false,
393
                "aoColumns" : [{ "sWidth": "12%", "sSortDataType": "dom-text", "sType": "numeric" },//AgentID
394
                               { "sWidth": "35%" },//Agent Name
395
                               { "sWidth": "40%" },//Email ID
396
                               { "sWidth": "13%", "sSortDataType": "dom-text", "sType": "numeric"}],//Manager ID
397
                "iDisplayLength" : 10,
398
                "sDom" : 'T<"clear">lfrtip',
399
                "oTableTools" : {
400
                    "sSwfPath" : "swf/copy_cvs_xls_pdf.swf"
401
                },
402
            });
403
		}
404
	});
405
}
406
 
3090 mandeep.dh 407
function createActivity(domId, params) {
3228 mandeep.dh 408
    $.ajax({
409
        type : "POST",
3339 mandeep.dh 410
        url : "/crm/activity",
3228 mandeep.dh 411
        data : params,
412
        success : function(response) {
413
            $('#' + domId).html(response);
3405 mandeep.dh 414
            var activityTable = createActivityDataTable('activity');
3228 mandeep.dh 415
        }
416
    });
3106 mandeep.dh 417
}
418
 
419
function goToHomePage() {
3228 mandeep.dh 420
    document.location.href = "/crm";
3106 mandeep.dh 421
}
422
 
3422 mandeep.dh 423
function loadTickets(domId, getURL, ticketId) {
3228 mandeep.dh 424
    $.ajax({
425
        type : "GET",
3234 mandeep.dh 426
        url : getURL,
3228 mandeep.dh 427
        success : function(response) {
428
            $('#' + domId).html(response);
3405 mandeep.dh 429
            var ticketTable = createTicketDataTable('tickets');
3422 mandeep.dh 430
            if (ticketId != null) {
431
                loadTicketInfo("bottom-infopane", ticketId, ticketTable.dataTable(), null);
432
                ticketTable.css('table-layout', 'fixed');
433
            }
3228 mandeep.dh 434
        }
435
    });
3106 mandeep.dh 436
}
5225 amar.kumar 437
function changeActivityFormValidCriteria(commonDescription) {
438
	if(commonDescription == "") {
439
		$('#description').addClass('required');
440
	} else {
441
		$('#description').removeClass('required');
442
	}
443
}
3137 mandeep.dh 444
 
3422 mandeep.dh 445
function processActivityTypeChange(activityType) {
5203 amar.kumar 446
	if(activityType != "RECEIVED_CALL_FROM_CUSTOMER") {
447
		$('select#common-activity-desc').hide();
5224 amar.kumar 448
		$('#description').addClass('required');
5203 amar.kumar 449
	} else {
450
		$('select#common-activity-desc').show();
451
	}
3269 mandeep.dh 452
    if (activityType == "SEND_EMAIL_TO_CUSTOMER") {
3228 mandeep.dh 453
        $.colorbox({
454
            inline : true,
3519 mandeep.dh 455
            width : "775px",
456
            height : "445px",
3228 mandeep.dh 457
            href : "div#mail-div",
458
            onClosed : function() {
3519 mandeep.dh 459
				CKEDITOR.instances['mail-body'].destroy(false);
3228 mandeep.dh 460
                $("div#mail-div").hide();
461
                $('select#activity-type').val('OTHER');
462
            }
463
        });
3206 mandeep.dh 464
 
3228 mandeep.dh 465
        $("div#mail-div").show();
3701 mandeep.dh 466
        $('#mail-body').ckeditor({toolbar : 'Basic', scayt_autoStartup : true});
3228 mandeep.dh 467
    }
4020 mandeep.dh 468
    else if (activityType == "ESCALATE_TICKET") {
469
        $.colorbox({
470
            inline : true,
471
            width : "675px",
4027 mandeep.dh 472
            height : "560px",
4020 mandeep.dh 473
            href : "div#escalation-div",
474
            onClosed : function() {
475
                CKEDITOR.instances['escalation-mail-body'].destroy(false);
476
                $("div#escalation-div").hide();
477
                $('select#activity-type').val('OTHER');
478
            }
479
        });
480
 
481
        $("div#escalation-div").show();
482
        $('#escalation-mail-body').ckeditor({toolbar : 'Basic', scayt_autoStartup : true});
483
    }
3206 mandeep.dh 484
}
485
 
486
function processInputFormSubmit() {
3228 mandeep.dh 487
    $.ajax({
488
        type : "POST",
489
        url : "/crm/",
490
        success : function(response) {
491
            $.html(response);
3405 mandeep.dh 492
            var ticketTable = createTicketDataTable('tickets');
3228 mandeep.dh 493
        }
494
    });
3339 mandeep.dh 495
}
496
 
497
function listActivities(domId, params) {
498
    $.ajax({
499
        type : "GET",
500
        url : "/crm/activity",
501
        data : params,
502
        success : function(response) {
503
            $('#' + domId).html(response);
3405 mandeep.dh 504
            var activityTable = createActivityDataTable('activity');
3339 mandeep.dh 505
        }
506
    });
507
}
508
 
509
function truncateText(widthSize) {
4241 anupam.sin 510
    $(".truncated-text").each(function() {
511
    	$(this).truncate({
512
            width : $(this).attr('truncatedTextWidth'),
513
            addtitle : true
514
        });
515
	})
3339 mandeep.dh 516
}
3390 mandeep.dh 517
 
518
function markAsRead(activityId) {
519
    $.ajax({
520
        type : "POST",
521
        url : "/crm/activity!markAsRead?activityId=" + activityId,
522
        success: function(response) {
523
            listActivities('infopane', "creatorId=1");
524
        }
525
    });
526
}
3397 mandeep.dh 527
 
528
function loadAdvancedSearchBox() {
529
    $.colorbox({
530
        inline : true,
531
        width : "535px",
532
        height : "465px",
533
        href : "form#search",
534
        onClosed : function() {
535
            $("form#search").hide();
536
        }
537
    });
538
 
539
    $("form#search").show();
540
}
541
 
542
function processSearchEntityChange(searchEntity) {
543
    if (searchEntity == "Tickets") {
544
        $("#assignee").show();
545
        $("#creator").hide();
4142 mandeep.dh 546
        $("tr#activityTypes").hide();
3397 mandeep.dh 547
    }
548
    else if (searchEntity == "Activities") {
549
        $("#assignee").hide();
550
        $("#creator").show();
4142 mandeep.dh 551
        $("tr#activityTypes").show();
3397 mandeep.dh 552
    }
553
}
3499 mandeep.dh 554
 
555
function increaseTrustLevel(domId, userId, trustLevelDelta) {
556
    $.ajax({
557
        type : "PUT",
558
        url : "/crm/user-info/" + userId + "?trustLevelDelta=" + trustLevelDelta,
559
        success : function(response) {
560
            $('#' + domId).html(response);
561
        }
562
    });
563
}
564
 
4241 anupam.sin 565
function displayCancelOrderPopUp() {
566
    	$.colorbox({
567
            inline : true,
568
            width : "650px",
4314 anupam.sin 569
            height : "550px",
4689 anupam.sin 570
            href : "div#cancel-div",
4241 anupam.sin 571
            onClosed : function() {
4689 anupam.sin 572
                CKEDITOR.instances['cancel-body'].destroy(false);
573
                $("div#cancel-div").hide();
4241 anupam.sin 574
            }
575
        });
576
 
4689 anupam.sin 577
        $("div#cancel-div").show();
578
        $('#cancel-body').ckeditor({toolbar : 'Basic', scayt_autoStartup : true});
4241 anupam.sin 579
}
580
 
581
function cancelOrder(domId, ticketId, orderId, orderStatus, formData) {
4704 anupam.sin 582
	if ($('#cancellationInitiator').val()) {
4689 anupam.sin 583
		var cancellationInitiator = $('#cancellationInitiator').val();
584
		var uri = "/crm/user-order-info!markOrderForCancellation?orderId=" + orderId
585
						+ "&cancellationInitiator=" + cancellationInitiator + "&" + formData;
586
		var cancellationResult = function() {
587
			document.location.href = "/crm?email=&orderId=" + orderId;
588
		}
589
	} else {
590
		var uri = "/crm/tickets!updateOrderStatus?id=" + ticketId + "&orderId=" + orderId
591
						+ "&orderStatus=" + orderStatus + "&" + formData;
592
		var cancellationResult = function(response) {
593
            $('#' + domId).html(response);
594
        }
595
	}
4241 anupam.sin 596
    $.ajax({
597
        type : "POST",
4689 anupam.sin 598
        url : uri,
599
        success : cancellationResult
4241 anupam.sin 600
    });
4681 amar.kumar 601
 
602
    if(formData.indexOf("LOWER_PRICE_AVAILABLE_ELSEWHERE")!=-1){
603
    	var desc = formData.split("&");
604
    	var description = "Order cancelled because of Lower Price Available elsewhere";
605
    	$.ajax({
606
    		type : "POST",
607
    		url : "/crm/tickets?orderId="+orderId+"&priority=MEDIUM&category=PRODUCT_PROCUREMENT"
608
    				+ "&assigneeEmailId=chaitnaya.vats@shop2020.in&description="+description+"&"+desc[1],
609
    		success : function(response){
610
    			alert("Ticket created for Lower Price Available elsewhere");
611
    		}
612
    	});
613
 
614
    }
4241 anupam.sin 615
}
4065 mandeep.dh 616
 
4241 anupam.sin 617
function updateOrderStatus(domId, ticketId, orderId, orderStatus) {
3499 mandeep.dh 618
    $.ajax({
3546 mandeep.dh 619
        type : "POST",
4241 anupam.sin 620
        url : "/crm/tickets!updateOrderStatus?id=" + ticketId + "&orderId=" + orderId
621
        					+ "&orderStatus=" + orderStatus,
3499 mandeep.dh 622
        success : function(response) {
3546 mandeep.dh 623
            $('#' + domId).html(response);
3499 mandeep.dh 624
        }
625
    });
3711 mandeep.dh 626
}
627
 
628
function loadUnreadActivities(domId) {
629
    $.ajax({
630
        type : "GET",
631
        url : "/crm/activity!getUnreadActivities",
632
        success : function(response) {
633
            $('#' + domId).html(response);
634
            var activityTable = createActivityDataTable('activity');
635
        }
636
    });
637
}
4065 mandeep.dh 638
 
639
function refreshSidebar() {
640
    $.ajax({
4142 mandeep.dh 641
        type : "PUT",
642
        url : "/crm",
643
        success : function(response) {
644
            $('#sidebar').html($(response).find('#sidebar').html());
645
        }
646
    });
647
}
648
 
649
function changeAddress(urlParams) {
650
    $.ajax({
4065 mandeep.dh 651
        type : "GET",
652
        url : "/crm",
653
        success : function(response) {
654
            $('#sidebar').html($(response).find('#sidebar').html());
655
        }
656
    });
4267 anupam.sin 657
}
658
 
4681 amar.kumar 659
function showHidecancelReasonDiv(cancelReason){
4793 amar.kumar 660
	var reasonsToShowDiv = ['LOWER_PRICE_AVAILABLE_ELSEWHERE','OTHER','OUT_OF_STOCK','COLOR_OUT_OF_STOCK'];
661
	if(($.inArray(cancelReason, reasonsToShowDiv))!=-1){
4681 amar.kumar 662
		$('#cancelReasonBox').show();
663
	} else {
664
		$('#cancelReasonBox').hide();
665
	}
666
}
667
 
4438 anupam.sin 668
function blockPayment(transactionId, ticketId, paymentId) {
4267 anupam.sin 669
	$.ajax({
670
		type : "GET",
4451 anupam.sin 671
		url : "/crm/tickets!blockPayment?transactionId=" + transactionId + "&id=" + ticketId + "&paymentId=" + paymentId,
4267 anupam.sin 672
		success : function(response) {
673
            $('#bottom-infopane').html(response);
674
        }
675
	});
676
}
677
 
4438 anupam.sin 678
function allowPayment(transactionId, ticketId, paymentId) {
4267 anupam.sin 679
	$.ajax({
680
		type : "GET",
4451 anupam.sin 681
		url : "/crm/tickets!allowPayment?transactionId=" + transactionId + "&id=" + ticketId + "&paymentId=" + paymentId,
4267 anupam.sin 682
		success : function(response) {
683
            $('#bottom-infopane').html(response);
684
        }
685
	});
4490 anupam.sin 686
}
687
 
688
function denyDOA(orderId, ticketId) {
689
	$.ajax({
690
		type : "GET",
691
		url : "/crm/tickets!denyDOA?orderId=" + orderId + "&id=" + ticketId,
692
		success : function(response) {
693
            $('#bottom-infopane').html(response);
694
        }
695
	});
696
}
697
 
698
 
699
function authorizeDOA(orderId, ticketId) {
700
	$.ajax({
701
		type : "GET",
702
		url : "/crm/tickets!authorizeDOA?orderId=" + orderId + "&id=" + ticketId,
703
		success : function(response) {
704
            $('#bottom-infopane').html(response);
705
        }
706
	});
707
}
708
 
709
function denyReturn(orderId, ticketId) {
710
	$.ajax({
711
		type : "GET",
712
		url : "/crm/tickets!denyReturn?orderId=" + orderId + "&id=" + ticketId,
713
		success : function(response) {
714
            $('#bottom-infopane').html(response);
715
        }
716
	});
717
}
718
 
719
 
720
function authorizeReturn(orderId, ticketId) {
721
	$.ajax({
722
		type : "GET",
723
		url : "/crm/tickets!authorizeReturn?orderId=" + orderId + "&id=" + ticketId,
724
		success : function(response) {
725
            $('#bottom-infopane').html(response);
726
        }
727
	});
4689 anupam.sin 728
}
729
 
730
function markOrderForCancellation(orderId, formData) {
731
	console.log(typeof(orderId), typeof(formData), orderId, formData);
732
 
733
	$.ajax({
734
		type : "GET",
735
		url : "/crm/user-order-info!markOrderForCancellation?orderId=" + orderId + "&cancellationInitiator=" + formData,
736
		success : function(response) {
737
			document.location.href = "/crm?email=&orderId=" + orderId;
738
        }
739
	});
4793 amar.kumar 740
}
741
 
742
function loadAgentCreationForm() {
743
	$.colorbox({
744
        inline : true,
745
        width : "550px",
746
        height : "400px",
747
        href : "div#create-agent-div",
748
        onClosed : function() {
749
            $("div#create-agent-div").hide();
750
        }
751
    });
752
 
753
    $("div#create-agent-div").show();
754
 
755
}
756
 
757
function deactivateAgentPopup() {
758
	$.colorbox({
759
        inline : true,
760
        width : "400px",
761
        height : "150px",
762
        href : "div#deactivate-agent-div",
763
        onClosed : function() {
764
            $("div#deactivate-agent-div").hide();
765
        }
766
    });
767
 
768
    $("div#deactivate-agent-div").show();
769
 
770
}
771
 
772
function changeAgentPasswordPopup(){
773
	$.colorbox({
774
        inline : true,
775
        width  : "350px",
776
        height : "350px",
777
        href   : "div#change-password-div",
778
        onClosed : function() {
779
            $("div#change-password-div").hide();
780
        }
781
    });
782
 
783
    $("div#change-password-div").show();
784
}
785
 
5168 amar.kumar 786
function changeAgentRolePopup(){
787
	$.colorbox({
788
        inline : true,
789
        width  : "375px",
790
        height : "350px",
791
        href   : "div#change-agent-role-div",
792
        onClosed : function() {
793
            $("div#change-agent-role-div").hide();
794
        }
795
    });
4793 amar.kumar 796
 
5168 amar.kumar 797
    $("div#change-agent-role-div").show();
798
}
799
 
4793 amar.kumar 800
function updateAgentPassword(){
801
	if(($('#change-password1').val().trim())==($('#change-password2').val().trim())){
802
		$.ajax({
803
			type : "POST",
804
			url : "/crm/agent!changePassword?emailId=" + $('#agentEmail').val() + "&newPassword=" + $('#change-password1').val().trim(),
805
			success : function(response) {
806
				alert("Password updated successfully");
807
				$.colorbox.close();
808
			}
809
		});
810
	}
811
	else { 
812
		alert("Passwords not matching");
813
		return false;
814
	}
815
}
816
 
817
function validateAgentCreationForm(){
818
	var formError = false;
819
	if($('#new-agent-name').val().length == 0) {
820
		$('#agent-name-error').html("Please enter the name");
821
		$('#new-agent-name').addClass('agent-form-error');
822
		formError = true;
823
	}
824
	if(($('#new-agent-id').val().length == 0)) {
825
		$('#agent-email-error').html("Please enter the Email-ID");
826
		$('#new-agent-id').addClass('agent-form-error');
827
		formError = true;
828
	}
829
	if($('#create-password1').val().length == 0) {
830
		$('#agent-password1-error').html("Please enter password");
831
		$('#create-password1').addClass('agent-form-error');
832
		formError = true;
833
	} else if($('#create-password2').val().length == 0){
834
		$('#agent-password2-error').html("Please re enter password");
835
		$('#create-password2').addClass('agent-form-error');
836
		formError = true;
837
	} else if($('#create-password1').val()!=$('#create-password2').val()) {
838
		$('#agent-password1-error').html("Please make sure you entered same passwords");
839
		$('#create-password1').addClass('agent-form-error');
840
		$('#create-password2').addClass('agent-form-error');
841
		formError = true;
842
	}
843
 
844
	if(formError){
845
		return false;
846
	}
847
	return true;
848
}
849
 
850
function clearAgentCreationForm() {
851
		$('#agent-name-error').html("");
852
		$('#new-agent-name').removeClass('agent-form-error');
853
		$('#agent-email-error').html("");
854
		$('#new-agent-id').removeClass('agent-form-error');
855
		$('#agent-password1-error').html("");
856
		$('#create-password1').removeClass('agent-form-error');
857
		$('#agent-password2-error').html("");
858
		$('#create-password2').removeClass('agent-form-error');
859
		$('#agent-password1-error').html("");
860
		$('#create-password1').removeClass('agent-form-error');
861
		$('#create-password2').removeClass('agent-form-error');
862
}
863
 
864
function deactivateAgent(emailId, id) {
865
	$.ajax({
866
		type : "POST",
867
		url : "/crm/agent!deActivateAgent?emailId=" + emailId+ "&id=" + id,
868
		success : function(response) {   
869
			alert("Agent : " + "deactivated successfully");
870
			$.colorbox.close();
871
			$('#infopane').html(response);
872
 
873
			var agentTable = $('#agents').dataTable({
874
                "aaSorting" : [ [ 1, 'asc' ] ],
875
                "bAutoWidth": false,
876
                "aoColumns" : [{ "sWidth": "12%", "sSortDataType": "dom-text", "sType": "numeric" },//AgentID
877
                               { "sWidth": "35%" },//Agent Name
878
                               { "sWidth": "40%" },//Email ID
879
                               { "sWidth": "13%", "sSortDataType": "dom-text", "sType": "numeric"}],//Manager ID
880
                "iDisplayLength" : 10,
881
                "sDom" : 'T<"clear">lfrtip',
882
                "oTableTools" : {
883
                    "sSwfPath" : "swf/copy_cvs_xls_pdf.swf"
884
                },
885
            });
886
		}
887
	});
5791 anupam.sin 888
}
889
 
890
function extendExpiryDate(domId, orderId, pickupExtension) {
891
    $.ajax({
892
        type : "POST",
893
        url : "/crm/tickets!extendExpiry?orderId=" + orderId + "&pickupExtension=" + pickupExtension,
894
        success : function(response) {
895
            $('#' + domId).html(response);
896
        }
897
    });
4241 anupam.sin 898
}