Subversion Repositories SmartDukaan

Rev

Rev 32339 | Go to most recent revision | Details | Compare with Previous | 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
 
32339 tejbeer 8
	$(document).on('click', ".add-combo-container", function() {
9
		var $htmlContainer = $('<li>'
10
			+ '<div class = "row" style="margin-top:12px" >'
11
			+ '<div class="">'
12
			+ '<div class="panel panel-default">'
32344 tejbeer 13
			+ ' <div class="panel-heading">Set</div>'
30683 tejbeer 14
 
32339 tejbeer 15
			+ '  <div class="panel-content">'
16
			+ '    <div id="cosummary">'
17
			+ '   <div class = "row" style="margin-top:12px" >'
18
			+ '     <div class="col-lg-3">'
19
			+ '   <label>Combo Item</label>'
20
			+ '	  	<input type="text" class="typeahead form-control item-mapping-search-text" name="Item" '
21
			+ '       data-provide="typeahead" autocomplete="off" value="" placeholder="Search for product..." />'
22
			+ '  </div>'
30683 tejbeer 23
 
32339 tejbeer 24
			+ ' <div class="col-lg-3">'
25
			+ '    <label>Combo Qty</label>'
26
			+ ' 	<input type="text"  class="typeahead form-control item-mapping-qty" name="item-mapping-qty" value=""  placeholder="Item Qty" />'
27
			+ '</div>'
28
 
29
			+ '<div class="col-lg-2">'
30
			+ ' <button class="btn btn-primary add-combo" style = "margin-top:25px" type="button">Add Combo</button>'
31
			+ ' </div>'
32
			+ '  </div>'
33
			+ '    <table class="table table-sm cm-table">'
34
			+ '	  <thead>'
35
			+ '	    <tr>'
36
			+ '      <th>catalogId</th>'
37
			+ '	      <th>Name</th>'
38
			+ '      <th>Quantity</th>'
39
 
40
			+ '    </tr>'
41
			+ '  </thead>'
42
			+ '    <tbody>'
43
 
44
			+ '   </tbody>'
45
			+ '</table>'
46
			+ ' </div>'
47
 
48
			+ ' </div>'
49
			+ ' </div>'
50
			+ ' </div>'
51
			+ ' </li> ');
52
 
53
		$("#list").append($htmlContainer);
54
 
55
 
56
		getItemAheadOptions($htmlContainer.find('.item-mapping-search-text'), true, function(
57
			selectedItem) {
58
 
59
 
60
			var mappedcatalogitemid = selectedItem.catalogId;
61
			console.log(mappedcatalogitemid);
62
 
63
 
64
			$htmlContainer.find('.add-combo').data('mappedcatalogitemid', mappedcatalogitemid)
65
 
66
 
67
		});
68
 
69
 
70
	})
30683 tejbeer 71
	$(document).on('click', ".add-combo", function() {
72
 
32339 tejbeer 73
		var $row = $(this).closest("li");
74
 
75
		var mappedCatalogItemId = $(this).data("mappedcatalogitemid");
76
 
77
		console.log(mappedCatalogItemId);
78
 
79
		if (mappedCatalogItemId === undefined) {
80
			alert("catalogId is required");
81
			return false;
82
		}
83
 
84
		var qty = $row.find('.item-mapping-qty').val();
85
 
86
		var item = $row.find('.item-mapping-search-text').val()
87
 
88
		if (item === " ") {
89
			alert("please select items");
90
			return false;
91
		}
92
 
93
 
94
		if (qty === "") {
95
			alert("qty is required");
96
			return false;
97
		}
98
 
99
 
30683 tejbeer 100
		var markup = "<tr><td>"
101
			+ mappedCatalogItemId
102
			+ "</td><td>"
32339 tejbeer 103
			+ $row.find('.item-mapping-search-text').val()
30683 tejbeer 104
			+ "</td><td>"
32339 tejbeer 105
			+ $row.find('.item-mapping-qty').val()
30683 tejbeer 106
			+ "</td><td><button type = 'button' class='btnDelete'>Delete</button></td></tr>";
32339 tejbeer 107
		$row.find('.cm-table > tbody:last-child').append(markup);
30683 tejbeer 108
 
32339 tejbeer 109
		$row.find('.item-mapping-search-text').val(" ");
110
		$row.find('.item-mapping-qty').val(" ")
30683 tejbeer 111
 
112
		console.log(markup)
113
 
114
	})
115
 
32339 tejbeer 116
 
117
 
118
 
30683 tejbeer 119
	$(document).on('click', ".create-combo-model", function() {
32339 tejbeer 120
 
121
 
30683 tejbeer 122
		var catalogId = catalogItemId
123
		var itemQty = $('#item-qty').val();
124
		var warehouseMap = ($("select.criteria-warehouseregion").val() || []).map(Number);
125
 
126
		var addComboModel = {}
127
		addComboModel['catalogId'] = catalogId;
128
		addComboModel['qty'] = itemQty
129
		addComboModel['warehouseId'] = warehouseMap
32339 tejbeer 130
		addComboModel['comboOptionModel'] = []
30683 tejbeer 131
 
132
 
32339 tejbeer 133
		$('#list').find('>li').each(function() {
134
			var coIdsJSon = [];
135
			var currentLi = $(this).closest("li");
30683 tejbeer 136
 
32339 tejbeer 137
			currentLi.find('.cm-table').find('tr').each(function() {
138
				var row = $(this);
139
				console.log(row);
140
				var currentRow = $(this).closest("tr");
30683 tejbeer 141
 
32339 tejbeer 142
				var catalogId = currentRow.find("td:eq(0)").html();
143
				var qty = currentRow.find("td:eq(2)").html();
30683 tejbeer 144
 
32339 tejbeer 145
				console.log(catalogId);
146
				if (catalogId != undefined) {
147
					var coIds = {
148
						"catalogId": catalogId,
149
						"qty": qty
150
 
151
					}
152
					console.log(coIds);
153
					coIdsJSon.push(coIds);
30683 tejbeer 154
				}
32339 tejbeer 155
			});
156
 
157
			addComboModel.comboOptionModel.push({ mappedComboModel: coIdsJSon });
158
 
30683 tejbeer 159
		});
160
 
32339 tejbeer 161
 
162
 
163
 
164
 
165
		if (itemQty == "") {
30683 tejbeer 166
			alert("itemQty is required");
167
			return false;
168
		}
169
 
32339 tejbeer 170
		for (var i = 0; i < addComboModel.comboOptionModel.length; i++) {
30683 tejbeer 171
 
32339 tejbeer 172
			if (addComboModel.comboOptionModel[i].mappedComboModel.length === 0) {
173
				alert("please add combo set");
174
				return false;
175
			}
176
 
30683 tejbeer 177
		}
178
 
179
 
32339 tejbeer 180
		console.log(JSON
181
			.stringify(addComboModel))
182
 
30683 tejbeer 183
		console.log(JSON.stringify(addComboModel));
184
		if (confirm("Are you sure you want to Add Combo!") == true) {
185
			doPostAjaxRequestWithJsonHandler(context
186
				+ "/addCombo", JSON
187
					.stringify(addComboModel), function(response) {
188
						if (response == 'true') {
189
							alert("successfully Add");
190
 
191
							loadCombo("main-content")
192
 
193
						}
194
					});
195
 
196
		}
197
 
198
 
199
	})
200
 
201
	$(document).on('click', ".btnDelete", function() {
202
		console.log("Hello");
203
 
204
		$(this).closest("tr").remove();
205
 
206
	});
207
 
208
 
209
 
210
 
211
	$(document).on('click', ".remove-combo", function() {
212
		var id = $(this).data('requestid');
213
		if (confirm("Are you sure to remove combo") == true) {
214
			doPostAjaxRequestHandler(context + "/combo/remove?id=" + id,
215
				function(response) {
216
 
217
					console.log(response);
218
					if (response == 'true') {
219
						alert("successfully remove");
220
						loadCombo("main-content")
221
					}
222
				});
223
 
224
 
225
		}
226
 
227
	});
228
 
229
 
230
})
231
 
232
function loadCombo(domId) {
233
	doGetAjaxRequestHandler(context + "/createCombo", function(response) {
234
		$('#' + domId).html(response);
235
 
236
	});
237
}