Subversion Repositories SmartDukaan

Rev

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