Subversion Repositories SmartDukaan

Rev

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