Subversion Repositories SmartDukaan

Rev

Rev 4065 | Rev 4241 | 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' ] ],
3996 mandeep.dh 23
                "fnDrawCallback": function() { truncateText(125); },
3228 mandeep.dh 24
                "iDisplayLength" : 5,
3339 mandeep.dh 25
                "sDom" : 'T<"clear">lfrtip',
26
                "oTableTools" : {
27
                    "sSwfPath" : "swf/copy_cvs_xls_pdf.swf"
28
                },
3228 mandeep.dh 29
                "aLengthMenu" : [ [ 5, 10, 20, -1 ], [ 5, 10, 20, "All" ] ]
30
            });
31
        }
32
    });
2674 vikas 33
}
34
 
3228 mandeep.dh 35
function loadCartPane(domId, userId, cartId) {
36
    $.ajax({
37
        type : "GET",
38
        url : "/crm/user-cart?userId=" + userId + "&cartId=" + cartId,
39
        success : function(response) {
40
            $('#' + domId).html(response);
41
            cartTable = $('#user-cart').dataTable({
42
                "aaSorting" : [ [ 1, 'desc' ] ],
43
                "iDisplayLength" : 10,
3339 mandeep.dh 44
                "sDom" : 'T<"clear">lfrtip',
45
                "oTableTools" : {
46
                    "sSwfPath" : "swf/copy_cvs_xls_pdf.swf"
47
                },
3228 mandeep.dh 48
                "aLengthMenu" : [ [ 5, 10, 20, -1 ], [ 5, 10, 20, "All" ] ]
49
            });
50
        }
51
    });
2714 vikas 52
}
53
 
3499 mandeep.dh 54
function loadOrderInfo(domId, orderId) {
3228 mandeep.dh 55
    $.ajax({
56
        type : "GET",
3499 mandeep.dh 57
        url : "/crm/user-order-info?orderId=" + orderId,
3228 mandeep.dh 58
        success : function(response) {
59
            $('#' + domId).html(response);
3220 mandeep.dh 60
 
3228 mandeep.dh 61
            var trId = 'order-row-' + orderId;
62
            if (orderTable != null) {
63
                for ( var index in orderTable.fnGetNodes()) {
64
                    var item = orderTable.fnGetNodes()[index];
65
                    if ($(item).attr('id') == trId) {
66
                        orderTable.fnDisplayRow(item);
67
                        break;
68
                    }
69
                }
70
            }
3220 mandeep.dh 71
 
3228 mandeep.dh 72
            $('#user-orders tr').removeClass('selected');
73
            $('#order-row-' + orderId).addClass('selected');
74
        }
75
    });
2714 vikas 76
}
77
 
3228 mandeep.dh 78
function loadLineInfo(domId, userId, itemId) {
79
    $.ajax({
80
        type : "GET",
81
        url : "/crm/user-line-info?userId=" + userId + "&itemId=" + itemId,
82
        success : function(response) {
83
            $('#' + domId).html(response);
84
            $('#user-cart tr').removeClass('selected');
85
            $('#cart-row-' + itemId).addClass('selected');
86
        }
87
    });
2830 vikas 88
}
89
 
3228 mandeep.dh 90
function loadTicketInfo(domId, ticketId, ticketTable, activityId) {
91
    $.ajax({
92
        type : "GET",
3405 mandeep.dh 93
        url : "/crm/tickets/" + ticketId + "/edit",
3228 mandeep.dh 94
        success : function(response) {
95
            $('#' + domId).html(response);
3206 mandeep.dh 96
 
3228 mandeep.dh 97
            var trId = 'ticket-row-' + ticketId;
98
            if (ticketTable != null) {
99
                for ( var index in ticketTable.fnGetNodes()) {
100
                    var item = ticketTable.fnGetNodes()[index];
101
                    if ($(item).attr('id') == trId) {
102
                        ticketTable.fnDisplayRow(item);
103
                        break;
104
                    }
105
                }
106
            }
3206 mandeep.dh 107
 
3228 mandeep.dh 108
            $('#tickets tr').removeClass('selected');
109
            $('#' + trId).addClass('selected');
110
 
111
            // For tickets accessed from activity page
112
            if (activityId != null) {
3339 mandeep.dh 113
                $('#activity tr').removeClass('selected');
3228 mandeep.dh 114
                $('#activity-row-' + activityId).addClass('selected');
115
            }
3546 mandeep.dh 116
 
117
            $('#order-table').dataTable({
118
                "aaSorting" : [ [ 2, 'desc' ] ],
119
                "iDisplayLength" : 5,
120
                "fnDrawCallback": function() {truncateText(100);},
121
                "aLengthMenu" : [ [ 5, 10, 20, -1 ], [ 5, 10, 20, "All" ] ]
122
            });
3228 mandeep.dh 123
        }
124
    });
3090 mandeep.dh 125
}
126
 
3405 mandeep.dh 127
function createTicketDataTable(domId) {
3499 mandeep.dh 128
    var ticketsTable = $('#' + domId).dataTable({
4142 mandeep.dh 129
         "aaSorting" : [ [ 3, 'asc' ] ],
3339 mandeep.dh 130
//         "bAutoWidth": false,
131
//         "aoColumns" : [{ "sWidth": "5%" },
3578 mandeep.dh 132
//                        { "sWidth": "20%" },
133
//                        { "sWidth": "20%" },
134
//                        { "sWidth": "12.5%" },
135
//                        { "sWidth": "12.5%" },
136
//                        { "sWidth": "10%" },
137
//                        { "sWidth": "10%" },
138
//                        { "sWidth": "10%" }],
3546 mandeep.dh 139
        "fnDrawCallback": function() {truncateText(85);},
3339 mandeep.dh 140
        "iDisplayLength" : 5,
141
        "sDom" : 'T<"clear">lfrtip',
142
        "oTableTools" : {
143
            "sSwfPath" : "swf/copy_cvs_xls_pdf.swf"
144
        },
145
        "aLengthMenu" : [ [ 5, 10, 20, -1 ], [ 5, 10, 20, "All" ] ]
146
    });
3499 mandeep.dh 147
 
148
    return ticketsTable;
3339 mandeep.dh 149
}
150
 
3422 mandeep.dh 151
function loadActivityInfo(domId, activityId) {
3228 mandeep.dh 152
    $.ajax({
153
        type : "GET",
3422 mandeep.dh 154
        url : "/crm/activity-info?activityId=" + activityId,
3228 mandeep.dh 155
        success : function(response) {
156
            $('#' + domId).html(response);
3339 mandeep.dh 157
            $('#activity tr').removeClass('selected');
3228 mandeep.dh 158
            $('#activity-row-' + activityId).addClass('selected');
3390 mandeep.dh 159
            $('#activity').css('table-layout', 'fixed');
3228 mandeep.dh 160
        }
161
    });
3090 mandeep.dh 162
}
163
 
3405 mandeep.dh 164
function createActivityDataTable(domId) {
3499 mandeep.dh 165
    var activityTable = $('#' + domId).dataTable({
3339 mandeep.dh 166
        "aaSorting" : [ [ 4, 'desc' ] ],
167
        "iDisplayLength" : 5,
168
        "sDom" : 'T<"clear">lfrtip',
3546 mandeep.dh 169
        "fnDrawCallback": function() {truncateText(95);},
3339 mandeep.dh 170
        "oTableTools" : {
171
            "sSwfPath" : "swf/copy_cvs_xls_pdf.swf"
172
        },
173
        "aLengthMenu" : [ [ 5, 10, 20, -1 ], [ 5, 10, 20, "All" ] ]
174
    });
3499 mandeep.dh 175
 
176
    return activityTable;
3339 mandeep.dh 177
}
178
 
3405 mandeep.dh 179
function loadTicketCreationForm(domId, params) {
3228 mandeep.dh 180
    $.ajax({
181
        type : "GET",
3339 mandeep.dh 182
        url : "/crm/tickets/new",
3405 mandeep.dh 183
        data : params,
3339 mandeep.dh 184
        success : function(response) {
185
            $('#' + domId).html(response);
186
        }
187
    });
188
}
189
 
3405 mandeep.dh 190
function loadActivityCreationForm(domId, params) {
3339 mandeep.dh 191
    $.ajax({
192
        type : "GET",
193
        url : "/crm/activity/new",
3405 mandeep.dh 194
        data : params,
3339 mandeep.dh 195
        success : function(response) {
196
            $('#' + domId).html(response);
197
        }
198
    });
199
}
200
 
3090 mandeep.dh 201
function updateTicket(domId, ticketId, params) {
3228 mandeep.dh 202
    $.ajax({
203
        type : "PUT",
3405 mandeep.dh 204
        url : "/crm/tickets/" + ticketId + "?" + params,
3228 mandeep.dh 205
        success : function(response) {
3339 mandeep.dh 206
            var ticketTable = $('table[id$="tickets"]');
207
            if (ticketTable.length == 1) {
208
                var rowIndex = ticketTable.dataTable().fnGetPosition($('tr#ticket-row-' + ticketId)[0]);
209
                var responseObj = jQuery(response);
3546 mandeep.dh 210
                var actionMessages = responseObj.find('#action-messages').html();
3339 mandeep.dh 211
                responseObj.find('#ticket-row-' + ticketId).children().each(
212
                        function(i, item) {
213
                            var th = responseObj.find('th').eq(i);
214
                            if (th.text() == "Ticket Id") {
215
                                return;
216
                            }
217
 
218
                            var thOld = ticketTable.find('th').filter(
219
                                    function(index) {
220
                                        if ($(this).text() == th.text()) {
221
                                            return true;
222
                                        }
223
 
224
                                        return false;
225
                                    });
226
 
227
                            if (thOld != null) {
228
                                ticketTable.dataTable().fnUpdate($(item).text(), rowIndex, $(thOld).index(), true, false);
229
                            }
230
                        });
231
 
3546 mandeep.dh 232
                loadTicketInfo("bottom-infopane", ticketId, ticketTable.dataTable(), null);
3339 mandeep.dh 233
                ticketTable.css('table-layout', 'fixed');
3546 mandeep.dh 234
 
235
                var alertString = jQuery.trim(actionMessages);
236
                if (alertString != '') {
237
                    alert(alertString);
238
                }
3339 mandeep.dh 239
            }
240
            else {
241
                loadTicketInfo("bottom-infopane", ticketId, null, null);
242
            }
243
 
3499 mandeep.dh 244
            truncateText(85);
3339 mandeep.dh 245
        }
246
    });
247
}
248
 
3090 mandeep.dh 249
function createTicket(domId, params) {
3228 mandeep.dh 250
    $.ajax({
251
        type : "POST",
3339 mandeep.dh 252
        url : "/crm/tickets",
3228 mandeep.dh 253
        data : params,
254
        success : function(response) {
255
            $('#' + domId).html(response);
3405 mandeep.dh 256
            var ticketTable = createTicketDataTable('tickets');
3228 mandeep.dh 257
        }
258
    });
3090 mandeep.dh 259
}
260
 
261
function createActivity(domId, params) {
3228 mandeep.dh 262
    $.ajax({
263
        type : "POST",
3339 mandeep.dh 264
        url : "/crm/activity",
3228 mandeep.dh 265
        data : params,
266
        success : function(response) {
267
            $('#' + domId).html(response);
3405 mandeep.dh 268
            var activityTable = createActivityDataTable('activity');
3228 mandeep.dh 269
        }
270
    });
3106 mandeep.dh 271
}
272
 
273
function goToHomePage() {
3228 mandeep.dh 274
    document.location.href = "/crm";
3106 mandeep.dh 275
}
276
 
3422 mandeep.dh 277
function loadTickets(domId, getURL, ticketId) {
3228 mandeep.dh 278
    $.ajax({
279
        type : "GET",
3234 mandeep.dh 280
        url : getURL,
3228 mandeep.dh 281
        success : function(response) {
282
            $('#' + domId).html(response);
3405 mandeep.dh 283
            var ticketTable = createTicketDataTable('tickets');
3422 mandeep.dh 284
            if (ticketId != null) {
285
                loadTicketInfo("bottom-infopane", ticketId, ticketTable.dataTable(), null);
286
                ticketTable.css('table-layout', 'fixed');
287
            }
3228 mandeep.dh 288
        }
289
    });
3106 mandeep.dh 290
}
3137 mandeep.dh 291
 
3422 mandeep.dh 292
function processActivityTypeChange(activityType) {
3269 mandeep.dh 293
    if (activityType == "SEND_EMAIL_TO_CUSTOMER") {
3228 mandeep.dh 294
        $.colorbox({
295
            inline : true,
3519 mandeep.dh 296
            width : "775px",
297
            height : "445px",
3228 mandeep.dh 298
            href : "div#mail-div",
299
            onClosed : function() {
3519 mandeep.dh 300
				CKEDITOR.instances['mail-body'].destroy(false);
3228 mandeep.dh 301
                $("div#mail-div").hide();
302
                $('select#activity-type').val('OTHER');
303
            }
304
        });
3206 mandeep.dh 305
 
3228 mandeep.dh 306
        $("div#mail-div").show();
3701 mandeep.dh 307
        $('#mail-body').ckeditor({toolbar : 'Basic', scayt_autoStartup : true});
3228 mandeep.dh 308
    }
4020 mandeep.dh 309
    else if (activityType == "ESCALATE_TICKET") {
310
        $.colorbox({
311
            inline : true,
312
            width : "675px",
4027 mandeep.dh 313
            height : "560px",
4020 mandeep.dh 314
            href : "div#escalation-div",
315
            onClosed : function() {
316
                CKEDITOR.instances['escalation-mail-body'].destroy(false);
317
                $("div#escalation-div").hide();
318
                $('select#activity-type').val('OTHER');
319
            }
320
        });
321
 
322
        $("div#escalation-div").show();
323
        $('#escalation-mail-body').ckeditor({toolbar : 'Basic', scayt_autoStartup : true});
324
    }
3206 mandeep.dh 325
}
326
 
327
function processInputFormSubmit() {
3228 mandeep.dh 328
    $.ajax({
329
        type : "POST",
330
        url : "/crm/",
331
        success : function(response) {
332
            $.html(response);
3405 mandeep.dh 333
            var ticketTable = createTicketDataTable('tickets');
3228 mandeep.dh 334
        }
335
    });
3339 mandeep.dh 336
}
337
 
338
function listActivities(domId, params) {
339
    $.ajax({
340
        type : "GET",
341
        url : "/crm/activity",
342
        data : params,
343
        success : function(response) {
344
            $('#' + domId).html(response);
3405 mandeep.dh 345
            var activityTable = createActivityDataTable('activity');
3339 mandeep.dh 346
        }
347
    });
348
}
349
 
350
function truncateText(widthSize) {
351
    $(".truncated-text").truncate({
352
        width : widthSize,
353
        addtitle : true
354
    });
355
}
3390 mandeep.dh 356
 
357
function markAsRead(activityId) {
358
    $.ajax({
359
        type : "POST",
360
        url : "/crm/activity!markAsRead?activityId=" + activityId,
361
        success: function(response) {
362
            listActivities('infopane', "creatorId=1");
363
        }
364
    });
365
}
3397 mandeep.dh 366
 
367
function loadAdvancedSearchBox() {
368
    $.colorbox({
369
        inline : true,
370
        width : "535px",
371
        height : "465px",
372
        href : "form#search",
373
        onClosed : function() {
374
            $("form#search").hide();
375
        }
376
    });
377
 
378
    $("form#search").show();
379
}
380
 
381
function processSearchEntityChange(searchEntity) {
382
    if (searchEntity == "Tickets") {
383
        $("#assignee").show();
384
        $("#creator").hide();
4142 mandeep.dh 385
        $("tr#activityTypes").hide();
3397 mandeep.dh 386
    }
387
    else if (searchEntity == "Activities") {
388
        $("#assignee").hide();
389
        $("#creator").show();
4142 mandeep.dh 390
        $("tr#activityTypes").show();
3397 mandeep.dh 391
    }
392
}
3499 mandeep.dh 393
 
394
function increaseTrustLevel(domId, userId, trustLevelDelta) {
395
    $.ajax({
396
        type : "PUT",
397
        url : "/crm/user-info/" + userId + "?trustLevelDelta=" + trustLevelDelta,
398
        success : function(response) {
399
            $('#' + domId).html(response);
400
        }
401
    });
402
}
403
 
3546 mandeep.dh 404
function updateOrderStatus(domId, ticketId, orderId, orderStatus) {
4065 mandeep.dh 405
    if (orderStatus == "CANCELED") {
406
        if (!confirm("Are you sure you want to cancel order id: " + orderId + " ?")) {
407
            return;
408
        }
409
    }
410
 
3499 mandeep.dh 411
    $.ajax({
3546 mandeep.dh 412
        type : "POST",
413
        url : "/crm/tickets!updateOrderStatus?id=" + ticketId + "&orderId=" + orderId + "&orderStatus=" + orderStatus,
3499 mandeep.dh 414
        success : function(response) {
3546 mandeep.dh 415
            $('#' + domId).html(response);
3499 mandeep.dh 416
        }
417
    });
3711 mandeep.dh 418
}
419
 
420
function loadUnreadActivities(domId) {
421
    $.ajax({
422
        type : "GET",
423
        url : "/crm/activity!getUnreadActivities",
424
        success : function(response) {
425
            $('#' + domId).html(response);
426
            var activityTable = createActivityDataTable('activity');
427
        }
428
    });
429
}
4065 mandeep.dh 430
 
431
function refreshSidebar() {
432
    $.ajax({
4142 mandeep.dh 433
        type : "PUT",
434
        url : "/crm",
435
        success : function(response) {
436
            $('#sidebar').html($(response).find('#sidebar').html());
437
        }
438
    });
439
}
440
 
441
function changeAddress(urlParams) {
442
    $.ajax({
4065 mandeep.dh 443
        type : "GET",
444
        url : "/crm",
445
        success : function(response) {
446
            $('#sidebar').html($(response).find('#sidebar').html());
447
        }
448
    });
4142 mandeep.dh 449
}