Subversion Repositories SmartDukaan

Rev

Rev 3405 | Rev 3499 | 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
 
3422 mandeep.dh 173
function loadActivityInfo(domId, activityId) {
3228 mandeep.dh 174
    $.ajax({
175
        type : "GET",
3422 mandeep.dh 176
        url : "/crm/activity-info?activityId=" + activityId,
3228 mandeep.dh 177
        success : function(response) {
178
            $('#' + domId).html(response);
3339 mandeep.dh 179
            $('#activity tr').removeClass('selected');
3228 mandeep.dh 180
            $('#activity-row-' + activityId).addClass('selected');
3390 mandeep.dh 181
            $('#activity').css('table-layout', 'fixed');
3228 mandeep.dh 182
        }
183
    });
3090 mandeep.dh 184
}
185
 
3405 mandeep.dh 186
function createActivityDataTable(domId) {
3339 mandeep.dh 187
    return $('#' + domId).dataTable({
188
        "aaSorting" : [ [ 4, 'desc' ] ],
189
        "iDisplayLength" : 5,
190
        "sDom" : 'T<"clear">lfrtip',
191
        "oTableTools" : {
192
            "sSwfPath" : "swf/copy_cvs_xls_pdf.swf"
193
        },
194
        "aLengthMenu" : [ [ 5, 10, 20, -1 ], [ 5, 10, 20, "All" ] ]
195
    });
196
}
197
 
3405 mandeep.dh 198
function loadTicketCreationForm(domId, params) {
3228 mandeep.dh 199
    $.ajax({
200
        type : "GET",
3339 mandeep.dh 201
        url : "/crm/tickets/new",
3405 mandeep.dh 202
        data : params,
3339 mandeep.dh 203
        success : function(response) {
204
            $('#' + domId).html(response);
205
        }
206
    });
207
}
208
 
3405 mandeep.dh 209
function loadActivityCreationForm(domId, params) {
3339 mandeep.dh 210
    $.ajax({
211
        type : "GET",
212
        url : "/crm/activity/new",
3405 mandeep.dh 213
        data : params,
3339 mandeep.dh 214
        success : function(response) {
215
            $('#' + domId).html(response);
216
        }
217
    });
218
}
219
 
3090 mandeep.dh 220
function updateTicket(domId, ticketId, params) {
3228 mandeep.dh 221
    $.ajax({
222
        type : "PUT",
3405 mandeep.dh 223
        url : "/crm/tickets/" + ticketId + "?" + params,
3228 mandeep.dh 224
        success : function(response) {
3339 mandeep.dh 225
            var ticketTable = $('table[id$="tickets"]');
226
            if (ticketTable.length == 1) {
227
                var rowIndex = ticketTable.dataTable().fnGetPosition($('tr#ticket-row-' + ticketId)[0]);
228
                var responseObj = jQuery(response);
229
                responseObj.find('#ticket-row-' + ticketId).children().each(
230
                        function(i, item) {
231
                            var th = responseObj.find('th').eq(i);
232
                            if (th.text() == "Ticket Id") {
233
                                return;
234
                            }
235
 
236
                            var thOld = ticketTable.find('th').filter(
237
                                    function(index) {
238
                                        if ($(this).text() == th.text()) {
239
                                            return true;
240
                                        }
241
 
242
                                        return false;
243
                                    });
244
 
245
                            if (thOld != null) {
246
                                ticketTable.dataTable().fnUpdate($(item).text(), rowIndex, $(thOld).index(), true, false);
247
                            }
248
                        });
249
 
250
                loadTicketInfo("bottom-infopane", ticketId, ticketTable
251
                        .dataTable(), null);
252
                ticketTable.css('table-layout', 'fixed');
253
            }
254
            else {
255
                loadTicketInfo("bottom-infopane", ticketId, null, null);
256
            }
257
 
258
            truncateText(70);
259
        }
260
    });
261
}
262
 
3090 mandeep.dh 263
function createTicket(domId, params) {
3228 mandeep.dh 264
    $.ajax({
265
        type : "POST",
3339 mandeep.dh 266
        url : "/crm/tickets",
3228 mandeep.dh 267
        data : params,
268
        success : function(response) {
269
            $('#' + domId).html(response);
3405 mandeep.dh 270
            var ticketTable = createTicketDataTable('tickets');
3228 mandeep.dh 271
        }
272
    });
3090 mandeep.dh 273
}
274
 
275
function createActivity(domId, params) {
3228 mandeep.dh 276
    $.ajax({
277
        type : "POST",
3339 mandeep.dh 278
        url : "/crm/activity",
3228 mandeep.dh 279
        data : params,
280
        success : function(response) {
281
            $('#' + domId).html(response);
3405 mandeep.dh 282
            var activityTable = createActivityDataTable('activity');
3228 mandeep.dh 283
        }
284
    });
3106 mandeep.dh 285
}
286
 
287
function goToHomePage() {
3228 mandeep.dh 288
    document.location.href = "/crm";
3106 mandeep.dh 289
}
290
 
3422 mandeep.dh 291
function loadTickets(domId, getURL, ticketId) {
3228 mandeep.dh 292
    $.ajax({
293
        type : "GET",
3234 mandeep.dh 294
        url : getURL,
3228 mandeep.dh 295
        success : function(response) {
296
            $('#' + domId).html(response);
3405 mandeep.dh 297
            var ticketTable = createTicketDataTable('tickets');
3422 mandeep.dh 298
            if (ticketId != null) {
299
                loadTicketInfo("bottom-infopane", ticketId, ticketTable.dataTable(), null);
300
                ticketTable.css('table-layout', 'fixed');
301
            }
3228 mandeep.dh 302
        }
303
    });
3106 mandeep.dh 304
}
3137 mandeep.dh 305
 
3422 mandeep.dh 306
function processActivityTypeChange(activityType) {
3269 mandeep.dh 307
    if (activityType == "SEND_EMAIL_TO_CUSTOMER") {
3228 mandeep.dh 308
        $.colorbox({
309
            inline : true,
310
            width : "735px",
311
            height : "365px",
312
            href : "div#mail-div",
313
            onClosed : function() {
314
                $("div#mail-div").hide();
315
                $('select#activity-type').val('OTHER');
316
            }
317
        });
3206 mandeep.dh 318
 
3228 mandeep.dh 319
        $("div#mail-div").show();
320
    }
3206 mandeep.dh 321
}
322
 
323
function processInputFormSubmit() {
3228 mandeep.dh 324
    $.ajax({
325
        type : "POST",
326
        url : "/crm/",
327
        success : function(response) {
328
            $.html(response);
3405 mandeep.dh 329
            var ticketTable = createTicketDataTable('tickets');
3228 mandeep.dh 330
        }
331
    });
3339 mandeep.dh 332
}
333
 
334
function listActivities(domId, params) {
335
    $.ajax({
336
        type : "GET",
337
        url : "/crm/activity",
338
        data : params,
339
        success : function(response) {
340
            $('#' + domId).html(response);
3405 mandeep.dh 341
            var activityTable = createActivityDataTable('activity');
3339 mandeep.dh 342
        }
343
    });
344
}
345
 
346
function truncateText(widthSize) {
347
    $(".truncated-text").truncate({
348
        width : widthSize,
349
        addtitle : true
350
    });
351
}
3390 mandeep.dh 352
 
353
function markAsRead(activityId) {
354
    $.ajax({
355
        type : "POST",
356
        url : "/crm/activity!markAsRead?activityId=" + activityId,
357
        success: function(response) {
358
            listActivities('infopane', "creatorId=1");
359
        }
360
    });
361
}
3397 mandeep.dh 362
 
363
function loadAdvancedSearchBox() {
364
    $.colorbox({
365
        inline : true,
366
        width : "535px",
367
        height : "465px",
368
        href : "form#search",
369
        onClosed : function() {
370
            $("form#search").hide();
371
        }
372
    });
373
 
374
    $("form#search").show();
375
}
376
 
377
function processSearchEntityChange(searchEntity) {
378
    if (searchEntity == "Tickets") {
379
        $("#assignee").show();
380
        $("#creator").hide();
381
    }
382
    else if (searchEntity == "Activities") {
383
        $("#assignee").hide();
384
        $("#creator").show();
385
    }
386
}