Subversion Repositories SmartDukaan

Rev

Rev 32339 | Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
30683 tejbeer 1
$(function() {
2
	$(document).on('click', ".create-combo", function() {
3
		loadCombo("main-content");
4
	});
5
 
6
 
7
 
8
 
9
 
10
	$(document).on('click', ".add-combo", function() {
11
 
12
		var markup = "<tr><td>"
13
			+ mappedCatalogItemId
14
			+ "</td><td>"
15
			+ $('#item-mapping-search-text').val()
16
			+ "</td><td>"
17
			+ $('#item-mapping-qty').val()
18
			+ "</td><td><button type = 'button' class='btnDelete'>Delete</button></td></tr>";
19
		$('#cm-table > tbody:last-child').append(markup);
20
 
21
		$('#item-mapping-search-text').val(" ");
22
		$('#item-mapping-qty').val(" ")
23
 
24
		console.log(markup)
25
 
26
	})
27
 
28
	$(document).on('click', ".create-combo-model", function() {
29
		var catalogId = catalogItemId
30
		var itemQty = $('#item-qty').val();
31
		var warehouseMap = ($("select.criteria-warehouseregion").val() || []).map(Number);
32
 
33
		var addComboModel = {}
34
		addComboModel['catalogId'] = catalogId;
35
		addComboModel['qty'] = itemQty
36
		addComboModel['warehouseId'] = warehouseMap
37
 
38
		var coIdsJSon = [];
39
		var coIds;
40
		$('#cm-table').find('tr').each(function() {
41
			var row = $(this);
42
 
43
			console.log(row);
44
			var currentRow = $(this).closest("tr");
45
 
46
			var catalogId = currentRow.find("td:eq(0)").html();
47
			var qty = currentRow.find("td:eq(2)").html();
48
 
49
			console.log(catalogId);
50
			if (catalogId != undefined) {
51
				coIds = {
52
					"catalogId": catalogId,
53
					"qty": qty
54
 
55
				}
56
				console.log(coIds);
57
				coIdsJSon.push(coIds);
58
			}
59
		});
60
 
61
		console.log(coIdsJSon)
62
		if (itemQty == " ") {
63
			alert("itemQty is required");
64
			return false;
65
		}
66
 
67
		if (catalogId == null) {
68
			alert("catalogId is required");
69
			return false;
70
		}
71
 
72
		if (catalogId == " ") {
73
			alert("warehosueId is required");
74
			return false;
75
		}
76
		if (coIdsJSon.length === 0) {
77
			alert("Atleast one Item added");
78
			return false;
79
		}
80
 
81
		addComboModel['mappedComboModel'] = coIdsJSon;
82
 
83
		console.log(JSON.stringify(addComboModel));
84
		if (confirm("Are you sure you want to Add Combo!") == true) {
85
			doPostAjaxRequestWithJsonHandler(context
86
				+ "/addCombo", JSON
87
					.stringify(addComboModel), function(response) {
88
						if (response == 'true') {
89
							alert("successfully Add");
90
 
91
							loadCombo("main-content")
92
 
93
						}
94
					});
95
 
96
		}
97
 
98
 
99
	})
100
 
101
	$(document).on('click', ".btnDelete", function() {
102
		console.log("Hello");
103
 
104
		$(this).closest("tr").remove();
105
 
106
	});
107
 
108
 
109
 
110
 
111
	$(document).on('click', ".remove-combo", function() {
112
		var id = $(this).data('requestid');
113
		if (confirm("Are you sure to remove combo") == true) {
114
			doPostAjaxRequestHandler(context + "/combo/remove?id=" + id,
115
				function(response) {
116
 
117
					console.log(response);
118
					if (response == 'true') {
119
						alert("successfully remove");
120
						loadCombo("main-content")
121
					}
122
				});
123
 
124
 
125
		}
126
 
127
	});
128
 
129
 
130
})
131
 
132
function loadCombo(domId) {
133
	doGetAjaxRequestHandler(context + "/createCombo", function(response) {
134
		$('#' + domId).html(response);
135
 
136
	});
137
}