Subversion Repositories SmartDukaan

Rev

Rev 3397 | Rev 3422 | 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;
2830 vikas 3
var userCommunicationTable;
3096 mandeep.dh 4
 
3090 mandeep.dh 5
function loadUserPane(domId, userId) {
3228 mandeep.dh 6
    $.ajax({
7
        type : "GET",
8
        url : "/crm/user-info?userId=" + userId,
9
        success : function(response) {
10
            $('#' + domId).html(response);
11
        }
12
    });
2674 vikas 13
}
14
 
3228 mandeep.dh 15
function loadOrderPane(domId, userId, orderId) {
16
    $.ajax({
17
        type : "GET",
18
        url : "/crm/user-orders?userId=" + userId,
19
        success : function(response) {
20
            $('#' + domId).html(response);
21
            loadOrderInfo("bottom-infopane", userId, orderId);
22
            orderTable = $('#user-orders').dataTable({
23
                "aaSorting" : [ [ 1, 'desc' ] ],
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
 
3228 mandeep.dh 54
function loadUserCommunicationPane(domId, userId) {
55
    $.ajax({
56
        type : "GET",
57
        url : "/crm/user-communications?userId=" + userId,
58
        success : function(response) {
59
            $('#' + domId).html(response);
60
            userCommunicationTable = $('#user-communications').dataTable({
61
                "aaSorting" : [ [ 0, 'desc' ] ],
62
                "iDisplayLength" : 5,
3339 mandeep.dh 63
                "sDom" : 'T<"clear">lfrtip',
64
                "oTableTools" : {
65
                    "sSwfPath" : "swf/copy_cvs_xls_pdf.swf"
66
                },
3228 mandeep.dh 67
                "aLengthMenu" : [ [ 5, 10, 20, -1 ], [ 5, 10, 20, "All" ] ]
68
            });
69
        }
70
    });
2830 vikas 71
}
72
 
3228 mandeep.dh 73
function loadOrderInfo(domId, userId, orderId) {
74
    $.ajax({
75
        type : "GET",
76
        url : "/crm/user-order-info?userId=" + userId + "&orderId=" + orderId,
77
        success : function(response) {
78
            $('#' + domId).html(response);
3220 mandeep.dh 79
 
3228 mandeep.dh 80
            var trId = 'order-row-' + orderId;
81
            if (orderTable != null) {
82
                for ( var index in orderTable.fnGetNodes()) {
83
                    var item = orderTable.fnGetNodes()[index];
84
                    if ($(item).attr('id') == trId) {
85
                        orderTable.fnDisplayRow(item);
86
                        break;
87
                    }
88
                }
89
            }
3220 mandeep.dh 90
 
3228 mandeep.dh 91
            $('#user-orders tr').removeClass('selected');
92
            $('#order-row-' + orderId).addClass('selected');
93
        }
94
    });
2714 vikas 95
}
96
 
3228 mandeep.dh 97
function loadLineInfo(domId, userId, itemId) {
98
    $.ajax({
99
        type : "GET",
100
        url : "/crm/user-line-info?userId=" + userId + "&itemId=" + itemId,
101
        success : function(response) {
102
            $('#' + domId).html(response);
103
            $('#user-cart tr').removeClass('selected');
104
            $('#cart-row-' + itemId).addClass('selected');
105
        }
106
    });
2830 vikas 107
}
108
 
109
function loadCommunicationInfo(domId, userId, commId) {
3228 mandeep.dh 110
    $.ajax({
111
        type : "GET",
112
        url : "/crm/user-communication-info?userId=" + userId + "&commId="
113
                + commId,
114
        success : function(response) {
115
            $('#' + domId).html(response);
116
            $('#user-cart tr').removeClass('selected');
117
            $('#cart-row-' + commId).addClass('selected');
118
        }
119
    });
3090 mandeep.dh 120
}
121
 
3228 mandeep.dh 122
function loadTicketInfo(domId, ticketId, ticketTable, activityId) {
123
    $.ajax({
124
        type : "GET",
3405 mandeep.dh 125
        url : "/crm/tickets/" + ticketId + "/edit",
3228 mandeep.dh 126
        success : function(response) {
127
            $('#' + domId).html(response);
3206 mandeep.dh 128
 
3228 mandeep.dh 129
            var trId = 'ticket-row-' + ticketId;
130
            if (ticketTable != null) {
131
                for ( var index in ticketTable.fnGetNodes()) {
132
                    var item = ticketTable.fnGetNodes()[index];
133
                    if ($(item).attr('id') == trId) {
134
                        ticketTable.fnDisplayRow(item);
135
                        break;
136
                    }
137
                }
138
            }
3206 mandeep.dh 139
 
3228 mandeep.dh 140
            $('#tickets tr').removeClass('selected');
141
            $('#' + trId).addClass('selected');
142
 
143
            // For tickets accessed from activity page
144
            if (activityId != null) {
3339 mandeep.dh 145
                $('#activity tr').removeClass('selected');
3228 mandeep.dh 146
                $('#activity-row-' + activityId).addClass('selected');
147
            }
148
        }
149
    });
3090 mandeep.dh 150
}
151
 
3405 mandeep.dh 152
function createTicketDataTable(domId) {
3339 mandeep.dh 153
    return $('#' + domId).dataTable({
154
         "aaSorting" : [ [ 2, 'desc' ] ],
155
//         "bAutoWidth": false,
156
//         "aoColumns" : [{ "sWidth": "5%" },
157
//                        { "sWidth": "25%" },
158
//                        { "sWidth": "5%" },
159
//                        { "sWidth": "5%" },
160
//                        { "sWidth": "5%" },
161
//                        { "sWidth": "5%" },
162
//                        { "sWidth": "5%" },
163
//                        { "sWidth": "5%" }],
164
        "iDisplayLength" : 5,
165
        "sDom" : 'T<"clear">lfrtip',
166
        "oTableTools" : {
167
            "sSwfPath" : "swf/copy_cvs_xls_pdf.swf"
168
        },
169
        "aLengthMenu" : [ [ 5, 10, 20, -1 ], [ 5, 10, 20, "All" ] ]
170
    });
171
}
172
 
3090 mandeep.dh 173
function loadActivityInfo(domId, userId, activityId) {
3228 mandeep.dh 174
    $.ajax({
175
        type : "GET",
3405 mandeep.dh 176
        url : "/crm/activity-info?userId=" + userId + "&activityId="
3228 mandeep.dh 177
                + activityId,
178
        success : function(response) {
179
            $('#' + domId).html(response);
3339 mandeep.dh 180
            $('#activity tr').removeClass('selected');
3228 mandeep.dh 181
            $('#activity-row-' + activityId).addClass('selected');
3390 mandeep.dh 182
            $('#activity').css('table-layout', 'fixed');
3228 mandeep.dh 183
        }
184
    });
3090 mandeep.dh 185
}
186
 
3405 mandeep.dh 187
function createActivityDataTable(domId) {
3339 mandeep.dh 188
    return $('#' + domId).dataTable({
189
        "aaSorting" : [ [ 4, 'desc' ] ],
190
        "iDisplayLength" : 5,
191
        "sDom" : 'T<"clear">lfrtip',
192
        "oTableTools" : {
193
            "sSwfPath" : "swf/copy_cvs_xls_pdf.swf"
194
        },
195
        "aLengthMenu" : [ [ 5, 10, 20, -1 ], [ 5, 10, 20, "All" ] ]
196
    });
197
}
198
 
3405 mandeep.dh 199
function loadTicketCreationForm(domId, params) {
3228 mandeep.dh 200
    $.ajax({
201
        type : "GET",
3339 mandeep.dh 202
        url : "/crm/tickets/new",
3405 mandeep.dh 203
        data : params,
3339 mandeep.dh 204
        success : function(response) {
205
            $('#' + domId).html(response);
206
        }
207
    });
208
}
209
 
3405 mandeep.dh 210
function loadActivityCreationForm(domId, params) {
3339 mandeep.dh 211
    $.ajax({
212
        type : "GET",
213
        url : "/crm/activity/new",
3405 mandeep.dh 214
        data : params,
3339 mandeep.dh 215
        success : function(response) {
216
            $('#' + domId).html(response);
217
        }
218
    });
219
}
220
 
3090 mandeep.dh 221
function updateTicket(domId, ticketId, params) {
3228 mandeep.dh 222
    $.ajax({
223
        type : "PUT",
3405 mandeep.dh 224
        url : "/crm/tickets/" + ticketId + "?" + params,
3228 mandeep.dh 225
        success : function(response) {
3339 mandeep.dh 226
            var ticketTable = $('table[id$="tickets"]');
227
            if (ticketTable.length == 1) {
228
                var rowIndex = ticketTable.dataTable().fnGetPosition($('tr#ticket-row-' + ticketId)[0]);
229
                var responseObj = jQuery(response);
230
                responseObj.find('#ticket-row-' + ticketId).children().each(
231
                        function(i, item) {
232
                            var th = responseObj.find('th').eq(i);
233
                            if (th.text() == "Ticket Id") {
234
                                return;
235
                            }
236
 
237
                            var thOld = ticketTable.find('th').filter(
238
                                    function(index) {
239
                                        if ($(this).text() == th.text()) {
240
                                            return true;
241
                                        }
242
 
243
                                        return false;
244
                                    });
245
 
246
                            if (thOld != null) {
247
                                ticketTable.dataTable().fnUpdate($(item).text(), rowIndex, $(thOld).index(), true, false);
248
                            }
249
                        });
250
 
251
                loadTicketInfo("bottom-infopane", ticketId, ticketTable
252
                        .dataTable(), null);
253
                ticketTable.css('table-layout', 'fixed');
254
            }
255
            else {
256
                loadTicketInfo("bottom-infopane", ticketId, null, null);
257
            }
258
 
259
            truncateText(70);
260
        }
261
    });
262
}
263
 
3090 mandeep.dh 264
function createTicket(domId, params) {
3228 mandeep.dh 265
    $.ajax({
266
        type : "POST",
3339 mandeep.dh 267
        url : "/crm/tickets",
3228 mandeep.dh 268
        data : params,
269
        success : function(response) {
270
            $('#' + domId).html(response);
3405 mandeep.dh 271
            var ticketTable = createTicketDataTable('tickets');
3228 mandeep.dh 272
        }
273
    });
3090 mandeep.dh 274
}
275
 
276
function createActivity(domId, params) {
3228 mandeep.dh 277
    $.ajax({
278
        type : "POST",
3339 mandeep.dh 279
        url : "/crm/activity",
3228 mandeep.dh 280
        data : params,
281
        success : function(response) {
282
            $('#' + domId).html(response);
3405 mandeep.dh 283
            var activityTable = createActivityDataTable('activity');
3228 mandeep.dh 284
        }
285
    });
3106 mandeep.dh 286
}
287
 
288
function goToHomePage() {
3228 mandeep.dh 289
    document.location.href = "/crm";
3106 mandeep.dh 290
}
291
 
3234 mandeep.dh 292
function loadTickets(domId, getURL) {
3228 mandeep.dh 293
    $.ajax({
294
        type : "GET",
3234 mandeep.dh 295
        url : getURL,
3228 mandeep.dh 296
        success : function(response) {
297
            $('#' + domId).html(response);
3405 mandeep.dh 298
            var ticketTable = createTicketDataTable('tickets');
3228 mandeep.dh 299
        }
300
    });
3106 mandeep.dh 301
}
3137 mandeep.dh 302
 
3206 mandeep.dh 303
function processActivityTypeChange(userId, activityType) {
3269 mandeep.dh 304
    if (activityType == "SEND_EMAIL_TO_CUSTOMER") {
3228 mandeep.dh 305
        $.colorbox({
306
            inline : true,
307
            width : "735px",
308
            height : "365px",
309
            href : "div#mail-div",
310
            onClosed : function() {
311
                $("div#mail-div").hide();
312
                $('select#activity-type').val('OTHER');
313
            }
314
        });
3206 mandeep.dh 315
 
3228 mandeep.dh 316
        $("div#mail-div").show();
317
    }
3206 mandeep.dh 318
}
319
 
320
function processInputFormSubmit() {
3228 mandeep.dh 321
    $.ajax({
322
        type : "POST",
323
        url : "/crm/",
324
        success : function(response) {
325
            $.html(response);
3405 mandeep.dh 326
            var ticketTable = createTicketDataTable('tickets');
3228 mandeep.dh 327
        }
328
    });
3339 mandeep.dh 329
}
330
 
331
function listActivities(domId, params) {
332
    $.ajax({
333
        type : "GET",
334
        url : "/crm/activity",
335
        data : params,
336
        success : function(response) {
337
            $('#' + domId).html(response);
3405 mandeep.dh 338
            var activityTable = createActivityDataTable('activity');
3339 mandeep.dh 339
        }
340
    });
341
}
342
 
343
function truncateText(widthSize) {
344
    $(".truncated-text").truncate({
345
        width : widthSize,
346
        addtitle : true
347
    });
348
}
3390 mandeep.dh 349
 
350
function markAsRead(activityId) {
351
    $.ajax({
352
        type : "POST",
353
        url : "/crm/activity!markAsRead?activityId=" + activityId,
354
        success: function(response) {
355
            listActivities('infopane', "creatorId=1");
356
        }
357
    });
358
}
3397 mandeep.dh 359
 
360
function loadAdvancedSearchBox() {
361
    $.colorbox({
362
        inline : true,
363
        width : "535px",
364
        height : "465px",
365
        href : "form#search",
366
        onClosed : function() {
367
            $("form#search").hide();
368
        }
369
    });
370
 
371
    $("form#search").show();
372
}
373
 
374
function processSearchEntityChange(searchEntity) {
375
    if (searchEntity == "Tickets") {
376
        $("#assignee").show();
377
        $("#creator").hide();
378
    }
379
    else if (searchEntity == "Activities") {
380
        $("#assignee").hide();
381
        $("#creator").show();
382
    }
383
}