Subversion Repositories SmartDukaan

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
7648 amar.kumar 1
$(function(){
2
 
3
	$('#addrow').live('click', function(){
4
		addNewRowForLineItem($('table#fbaSheetTable'));
5
	});
6
 
7
	$('a#remove-lineitem').live('click', function(){
8
		$(this).closest('tr').remove();
9
	});
10
 
11
	$('#generateSheet').live('click', function(){
12
		downloadSheet();
13
	});
14
});
15
 
16
function addNewRowForLineItem(table) {
17
    $(table).find('#new-item-detail').clone(true).insertAfter($(table).find('tbody>tr:last'));
18
 
19
    var newRow = $(table).find('tbody>tr:last');
20
 
21
    // Enabling the new record added
22
    $(newRow).find('input').removeAttr('disabled');
23
    $(newRow).removeAttr('id');
24
 
25
    // Making this row visible
26
    $(newRow).show();
27
}
28
 
29
function downloadSheet() {
30
	var jsonData = '[';
31
	var rowCount = 0;
32
	$('#fbaSheetTable tr').each(function(){
33
		rowCount++;
34
		if(rowCount<=2){
35
			;
36
		} else {
37
			jsonData = jsonData + '{"itemId":"';
38
			jsonData = jsonData + $(this).find('input.itemId').val();
39
			jsonData = jsonData + '","quantity":"';
40
			jsonData = jsonData + $(this).find('input.quantity').val();
41
			jsonData = jsonData + '"},'
42
		}
43
	});
44
	jsonData = jsonData.substring(0,jsonData.length-1);
45
	jsonData = jsonData + ']';
46
 
47
	$('<form id = "tempForm" method = "POST" action = "/inventory/fba-sheet-generator/">').appendTo('body');
48
	$('form#tempForm').append($('<input id = "jsoninput" name = "jsonData" value ='+jsonData +'>'));
49
	$('form#tempForm').append($('#warehouseSelector'));
50
	$('form#tempForm').submit();
51
}