Subversion Repositories SmartDukaan

Rev

Rev 4241 | Rev 4267 | 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); },
3228 mandeep.dh 31
                "iDisplayLength" : 5,
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%" }],
3546 mandeep.dh 142
                "iDisplayLength" : 5,
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);},
3339 mandeep.dh 163
        "iDisplayLength" : 5,
164
        "sDom" : 'T<"clear">lfrtip',
165
        "oTableTools" : {
166
            "sSwfPath" : "swf/copy_cvs_xls_pdf.swf"
167
        },
168
        "aLengthMenu" : [ [ 5, 10, 20, -1 ], [ 5, 10, 20, "All" ] ]
169
    });
3499 mandeep.dh 170
 
171
    return ticketsTable;
3339 mandeep.dh 172
}
173
 
4241 anupam.sin 174
function loadActivityDescription(domId, aActivityId) {
175
	$('#' + domId).html("<h4>Activity Description :</h4><pre>" + $(aActivityId).parent().siblings('td[id="activity-description"]').attr('title') + '</pre>');
176
    $('#activity-table tr').removeClass('selected');
177
    $(aActivityId).parent().parent().addClass('selected');
178
}
179
 
3422 mandeep.dh 180
function loadActivityInfo(domId, activityId) {
3228 mandeep.dh 181
    $.ajax({
182
        type : "GET",
3422 mandeep.dh 183
        url : "/crm/activity-info?activityId=" + activityId,
3228 mandeep.dh 184
        success : function(response) {
185
            $('#' + domId).html(response);
3339 mandeep.dh 186
            $('#activity tr').removeClass('selected');
3228 mandeep.dh 187
            $('#activity-row-' + activityId).addClass('selected');
3390 mandeep.dh 188
            $('#activity').css('table-layout', 'fixed');
3228 mandeep.dh 189
        }
190
    });
3090 mandeep.dh 191
}
192
 
3405 mandeep.dh 193
function createActivityDataTable(domId) {
3499 mandeep.dh 194
    var activityTable = $('#' + domId).dataTable({
3339 mandeep.dh 195
        "aaSorting" : [ [ 4, 'desc' ] ],
4241 anupam.sin 196
     "bAutoWidth": false,
197
      "aoColumns" : [{ "sWidth": "10%" },//id
198
                     { "sWidth": "22%" },//activity type
199
                     { "sWidth": "15%" },//description
200
                     { "sWidth": "12%" },//timestamp
201
                     { "sWidth": "12%" },//creator
202
                     { "sWidth": "12%" },//customer id
203
                     { "sWidth": "9%" },//ticket id
204
                     { "sWidth": "8%" }],//category
3339 mandeep.dh 205
        "iDisplayLength" : 5,
206
        "sDom" : 'T<"clear">lfrtip',
3546 mandeep.dh 207
        "fnDrawCallback": function() {truncateText(95);},
3339 mandeep.dh 208
        "oTableTools" : {
209
            "sSwfPath" : "swf/copy_cvs_xls_pdf.swf"
210
        },
211
        "aLengthMenu" : [ [ 5, 10, 20, -1 ], [ 5, 10, 20, "All" ] ]
212
    });
3499 mandeep.dh 213
 
214
    return activityTable;
3339 mandeep.dh 215
}
216
 
3405 mandeep.dh 217
function loadTicketCreationForm(domId, params) {
3228 mandeep.dh 218
    $.ajax({
219
        type : "GET",
3339 mandeep.dh 220
        url : "/crm/tickets/new",
3405 mandeep.dh 221
        data : params,
3339 mandeep.dh 222
        success : function(response) {
223
            $('#' + domId).html(response);
224
        }
225
    });
226
}
227
 
3405 mandeep.dh 228
function loadActivityCreationForm(domId, params) {
3339 mandeep.dh 229
    $.ajax({
230
        type : "GET",
231
        url : "/crm/activity/new",
3405 mandeep.dh 232
        data : params,
3339 mandeep.dh 233
        success : function(response) {
234
            $('#' + domId).html(response);
235
        }
236
    });
237
}
238
 
3090 mandeep.dh 239
function updateTicket(domId, ticketId, params) {
3228 mandeep.dh 240
    $.ajax({
241
        type : "PUT",
3405 mandeep.dh 242
        url : "/crm/tickets/" + ticketId + "?" + params,
3228 mandeep.dh 243
        success : function(response) {
3339 mandeep.dh 244
            var ticketTable = $('table[id$="tickets"]');
245
            if (ticketTable.length == 1) {
246
                var rowIndex = ticketTable.dataTable().fnGetPosition($('tr#ticket-row-' + ticketId)[0]);
247
                var responseObj = jQuery(response);
3546 mandeep.dh 248
                var actionMessages = responseObj.find('#action-messages').html();
3339 mandeep.dh 249
                responseObj.find('#ticket-row-' + ticketId).children().each(
250
                        function(i, item) {
251
                            var th = responseObj.find('th').eq(i);
252
                            if (th.text() == "Ticket Id") {
253
                                return;
254
                            }
255
 
256
                            var thOld = ticketTable.find('th').filter(
257
                                    function(index) {
258
                                        if ($(this).text() == th.text()) {
259
                                            return true;
260
                                        }
261
 
262
                                        return false;
263
                                    });
264
 
4249 anupam.sin 265
                            if ($(thOld).length != 0) {
3339 mandeep.dh 266
                                ticketTable.dataTable().fnUpdate($(item).text(), rowIndex, $(thOld).index(), true, false);
267
                            }
268
                        });
269
 
3546 mandeep.dh 270
                loadTicketInfo("bottom-infopane", ticketId, ticketTable.dataTable(), null);
3339 mandeep.dh 271
                ticketTable.css('table-layout', 'fixed');
3546 mandeep.dh 272
 
273
                var alertString = jQuery.trim(actionMessages);
274
                if (alertString != '') {
275
                    alert(alertString);
276
                }
3339 mandeep.dh 277
            }
278
            else {
279
                loadTicketInfo("bottom-infopane", ticketId, null, null);
280
            }
281
 
3499 mandeep.dh 282
            truncateText(85);
3339 mandeep.dh 283
        }
284
    });
285
}
286
 
3090 mandeep.dh 287
function createTicket(domId, params) {
3228 mandeep.dh 288
    $.ajax({
289
        type : "POST",
3339 mandeep.dh 290
        url : "/crm/tickets",
3228 mandeep.dh 291
        data : params,
292
        success : function(response) {
293
            $('#' + domId).html(response);
3405 mandeep.dh 294
            var ticketTable = createTicketDataTable('tickets');
3228 mandeep.dh 295
        }
296
    });
3090 mandeep.dh 297
}
298
 
299
function createActivity(domId, params) {
3228 mandeep.dh 300
    $.ajax({
301
        type : "POST",
3339 mandeep.dh 302
        url : "/crm/activity",
3228 mandeep.dh 303
        data : params,
304
        success : function(response) {
305
            $('#' + domId).html(response);
3405 mandeep.dh 306
            var activityTable = createActivityDataTable('activity');
3228 mandeep.dh 307
        }
308
    });
3106 mandeep.dh 309
}
310
 
311
function goToHomePage() {
3228 mandeep.dh 312
    document.location.href = "/crm";
3106 mandeep.dh 313
}
314
 
3422 mandeep.dh 315
function loadTickets(domId, getURL, ticketId) {
3228 mandeep.dh 316
    $.ajax({
317
        type : "GET",
3234 mandeep.dh 318
        url : getURL,
3228 mandeep.dh 319
        success : function(response) {
320
            $('#' + domId).html(response);
3405 mandeep.dh 321
            var ticketTable = createTicketDataTable('tickets');
3422 mandeep.dh 322
            if (ticketId != null) {
323
                loadTicketInfo("bottom-infopane", ticketId, ticketTable.dataTable(), null);
324
                ticketTable.css('table-layout', 'fixed');
325
            }
3228 mandeep.dh 326
        }
327
    });
3106 mandeep.dh 328
}
3137 mandeep.dh 329
 
3422 mandeep.dh 330
function processActivityTypeChange(activityType) {
3269 mandeep.dh 331
    if (activityType == "SEND_EMAIL_TO_CUSTOMER") {
3228 mandeep.dh 332
        $.colorbox({
333
            inline : true,
3519 mandeep.dh 334
            width : "775px",
335
            height : "445px",
3228 mandeep.dh 336
            href : "div#mail-div",
337
            onClosed : function() {
3519 mandeep.dh 338
				CKEDITOR.instances['mail-body'].destroy(false);
3228 mandeep.dh 339
                $("div#mail-div").hide();
340
                $('select#activity-type').val('OTHER');
341
            }
342
        });
3206 mandeep.dh 343
 
3228 mandeep.dh 344
        $("div#mail-div").show();
3701 mandeep.dh 345
        $('#mail-body').ckeditor({toolbar : 'Basic', scayt_autoStartup : true});
3228 mandeep.dh 346
    }
4020 mandeep.dh 347
    else if (activityType == "ESCALATE_TICKET") {
348
        $.colorbox({
349
            inline : true,
350
            width : "675px",
4027 mandeep.dh 351
            height : "560px",
4020 mandeep.dh 352
            href : "div#escalation-div",
353
            onClosed : function() {
354
                CKEDITOR.instances['escalation-mail-body'].destroy(false);
355
                $("div#escalation-div").hide();
356
                $('select#activity-type').val('OTHER');
357
            }
358
        });
359
 
360
        $("div#escalation-div").show();
361
        $('#escalation-mail-body').ckeditor({toolbar : 'Basic', scayt_autoStartup : true});
362
    }
3206 mandeep.dh 363
}
364
 
365
function processInputFormSubmit() {
3228 mandeep.dh 366
    $.ajax({
367
        type : "POST",
368
        url : "/crm/",
369
        success : function(response) {
370
            $.html(response);
3405 mandeep.dh 371
            var ticketTable = createTicketDataTable('tickets');
3228 mandeep.dh 372
        }
373
    });
3339 mandeep.dh 374
}
375
 
376
function listActivities(domId, params) {
377
    $.ajax({
378
        type : "GET",
379
        url : "/crm/activity",
380
        data : params,
381
        success : function(response) {
382
            $('#' + domId).html(response);
3405 mandeep.dh 383
            var activityTable = createActivityDataTable('activity');
3339 mandeep.dh 384
        }
385
    });
386
}
387
 
388
function truncateText(widthSize) {
4241 anupam.sin 389
    $(".truncated-text").each(function() {
390
    	$(this).truncate({
391
            width : $(this).attr('truncatedTextWidth'),
392
            addtitle : true
393
        });
394
	})
3339 mandeep.dh 395
}
3390 mandeep.dh 396
 
397
function markAsRead(activityId) {
398
    $.ajax({
399
        type : "POST",
400
        url : "/crm/activity!markAsRead?activityId=" + activityId,
401
        success: function(response) {
402
            listActivities('infopane', "creatorId=1");
403
        }
404
    });
405
}
3397 mandeep.dh 406
 
407
function loadAdvancedSearchBox() {
408
    $.colorbox({
409
        inline : true,
410
        width : "535px",
411
        height : "465px",
412
        href : "form#search",
413
        onClosed : function() {
414
            $("form#search").hide();
415
        }
416
    });
417
 
418
    $("form#search").show();
419
}
420
 
421
function processSearchEntityChange(searchEntity) {
422
    if (searchEntity == "Tickets") {
423
        $("#assignee").show();
424
        $("#creator").hide();
4142 mandeep.dh 425
        $("tr#activityTypes").hide();
3397 mandeep.dh 426
    }
427
    else if (searchEntity == "Activities") {
428
        $("#assignee").hide();
429
        $("#creator").show();
4142 mandeep.dh 430
        $("tr#activityTypes").show();
3397 mandeep.dh 431
    }
432
}
3499 mandeep.dh 433
 
434
function increaseTrustLevel(domId, userId, trustLevelDelta) {
435
    $.ajax({
436
        type : "PUT",
437
        url : "/crm/user-info/" + userId + "?trustLevelDelta=" + trustLevelDelta,
438
        success : function(response) {
439
            $('#' + domId).html(response);
440
        }
441
    });
442
}
443
 
4241 anupam.sin 444
function displayCancelOrderPopUp() {
445
    	$.colorbox({
446
            inline : true,
447
            width : "650px",
448
            height : "520px",
449
            href : "div#cancel-cod-div",
450
            onClosed : function() {
451
                CKEDITOR.instances['cancel-cod-body'].destroy(false);
452
                $("div#cancel-cod-div").hide();
453
            }
454
        });
455
 
456
        $("div#cancel-cod-div").show();
457
        $('#cancel-cod-body').ckeditor({toolbar : 'Basic', scayt_autoStartup : true});
458
}
459
 
460
function cancelOrder(domId, ticketId, orderId, orderStatus, formData) {
461
    $.ajax({
462
        type : "POST",
463
        url : "/crm/tickets!updateOrderStatus?id=" + ticketId + "&orderId=" + orderId
464
        					+ "&orderStatus=" + orderStatus + "&" + formData,
465
        success : function(response) {
466
            $('#' + domId).html(response);
4065 mandeep.dh 467
        }
4241 anupam.sin 468
    });
469
}
4065 mandeep.dh 470
 
4241 anupam.sin 471
function updateOrderStatus(domId, ticketId, orderId, orderStatus) {
3499 mandeep.dh 472
    $.ajax({
3546 mandeep.dh 473
        type : "POST",
4241 anupam.sin 474
        url : "/crm/tickets!updateOrderStatus?id=" + ticketId + "&orderId=" + orderId
475
        					+ "&orderStatus=" + orderStatus,
3499 mandeep.dh 476
        success : function(response) {
3546 mandeep.dh 477
            $('#' + domId).html(response);
3499 mandeep.dh 478
        }
479
    });
3711 mandeep.dh 480
}
481
 
482
function loadUnreadActivities(domId) {
483
    $.ajax({
484
        type : "GET",
485
        url : "/crm/activity!getUnreadActivities",
486
        success : function(response) {
487
            $('#' + domId).html(response);
488
            var activityTable = createActivityDataTable('activity');
489
        }
490
    });
491
}
4065 mandeep.dh 492
 
493
function refreshSidebar() {
494
    $.ajax({
4142 mandeep.dh 495
        type : "PUT",
496
        url : "/crm",
497
        success : function(response) {
498
            $('#sidebar').html($(response).find('#sidebar').html());
499
        }
500
    });
501
}
502
 
503
function changeAddress(urlParams) {
504
    $.ajax({
4065 mandeep.dh 505
        type : "GET",
506
        url : "/crm",
507
        success : function(response) {
508
            $('#sidebar').html($(response).find('#sidebar').html());
509
        }
510
    });
4241 anupam.sin 511
}