Subversion Repositories SmartDukaan

Rev

Rev 31568 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
27754 amit.gupta 1
$(document).on('click', ".web-listing", function() {
26738 amit.gupta 2
	loadWebListing("main-content");
3
});
27754 amit.gupta 4
$(document).on('click', "a.listing-details", function() {
26738 amit.gupta 5
	var webListingId = $(this).data("id");
6
	doAjaxRequestHandler(`${context}/web-listing/${webListingId}`, "GET", function(response) {
7
		$('.web-products-container').html(response);
26731 amit.gupta 8
	});
28270 tejbeer 9
 
26738 amit.gupta 10
})
11
 
28270 tejbeer 12
 
29515 tejbeer 13
$(document).on('click', ".web-sctrach-offer", function() {
14
	loadScratchOffer("main-content");
15
 
16
})
17
 
18
 
19
$(document).on('click', "#downloadSctrachTemplate", function() {
20
 
21
	window.location.href = context + "/sctrachOffer/downloadTemplate";
22
});
23
 
24
 
25
$(document).on('click', ".sctrachOfferfileUpload", function() {
26
 
27
	console.log("hello");
28
	if (confirm('Confirm upload ?')) {
29
		var fileSelector = $(this)[0];
30
		if (fileSelector != undefined) {
31
			var url = `${context}/sctrachOffer/upload`;
32
			console.log(url);
33
			var file = $("#sctrachOffer")[0].files[0];
34
			let fileInput = $(this);
35
			console.log("file" + file);
36
			console.log("fileInput" + fileInput);
37
			doAjaxUploadRequestHandler(
38
				url,
39
				'POST',
40
				file, function(response) {
41
 
42
					console.log(response)
43
					alert("successfully uploaded");
44
 
45
				});
46
 
47
		}
48
	}
49
});
50
 
28270 tejbeer 51
$(document).on('click', "a.prodcut-remove", function() {
52
	var webProductId = $(this).data("productid");
53
	var webListingId = $(this).data("id");
54
	if (confirm("Are you sure you want to remove the Item!") == true) {
55
 
56
		doDeleteAjaxRequestHandler(context + "/webProductListing/removeItem?id="
57
			+ webProductId + "&webListingId=" + webListingId, function(response) {
58
 
59
				alert("Product removed successfully");
60
				$('.web-products-container').html(response);
61
 
62
			});
63
	}
64
 
65
})
66
 
67
$(document).on('click', ".web-listing-active", function() {
68
	var webListingId = $(this).data("id");
69
	var status = $(this).data("active");
70
	if (status == true) {
71
		status = false;
72
	} else {
73
		status = true;
74
	}
75
 
76
 
77
	if (confirm("Are you sure you want to Update the Status!") == true) {
78
		doPostAjaxRequestHandler(context
79
			+ "/web-listing/updateStatus?id=" + webListingId + "&status=" + status,
80
			function(response) {
81
				$('#main-content').html(response);
82
			});
83
	}
84
})
85
 
86
$(document).on('click', "#update-rank", function() {
87
	if (confirm("Are you sure you want to update ranks?")) {
88
		var webListingId = $(this).data("id");
89
		var webProductIds = [];
90
		$("#web-product-listing-tbody").find("tr").each(function() {
26738 amit.gupta 91
			console.log(this);
92
			webProductIds.push($(this).data("id"));
93
		});
94
		doPostAjaxRequestWithJsonHandler(`${context}/web-listing/order/${webListingId}`, JSON.stringify(webProductIds), function(response) {
95
			$('.web-products-container').html(response);
96
		});
97
	}
26731 amit.gupta 98
});
28270 tejbeer 99
 
100
 
101
$(document).on('click', "#weblisting-update-rank", function() {
102
	if (confirm("Are you sure you want to update ranks?")) {
103
		var webListingIds = [];
104
		$("#web-listing-tbody").find("tr").each(function() {
105
			console.log(this);
106
			webListingIds.push($(this).data("id"));
107
		});
108
 
109
		console.log(webListingIds)
110
		doPostAjaxRequestWithJsonHandler(`${context}/web-listing/order-listing`, JSON.stringify(webListingIds), function(response) {
111
			$('#main-content').html(response);
112
		});
113
	}
114
});
115
 
116
 
117
 
118
$(document).on('click', ".web-listing-id", function() {
119
	var webListingId = $(this).data("id");
120
	doAjaxRequestHandler(`${context}/getweb-listing/${webListingId}`, "GET", function(response) {
121
		$('.web-listing-edit-container .modal-content').html(response);
122
	});
123
});
124
 
125
$(document).on('click', ".edit-web-listing", function() {
126
	var webListingId = $(this).data("id");
127
 
128
	webListingTitle = $("#web-listing-edit-title").val();
129
	webListingUrl = $("#web-listing-edit-url").val();
130
	webListingRank = $("#web-listing-edit-rank").val();
28301 tejbeer 131
	webListingBannerUrl = $("#web-listing-edit-bannerurl").val();
28270 tejbeer 132
 
28566 tejbeer 133
	webListingHeaderUrl = $("#web-listing-edit-headerurl").val();
134
 
28270 tejbeer 135
	if (webListingTitle === "") {
136
		alert("Title is required!");
137
		return false;
138
	}
139
 
140
	if (webListingUrl === "") {
141
		alert("Url is required!");
142
		return false;
143
	}
144
 
145
	if (webListingRank === "") {
146
		alert("Rank  is required!");
147
		return false;
148
	}
149
 
28566 tejbeer 150
	json = { title: webListingTitle, url: webListingUrl, rank: webListingRank, bannerUrl: webListingBannerUrl, headerUrl: webListingHeaderUrl };
28270 tejbeer 151
	console.log(json)
152
	if (confirm("Are you sure you want to Edit the Web Listing!") == true) {
153
		doPostAjaxRequestWithJsonHandler(`${context}/web-listing-edit/${webListingId}`, JSON.stringify(json),
154
			function(response) {
155
				$('#main-content').html(response);
156
 
157
			});
158
	}
159
});
160
 
27754 amit.gupta 161
$(document).on('click', "#add-listing", function() {
28270 tejbeer 162
	var webListingId = $(this).data("id");
26738 amit.gupta 163
	var entityIds = [entityId];
26731 amit.gupta 164
 
28270 tejbeer 165
	var entityIdTxt = $("#entityData").val();
166
	if (entityIdTxt.length > 0) {
167
		if (entityIdTxt.indexOf(",") > 0) {
26738 amit.gupta 168
			entityIds = entityIdTxt.split(",");
169
		}
170
	} else {
171
		alert("Please enter items");
172
		return;
173
	}
174
	json = [];
28270 tejbeer 175
	for (var e of entityIds) {
176
		json.push({ webListingId: webListingId, entityId: e });
26738 amit.gupta 177
	}
178
	console.log(json);
179
	console.log(JSON.stringify(json))
180
	doPostAjaxRequestWithJsonHandler(`${context}/web-product-listing/add`, JSON.stringify(json), function(response) {
181
		$('.web-products-container').html(response);
182
	});
28270 tejbeer 183
 
26738 amit.gupta 184
});
185
 
26731 amit.gupta 186
function loadWebListing(domId) {
187
	doAjaxRequestHandler(context + "/web-listing", "GET", function(response) {
188
		$('#' + domId).html(response);
189
	});
190
}
29515 tejbeer 191
 
192
 
193
 
194
function loadScratchOffer(domId) {
195
 
196
	doAjaxRequestHandler(context + "/scratchOffer", "GET", function(response) {
197
		$('#' + domId).html(response);
198
	});
199
}
200
 
26738 amit.gupta 201
function addWebListing() {
202
	webListingTitle = $("#web-listing-title").val();
203
	webListingUrl = $("#web-listing-url").val();
28270 tejbeer 204
	webListingRank = $("#web-listing-rank").val();
28301 tejbeer 205
	webListingBannerUrl = $("#web-listing-bannerurl").val();
28566 tejbeer 206
 
31447 tejbeer 207
	webListingSource = $("#listingSource").val();
208
 
31568 tejbeer 209
	webListingType = $("#webType").val();
31570 tejbeer 210
	webSolrQuery = $("#web-listing-solrQuery").val();
31568 tejbeer 211
 
28566 tejbeer 212
	webListingHeaderUrl = $("#web-listing-headerurl").val();
213
 
28270 tejbeer 214
	if (webListingTitle === "") {
215
		alert("Title is required!");
216
		return false;
217
	}
218
 
219
	if (webListingUrl === "") {
220
		alert("Url is required!");
221
		return false;
222
	}
223
 
224
	if (webListingRank === "") {
225
		alert("Rank  is required!");
226
		return false;
227
	}
228
 
28301 tejbeer 229
 
31447 tejbeer 230
	if (webListingSource === "") {
31568 tejbeer 231
		alert("Source  is required!");
31447 tejbeer 232
		return false;
233
	}
31568 tejbeer 234
	if (webListingType === "") {
235
		alert("Type  is required!");
236
		return false;
237
	}
31447 tejbeer 238
 
239
 
31570 tejbeer 240
	json = {
241
		title: webListingTitle, url: webListingUrl, rank: webListingRank, bannerUrl: webListingBannerUrl, headerUrl: webListingHeaderUrl,
242
		targetSource: webListingSource, type: webListingType, solrQuery: webSolrQuery
243
	};
31568 tejbeer 244
 
31447 tejbeer 245
	console.log(json)
26738 amit.gupta 246
	doPostAjaxRequestWithJsonHandler(context + "/web-listing/add", JSON.stringify(json), function(response) {
247
		$('#main-content').html(response);
26731 amit.gupta 248
	});
249
}
250
 
251
 
28270 tejbeer 252
$(document).on('mousedown', ".grab", function(e) {
253
	var tr = $(e.target).closest("#web-product-listing-table tr"), si = tr.index(), sy = e.pageY, b = $(document.body), drag;
254
	b.addClass("grabCursor").css("userSelect", "none");
255
	tr.addClass("grabbed");
256
	function move(e) {
257
		console.log(Math.abs(e.pageY - sy));
258
		if (!drag && Math.abs(e.pageY - sy) < 10) return;
259
		drag = true;
260
		tr.siblings().each(function() {
261
			var s = $(this), i = s.index(), y = s.offset().top;
262
			if (e.pageY >= y && e.pageY < y + s.outerHeight()) {
263
				if (e.pageY <= y + (s.outerHeight() / 2))
264
					tr.insertBefore(s);
265
				else
266
					tr.insertAfter(s);
267
				return false;
268
			}
269
		});
270
	}
271
	function up(e) {
272
		if (drag && si != tr.index()) {
273
			drag = false;
274
			$("#update-rank").prop('disabled', false);
275
		}
276
		$(document).unbind("mousemove", move).unbind("mouseup", up);
277
		b.removeClass("grabCursor").css("userSelect", "none");
278
		tr.removeClass("grabbed");
279
	}
280
	$(document).mousemove(move).mouseup(up);
26738 amit.gupta 281
});
26731 amit.gupta 282
 
283
 
28270 tejbeer 284
$(document).on('mousedown', ".grab", function(e) {
285
	var tr = $(e.target).closest("#catalog-feature-table tr"), si = tr.index(), sy = e.pageY, b = $(document.body), drag;
286
	b.addClass("grabCursor").css("userSelect", "none");
287
	tr.addClass("grabbed");
288
	function move(e) {
289
		console.log(Math.abs(e.pageY - sy));
290
		if (!drag && Math.abs(e.pageY - sy) < 10) return;
291
		drag = true;
292
		tr.siblings().each(function() {
293
			var s = $(this), i = s.index(), y = s.offset().top;
294
			if (e.pageY >= y && e.pageY < y + s.outerHeight()) {
295
				if (e.pageY <= y + (s.outerHeight() / 2))
296
					tr.insertBefore(s);
297
				else
298
					tr.insertAfter(s);
299
				return false;
300
			}
301
		});
302
	}
303
	function up(e) {
304
		if (drag && si != tr.index()) {
305
			drag = false;
306
			$("#weblisting-update-rank").prop('disabled', false);
307
		}
308
		$(document).unbind("mousemove", move).unbind("mouseup", up);
309
		b.removeClass("grabCursor").css("userSelect", "none");
310
		tr.removeClass("grabbed");
311
	}
312
	$(document).mousemove(move).mouseup(up);
313
});
26738 amit.gupta 314
 
315
 
28270 tejbeer 316
 
317
 
318
 
319