Subversion Repositories SmartDukaan

Rev

Rev 5521 | Rev 5909 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

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