Subversion Repositories SmartDukaan

Rev

Rev 28270 | Rev 28566 | Go to most recent revision | 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
 
13
$(document).on('click', "a.prodcut-remove", function() {
14
	var webProductId = $(this).data("productid");
15
	var webListingId = $(this).data("id");
16
	if (confirm("Are you sure you want to remove the Item!") == true) {
17
 
18
		doDeleteAjaxRequestHandler(context + "/webProductListing/removeItem?id="
19
			+ webProductId + "&webListingId=" + webListingId, function(response) {
20
 
21
				alert("Product removed successfully");
22
				$('.web-products-container').html(response);
23
 
24
			});
25
	}
26
 
27
})
28
 
29
$(document).on('click', ".web-listing-active", function() {
30
	var webListingId = $(this).data("id");
31
	var status = $(this).data("active");
32
	if (status == true) {
33
		status = false;
34
	} else {
35
		status = true;
36
	}
37
 
38
 
39
	if (confirm("Are you sure you want to Update the Status!") == true) {
40
		doPostAjaxRequestHandler(context
41
			+ "/web-listing/updateStatus?id=" + webListingId + "&status=" + status,
42
			function(response) {
43
				$('#main-content').html(response);
44
			});
45
	}
46
})
47
 
48
$(document).on('click', "#update-rank", function() {
49
	if (confirm("Are you sure you want to update ranks?")) {
50
		var webListingId = $(this).data("id");
51
		var webProductIds = [];
52
		$("#web-product-listing-tbody").find("tr").each(function() {
26738 amit.gupta 53
			console.log(this);
54
			webProductIds.push($(this).data("id"));
55
		});
56
		doPostAjaxRequestWithJsonHandler(`${context}/web-listing/order/${webListingId}`, JSON.stringify(webProductIds), function(response) {
57
			$('.web-products-container').html(response);
58
		});
59
	}
26731 amit.gupta 60
});
28270 tejbeer 61
 
62
 
63
$(document).on('click', "#weblisting-update-rank", function() {
64
	if (confirm("Are you sure you want to update ranks?")) {
65
		var webListingIds = [];
66
		$("#web-listing-tbody").find("tr").each(function() {
67
			console.log(this);
68
			webListingIds.push($(this).data("id"));
69
		});
70
 
71
		console.log(webListingIds)
72
		doPostAjaxRequestWithJsonHandler(`${context}/web-listing/order-listing`, JSON.stringify(webListingIds), function(response) {
73
			$('#main-content').html(response);
74
		});
75
	}
76
});
77
 
78
 
79
 
80
$(document).on('click', ".web-listing-id", function() {
81
	var webListingId = $(this).data("id");
82
	doAjaxRequestHandler(`${context}/getweb-listing/${webListingId}`, "GET", function(response) {
83
		$('.web-listing-edit-container .modal-content').html(response);
84
	});
85
});
86
 
87
$(document).on('click', ".edit-web-listing", function() {
88
	var webListingId = $(this).data("id");
89
 
90
	webListingTitle = $("#web-listing-edit-title").val();
91
	webListingUrl = $("#web-listing-edit-url").val();
92
	webListingRank = $("#web-listing-edit-rank").val();
28301 tejbeer 93
	webListingBannerUrl = $("#web-listing-edit-bannerurl").val();
28270 tejbeer 94
 
95
	if (webListingTitle === "") {
96
		alert("Title is required!");
97
		return false;
98
	}
99
 
100
	if (webListingUrl === "") {
101
		alert("Url is required!");
102
		return false;
103
	}
104
 
105
	if (webListingRank === "") {
106
		alert("Rank  is required!");
107
		return false;
108
	}
109
 
28301 tejbeer 110
	json = { title: webListingTitle, url: webListingUrl, rank: webListingRank, bannerUrl: webListingBannerUrl };
28270 tejbeer 111
	console.log(json)
112
	if (confirm("Are you sure you want to Edit the Web Listing!") == true) {
113
		doPostAjaxRequestWithJsonHandler(`${context}/web-listing-edit/${webListingId}`, JSON.stringify(json),
114
			function(response) {
115
				$('#main-content').html(response);
116
 
117
			});
118
	}
119
});
120
 
27754 amit.gupta 121
$(document).on('click', "#add-listing", function() {
28270 tejbeer 122
	var webListingId = $(this).data("id");
26738 amit.gupta 123
	var entityIds = [entityId];
26731 amit.gupta 124
 
28270 tejbeer 125
	var entityIdTxt = $("#entityData").val();
126
	if (entityIdTxt.length > 0) {
127
		if (entityIdTxt.indexOf(",") > 0) {
26738 amit.gupta 128
			entityIds = entityIdTxt.split(",");
129
		}
130
	} else {
131
		alert("Please enter items");
132
		return;
133
	}
134
	json = [];
28270 tejbeer 135
	for (var e of entityIds) {
136
		json.push({ webListingId: webListingId, entityId: e });
26738 amit.gupta 137
	}
138
	console.log(json);
139
	console.log(JSON.stringify(json))
140
	doPostAjaxRequestWithJsonHandler(`${context}/web-product-listing/add`, JSON.stringify(json), function(response) {
141
		$('.web-products-container').html(response);
142
	});
28270 tejbeer 143
 
26738 amit.gupta 144
});
145
 
26731 amit.gupta 146
function loadWebListing(domId) {
147
	doAjaxRequestHandler(context + "/web-listing", "GET", function(response) {
148
		$('#' + domId).html(response);
149
	});
150
}
26738 amit.gupta 151
function addWebListing() {
152
	webListingTitle = $("#web-listing-title").val();
153
	webListingUrl = $("#web-listing-url").val();
28270 tejbeer 154
	webListingRank = $("#web-listing-rank").val();
28301 tejbeer 155
	webListingBannerUrl = $("#web-listing-bannerurl").val();
28270 tejbeer 156
	if (webListingTitle === "") {
157
		alert("Title is required!");
158
		return false;
159
	}
160
 
161
	if (webListingUrl === "") {
162
		alert("Url is required!");
163
		return false;
164
	}
165
 
166
	if (webListingRank === "") {
167
		alert("Rank  is required!");
168
		return false;
169
	}
170
 
28301 tejbeer 171
 
172
	json = { title: webListingTitle, url: webListingUrl, rank: webListingRank, bannerUrl: webListingBannerUrl };
26738 amit.gupta 173
	doPostAjaxRequestWithJsonHandler(context + "/web-listing/add", JSON.stringify(json), function(response) {
174
		$('#main-content').html(response);
26731 amit.gupta 175
	});
176
}
177
 
178
 
28270 tejbeer 179
$(document).on('mousedown', ".grab", function(e) {
180
	var tr = $(e.target).closest("#web-product-listing-table tr"), si = tr.index(), sy = e.pageY, b = $(document.body), drag;
181
	b.addClass("grabCursor").css("userSelect", "none");
182
	tr.addClass("grabbed");
183
	function move(e) {
184
		console.log(Math.abs(e.pageY - sy));
185
		if (!drag && Math.abs(e.pageY - sy) < 10) return;
186
		drag = true;
187
		tr.siblings().each(function() {
188
			var s = $(this), i = s.index(), y = s.offset().top;
189
			if (e.pageY >= y && e.pageY < y + s.outerHeight()) {
190
				if (e.pageY <= y + (s.outerHeight() / 2))
191
					tr.insertBefore(s);
192
				else
193
					tr.insertAfter(s);
194
				return false;
195
			}
196
		});
197
	}
198
	function up(e) {
199
		if (drag && si != tr.index()) {
200
			drag = false;
201
			$("#update-rank").prop('disabled', false);
202
		}
203
		$(document).unbind("mousemove", move).unbind("mouseup", up);
204
		b.removeClass("grabCursor").css("userSelect", "none");
205
		tr.removeClass("grabbed");
206
	}
207
	$(document).mousemove(move).mouseup(up);
26738 amit.gupta 208
});
26731 amit.gupta 209
 
210
 
28270 tejbeer 211
$(document).on('mousedown', ".grab", function(e) {
212
	var tr = $(e.target).closest("#catalog-feature-table tr"), si = tr.index(), sy = e.pageY, b = $(document.body), drag;
213
	b.addClass("grabCursor").css("userSelect", "none");
214
	tr.addClass("grabbed");
215
	function move(e) {
216
		console.log(Math.abs(e.pageY - sy));
217
		if (!drag && Math.abs(e.pageY - sy) < 10) return;
218
		drag = true;
219
		tr.siblings().each(function() {
220
			var s = $(this), i = s.index(), y = s.offset().top;
221
			if (e.pageY >= y && e.pageY < y + s.outerHeight()) {
222
				if (e.pageY <= y + (s.outerHeight() / 2))
223
					tr.insertBefore(s);
224
				else
225
					tr.insertAfter(s);
226
				return false;
227
			}
228
		});
229
	}
230
	function up(e) {
231
		if (drag && si != tr.index()) {
232
			drag = false;
233
			$("#weblisting-update-rank").prop('disabled', false);
234
		}
235
		$(document).unbind("mousemove", move).unbind("mouseup", up);
236
		b.removeClass("grabCursor").css("userSelect", "none");
237
		tr.removeClass("grabbed");
238
	}
239
	$(document).mousemove(move).mouseup(up);
240
});
26738 amit.gupta 241
 
242
 
28270 tejbeer 243
 
244
 
245
 
246