Subversion Repositories SmartDukaan

Rev

Rev 3234 | Rev 3339 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | RSS feed

var orderTable;
var cartTable;
var userCommunicationTable;

function loadUserPane(domId, userId) {
    $.ajax({
        type : "GET",
        url : "/crm/user-info?userId=" + userId,
        success : function(response) {
            $('#' + domId).html(response);
        }
    });
}

function loadOrderPane(domId, userId, orderId) {
    $.ajax({
        type : "GET",
        url : "/crm/user-orders?userId=" + userId,
        success : function(response) {
            $('#' + domId).html(response);
            loadOrderInfo("bottom-infopane", userId, orderId);
            orderTable = $('#user-orders').dataTable({
                "aaSorting" : [ [ 1, 'desc' ] ],
                "iDisplayLength" : 5,
                "sDom": 'T<"clear">lfrtip',
                "oTableTools": {"sSwfPath": "swf/copy_cvs_xls_pdf.swf"},
                "aLengthMenu" : [ [ 5, 10, 20, -1 ], [ 5, 10, 20, "All" ] ]
            });
        }
    });
}

function loadCartPane(domId, userId, cartId) {
    $.ajax({
        type : "GET",
        url : "/crm/user-cart?userId=" + userId + "&cartId=" + cartId,
        success : function(response) {
            $('#' + domId).html(response);
            cartTable = $('#user-cart').dataTable({
                "aaSorting" : [ [ 1, 'desc' ] ],
                "iDisplayLength" : 10,
                "sDom": 'T<"clear">lfrtip',
                "oTableTools": {"sSwfPath": "swf/copy_cvs_xls_pdf.swf"},                
                "aLengthMenu" : [ [ 5, 10, 20, -1 ], [ 5, 10, 20, "All" ] ]
            });
        }
    });
}

function loadUserCommunicationPane(domId, userId) {
    $.ajax({
        type : "GET",
        url : "/crm/user-communications?userId=" + userId,
        success : function(response) {
            $('#' + domId).html(response);
            userCommunicationTable = $('#user-communications').dataTable({
                "aaSorting" : [ [ 0, 'desc' ] ],
                "iDisplayLength" : 5,
                "sDom": 'T<"clear">lfrtip',
                "oTableTools": {"sSwfPath": "swf/copy_cvs_xls_pdf.swf"},                
                "aLengthMenu" : [ [ 5, 10, 20, -1 ], [ 5, 10, 20, "All" ] ]
            });
        }
    });
}

function loadOrderInfo(domId, userId, orderId) {
    $.ajax({
        type : "GET",
        url : "/crm/user-order-info?userId=" + userId + "&orderId=" + orderId,
        success : function(response) {
            $('#' + domId).html(response);

            var trId = 'order-row-' + orderId;
            if (orderTable != null) {
                for ( var index in orderTable.fnGetNodes()) {
                    var item = orderTable.fnGetNodes()[index];
                    if ($(item).attr('id') == trId) {
                        orderTable.fnDisplayRow(item);
                        break;
                    }
                }
            }

            $('#user-orders tr').removeClass('selected');
            $('#order-row-' + orderId).addClass('selected');
        }
    });
}

function loadLineInfo(domId, userId, itemId) {
    $.ajax({
        type : "GET",
        url : "/crm/user-line-info?userId=" + userId + "&itemId=" + itemId,
        success : function(response) {
            $('#' + domId).html(response);
            $('#user-cart tr').removeClass('selected');
            $('#cart-row-' + itemId).addClass('selected');
        }
    });
}

function loadCommunicationInfo(domId, userId, commId) {
    $.ajax({
        type : "GET",
        url : "/crm/user-communication-info?userId=" + userId + "&commId="
                + commId,
        success : function(response) {
            $('#' + domId).html(response);
            $('#user-cart tr').removeClass('selected');
            $('#cart-row-' + commId).addClass('selected');
        }
    });
}

function loadTicketInfo(domId, ticketId, ticketTable, activityId) {
    $.ajax({
        type : "GET",
        url : "/crm/user-tickets/" + ticketId + "/edit",
        success : function(response) {
            $('#' + domId).html(response);

            var trId = 'ticket-row-' + ticketId;
            if (ticketTable != null) {
                for ( var index in ticketTable.fnGetNodes()) {
                    var item = ticketTable.fnGetNodes()[index];
                    if ($(item).attr('id') == trId) {
                        ticketTable.fnDisplayRow(item);
                        break;
                    }
                }
            }

            $('#user-tickets tr').removeClass('selected');
            $('#tickets tr').removeClass('selected');
            $('#' + trId).addClass('selected');

            // For tickets accessed from activity page
            if (activityId != null) {
                $('#user-activity tr').removeClass('selected');
                $('#activity-row-' + activityId).addClass('selected');
            }
        }
    });
}

function loadTicketPane(domId, userId, ticketId) {
    $.ajax({
        type : "GET",
        url : "/crm/user-tickets?userId=" + userId,
        success : function(response) {
            $('#' + domId).html(response);
            var ticketTable = $('#user-tickets').dataTable({
                "aaSorting" : [ [ 2, 'desc' ] ],
                "iDisplayLength" : 5,
                "sDom": 'T<"clear">lfrtip',
                "oTableTools": {"sSwfPath": "swf/copy_cvs_xls_pdf.swf"},                
                "aLengthMenu" : [ [ 5, 10, 20, -1 ], [ 5, 10, 20, "All" ] ]
            });
            if (ticketId) {
                loadTicketInfo("bottom-infopane", ticketId, ticketTable, null);
            }
        }
    });
}

function loadActivityInfo(domId, userId, activityId) {
    $.ajax({
        type : "GET",
        url : "/crm/user-activity-info?userId=" + userId + "&activityId="
                + activityId,
        success : function(response) {
            $('#' + domId).html(response);
            $('#user-activity tr').removeClass('selected');
            $('#activity-row-' + activityId).addClass('selected');
        }
    });
}

function loadActivityPane(domId, userId) {
    $.ajax({
        type : "GET",
        url : "/crm/user-activity?userId=" + userId,
        success : function(response) {
            $('#' + domId).html(response);
            var activityTable = $('#user-activity').dataTable({
                "aaSorting" : [ [ 4, 'desc' ] ],
                "iDisplayLength" : 5,
                "sDom": 'T<"clear">lfrtip',
                "oTableTools": {"sSwfPath": "swf/copy_cvs_xls_pdf.swf"},
                "aLengthMenu" : [ [ 5, 10, 20, -1 ], [ 5, 10, 20, "All" ] ]
            });
        }
    });
}

function loadTicketCreationForm(domId, userId) {
    $.ajax({
        type : "GET",
        url : "/crm/user-tickets/new?userId=" + userId,
        success : function(response) {
            $('#' + domId).html(response);
        }
    });
}

function loadActivityCreationForm(domId, userId) {
    $.ajax({
        type : "GET",
        url : "/crm/user-activity/new?userId=" + userId,
        success : function(response) {
            $('#' + domId).html(response);
        }
    });
}

function updateTicket(domId, ticketId, params) {
    $.ajax({
        type : "PUT",
        url : "/crm/user-tickets/" + ticketId + "?" + params,
        success : function(response) {
            $('#' + domId).html(response);
            var ticketTable = $('#user-tickets').dataTable({
                "aaSorting" : [ [ 2, 'desc' ] ],
                "iDisplayLength" : 5,
                "sDom": 'T<"clear">lfrtip',
                "oTableTools": {"sSwfPath": "swf/copy_cvs_xls_pdf.swf"},
                "aLengthMenu" : [ [ 5, 10, 20, -1 ], [ 5, 10, 20, "All" ] ]
            });
            loadTicketInfo("bottom-infopane", ticketId, ticketTable, null);
        }
    });
}

function createTicket(domId, params) {
    $.ajax({
        type : "POST",
        url : "/crm/user-tickets",
        data : params,
        success : function(response) {
            $('#' + domId).html(response);
            var ticketTable = $('#user-tickets').dataTable({
                "aaSorting" : [ [ 2, 'desc' ] ],
                "iDisplayLength" : 5,
                "sDom": 'T<"clear">lfrtip',
                "oTableTools": {"sSwfPath": "swf/copy_cvs_xls_pdf.swf"},
                "aLengthMenu" : [ [ 5, 10, 20, -1 ], [ 5, 10, 20, "All" ] ]
            });
        }
    });
}

function createActivity(domId, params) {
    $.ajax({
        type : "POST",
        url : "/crm/user-activity",
        data : params,
        success : function(response) {
            $('#' + domId).html(response);
            var activityTable = $('#user-activity').dataTable({
                "aaSorting" : [ [ 4, 'desc' ] ],
                "iDisplayLength" : 5,
                "sDom": 'T<"clear">lfrtip',
                "oTableTools": {"sSwfPath": "swf/copy_cvs_xls_pdf.swf"},
                "aLengthMenu" : [ [ 5, 10, 20, -1 ], [ 5, 10, 20, "All" ] ]
            });
        }
    });
}

function goToHomePage() {
    document.location.href = "/crm";
}

function loadTickets(domId, getURL) {
    $.ajax({
        type : "GET",
        url : getURL,
        success : function(response) {
            $('#' + domId).html(response);
            var ticketTable = $('table#tickets').dataTable({
                "aaSorting" : [ [ 3, 'desc' ] ],
                "iDisplayLength" : 5,
                "sDom": 'T<"clear">lfrtip',
                "oTableTools": {"sSwfPath": "swf/copy_cvs_xls_pdf.swf"},
                "aLengthMenu" : [ [ 5, 10, 20, -1 ], [ 5, 10, 20, "All" ] ]
            });
        }
    });
}

function processActivityTypeChange(userId, activityType) {
    if (activityType == "SEND_EMAIL_TO_CUSTOMER") {
        $.colorbox({
            inline : true,
            width : "735px",
            height : "365px",
            href : "div#mail-div",
            onClosed : function() {
                $("div#mail-div").hide();
                $('select#activity-type').val('OTHER');
            }
        });

        $("div#mail-div").show();
    }
}

function processInputFormSubmit() {
    $.ajax({
        type : "POST",
        url : "/crm/",
        success : function(response) {
            $.html(response);
            var ticketTable = $('table#tickets').dataTable({
                "aaSorting" : [ [ 3, 'desc' ] ],
                "iDisplayLength" : 5,
                "sDom": 'T<"clear">lfrtip',
                "oTableTools": {"sSwfPath": "swf/copy_cvs_xls_pdf.swf"},
                "aLengthMenu" : [ [ 5, 10, 20, -1 ], [ 5, 10, 20, "All" ] ]
            });
        }
    });
}