Subversion Repositories SmartDukaan

Rev

Rev 5203 | Rev 5225 | 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();
5224 amar.kumar 416
		$('#description').addClass('required');
5203 amar.kumar 417
	} else {
418
		$('select#common-activity-desc').show();
5224 amar.kumar 419
		$('#description').removeClass('required');
5203 amar.kumar 420
	}
3269 mandeep.dh 421
    if (activityType == "SEND_EMAIL_TO_CUSTOMER") {
3228 mandeep.dh 422
        $.colorbox({
423
            inline : true,
3519 mandeep.dh 424
            width : "775px",
425
            height : "445px",
3228 mandeep.dh 426
            href : "div#mail-div",
427
            onClosed : function() {
3519 mandeep.dh 428
				CKEDITOR.instances['mail-body'].destroy(false);
3228 mandeep.dh 429
                $("div#mail-div").hide();
430
                $('select#activity-type').val('OTHER');
431
            }
432
        });
3206 mandeep.dh 433
 
3228 mandeep.dh 434
        $("div#mail-div").show();
3701 mandeep.dh 435
        $('#mail-body').ckeditor({toolbar : 'Basic', scayt_autoStartup : true});
3228 mandeep.dh 436
    }
4020 mandeep.dh 437
    else if (activityType == "ESCALATE_TICKET") {
438
        $.colorbox({
439
            inline : true,
440
            width : "675px",
4027 mandeep.dh 441
            height : "560px",
4020 mandeep.dh 442
            href : "div#escalation-div",
443
            onClosed : function() {
444
                CKEDITOR.instances['escalation-mail-body'].destroy(false);
445
                $("div#escalation-div").hide();
446
                $('select#activity-type').val('OTHER');
447
            }
448
        });
449
 
450
        $("div#escalation-div").show();
451
        $('#escalation-mail-body').ckeditor({toolbar : 'Basic', scayt_autoStartup : true});
452
    }
3206 mandeep.dh 453
}
454
 
455
function processInputFormSubmit() {
3228 mandeep.dh 456
    $.ajax({
457
        type : "POST",
458
        url : "/crm/",
459
        success : function(response) {
460
            $.html(response);
3405 mandeep.dh 461
            var ticketTable = createTicketDataTable('tickets');
3228 mandeep.dh 462
        }
463
    });
3339 mandeep.dh 464
}
465
 
466
function listActivities(domId, params) {
467
    $.ajax({
468
        type : "GET",
469
        url : "/crm/activity",
470
        data : params,
471
        success : function(response) {
472
            $('#' + domId).html(response);
3405 mandeep.dh 473
            var activityTable = createActivityDataTable('activity');
3339 mandeep.dh 474
        }
475
    });
476
}
477
 
478
function truncateText(widthSize) {
4241 anupam.sin 479
    $(".truncated-text").each(function() {
480
    	$(this).truncate({
481
            width : $(this).attr('truncatedTextWidth'),
482
            addtitle : true
483
        });
484
	})
3339 mandeep.dh 485
}
3390 mandeep.dh 486
 
487
function markAsRead(activityId) {
488
    $.ajax({
489
        type : "POST",
490
        url : "/crm/activity!markAsRead?activityId=" + activityId,
491
        success: function(response) {
492
            listActivities('infopane', "creatorId=1");
493
        }
494
    });
495
}
3397 mandeep.dh 496
 
497
function loadAdvancedSearchBox() {
498
    $.colorbox({
499
        inline : true,
500
        width : "535px",
501
        height : "465px",
502
        href : "form#search",
503
        onClosed : function() {
504
            $("form#search").hide();
505
        }
506
    });
507
 
508
    $("form#search").show();
509
}
510
 
511
function processSearchEntityChange(searchEntity) {
512
    if (searchEntity == "Tickets") {
513
        $("#assignee").show();
514
        $("#creator").hide();
4142 mandeep.dh 515
        $("tr#activityTypes").hide();
3397 mandeep.dh 516
    }
517
    else if (searchEntity == "Activities") {
518
        $("#assignee").hide();
519
        $("#creator").show();
4142 mandeep.dh 520
        $("tr#activityTypes").show();
3397 mandeep.dh 521
    }
522
}
3499 mandeep.dh 523
 
524
function increaseTrustLevel(domId, userId, trustLevelDelta) {
525
    $.ajax({
526
        type : "PUT",
527
        url : "/crm/user-info/" + userId + "?trustLevelDelta=" + trustLevelDelta,
528
        success : function(response) {
529
            $('#' + domId).html(response);
530
        }
531
    });
532
}
533
 
4241 anupam.sin 534
function displayCancelOrderPopUp() {
535
    	$.colorbox({
536
            inline : true,
537
            width : "650px",
4314 anupam.sin 538
            height : "550px",
4689 anupam.sin 539
            href : "div#cancel-div",
4241 anupam.sin 540
            onClosed : function() {
4689 anupam.sin 541
                CKEDITOR.instances['cancel-body'].destroy(false);
542
                $("div#cancel-div").hide();
4241 anupam.sin 543
            }
544
        });
545
 
4689 anupam.sin 546
        $("div#cancel-div").show();
547
        $('#cancel-body').ckeditor({toolbar : 'Basic', scayt_autoStartup : true});
4241 anupam.sin 548
}
549
 
550
function cancelOrder(domId, ticketId, orderId, orderStatus, formData) {
4704 anupam.sin 551
	if ($('#cancellationInitiator').val()) {
4689 anupam.sin 552
		var cancellationInitiator = $('#cancellationInitiator').val();
553
		var uri = "/crm/user-order-info!markOrderForCancellation?orderId=" + orderId
554
						+ "&cancellationInitiator=" + cancellationInitiator + "&" + formData;
555
		var cancellationResult = function() {
556
			document.location.href = "/crm?email=&orderId=" + orderId;
557
		}
558
	} else {
559
		var uri = "/crm/tickets!updateOrderStatus?id=" + ticketId + "&orderId=" + orderId
560
						+ "&orderStatus=" + orderStatus + "&" + formData;
561
		var cancellationResult = function(response) {
562
            $('#' + domId).html(response);
563
        }
564
	}
4241 anupam.sin 565
    $.ajax({
566
        type : "POST",
4689 anupam.sin 567
        url : uri,
568
        success : cancellationResult
4241 anupam.sin 569
    });
4681 amar.kumar 570
 
571
    if(formData.indexOf("LOWER_PRICE_AVAILABLE_ELSEWHERE")!=-1){
572
    	var desc = formData.split("&");
573
    	var description = "Order cancelled because of Lower Price Available elsewhere";
574
    	$.ajax({
575
    		type : "POST",
576
    		url : "/crm/tickets?orderId="+orderId+"&priority=MEDIUM&category=PRODUCT_PROCUREMENT"
577
    				+ "&assigneeEmailId=chaitnaya.vats@shop2020.in&description="+description+"&"+desc[1],
578
    		success : function(response){
579
    			alert("Ticket created for Lower Price Available elsewhere");
580
    		}
581
    	});
582
 
583
    }
4241 anupam.sin 584
}
4065 mandeep.dh 585
 
4241 anupam.sin 586
function updateOrderStatus(domId, ticketId, orderId, orderStatus) {
3499 mandeep.dh 587
    $.ajax({
3546 mandeep.dh 588
        type : "POST",
4241 anupam.sin 589
        url : "/crm/tickets!updateOrderStatus?id=" + ticketId + "&orderId=" + orderId
590
        					+ "&orderStatus=" + orderStatus,
3499 mandeep.dh 591
        success : function(response) {
3546 mandeep.dh 592
            $('#' + domId).html(response);
3499 mandeep.dh 593
        }
594
    });
3711 mandeep.dh 595
}
596
 
597
function loadUnreadActivities(domId) {
598
    $.ajax({
599
        type : "GET",
600
        url : "/crm/activity!getUnreadActivities",
601
        success : function(response) {
602
            $('#' + domId).html(response);
603
            var activityTable = createActivityDataTable('activity');
604
        }
605
    });
606
}
4065 mandeep.dh 607
 
608
function refreshSidebar() {
609
    $.ajax({
4142 mandeep.dh 610
        type : "PUT",
611
        url : "/crm",
612
        success : function(response) {
613
            $('#sidebar').html($(response).find('#sidebar').html());
614
        }
615
    });
616
}
617
 
618
function changeAddress(urlParams) {
619
    $.ajax({
4065 mandeep.dh 620
        type : "GET",
621
        url : "/crm",
622
        success : function(response) {
623
            $('#sidebar').html($(response).find('#sidebar').html());
624
        }
625
    });
4267 anupam.sin 626
}
627
 
4681 amar.kumar 628
function showHidecancelReasonDiv(cancelReason){
4793 amar.kumar 629
	var reasonsToShowDiv = ['LOWER_PRICE_AVAILABLE_ELSEWHERE','OTHER','OUT_OF_STOCK','COLOR_OUT_OF_STOCK'];
630
	if(($.inArray(cancelReason, reasonsToShowDiv))!=-1){
4681 amar.kumar 631
		$('#cancelReasonBox').show();
632
	} else {
633
		$('#cancelReasonBox').hide();
634
	}
635
}
636
 
4438 anupam.sin 637
function blockPayment(transactionId, ticketId, paymentId) {
4267 anupam.sin 638
	$.ajax({
639
		type : "GET",
4451 anupam.sin 640
		url : "/crm/tickets!blockPayment?transactionId=" + transactionId + "&id=" + ticketId + "&paymentId=" + paymentId,
4267 anupam.sin 641
		success : function(response) {
642
            $('#bottom-infopane').html(response);
643
        }
644
	});
645
}
646
 
4438 anupam.sin 647
function allowPayment(transactionId, ticketId, paymentId) {
4267 anupam.sin 648
	$.ajax({
649
		type : "GET",
4451 anupam.sin 650
		url : "/crm/tickets!allowPayment?transactionId=" + transactionId + "&id=" + ticketId + "&paymentId=" + paymentId,
4267 anupam.sin 651
		success : function(response) {
652
            $('#bottom-infopane').html(response);
653
        }
654
	});
4490 anupam.sin 655
}
656
 
657
function denyDOA(orderId, ticketId) {
658
	$.ajax({
659
		type : "GET",
660
		url : "/crm/tickets!denyDOA?orderId=" + orderId + "&id=" + ticketId,
661
		success : function(response) {
662
            $('#bottom-infopane').html(response);
663
        }
664
	});
665
}
666
 
667
 
668
function authorizeDOA(orderId, ticketId) {
669
	$.ajax({
670
		type : "GET",
671
		url : "/crm/tickets!authorizeDOA?orderId=" + orderId + "&id=" + ticketId,
672
		success : function(response) {
673
            $('#bottom-infopane').html(response);
674
        }
675
	});
676
}
677
 
678
function denyReturn(orderId, ticketId) {
679
	$.ajax({
680
		type : "GET",
681
		url : "/crm/tickets!denyReturn?orderId=" + orderId + "&id=" + ticketId,
682
		success : function(response) {
683
            $('#bottom-infopane').html(response);
684
        }
685
	});
686
}
687
 
688
 
689
function authorizeReturn(orderId, ticketId) {
690
	$.ajax({
691
		type : "GET",
692
		url : "/crm/tickets!authorizeReturn?orderId=" + orderId + "&id=" + ticketId,
693
		success : function(response) {
694
            $('#bottom-infopane').html(response);
695
        }
696
	});
4689 anupam.sin 697
}
698
 
699
function markOrderForCancellation(orderId, formData) {
700
	console.log(typeof(orderId), typeof(formData), orderId, formData);
701
 
702
	$.ajax({
703
		type : "GET",
704
		url : "/crm/user-order-info!markOrderForCancellation?orderId=" + orderId + "&cancellationInitiator=" + formData,
705
		success : function(response) {
706
			document.location.href = "/crm?email=&orderId=" + orderId;
707
        }
708
	});
4793 amar.kumar 709
}
710
 
711
function loadAgentCreationForm() {
712
	$.colorbox({
713
        inline : true,
714
        width : "550px",
715
        height : "400px",
716
        href : "div#create-agent-div",
717
        onClosed : function() {
718
            $("div#create-agent-div").hide();
719
        }
720
    });
721
 
722
    $("div#create-agent-div").show();
723
 
724
}
725
 
726
function deactivateAgentPopup() {
727
	$.colorbox({
728
        inline : true,
729
        width : "400px",
730
        height : "150px",
731
        href : "div#deactivate-agent-div",
732
        onClosed : function() {
733
            $("div#deactivate-agent-div").hide();
734
        }
735
    });
736
 
737
    $("div#deactivate-agent-div").show();
738
 
739
}
740
 
741
function changeAgentPasswordPopup(){
742
	$.colorbox({
743
        inline : true,
744
        width  : "350px",
745
        height : "350px",
746
        href   : "div#change-password-div",
747
        onClosed : function() {
748
            $("div#change-password-div").hide();
749
        }
750
    });
751
 
752
    $("div#change-password-div").show();
753
}
754
 
5168 amar.kumar 755
function changeAgentRolePopup(){
756
	$.colorbox({
757
        inline : true,
758
        width  : "375px",
759
        height : "350px",
760
        href   : "div#change-agent-role-div",
761
        onClosed : function() {
762
            $("div#change-agent-role-div").hide();
763
        }
764
    });
4793 amar.kumar 765
 
5168 amar.kumar 766
    $("div#change-agent-role-div").show();
767
}
768
 
4793 amar.kumar 769
function updateAgentPassword(){
770
	if(($('#change-password1').val().trim())==($('#change-password2').val().trim())){
771
		$.ajax({
772
			type : "POST",
773
			url : "/crm/agent!changePassword?emailId=" + $('#agentEmail').val() + "&newPassword=" + $('#change-password1').val().trim(),
774
			success : function(response) {
775
				alert("Password updated successfully");
776
				$.colorbox.close();
777
			}
778
		});
779
	}
780
	else { 
781
		alert("Passwords not matching");
782
		return false;
783
	}
784
}
785
 
786
function validateAgentCreationForm(){
787
	var formError = false;
788
	if($('#new-agent-name').val().length == 0) {
789
		$('#agent-name-error').html("Please enter the name");
790
		$('#new-agent-name').addClass('agent-form-error');
791
		formError = true;
792
	}
793
	if(($('#new-agent-id').val().length == 0)) {
794
		$('#agent-email-error').html("Please enter the Email-ID");
795
		$('#new-agent-id').addClass('agent-form-error');
796
		formError = true;
797
	}
798
	if($('#create-password1').val().length == 0) {
799
		$('#agent-password1-error').html("Please enter password");
800
		$('#create-password1').addClass('agent-form-error');
801
		formError = true;
802
	} else if($('#create-password2').val().length == 0){
803
		$('#agent-password2-error').html("Please re enter password");
804
		$('#create-password2').addClass('agent-form-error');
805
		formError = true;
806
	} else if($('#create-password1').val()!=$('#create-password2').val()) {
807
		$('#agent-password1-error').html("Please make sure you entered same passwords");
808
		$('#create-password1').addClass('agent-form-error');
809
		$('#create-password2').addClass('agent-form-error');
810
		formError = true;
811
	}
812
 
813
	if(formError){
814
		return false;
815
	}
816
	return true;
817
}
818
 
819
function clearAgentCreationForm() {
820
		$('#agent-name-error').html("");
821
		$('#new-agent-name').removeClass('agent-form-error');
822
		$('#agent-email-error').html("");
823
		$('#new-agent-id').removeClass('agent-form-error');
824
		$('#agent-password1-error').html("");
825
		$('#create-password1').removeClass('agent-form-error');
826
		$('#agent-password2-error').html("");
827
		$('#create-password2').removeClass('agent-form-error');
828
		$('#agent-password1-error').html("");
829
		$('#create-password1').removeClass('agent-form-error');
830
		$('#create-password2').removeClass('agent-form-error');
831
}
832
 
833
function deactivateAgent(emailId, id) {
834
	$.ajax({
835
		type : "POST",
836
		url : "/crm/agent!deActivateAgent?emailId=" + emailId+ "&id=" + id,
837
		success : function(response) {   
838
			alert("Agent : " + "deactivated successfully");
839
			$.colorbox.close();
840
			$('#infopane').html(response);
841
 
842
			var agentTable = $('#agents').dataTable({
843
                "aaSorting" : [ [ 1, 'asc' ] ],
844
                "bAutoWidth": false,
845
                "aoColumns" : [{ "sWidth": "12%", "sSortDataType": "dom-text", "sType": "numeric" },//AgentID
846
                               { "sWidth": "35%" },//Agent Name
847
                               { "sWidth": "40%" },//Email ID
848
                               { "sWidth": "13%", "sSortDataType": "dom-text", "sType": "numeric"}],//Manager ID
849
                "iDisplayLength" : 10,
850
                "sDom" : 'T<"clear">lfrtip',
851
                "oTableTools" : {
852
                    "sSwfPath" : "swf/copy_cvs_xls_pdf.swf"
853
                },
854
            });
855
		}
856
	});
4241 anupam.sin 857
}