Subversion Repositories SmartDukaan

Rev

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