Subversion Repositories SmartDukaan

Rev

Rev 28301 | Rev 29515 | 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
 
28566 tejbeer 95
	webListingHeaderUrl = $("#web-listing-edit-headerurl").val();
96
 
28270 tejbeer 97
	if (webListingTitle === "") {
98
		alert("Title is required!");
99
		return false;
100
	}
101
 
102
	if (webListingUrl === "") {
103
		alert("Url is required!");
104
		return false;
105
	}
106
 
107
	if (webListingRank === "") {
108
		alert("Rank  is required!");
109
		return false;
110
	}
111
 
28566 tejbeer 112
	json = { title: webListingTitle, url: webListingUrl, rank: webListingRank, bannerUrl: webListingBannerUrl, headerUrl: webListingHeaderUrl };
28270 tejbeer 113
	console.log(json)
114
	if (confirm("Are you sure you want to Edit the Web Listing!") == true) {
115
		doPostAjaxRequestWithJsonHandler(`${context}/web-listing-edit/${webListingId}`, JSON.stringify(json),
116
			function(response) {
117
				$('#main-content').html(response);
118
 
119
			});
120
	}
121
});
122
 
27754 amit.gupta 123
$(document).on('click', "#add-listing", function() {
28270 tejbeer 124
	var webListingId = $(this).data("id");
26738 amit.gupta 125
	var entityIds = [entityId];
26731 amit.gupta 126
 
28270 tejbeer 127
	var entityIdTxt = $("#entityData").val();
128
	if (entityIdTxt.length > 0) {
129
		if (entityIdTxt.indexOf(",") > 0) {
26738 amit.gupta 130
			entityIds = entityIdTxt.split(",");
131
		}
132
	} else {
133
		alert("Please enter items");
134
		return;
135
	}
136
	json = [];
28270 tejbeer 137
	for (var e of entityIds) {
138
		json.push({ webListingId: webListingId, entityId: e });
26738 amit.gupta 139
	}
140
	console.log(json);
141
	console.log(JSON.stringify(json))
142
	doPostAjaxRequestWithJsonHandler(`${context}/web-product-listing/add`, JSON.stringify(json), function(response) {
143
		$('.web-products-container').html(response);
144
	});
28270 tejbeer 145
 
26738 amit.gupta 146
});
147
 
26731 amit.gupta 148
function loadWebListing(domId) {
149
	doAjaxRequestHandler(context + "/web-listing", "GET", function(response) {
150
		$('#' + domId).html(response);
151
	});
152
}
26738 amit.gupta 153
function addWebListing() {
154
	webListingTitle = $("#web-listing-title").val();
155
	webListingUrl = $("#web-listing-url").val();
28270 tejbeer 156
	webListingRank = $("#web-listing-rank").val();
28301 tejbeer 157
	webListingBannerUrl = $("#web-listing-bannerurl").val();
28566 tejbeer 158
 
159
	webListingHeaderUrl = $("#web-listing-headerurl").val();
160
 
28270 tejbeer 161
	if (webListingTitle === "") {
162
		alert("Title is required!");
163
		return false;
164
	}
165
 
166
	if (webListingUrl === "") {
167
		alert("Url is required!");
168
		return false;
169
	}
170
 
171
	if (webListingRank === "") {
172
		alert("Rank  is required!");
173
		return false;
174
	}
175
 
28301 tejbeer 176
 
28566 tejbeer 177
	json = { title: webListingTitle, url: webListingUrl, rank: webListingRank, bannerUrl: webListingBannerUrl, headerUrl: webListingHeaderUrl };
26738 amit.gupta 178
	doPostAjaxRequestWithJsonHandler(context + "/web-listing/add", JSON.stringify(json), function(response) {
179
		$('#main-content').html(response);
26731 amit.gupta 180
	});
181
}
182
 
183
 
28270 tejbeer 184
$(document).on('mousedown', ".grab", function(e) {
185
	var tr = $(e.target).closest("#web-product-listing-table tr"), si = tr.index(), sy = e.pageY, b = $(document.body), drag;
186
	b.addClass("grabCursor").css("userSelect", "none");
187
	tr.addClass("grabbed");
188
	function move(e) {
189
		console.log(Math.abs(e.pageY - sy));
190
		if (!drag && Math.abs(e.pageY - sy) < 10) return;
191
		drag = true;
192
		tr.siblings().each(function() {
193
			var s = $(this), i = s.index(), y = s.offset().top;
194
			if (e.pageY >= y && e.pageY < y + s.outerHeight()) {
195
				if (e.pageY <= y + (s.outerHeight() / 2))
196
					tr.insertBefore(s);
197
				else
198
					tr.insertAfter(s);
199
				return false;
200
			}
201
		});
202
	}
203
	function up(e) {
204
		if (drag && si != tr.index()) {
205
			drag = false;
206
			$("#update-rank").prop('disabled', false);
207
		}
208
		$(document).unbind("mousemove", move).unbind("mouseup", up);
209
		b.removeClass("grabCursor").css("userSelect", "none");
210
		tr.removeClass("grabbed");
211
	}
212
	$(document).mousemove(move).mouseup(up);
26738 amit.gupta 213
});
26731 amit.gupta 214
 
215
 
28270 tejbeer 216
$(document).on('mousedown', ".grab", function(e) {
217
	var tr = $(e.target).closest("#catalog-feature-table tr"), si = tr.index(), sy = e.pageY, b = $(document.body), drag;
218
	b.addClass("grabCursor").css("userSelect", "none");
219
	tr.addClass("grabbed");
220
	function move(e) {
221
		console.log(Math.abs(e.pageY - sy));
222
		if (!drag && Math.abs(e.pageY - sy) < 10) return;
223
		drag = true;
224
		tr.siblings().each(function() {
225
			var s = $(this), i = s.index(), y = s.offset().top;
226
			if (e.pageY >= y && e.pageY < y + s.outerHeight()) {
227
				if (e.pageY <= y + (s.outerHeight() / 2))
228
					tr.insertBefore(s);
229
				else
230
					tr.insertAfter(s);
231
				return false;
232
			}
233
		});
234
	}
235
	function up(e) {
236
		if (drag && si != tr.index()) {
237
			drag = false;
238
			$("#weblisting-update-rank").prop('disabled', false);
239
		}
240
		$(document).unbind("mousemove", move).unbind("mouseup", up);
241
		b.removeClass("grabCursor").css("userSelect", "none");
242
		tr.removeClass("grabbed");
243
	}
244
	$(document).mousemove(move).mouseup(up);
245
});
26738 amit.gupta 246
 
247
 
28270 tejbeer 248
 
249
 
250
 
251