Subversion Repositories SmartDukaan

Rev

Blame | Last modification | View Log | RSS feed

$(function(){
        
        $('#addrow').live('click', function(){
                addNewRowForLineItem($('table#fbaSheetTable'));
        });
        
        $('a#remove-lineitem').live('click', function(){
                $(this).closest('tr').remove();
        });

        $('#generateSheet').live('click', function(){
                downloadSheet();
        });
});

function addNewRowForLineItem(table) {
    $(table).find('#new-item-detail').clone(true).insertAfter($(table).find('tbody>tr:last'));

    var newRow = $(table).find('tbody>tr:last');

    // Enabling the new record added
    $(newRow).find('input').removeAttr('disabled');
    $(newRow).removeAttr('id');

    // Making this row visible
    $(newRow).show();
}

function downloadSheet() {
        var jsonData = '[';
        var rowCount = 0;
        $('#fbaSheetTable tr').each(function(){
                rowCount++;
                if(rowCount<=2){
                        ;
                } else {
                        jsonData = jsonData + '{"itemId":"';
                        jsonData = jsonData + $(this).find('input.itemId').val();
                        jsonData = jsonData + '","quantity":"';
                        jsonData = jsonData + $(this).find('input.quantity').val();
                        jsonData = jsonData + '"},'
                }
        });
        jsonData = jsonData.substring(0,jsonData.length-1);
        jsonData = jsonData + ']';
        
        $('<form id = "tempForm" method = "POST" action = "/inventory/fba-sheet-generator/">').appendTo('body');
        $('form#tempForm').append($('<input id = "jsoninput" name = "jsonData" value ='+jsonData +'>'));
        $('form#tempForm').append($('#warehouseSelector'));
        $('form#tempForm').submit();
}